[Android] Save videos list on rotation & limit updates

Geoffrey Métais git at videolan.org
Thu Aug 3 18:52:30 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Aug  3 18:13:05 2017 +0200| [f105e213191819e22ca6897d49bad60b5319b3e9] | committer: Geoffrey Métais

Save videos list on rotation & limit updates

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

 .../src/org/videolan/vlc/gui/video/VideoGridFragment.java     | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
index 955920ef3..52cd0253b 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
@@ -71,9 +71,11 @@ import org.videolan.vlc.interfaces.IEventsHandler;
 import org.videolan.vlc.media.MediaGroup;
 import org.videolan.vlc.media.MediaUtils;
 import org.videolan.vlc.util.FileUtils;
+import org.videolan.vlc.util.Util;
 import org.videolan.vlc.util.VLCInstance;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 
 public class VideoGridFragment extends SortableFragment<VideoListAdapter> implements MediaUpdatedCb, SwipeRefreshLayout.OnRefreshListener, MediaAddedCb, Filterable, IEventsHandler {
@@ -147,6 +149,11 @@ public class VideoGridFragment extends SortableFragment<VideoListAdapter> implem
         mAdapter = new VideoListAdapter(this);
         if (mAdapter.isListMode())
             mGridView.addItemDecoration(mDividerItemDecoration);
+        if (savedInstanceState != null) {
+            final ArrayList<MediaWrapper> list = (ArrayList<MediaWrapper>) VLCApplication.getData("list"+getTitle());
+            if (!Util.isListEmpty(list))
+                mAdapter.addAll(list);
+        }
         mGridView.setAdapter(mAdapter);
     }
 
@@ -182,6 +189,7 @@ public class VideoGridFragment extends SortableFragment<VideoListAdapter> implem
     public void onSaveInstanceState(Bundle outState) {
         super.onSaveInstanceState(outState);
         outState.putString(KEY_GROUP, mGroup);
+        VLCApplication.storeData("list"+getTitle(), mAdapter.getAll());
     }
 
     protected void onMedialibraryReady() {
@@ -190,7 +198,8 @@ public class VideoGridFragment extends SortableFragment<VideoListAdapter> implem
             mMediaLibrary.setMediaUpdatedCb(this, Medialibrary.FLAG_MEDIA_UPDATED_VIDEO);
             mMediaLibrary.setMediaAddedCb(this, Medialibrary.FLAG_MEDIA_ADDED_VIDEO);
         }
-        mHandler.sendEmptyMessage(UPDATE_LIST);
+        if (!isHidden() && mAdapter.isEmpty())
+            mHandler.sendEmptyMessage(UPDATE_LIST);
     }
 
     public String getTitle() {



More information about the Android mailing list