[Android] Onboarding behavior improvements

Nicolas Pomepuy git at videolan.org
Wed Feb 27 15:55:26 CET 2019


vlc-android | branch: master | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Wed Feb 27 07:19:15 2019 +0100| [8d2bc85b282f80fbb8d1e9c165366dd18835de4d] | committer: Geoffrey Métais

Onboarding behavior improvements

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

 .../vlc/gui/browser/StorageBrowserAdapter.kt       | 13 ++++++--
 .../vlc/gui/browser/StorageBrowserFragment.kt      |  6 ++--
 .../vlc/gui/onboarding/OnboardingActivity.kt       | 24 +++++++++++----
 vlc-android/src/org/videolan/vlc/util/PathUtils.kt | 35 ++++++++++++++++++++++
 4 files changed, 68 insertions(+), 10 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserAdapter.kt b/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserAdapter.kt
index 3e5397839..51041ce88 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserAdapter.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserAdapter.kt
@@ -31,9 +31,11 @@ import kotlinx.coroutines.launch
 import org.videolan.medialibrary.media.MediaLibraryItem
 import org.videolan.medialibrary.media.MediaWrapper
 import org.videolan.medialibrary.media.Storage
+import org.videolan.vlc.MediaParsingService
 import org.videolan.vlc.VLCApplication
 import org.videolan.vlc.gui.helpers.ThreeStatesCheckbox
 import org.videolan.vlc.repository.DirectoryRepository
+import org.videolan.vlc.util.containsPath
 
 internal class StorageBrowserAdapter(fragment: StorageBrowserFragment) : BaseBrowserAdapter(fragment) {
 
@@ -55,7 +57,7 @@ internal class StorageBrowserAdapter(fragment: StorageBrowserFragment) : BaseBro
             if (!storagePath.endsWith("/")) storagePath += "/"
             job?.join()
             val hasContextMenu = customDirsLocation.contains(storagePath)
-            val checked = (fragment as StorageBrowserFragment).mScannedDirectory || mediaDirsLocation.contains(storagePath)
+            val checked = (fragment as StorageBrowserFragment).mScannedDirectory || mediaDirsLocation.containsPath(storagePath)
             vh.binding.setItem(storage)
             vh.binding.hasContextMenu = hasContextMenu
             when {
@@ -80,7 +82,14 @@ internal class StorageBrowserAdapter(fragment: StorageBrowserFragment) : BaseBro
 
     fun updateMediaDirs(context: Context) {
         mediaDirsLocation.clear()
-        val folders = VLCApplication.getMLInstance().foldersList
+
+        val folders = if (!VLCApplication.getMLInstance().isInitiated) {
+            MediaParsingService.preselectedStorages.toTypedArray()
+        } else {
+            VLCApplication.getMLInstance().foldersList
+        }
+
+
 
         folders.forEach {
             mediaDirsLocation.add(Uri.decode(if (it.startsWith("file://")) it.substring(7) else it))
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.kt b/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.kt
index 1121499ab..a0b588c3e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.kt
@@ -54,6 +54,7 @@ import org.videolan.vlc.gui.dialogs.showContext
 import org.videolan.vlc.gui.helpers.MedialibraryUtils
 import org.videolan.vlc.gui.helpers.ThreeStatesCheckbox
 import org.videolan.vlc.gui.helpers.UiTools
+import org.videolan.vlc.util.sanitizePath
 import org.videolan.vlc.gui.onboarding.OnboardingActivity
 import org.videolan.vlc.util.*
 import org.videolan.vlc.viewmodels.browser.BrowserModel
@@ -175,8 +176,9 @@ class StorageBrowserFragment : FileBrowserFragment(), EntryPointsEventsCb, Corou
         val checked = tscb.state == ThreeStatesCheckbox.STATE_CHECKED
         val activity = requireActivity()
         if (activity is OnboardingActivity) {
-            if (checked) MediaParsingService.preselectedStorages.add(mrl)
-            else MediaParsingService.preselectedStorages.remove(mrl)
+
+            if (checked) MediaParsingService.preselectedStorages.add(mrl.sanitizePath())
+            else MediaParsingService.preselectedStorages.remove(mrl.sanitizePath())
         } else {
             if (checked) {
                 MedialibraryUtils.addDir(mrl, v.context.applicationContext)
diff --git a/vlc-android/src/org/videolan/vlc/gui/onboarding/OnboardingActivity.kt b/vlc-android/src/org/videolan/vlc/gui/onboarding/OnboardingActivity.kt
index e63c30ca7..fc1f1cf5e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/onboarding/OnboardingActivity.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/onboarding/OnboardingActivity.kt
@@ -42,6 +42,12 @@ class OnboardingActivity : AppCompatActivity(), ViewPager.OnPageChangeListener,
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
 
+        launch {
+            if (viewModel.scanStorages && !viewModel.customizeMediaFolders) {
+                MediaParsingService.preselectedStorages.addAll(DirectoryRepository.getInstance(this at OnboardingActivity).getMediaDirectories())
+            }
+        }
+
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
             window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
             window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
@@ -84,7 +90,9 @@ class OnboardingActivity : AppCompatActivity(), ViewPager.OnPageChangeListener,
 
 
         previousButton.setOnClickListener {
-            if (viewPager.currentItem > 0) { viewPager.currentItem = viewPager.currentItem - 1 }
+            if (viewPager.currentItem > 0) {
+                viewPager.currentItem = viewPager.currentItem - 1
+            }
         }
 
         nextButton.setOnClickListener {
@@ -104,7 +112,7 @@ class OnboardingActivity : AppCompatActivity(), ViewPager.OnPageChangeListener,
             }
         }
 
-        doneButton.setOnClickListener { completeOnBoarding() }
+        doneButton.setOnClickListener { finish() }
 
         val count = viewModel.adapterCount
 
@@ -127,14 +135,18 @@ class OnboardingActivity : AppCompatActivity(), ViewPager.OnPageChangeListener,
                 .putInt("fragment_id", if (viewModel.scanStorages) R.id.nav_video else R.id.nav_directories)
                 .apply()
         launch {
-            if (viewModel.scanStorages && !viewModel.customizeMediaFolders) {
-                MediaParsingService.preselectedStorages.addAll(DirectoryRepository.getInstance(this at OnboardingActivity).getMediaDirectories())
+            if (!viewModel.scanStorages) {
+                MediaParsingService.preselectedStorages.clear()
             }
             startMedialibrary(firstRun = true, upgrade = true, parse = viewModel.scanStorages)
-            finish()
         }
     }
 
+    override fun finish() {
+        completeOnBoarding()
+        super.finish()
+    }
+
     override fun onBackPressed() {
         if (viewPager.currentItem != 0) super.onBackPressed()
     }
@@ -176,7 +188,7 @@ class OnboardingActivity : AppCompatActivity(), ViewPager.OnPageChangeListener,
         }
     }
 
-    override fun onPageScrollStateChanged(state: Int) { }
+    override fun onPageScrollStateChanged(state: Int) {}
 
     override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {}
 
diff --git a/vlc-android/src/org/videolan/vlc/util/PathUtils.kt b/vlc-android/src/org/videolan/vlc/util/PathUtils.kt
new file mode 100644
index 000000000..f5593fd88
--- /dev/null
+++ b/vlc-android/src/org/videolan/vlc/util/PathUtils.kt
@@ -0,0 +1,35 @@
+package org.videolan.vlc.util
+
+/**
+ *  Checks if the specified (sanitized) path is contained in this collection (of sanitized pathes)
+ */
+fun List<String>.containsPath(path: String): Boolean {
+    for (string in this) {
+        if (string.sanitizePath() == path.sanitizePath()) {
+            return true
+        }
+    }
+    return false
+}
+
+/**
+ *  Checks if the specified (sanitized) path is contained in this array (of sanitized pathes)
+ */
+fun Array<String>.containsPath(path: String): Boolean {
+
+    return toList().containsPath(path)
+}
+
+/**
+ * Sanitize a path [String] to remove leading "file://" and trailing "/"
+ */
+fun String.sanitizePath(): String {
+    var result = this
+    if (result.endsWith('/')) {
+        result = result.substringBeforeLast("/")
+    }
+    if (result.startsWith("file://")) {
+        result = result.substring(7)
+    }
+    return result
+}



More information about the Android mailing list