[Android] Hack to improve browsers restoration

Geoffrey Métais git at videolan.org
Mon Mar 5 17:02:42 CET 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Mar  5 17:02:19 2018 +0100| [d5ea34393807bc4181bea505949e135355168a7e] | committer: Geoffrey Métais

Hack to improve browsers restoration

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

 .../src/org/videolan/vlc/gui/MainActivity.java     |  6 +----
 .../vlc/gui/browser/BaseBrowserFragment.java       | 27 +++++++++-------------
 2 files changed, 12 insertions(+), 21 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index e14218dfa..c84d5518a 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -66,14 +66,12 @@ import org.videolan.vlc.gui.browser.ExtensionBrowser;
 import org.videolan.vlc.gui.browser.FileBrowserFragment;
 import org.videolan.vlc.gui.browser.MediaBrowserFragment;
 import org.videolan.vlc.gui.browser.NetworkBrowserFragment;
-import org.videolan.vlc.gui.dialogs.RenderersDialog;
 import org.videolan.vlc.gui.helpers.UiTools;
 import org.videolan.vlc.gui.network.MRLPanelFragment;
 import org.videolan.vlc.gui.preferences.PreferencesActivity;
 import org.videolan.vlc.gui.preferences.PreferencesFragment;
 import org.videolan.vlc.gui.video.VideoGridFragment;
 import org.videolan.vlc.gui.view.HackyDrawerLayout;
-import org.videolan.vlc.interfaces.Filterable;
 import org.videolan.vlc.interfaces.IRefreshable;
 import org.videolan.vlc.media.MediaUtils;
 import org.videolan.vlc.util.Constants;
@@ -197,8 +195,7 @@ public class MainActivity extends ContentActivity implements FilterQueryProvider
                         ft.remove(fragment);
                     } else if ((fragment instanceof MediaBrowserFragment)) {
                         mFragmentsStack.put(fragment.getTag(), new WeakReference<>(fragment));
-                        if (fragment != displayed)
-                            ft.hide(fragment);
+                        if (!TextUtils.equals(fragment.getTag(), displayed.getTag())) ft.hide(fragment);
                     }
                 }
             ft.commit();
@@ -211,7 +208,6 @@ public class MainActivity extends ContentActivity implements FilterQueryProvider
             MenuItem item = mNavigationView.getMenu().findItem(R.id.nav_directories);
             item.setTitle(R.string.open);
         }
-
         mNavigationView.getMenu().findItem(R.id.nav_history).setVisible(mSettings.getBoolean(PreferencesFragment.PLAYBACK_HISTORY, true));
     }
 
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
index 354b69a88..5ac112efa 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
@@ -141,21 +141,16 @@ public abstract class BaseBrowserFragment extends SortableFragment<BaseBrowserAd
         if (bundle == null)
             bundle = getArguments();
         if (bundle != null) {
-            if (VLCApplication.hasData(KEY_CONTENT_LIST))
-                mFoldersContentLists = (SimpleArrayMap<MediaLibraryItem, List<MediaLibraryItem>>) VLCApplication.getData(KEY_CONTENT_LIST);
             mCurrentMedia = bundle.getParcelable(KEY_MEDIA);
-            if (mCurrentMedia != null)
-                mMrl = mCurrentMedia.getLocation();
-            else
-                mMrl = bundle.getString(KEY_MRL);
+            if (mCurrentMedia != null) mMrl = mCurrentMedia.getLocation();
+            else mMrl = bundle.getString(KEY_MRL);
             mSavedPosition = bundle.getInt(KEY_POSITION);
         } else if (getActivity().getIntent() != null){
             mMrl = getActivity().getIntent().getDataString();
             getActivity().setIntent(null);
         }
         mRoot = defineIsRoot();
-        if (mFoldersContentLists == null)
-            mFoldersContentLists = new SimpleArrayMap<>();
+        if (mFoldersContentLists == null) mFoldersContentLists = new SimpleArrayMap<>();
     }
 
     @Override
@@ -194,12 +189,9 @@ public abstract class BaseBrowserFragment extends SortableFragment<BaseBrowserAd
         mRecyclerView.setAdapter(mAdapter);
         registerForContextMenu(mRecyclerView);
         mSwipeRefreshLayout.setOnRefreshListener(this);
-
-        VLCApplication.storeData(KEY_CONTENT_LIST+mMrl, mFoldersContentLists);
         @SuppressWarnings("unchecked")
         final SimpleArrayMap<MediaLibraryItem, List<MediaLibraryItem>> content = (SimpleArrayMap<MediaLibraryItem, List<MediaLibraryItem>>) VLCApplication.getData(KEY_CONTENT_LIST + mMrl);
-        if (content != null)
-            mFoldersContentLists = content;
+        if (content != null) mFoldersContentLists = content;
         @SuppressWarnings("unchecked")
         final List<MediaLibraryItem> mediaList = mRoot ? null : (List<MediaLibraryItem>) VLCApplication.getData(KEY_MEDIA_LIST + mMrl);
         if (!Util.isListEmpty(mediaList)) {
@@ -213,10 +205,8 @@ public abstract class BaseBrowserFragment extends SortableFragment<BaseBrowserAd
         super.onResume();
         if (mCurrentMedia != null)
         setSearchVisibility(false);
-        if (goBack)
-            goBack();
-        else
-            restoreList();
+        if (goBack) goBack();
+        else restoreList();
     }
 
     @Override
@@ -278,8 +268,13 @@ public abstract class BaseBrowserFragment extends SortableFragment<BaseBrowserAd
         final FragmentActivity activity = getActivity();
         if (activity == null) return false;
         if (!mRoot) {
+            final FragmentManager fm = activity.getSupportFragmentManager();
+            final String tag = fm.getBackStackEntryAt(fm.getBackStackEntryCount()-1).getName();
             if (!activity.getSupportFragmentManager().popBackStackImmediate() && activity instanceof MainActivity)
                 ((MainActivity)activity).showFragment(this instanceof NetworkBrowserFragment ? R.id.nav_network : R.id.nav_directories);
+            final Fragment current = fm.findFragmentByTag(tag);
+            final View view = current != null ? current.getView() : null;
+            if (view != null) view.setVisibility(View.VISIBLE);
         }
         return !mRoot;
     }



More information about the Android mailing list