[Android] File browser: use the correct ViewModel
Geoffrey Métais
git at videolan.org
Tue Feb 4 15:31:03 CET 2020
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Feb 4 09:03:06 2020 +0100| [9271fcf8f3f28fe2b65bc9b8248010619c0f5702] | committer: Geoffrey Métais
File browser: use the correct ViewModel
> https://code.videolan.org/videolan/vlc-android/commit/9271fcf8f3f28fe2b65bc9b8248010619c0f5702
---
.../org/videolan/television/ui/browser/FileBrowserTvFragment.kt | 3 +--
.../java/org/videolan/television/ui/browser/VerticalGridActivity.kt | 1 -
.../src/org/videolan/vlc/gui/browser/FileBrowserFragment.kt | 6 ++----
.../src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.kt | 4 +++-
.../src/org/videolan/vlc/gui/browser/StorageBrowserFragment.kt | 3 ++-
.../src/org/videolan/vlc/viewmodels/browser/BrowserModel.kt | 2 +-
6 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/application/television/src/main/java/org/videolan/television/ui/browser/FileBrowserTvFragment.kt b/application/television/src/main/java/org/videolan/television/ui/browser/FileBrowserTvFragment.kt
index 07415bc9c..50d17c0d4 100644
--- a/application/television/src/main/java/org/videolan/television/ui/browser/FileBrowserTvFragment.kt
+++ b/application/television/src/main/java/org/videolan/television/ui/browser/FileBrowserTvFragment.kt
@@ -9,7 +9,6 @@ import android.view.View
import androidx.core.content.ContextCompat
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.Observer
-import androidx.lifecycle.ViewModelProviders
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
@@ -71,7 +70,7 @@ class FileBrowserTvFragment : BaseBrowserTvFragment<MediaLibraryItem>(), PathAda
isRootLevel = arguments?.getBoolean("rootLevel") ?: false
(item as? MediaWrapper)?.run { mrl = location }
- viewModel = ViewModelProviders.of(this, NetworkModel.Factory(requireContext(), mrl, false)).get(NetworkModel::class.java)
+ viewModel = getBrowserModel(category = getCategory(), url = mrl, showHiddenFiles = false)
viewModel.currentItem = item
browserFavRepository = BrowserFavRepository.getInstance(requireContext())
diff --git a/application/television/src/main/java/org/videolan/television/ui/browser/VerticalGridActivity.kt b/application/television/src/main/java/org/videolan/television/ui/browser/VerticalGridActivity.kt
index fb8e185c8..bb60090a5 100644
--- a/application/television/src/main/java/org/videolan/television/ui/browser/VerticalGridActivity.kt
+++ b/application/television/src/main/java/org/videolan/television/ui/browser/VerticalGridActivity.kt
@@ -75,7 +75,6 @@ class VerticalGridActivity : BaseTvActivity(), BrowserActivityInterface {
fragment = FileBrowserTvFragment.newInstance(TYPE_NETWORK, item, item === null)
} else if (type == HEADER_MOVIES || type == HEADER_TV_SHOW) {
-
fragment = MoviepediaBrowserTvFragment.newInstance(type)
} else if (type == HEADER_DIRECTORIES) {
fragment = FileBrowserTvFragment.newInstance(TYPE_FILE, intent.data?.let { MLServiceLocator.getAbstractMediaWrapper(it) }, true)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.kt
index 4b42f1260..f52ee9019 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.kt
@@ -50,6 +50,7 @@ import org.videolan.vlc.gui.helpers.hf.OtgAccess
import org.videolan.vlc.util.FileUtils
import org.videolan.vlc.viewmodels.browser.BrowserModel
import org.videolan.vlc.viewmodels.browser.TYPE_FILE
+import org.videolan.vlc.viewmodels.browser.getBrowserModel
@ObsoleteCoroutinesApi
@ExperimentalCoroutinesApi
@@ -87,10 +88,7 @@ open class FileBrowserFragment : BaseBrowserFragment() {
}
protected open fun setupBrowser() {
- viewModel = if (isRootDirectory)
- ViewModelProviders.of(requireActivity(), BrowserModel.Factory(requireContext(), null, TYPE_FILE, showHiddenFiles)).get(BrowserModel::class.java)
- else
- ViewModelProviders.of(this, BrowserModel.Factory(requireContext(), mrl, TYPE_FILE, showHiddenFiles)).get(BrowserModel::class.java)
+ viewModel = getBrowserModel(category = TYPE_FILE, url = if (!isRootDirectory) mrl else null, showHiddenFiles = showHiddenFiles)
}
override fun getTitle(): String = if (isRootDirectory)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.kt
index 3a0203348..fef3f6002 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.kt
@@ -47,6 +47,8 @@ import org.videolan.vlc.gui.dialogs.NetworkServerDialog
import org.videolan.vlc.gui.view.EmptyLoadingState
import org.videolan.vlc.util.*
import org.videolan.vlc.viewmodels.browser.NetworkModel
+import org.videolan.vlc.viewmodels.browser.TYPE_NETWORK
+import org.videolan.vlc.viewmodels.browser.getBrowserModel
@ExperimentalCoroutinesApi
@ObsoleteCoroutinesApi
@@ -66,7 +68,7 @@ class NetworkBrowserFragment : BaseBrowserFragment(), IDialogManager {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
- viewModel = ViewModelProviders.of(this, NetworkModel.Factory(requireContext(), mrl, showHiddenFiles)).get(NetworkModel::class.java)
+ viewModel = getBrowserModel(TYPE_NETWORK, mrl, showHiddenFiles)
if (isRootDirectory) swipeRefreshLayout.isEnabled = false
}
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.kt
index 9e895fa7c..ddd49320b 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.kt
@@ -66,6 +66,7 @@ import org.videolan.vlc.gui.helpers.UiTools
import org.videolan.vlc.gui.onboarding.OnboardingActivity
import org.videolan.vlc.viewmodels.browser.BrowserModel
import org.videolan.vlc.viewmodels.browser.TYPE_STORAGE
+import org.videolan.vlc.viewmodels.browser.getBrowserModel
import java.io.File
const val KEY_IN_MEDIALIB = "key_in_medialib"
@@ -104,7 +105,7 @@ class StorageBrowserFragment : FileBrowserFragment(), EntryPointsEventsCb {
}
override fun setupBrowser() {
- viewModel = ViewModelProviders.of(this, BrowserModel.Factory(requireContext(), mrl, TYPE_STORAGE, showHiddenFiles)).get(BrowserModel::class.java)
+ viewModel = getBrowserModel(TYPE_STORAGE, mrl, showHiddenFiles)
}
override fun onStart() {
diff --git a/application/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserModel.kt b/application/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserModel.kt
index 8d33035f5..0517647f6 100644
--- a/application/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserModel.kt
+++ b/application/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserModel.kt
@@ -133,7 +133,7 @@ private val descComp by lazy {
}
@ExperimentalCoroutinesApi
-fun Fragment.getBrowserModel(category: Long, url: String?, showHiddenFiles: Boolean, showDummyCategory: Boolean) = if (category == TYPE_NETWORK)
+fun Fragment.getBrowserModel(category: Long, url: String?, showHiddenFiles: Boolean, showDummyCategory: Boolean = false) = if (category == TYPE_NETWORK)
ViewModelProviders.of(this, NetworkModel.Factory(requireContext(), url, showHiddenFiles)).get(NetworkModel::class.java)
else
ViewModelProviders.of(this, BrowserModel.Factory(requireContext(), url, category, showHiddenFiles, showDummyCategory = showDummyCategory)).get(BrowserModel::class.java)
More information about the Android
mailing list