[Android] Restore state after filter query

Geoffrey Métais git at videolan.org
Sun Nov 6 00:59:07 CET 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Sun Nov  6 00:57:25 2016 +0100| [31c48c373003da701f8948fa79f06f510ef7444a] | committer: Geoffrey Métais

Restore state after filter query

> https://code.videolan.org/videolan/vlc-android/commit/31c48c373003da701f8948fa79f06f510ef7444a
---

 vlc-android/src/org/videolan/vlc/gui/MainActivity.java      |  6 ++++++
 .../src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java | 10 ++++++----
 .../org/videolan/vlc/gui/audio/AudioBrowserFragment.java    |  6 +++++-
 .../src/org/videolan/vlc/gui/video/VideoListAdapter.java    | 13 +++++++------
 4 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index cdc864b..fa5ec40 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -360,6 +360,8 @@ public class MainActivity extends AudioPlayerContainerActivity implements Device
         /* Load media items from database and storage */
         if (mScanNeeded && Permissions.canReadStorage())
             mMediaLibrary.reload();
+        else
+            restoreCurrentList();
         mNavigationView.setCheckedItem(mCurrentFragmentId);
         mCurrentFragmentId = mSettings.getInt("fragment_id", R.id.nav_video);
     }
@@ -784,6 +786,10 @@ public class MainActivity extends AudioPlayerContainerActivity implements Device
         return true;
     }
 
+    public void closeSearchView() {
+        MenuItemCompat.collapseActionView(mMenu.findItem(R.id.ml_menu_filter));
+    }
+
     public void restoreCurrentList() {
         Fragment current = getSupportFragmentManager().findFragmentById(R.id.fragment_placeholder);
         if (current instanceof Filterable) {
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java
index c593515..e4dcf3d 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java
@@ -201,10 +201,12 @@ public class AudioBrowserAdapter extends RecyclerView.Adapter<AudioBrowserAdapte
     }
 
     public void restoreList() {
-        mDataList.clear();
-        mDataList.addAll(mOriginalDataSet);
-        mOriginalDataSet = null;
-        notifyDataSetChanged();
+        if (mOriginalDataSet != null) {
+            mDataList.clear();
+            mDataList.addAll(mOriginalDataSet);
+            mOriginalDataSet = null;
+            notifyDataSetChanged();
+        }
     }
 
     public class ViewHolder extends RecyclerView.ViewHolder {
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
index add52bf..d8ffcfc 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -36,6 +36,7 @@ import android.support.v4.app.FragmentManager;
 import android.support.v4.view.ViewPager;
 import android.support.v7.widget.LinearLayoutManager;
 import android.support.v7.widget.RecyclerView;
+import android.util.Log;
 import android.view.KeyEvent;
 import android.view.LayoutInflater;
 import android.view.Menu;
@@ -584,7 +585,10 @@ public class AudioBrowserFragment extends MediaBrowserFragment implements Device
     }
 
     @Override
-    public void onTabUnselected(TabLayout.Tab tab) {}
+    public void onTabUnselected(TabLayout.Tab tab) {
+        mMainActivity.closeSearchView();
+        ((AudioBrowserAdapter)((RecyclerView)mLists.get(tab.getPosition())).getAdapter()).restoreList();
+    }
 
     @Override
     public void onTabReselected(TabLayout.Tab tab) {
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
index c815ad5..1874661 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
@@ -37,6 +37,7 @@ import android.widget.Filter;
 import android.widget.Filterable;
 import android.widget.ImageView;
 
+import org.videolan.medialibrary.Tools;
 import org.videolan.medialibrary.media.MediaWrapper;
 import org.videolan.vlc.BR;
 import org.videolan.vlc.R;
@@ -268,8 +269,6 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
             if (media == null)
                 return;
             Activity activity = mFragment.getActivity();
-            if (activity instanceof MainActivity)
-                ((MainActivity)activity).restoreCurrentList();
             if (media instanceof MediaGroup) {
                 String title = media.getTitle().substring(media.getTitle().toLowerCase().startsWith("the") ? 4 : 0);
                 ((MainActivity)activity).showSecondaryFragment(SecondaryActivity.VIDEO_GROUP_LIST, title);
@@ -431,10 +430,12 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
     }
 
     public void restoreList() {
-        mVideos.clear();
-        mVideos.addAll(mOriginalData);
-        mOriginalData = null;
-        notifyDataSetChanged();
+        if (mOriginalData != null) {
+            mVideos.clear();
+            mVideos.addAll(mOriginalData);
+            mOriginalData = null;
+            notifyDataSetChanged();
+        }
     }
 
     private class ItemFilter extends Filter {



More information about the Android mailing list