aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2016-05-30 16:51:09 -0500
committerScott Jackson <daneren2005@gmail.com>2016-05-30 16:51:09 -0500
commiteaca7e8c966cb085096486b7e1d27e349e7c7aa8 (patch)
tree3f396f5dced3c706fed5838e8227923ca811b3ee
parentfb6048141ee594dc2d30a96be3150b6a94983852 (diff)
downloaddsub-eaca7e8c966cb085096486b7e1d27e349e7c7aa8.tar.gz
dsub-eaca7e8c966cb085096486b7e1d27e349e7c7aa8.tar.bz2
dsub-eaca7e8c966cb085096486b7e1d27e349e7c7aa8.zip
Fixes #690: Modernize the action bar search with SearchView
-rw-r--r--app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java5
-rw-r--r--app/src/main/java/github/daneren2005/dsub/fragments/MainFragment.java1
-rw-r--r--app/src/main/java/github/daneren2005/dsub/fragments/SearchFragment.java22
-rw-r--r--app/src/main/java/github/daneren2005/dsub/fragments/SelectRecyclerFragment.java6
-rw-r--r--app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java37
-rw-r--r--app/src/main/res/menu/abstract_top_menu.xml3
-rw-r--r--app/src/main/res/menu/main.xml5
-rw-r--r--app/src/main/res/menu/search.xml3
-rw-r--r--app/src/main/res/menu/select_artist.xml5
-rw-r--r--app/src/main/res/menu/select_podcasts.xml5
10 files changed, 64 insertions, 28 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java
index 51de1f6c..17cfdb42 100644
--- a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java
+++ b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java
@@ -396,14 +396,9 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo
if(currentFragment instanceof SearchFragment) {
String query = intent.getStringExtra(Constants.INTENT_EXTRA_NAME_QUERY);
boolean autoplay = intent.getBooleanExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, false);
- boolean requestsearch = intent.getBooleanExtra(Constants.INTENT_EXTRA_REQUEST_SEARCH, false);
if (query != null) {
((SearchFragment)currentFragment).search(query, autoplay);
- } else {
- if (requestsearch) {
- onSearchRequested();
- }
}
getIntent().removeExtra(Constants.INTENT_EXTRA_NAME_QUERY);
} else {
diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/MainFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/MainFragment.java
index f3d675f0..4f5f7e6b 100644
--- a/app/src/main/java/github/daneren2005/dsub/fragments/MainFragment.java
+++ b/app/src/main/java/github/daneren2005/dsub/fragments/MainFragment.java
@@ -63,6 +63,7 @@ public class MainFragment extends SelectRecyclerFragment<Integer> {
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
menuInflater.inflate(R.menu.main, menu);
+ onFinishSetupOptionsMenu(menu);
try {
if (!ServerInfo.isMadsonic(context) || !UserUtil.isCurrentAdmin()) {
diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SearchFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SearchFragment.java
index c891da34..eed714af 100644
--- a/app/src/main/java/github/daneren2005/dsub/fragments/SearchFragment.java
+++ b/app/src/main/java/github/daneren2005/dsub/fragments/SearchFragment.java
@@ -7,6 +7,7 @@ import java.util.List;
import android.content.Intent;
import android.os.Bundle;
+import android.support.v4.view.MenuItemCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
@@ -125,18 +126,7 @@ public class SearchFragment extends SubsonicFragment implements SectionAdapter.O
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
menuInflater.inflate(R.menu.search, menu);
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case R.id.menu_global_search:
- context.startSearch(currentQuery, false, null, false);
- return true;
- }
-
- return super.onOptionsItemSelected(item);
-
+ onFinishSetupOptionsMenu(menu);
}
@Override
@@ -218,6 +208,14 @@ public class SearchFragment extends SubsonicFragment implements SectionAdapter.O
}
};
task.execute();
+
+ if(searchItem != null) {
+ MenuItemCompat.collapseActionView(searchItem);
+ }
+ }
+
+ protected String getCurrentQuery() {
+ return currentQuery;
}
private void onArtistSelected(Artist artist, boolean autoplay) {
diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SelectRecyclerFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SelectRecyclerFragment.java
index 7ae7fff8..0d4506ac 100644
--- a/app/src/main/java/github/daneren2005/dsub/fragments/SelectRecyclerFragment.java
+++ b/app/src/main/java/github/daneren2005/dsub/fragments/SelectRecyclerFragment.java
@@ -15,10 +15,15 @@
package github.daneren2005.dsub.fragments;
+import android.app.SearchManager;
+import android.app.SearchableInfo;
+import android.content.Context;
import android.os.Bundle;
+import android.support.v4.view.MenuItemCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
+import android.support.v7.widget.SearchView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
@@ -102,6 +107,7 @@ public abstract class SelectRecyclerFragment<T> extends SubsonicFragment impleme
}
menuInflater.inflate(getOptionsMenu(), menu);
+ onFinishSetupOptionsMenu(menu);
}
@Override
diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java
index f733c977..9cc27128 100644
--- a/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java
+++ b/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java
@@ -20,6 +20,9 @@ package github.daneren2005.dsub.fragments;
import android.annotation.TargetApi;
import android.app.Activity;
+import android.app.SearchManager;
+import android.app.SearchableInfo;
+import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
@@ -37,6 +40,7 @@ import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
+import android.support.v7.widget.SearchView;
import android.util.Log;
import android.view.GestureDetector;
import android.view.Menu;
@@ -125,6 +129,8 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
protected boolean artistOverride = false;
protected SwipeRefreshLayout refreshLayout;
protected boolean firstRun;
+ protected MenuItem searchItem;
+ protected SearchView searchView;
public SubsonicFragment() {
super();
@@ -177,15 +183,36 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
this.context = context;
}
+ protected void onFinishSetupOptionsMenu(final Menu menu) {
+ searchItem = menu.findItem(R.id.menu_global_search);
+ if(searchItem != null) {
+ searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
+ SearchManager searchManager = (SearchManager) context.getSystemService(Context.SEARCH_SERVICE);
+ SearchableInfo searchableInfo = searchManager.getSearchableInfo(context.getComponentName());
+ if(searchableInfo == null) {
+ Log.w(TAG, "Failed to get SearchableInfo");
+ } else {
+ searchView.setSearchableInfo(searchableInfo);
+ }
+
+ String currentQuery = getCurrentQuery();
+ if(currentQuery != null) {
+ searchView.setOnSearchClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ searchView.setQuery(getCurrentQuery(), false);
+ }
+ });
+ }
+ }
+ }
+
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_global_shuffle:
onShuffleRequested();
return true;
- case R.id.menu_global_search:
- context.onSearchRequested();
- return true;
case R.id.menu_exit:
exit();
return true;
@@ -1927,6 +1954,10 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
return false;
}
+ protected String getCurrentQuery() {
+ return null;
+ }
+
public abstract class RecursiveLoader extends LoadingTask<Boolean> {
protected MusicService musicService;
protected static final int MAX_SONGS = 500;
diff --git a/app/src/main/res/menu/abstract_top_menu.xml b/app/src/main/res/menu/abstract_top_menu.xml
index 7c8d414d..b768879d 100644
--- a/app/src/main/res/menu/abstract_top_menu.xml
+++ b/app/src/main/res/menu/abstract_top_menu.xml
@@ -5,7 +5,8 @@
android:id="@+id/menu_global_search"
android:icon="?attr/search"
android:title="@string/menu.search"
- compat:showAsAction="always|withText"/>
+ compat:actionViewClass="android.support.v7.widget.SearchView"
+ compat:showAsAction="always|collapseActionView"/>
<group android:id="@+id/not_touchscreen">
<item
diff --git a/app/src/main/res/menu/main.xml b/app/src/main/res/menu/main.xml
index 0970c8ce..4b542668 100644
--- a/app/src/main/res/menu/main.xml
+++ b/app/src/main/res/menu/main.xml
@@ -5,13 +5,14 @@
android:id="@+id/menu_global_search"
android:icon="?attr/search"
android:title="@string/menu.search"
- compat:showAsAction="always|withText"/>
+ compat:actionViewClass="android.support.v7.widget.SearchView"
+ compat:showAsAction="ifRoom|collapseActionView"/>
<item
android:id="@+id/menu_global_shuffle"
android:icon="?attr/shuffle"
android:title="@string/menu.shuffle"
- compat:showAsAction="always|withText"/>
+ compat:showAsAction="ifRoom|withText"/>
<group android:id="@+id/madsonic">
<item
diff --git a/app/src/main/res/menu/search.xml b/app/src/main/res/menu/search.xml
index e9377d68..b957a1e4 100644
--- a/app/src/main/res/menu/search.xml
+++ b/app/src/main/res/menu/search.xml
@@ -5,7 +5,8 @@
android:id="@+id/menu_global_search"
android:icon="?attr/search"
android:title="@string/menu.search"
- compat:showAsAction="ifRoom|withText"/>
+ compat:actionViewClass="android.support.v7.widget.SearchView"
+ compat:showAsAction="always|collapseActionView"/>
<item
android:id="@+id/menu_exit"
diff --git a/app/src/main/res/menu/select_artist.xml b/app/src/main/res/menu/select_artist.xml
index f94cda8b..e974c28e 100644
--- a/app/src/main/res/menu/select_artist.xml
+++ b/app/src/main/res/menu/select_artist.xml
@@ -5,13 +5,14 @@
android:id="@+id/menu_global_search"
android:icon="?attr/search"
android:title="@string/menu.search"
- compat:showAsAction="always|withText"/>
+ compat:actionViewClass="android.support.v7.widget.SearchView"
+ compat:showAsAction="ifRoom|collapseActionView"/>
<item
android:id="@+id/menu_global_shuffle"
android:icon="?attr/shuffle"
android:title="@string/menu.shuffle"
- compat:showAsAction="always|withText"/>
+ compat:showAsAction="ifRoom|withText"/>
<group android:id="@+id/not_touchscreen">
<item
diff --git a/app/src/main/res/menu/select_podcasts.xml b/app/src/main/res/menu/select_podcasts.xml
index 41ad62fa..25bb6188 100644
--- a/app/src/main/res/menu/select_podcasts.xml
+++ b/app/src/main/res/menu/select_podcasts.xml
@@ -5,13 +5,14 @@
android:id="@+id/menu_global_search"
android:icon="?attr/search"
android:title="@string/menu.search"
- compat:showAsAction="always|withText"/>
+ compat:actionViewClass="android.support.v7.widget.SearchView"
+ compat:showAsAction="ifRoom|collapseActionView"/>
<item
android:id="@+id/menu_add_podcast"
android:icon="?attr/add"
android:title="@string/menu.add_podcast"
- compat:showAsAction="always|withText"/>
+ compat:showAsAction="ifRoom|withText"/>
<group android:id="@+id/not_touchscreen">
<item