aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/github
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/github')
-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
5 files changed, 51 insertions, 20 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;