[Android] [PATCH] Keep search filter on screen rotation
Romain Vimont
rom1v at videolabs.io
Wed Apr 11 12:00:53 CEST 2018
Save and restore the search query state along with the activity.
Fixes #404
---
.../org/videolan/vlc/gui/ContentActivity.java | 23 +++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/vlc-android/src/org/videolan/vlc/gui/ContentActivity.java b/vlc-android/src/org/videolan/vlc/gui/ContentActivity.java
index 2da5bca3b..510ebc225 100644
--- a/vlc-android/src/org/videolan/vlc/gui/ContentActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/ContentActivity.java
@@ -55,9 +55,26 @@ import java.util.List;
public class ContentActivity extends AudioPlayerContainerActivity implements SearchView.OnQueryTextListener, MenuItem.OnActionExpandListener {
public static final String TAG = "VLC/ContentActivity";
+ private static final String KEY_SEARCH_QUERY = "org.videolan.vlc.SEARCH_QUERY";
+
private SearchView mSearchView;
+ private CharSequence mSavedSearchQuery;
private boolean showRenderers = !AndroidDevices.isChromeBook && !Util.isListEmpty(RendererDelegate.INSTANCE.getRenderers().getValue());
+ @Override
+ protected void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+ if (mSearchView != null) {
+ outState.putCharSequence(KEY_SEARCH_QUERY, mSearchView.getQuery());
+ }
+ }
+
+ @Override
+ protected void onRestoreInstanceState(Bundle savedInstanceState) {
+ super.onRestoreInstanceState(savedInstanceState);
+ mSavedSearchQuery = savedInstanceState.getCharSequence(KEY_SEARCH_QUERY);
+ }
+
@Override
protected void initAudioPlayerContainerActivity() {
super.initAudioPlayerContainerActivity();
@@ -103,6 +120,12 @@ public class ContentActivity extends AudioPlayerContainerActivity implements Sea
mSearchView.setQueryHint(getString(R.string.search_list_hint));
mSearchView.setOnQueryTextListener(this);
searchItem.setOnActionExpandListener(this);
+ if (mSavedSearchQuery != null) {
+ searchItem.expandActionView();
+ mSearchView.setQuery(mSavedSearchQuery, false);
+ mSavedSearchQuery = null;
+ setSearchVisibility(true);
+ }
}
else
menu.findItem(R.id.ml_menu_filter).setVisible(false);
--
2.17.0
More information about the Android
mailing list