[Android] Navigator: Deactivate fragments caching

Geoffrey Métais git at videolan.org
Tue Apr 30 16:02:15 CEST 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Apr 30 16:01:30 2019 +0200| [62d72865c86ffdb1ec2bec659bcfb6f07797f8a0] | committer: Geoffrey Métais

Navigator: Deactivate fragments caching

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

 .../src/org/videolan/vlc/gui/helpers/Navigator.kt  | 28 ++++------------------
 1 file changed, 5 insertions(+), 23 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/Navigator.kt b/vlc-android/src/org/videolan/vlc/gui/helpers/Navigator.kt
index af33afc39..4e187ad24 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/Navigator.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/Navigator.kt
@@ -27,7 +27,6 @@ import android.content.Intent
 import android.content.SharedPreferences
 import android.os.Bundle
 import android.view.MenuItem
-import androidx.collection.SimpleArrayMap
 import androidx.fragment.app.Fragment
 import androidx.fragment.app.FragmentManager
 import androidx.lifecycle.Lifecycle
@@ -44,13 +43,15 @@ import org.videolan.vlc.gui.MainActivity
 import org.videolan.vlc.gui.PlaylistFragment
 import org.videolan.vlc.gui.SecondaryActivity
 import org.videolan.vlc.gui.audio.AudioBrowserFragment
-import org.videolan.vlc.gui.browser.*
+import org.videolan.vlc.gui.browser.BaseBrowserFragment
+import org.videolan.vlc.gui.browser.ExtensionBrowser
+import org.videolan.vlc.gui.browser.FileBrowserFragment
+import org.videolan.vlc.gui.browser.NetworkBrowserFragment
 import org.videolan.vlc.gui.folders.FoldersFragment
 import org.videolan.vlc.gui.network.MRLPanelFragment
 import org.videolan.vlc.gui.preferences.PreferencesActivity
 import org.videolan.vlc.gui.video.VideoGridFragment
 import org.videolan.vlc.util.*
-import java.lang.ref.WeakReference
 
 private const val TAG = "Navigator"
 @ObsoleteCoroutinesApi
@@ -62,7 +63,6 @@ class Navigator(private val activity: MainActivity,
                 target: Int
 ): com.google.android.material.navigation.NavigationView.OnNavigationItemSelectedListener, LifecycleObserver {
 
-    private val fragmentsStack = SimpleArrayMap<String, WeakReference<Fragment>>()
     private val defaultFragmentId= R.id.nav_video
     var currentFragmentId = target
     var currentFragment: Fragment? = null
@@ -73,8 +73,6 @@ class Navigator(private val activity: MainActivity,
         state?.let {
             val fm = activity.supportFragmentManager
             currentFragment = fm.getFragment(it, "current_fragment")
-            //Restore fragments stack
-            restoreFragmentsStack(fm)
         }
     }
 
@@ -101,13 +99,7 @@ class Navigator(private val activity: MainActivity,
 
     fun showFragment(id: Int) {
         val tag = getTag(id)
-        //Get new fragment
-        val wr = fragmentsStack.get(tag)
-        var fragment = wr?.get()
-        if (fragment === null) {
-            fragment = getNewFragment(id)
-            fragmentsStack.put(tag, WeakReference(fragment))
-        }
+        val fragment = getNewFragment(id)
         showFragment(fragment, id, tag)
     }
 
@@ -123,16 +115,6 @@ class Navigator(private val activity: MainActivity,
         currentFragmentId = id
     }
 
-    private fun restoreFragmentsStack(fm: FragmentManager) {
-        val fragments = fm.fragments
-        val ft = fm.beginTransaction()
-        for (fragment in fragments) {
-            if (fragment is ExtensionBrowser) ft.remove(fragment)
-            else if (fragment is MediaBrowserFragment<*>) fragmentsStack.put(fragment.tag, WeakReference(fragment))
-        }
-        ft.commit()
-    }
-
     /**
      * Show a secondary fragment.
      */



More information about the Android mailing list