mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-19 12:28:53 +01:00
Moved search to new activity
This commit is contained in:
@@ -99,6 +99,7 @@
|
|||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity android:name=".ui.settings.SettingsActivity" />
|
<activity android:name=".ui.settings.SettingsActivity" />
|
||||||
|
<activity android:name=".ui.search.SearchActivity" />
|
||||||
|
|
||||||
<activity-alias
|
<activity-alias
|
||||||
android:name=".ui.MainActivity-Teal"
|
android:name=".ui.MainActivity-Teal"
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ import com.moez.QKSMS.ui.dialog.QKDialog;
|
|||||||
import com.moez.QKSMS.ui.dialog.mms.MMSSetupFragment;
|
import com.moez.QKSMS.ui.dialog.mms.MMSSetupFragment;
|
||||||
import com.moez.QKSMS.ui.messagelist.MessageListFragment;
|
import com.moez.QKSMS.ui.messagelist.MessageListFragment;
|
||||||
import com.moez.QKSMS.ui.popup.QKReplyActivity;
|
import com.moez.QKSMS.ui.popup.QKReplyActivity;
|
||||||
import com.moez.QKSMS.ui.search.SearchFragment;
|
import com.moez.QKSMS.ui.search.SearchActivity;
|
||||||
import com.moez.QKSMS.ui.settings.SettingsFragment;
|
import com.moez.QKSMS.ui.settings.SettingsFragment;
|
||||||
import com.moez.QKSMS.ui.view.slidingmenu.SlidingMenu;
|
import com.moez.QKSMS.ui.view.slidingmenu.SlidingMenu;
|
||||||
import com.moez.QKSMS.ui.welcome.WelcomeActivity;
|
import com.moez.QKSMS.ui.welcome.WelcomeActivity;
|
||||||
@@ -235,7 +235,7 @@ public class MainActivity extends QKActivity implements SlidingMenu.SlidingMenuL
|
|||||||
onKeyUp(KeyEvent.KEYCODE_BACK, null);
|
onKeyUp(KeyEvent.KEYCODE_BACK, null);
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_search:
|
case R.id.menu_search:
|
||||||
switchContent(new SearchFragment(), true);
|
startActivity(SearchActivity.class);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.moez.QKSMS.ui.search;
|
||||||
|
|
||||||
|
import android.app.FragmentManager;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuInflater;
|
||||||
|
import com.moez.QKSMS.R;
|
||||||
|
import com.moez.QKSMS.ui.base.QKSwipeBackActivity;
|
||||||
|
|
||||||
|
public class SearchActivity extends QKSwipeBackActivity {
|
||||||
|
|
||||||
|
private SearchFragment mSearchFragment;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setTitle(R.string.title_search);
|
||||||
|
|
||||||
|
FragmentManager fm = getFragmentManager();
|
||||||
|
mSearchFragment = (SearchFragment) fm.findFragmentById(R.id.content_frame);
|
||||||
|
if (mSearchFragment == null) {
|
||||||
|
mSearchFragment = new SearchFragment();
|
||||||
|
}
|
||||||
|
|
||||||
|
fm.beginTransaction()
|
||||||
|
.replace(R.id.content_frame, mSearchFragment)
|
||||||
|
.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
new MenuInflater(this).inflate(R.menu.search, menu);
|
||||||
|
return super.onCreateOptionsMenu(menu);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,26 +1,22 @@
|
|||||||
package com.moez.QKSMS.ui.search;
|
package com.moez.QKSMS.ui.search;
|
||||||
|
|
||||||
import android.content.AsyncQueryHandler;
|
import android.content.AsyncQueryHandler;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
import android.provider.Telephony;
|
import android.provider.Telephony;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.view.KeyEvent;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
|
||||||
import android.view.MenuInflater;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.inputmethod.EditorInfo;
|
import android.view.inputmethod.EditorInfo;
|
||||||
import com.moez.QKSMS.R;
|
import com.moez.QKSMS.R;
|
||||||
import com.moez.QKSMS.common.utils.KeyboardUtils;
|
import com.moez.QKSMS.common.utils.KeyboardUtils;
|
||||||
import com.moez.QKSMS.data.Contact;
|
import com.moez.QKSMS.data.Contact;
|
||||||
import com.moez.QKSMS.ui.base.QKActivity;
|
import com.moez.QKSMS.ui.base.QKFragment;
|
||||||
import com.moez.QKSMS.ui.base.QKContentFragment;
|
|
||||||
import com.moez.QKSMS.ui.base.RecyclerCursorAdapter;
|
import com.moez.QKSMS.ui.base.RecyclerCursorAdapter;
|
||||||
import com.moez.QKSMS.ui.messagelist.MessageListActivity;
|
import com.moez.QKSMS.ui.messagelist.MessageListActivity;
|
||||||
import com.moez.QKSMS.ui.view.MessageListRecyclerView;
|
import com.moez.QKSMS.ui.view.MessageListRecyclerView;
|
||||||
@@ -30,7 +26,7 @@ import com.moez.QKSMS.ui.view.QKTextView;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class SearchFragment extends QKContentFragment implements RecyclerCursorAdapter.ItemClickListener<SearchData> {
|
public class SearchFragment extends QKFragment implements RecyclerCursorAdapter.ItemClickListener<SearchData> {
|
||||||
private AsyncQueryHandler mQueryHandler;
|
private AsyncQueryHandler mQueryHandler;
|
||||||
|
|
||||||
// Track which TextView's show which Contact objects so that we can update
|
// Track which TextView's show which Contact objects so that we can update
|
||||||
@@ -47,6 +43,10 @@ public class SearchFragment extends QKContentFragment implements RecyclerCursorA
|
|||||||
private SearchAdapter mAdapter;
|
private SearchAdapter mAdapter;
|
||||||
private Pattern mPattern;
|
private Pattern mPattern;
|
||||||
|
|
||||||
|
public SearchFragment() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@@ -68,27 +68,21 @@ public class SearchFragment extends QKContentFragment implements RecyclerCursorA
|
|||||||
View view = inflater.inflate(R.layout.fragment_search, container, false);
|
View view = inflater.inflate(R.layout.fragment_search, container, false);
|
||||||
|
|
||||||
mQuery = (QKEditText) view.findViewById(R.id.search_query);
|
mQuery = (QKEditText) view.findViewById(R.id.search_query);
|
||||||
mQuery.setTextChangedListener(new QKEditText.TextChangedListener() {
|
mQuery.setTextChangedListener(s -> {
|
||||||
@Override
|
mSearchString = s.toString();
|
||||||
public void onTextChanged(CharSequence s) {
|
query();
|
||||||
mSearchString = s.toString();
|
|
||||||
query();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
mQuery.setOnEditorActionListener(new QKTextView.OnEditorActionListener() {
|
mQuery.setOnEditorActionListener((v, actionId, event) -> {
|
||||||
@Override
|
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
|
||||||
public boolean onEditorAction(android.widget.TextView v, int actionId, KeyEvent event) {
|
mSearchString = mQuery.getText().toString();
|
||||||
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
|
query();
|
||||||
mSearchString = mQuery.getText().toString();
|
|
||||||
query();
|
|
||||||
|
|
||||||
// Hide the keyboard when the user makes a query
|
// Hide the keyboard when the user makes a query
|
||||||
mQuery.clearFocus();
|
mQuery.clearFocus();
|
||||||
KeyboardUtils.hide(mContext, mQuery);
|
KeyboardUtils.hide(mContext, mQuery);
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
mLayoutManager = new LinearLayoutManager(mContext);
|
mLayoutManager = new LinearLayoutManager(mContext);
|
||||||
@@ -100,6 +94,7 @@ public class SearchFragment extends QKContentFragment implements RecyclerCursorA
|
|||||||
mRecyclerView.setLayoutManager(mLayoutManager);
|
mRecyclerView.setLayoutManager(mLayoutManager);
|
||||||
mRecyclerView.setAdapter(mAdapter);
|
mRecyclerView.setAdapter(mAdapter);
|
||||||
|
|
||||||
|
new Handler().postDelayed(() -> KeyboardUtils.showAndFocus(mContext, mQuery), 50);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,12 +109,10 @@ public class SearchFragment extends QKContentFragment implements RecyclerCursorA
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Contact.UpdateListener mContactListener = new Contact.UpdateListener() {
|
Contact.UpdateListener mContactListener = updated -> {
|
||||||
public void onUpdate(Contact updated) {
|
QKTextView tv = mContactMap.get(updated);
|
||||||
QKTextView tv = mContactMap.get(updated);
|
if (tv != null) {
|
||||||
if (tv != null) {
|
tv.setText(updated.getNameAndNumber());
|
||||||
tv.setText(updated.getNameAndNumber());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -129,28 +122,10 @@ public class SearchFragment extends QKContentFragment implements RecyclerCursorA
|
|||||||
Contact.removeListener(mContactListener);
|
Contact.removeListener(mContactListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onContentOpened() {
|
|
||||||
// Show the keyboard and focus on the query text when the fragment is opened.
|
|
||||||
KeyboardUtils.showAndFocus(mContext, mQuery);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onMenuChanging(float percentOpen) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void inflateToolbar(Menu menu, MenuInflater inflater, Context context) {
|
|
||||||
inflater.inflate(R.menu.search, menu);
|
|
||||||
((QKActivity) context).setTitle(R.string.title_search);
|
|
||||||
|
|
||||||
super.onCreateOptionsMenu(menu, inflater);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemClick(SearchData data, View view) {
|
public void onItemClick(SearchData data, View view) {
|
||||||
MessageListActivity.launch(mContext, data.threadId, data.rowId, mSearchString, true);
|
MessageListActivity.launch(mContext, data.threadId, data.rowId, mSearchString, true);
|
||||||
|
mContext.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user