Skip to content

Commit

Permalink
Use search widget (close kontalk#596)
Browse files Browse the repository at this point in the history
Signed-off-by: Daniele Ricci <[email protected]>
  • Loading branch information
daniele-athome committed Jan 25, 2016
1 parent 44407c9 commit fe2a8e0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions app/proguard.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,5 @@
-keepnames class * implements android.os.Parcelable {
public static final ** CREATOR;
}

-keep class android.support.v7.widget.SearchView { *; }
13 changes: 8 additions & 5 deletions app/src/main/java/org/kontalk/ui/ConversationListFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.akalipetis.fragment.ActionModeListFragment;
import com.akalipetis.fragment.MultiChoiceModeListener;

import android.app.SearchManager;
import android.content.AsyncQueryHandler;
import android.content.ContentResolver;
import android.content.Context;
Expand All @@ -42,7 +43,9 @@
import android.database.sqlite.SQLiteDiskIOException;
import android.database.sqlite.SQLiteException;
import android.os.Bundle;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.view.ActionMode;
import android.support.v7.widget.SearchView;
import android.util.Log;
import android.util.SparseBooleanArray;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -215,7 +218,11 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {

// search
mSearchMenu = menu.findItem(R.id.menu_search);
//MenuItemCompat.setShowAsAction(mSearchMenu, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(mSearchMenu);
SearchManager searchManager = (SearchManager) getContext().getSystemService(Context.SEARCH_SERVICE);
searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
// LayoutParams.MATCH_PARENT does not work, use a big value instead
searchView.setMaxWidth(1000000);

mDeleteAllMenu = menu.findItem(R.id.menu_delete_all);

Expand Down Expand Up @@ -258,10 +265,6 @@ public void onClick(DialogInterface dialog, int which) {
}
return true;

case R.id.menu_search:
getActivity().onSearchRequested();
return true;

case R.id.menu_delete_all:
deleteAll();
return true;
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/menu/conversation_list_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
xmlns:app="http://schemas.android.com/apk/res-auto">

<!-- actions -->
<item android:id="@+id/menu_search" android:title="@string/menu_search" android:icon="@drawable/ic_menu_search" app:showAsAction="always"/>
<item android:id="@+id/menu_search" android:title="@string/menu_search" android:icon="@drawable/ic_menu_search"
app:actionViewClass="android.support.v7.widget.SearchView" app:showAsAction="collapseActionView|ifRoom"/>

<!-- menu -->
<item android:id="@+id/menu_offline" android:title="@string/menu_offline" android:icon="@drawable/ic_menu_cancel"/>
Expand Down

0 comments on commit fe2a8e0

Please sign in to comment.