[Android] Hardcoded string exctraction
Geoffrey Métais
git at videolan.org
Mon Mar 23 15:52:11 CET 2020
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Mar 18 09:42:47 2020 +0100| [ab810f87ed29e2f5cb715dc8dd0a2653f1f311b3] | committer: Geoffrey Métais
Hardcoded string exctraction
> https://code.videolan.org/videolan/vlc-android/commit/ab810f87ed29e2f5cb715dc8dd0a2653f1f311b3
---
.../src/main/java/org/videolan/tools/Settings.kt | 2 +-
.../gui/preferences/PreferencesFragmentUITest.kt | 5 ++---
.../src/org/videolan/vlc/MediaParsingService.kt | 2 +-
.../src/org/videolan/vlc/gui/MainActivity.kt | 2 +-
.../gui/onboarding/OnboardingScanningFragment.kt | 23 ++++++----------------
5 files changed, 11 insertions(+), 23 deletions(-)
diff --git a/application/tools/src/main/java/org/videolan/tools/Settings.kt b/application/tools/src/main/java/org/videolan/tools/Settings.kt
index ac6fd6f88..6bb31ea2e 100644
--- a/application/tools/src/main/java/org/videolan/tools/Settings.kt
+++ b/application/tools/src/main/java/org/videolan/tools/Settings.kt
@@ -44,6 +44,7 @@ const val KEY_BLACK_THEME = "enable_black_theme"
const val KEY_DAYNIGHT = "daynight"
const val SHOW_VIDEO_THUMBNAILS = "show_video_thumbnails"
const val KEY_VIDEO_CONFIRM_RESUME = "video_confirm_resume"
+const val KEY_MEDIALIBRARY_AUTO_RESCAN = "auto_rescan"
//UI
const val LIST_TITLE_ELLIPSIZE = "list_title_ellipsize"
@@ -103,5 +104,4 @@ class DeviceInfo(context: Context) {
val hasPiP = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && pm.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)
|| Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && isAndroidTv
val pipAllowed = hasPiP || hasTsp && Build.VERSION.SDK_INT < Build.VERSION_CODES.O
-
}
\ No newline at end of file
diff --git a/application/vlc-android/androidTest/org/videolan/vlc/gui/preferences/PreferencesFragmentUITest.kt b/application/vlc-android/androidTest/org/videolan/vlc/gui/preferences/PreferencesFragmentUITest.kt
index c0400248a..4d299cac8 100644
--- a/application/vlc-android/androidTest/org/videolan/vlc/gui/preferences/PreferencesFragmentUITest.kt
+++ b/application/vlc-android/androidTest/org/videolan/vlc/gui/preferences/PreferencesFragmentUITest.kt
@@ -13,6 +13,7 @@ import kotlinx.coroutines.ObsoleteCoroutinesApi
import org.hamcrest.Matchers.allOf
import org.junit.Rule
import org.junit.Test
+import org.videolan.tools.KEY_MEDIALIBRARY_AUTO_RESCAN
import org.videolan.vlc.PreferenceMatchers.withKey
import org.videolan.vlc.R
import org.videolan.vlc.gui.SecondaryActivity
@@ -48,9 +49,7 @@ class PreferencesFragmentUITest: BasePreferenceUITest() {
@Test
fun clickOnToggleRescan_keyToggled() {
- val key = "auto_rescan"
-
- checkToggleWorks(key, settings)
+ checkToggleWorks(KEY_MEDIALIBRARY_AUTO_RESCAN, settings)
}
@Test
diff --git a/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt b/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
index 2642af3e4..fc0193325 100644
--- a/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
+++ b/application/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
@@ -289,7 +289,7 @@ class MediaParsingService : LifecycleService(), DevicesDiscoveryCb {
medialibrary.unbanFolder("${AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY}/WhatsApp/")
medialibrary.banFolder("${AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY}/WhatsApp/Media/WhatsApp Animated Gifs/")
}
- settings.getBoolean("auto_rescan", true) -> reload(null)
+ settings.getBoolean(KEY_MEDIALIBRARY_AUTO_RESCAN, true) -> reload(null)
else -> exitCommand()
}
}
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/MainActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/MainActivity.kt
index 178e8cad9..10ea8e307 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/MainActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/MainActivity.kt
@@ -90,7 +90,7 @@ class MainActivity : ContentActivity(),
/* Set up the action bar */
prepareActionBar()
/* Reload the latest preferences */
- scanNeeded = savedInstanceState == null && settings.getBoolean("auto_rescan", true)
+ scanNeeded = savedInstanceState == null && settings.getBoolean(KEY_MEDIALIBRARY_AUTO_RESCAN, true)
if (BuildConfig.DEBUG) extensionsManager = ExtensionsManager.getInstance()
mediaLibrary = Medialibrary.getInstance()
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/onboarding/OnboardingScanningFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/onboarding/OnboardingScanningFragment.kt
index a92452c56..c1b70a68a 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/onboarding/OnboardingScanningFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/onboarding/OnboardingScanningFragment.kt
@@ -7,16 +7,13 @@ import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import kotlinx.android.synthetic.main.onboarding_scanning.*
-import org.videolan.tools.KEY_MEDIALIBRARY_SCAN
-import org.videolan.tools.ML_SCAN_OFF
-import org.videolan.tools.ML_SCAN_ON
-import org.videolan.tools.Settings
+import org.videolan.tools.*
import org.videolan.vlc.R
class OnboardingScanningFragment : Fragment() {
- lateinit var onScanningCustomizeChangedListener: IOnScanningCustomizeChangedListener
+ private val onScanningCustomizeChangedListener by lazy(LazyThreadSafetyMode.NONE) { requireActivity() as IOnScanningCustomizeChangedListener }
private val viewModel: OnboardingViewModel by activityViewModels()
- private val preferences by lazy { Settings.getInstance(requireActivity()) }
+ private val preferences by lazy(LazyThreadSafetyMode.NONE) { Settings.getInstance(requireActivity()) }
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.onboarding_scanning, container, false)
@@ -34,27 +31,19 @@ class OnboardingScanningFragment : Fragment() {
}
autoScanningCheckbox.setOnCheckedChangeListener { _, isChecked ->
- preferences.edit().putBoolean("auto_rescan", isChecked).apply()
+ preferences.edit().putBoolean(KEY_MEDIALIBRARY_AUTO_RESCAN, isChecked).apply()
}
- onScanningCustomizeChangedListener = requireActivity() as IOnScanningCustomizeChangedListener
-
scanningFolderCheckbox.isChecked = viewModel.customizeMediaFolders
scanningFolderCheckbox.setOnCheckedChangeListener { _, isChecked ->
-
viewModel.customizeMediaFolders = isChecked
-
- if (::onScanningCustomizeChangedListener.isInitialized) {
- onScanningCustomizeChangedListener.onCustomizedChanged(isChecked)
- }
+ onScanningCustomizeChangedListener.onCustomizedChanged(isChecked)
}
}
companion object {
- fun newInstance(): OnboardingScanningFragment {
- return OnboardingScanningFragment()
- }
+ fun newInstance() = OnboardingScanningFragment()
}
}
More information about the Android
mailing list