[Android] Avoid using hardcoded values for tablet threshold

Nicolas Pomepuy git at videolan.org
Thu Dec 23 09:45:07 UTC 2021


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Dec  6 07:22:11 2021 +0100| [4c7519257c7452866ac1e7e008dae7555bda925f] | committer: Nicolas Pomepuy

Avoid using hardcoded values for tablet threshold

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

 application/resources/src/main/res/values-w600dp/booleans.xml        | 4 ++++
 application/resources/src/main/res/values/booleans.xml               | 1 +
 application/vlc-android/src/org/videolan/vlc/gui/BaseFragment.kt     | 3 ++-
 application/vlc-android/src/org/videolan/vlc/gui/MainActivity.kt     | 3 ++-
 .../vlc-android/src/org/videolan/vlc/gui/helpers/Navigator.kt        | 5 +++--
 application/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt  | 2 ++
 .../vlc-android/src/org/videolan/vlc/gui/video/VideoStatsDelegate.kt | 3 ++-
 7 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/application/resources/src/main/res/values-w600dp/booleans.xml b/application/resources/src/main/res/values-w600dp/booleans.xml
new file mode 100644
index 000000000..5fc3a0d0d
--- /dev/null
+++ b/application/resources/src/main/res/values-w600dp/booleans.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <bool name="is_tablet">true</bool>
+</resources>
\ No newline at end of file
diff --git a/application/resources/src/main/res/values/booleans.xml b/application/resources/src/main/res/values/booleans.xml
index fdb2f0e3d..877bef45a 100644
--- a/application/resources/src/main/res/values/booleans.xml
+++ b/application/resources/src/main/res/values/booleans.xml
@@ -2,4 +2,5 @@
 <resources>
     <bool name="list_mode">true</bool>
     <bool name="time_stretching_default">false</bool>
+    <bool name="is_tablet">false</bool>
 </resources>
\ No newline at end of file
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/BaseFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/BaseFragment.kt
index 32786cfbb..e4cfb59c4 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/BaseFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/BaseFragment.kt
@@ -29,6 +29,7 @@ import org.videolan.vlc.R
 import org.videolan.vlc.gui.browser.KEY_IN_MEDIALIB
 import org.videolan.vlc.gui.browser.KEY_MEDIA
 import org.videolan.vlc.gui.helpers.FloatingActionButtonBehavior
+import org.videolan.vlc.gui.helpers.UiTools.isTablet
 import org.videolan.vlc.gui.view.SwipeRefreshLayout
 import org.videolan.vlc.util.getScreenWidth
 
@@ -84,7 +85,7 @@ abstract class BaseFragment : Fragment(), ActionMode.Callback {
         val fabLarge = requireActivity().findViewById<FloatingActionButton>(R.id.fab_large)
         fab.setGone()
         fabLarge.setGone()
-        fabPlay = if (requireActivity().getScreenWidth() >= 600.dp) fabLarge else fab
+        fabPlay = if (requireActivity().isTablet()) fabLarge else fab
         visibility?.let { fabPlay?.visibility = it }
     }
 
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 98e27903e..0eb90c2f3 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/MainActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/MainActivity.kt
@@ -55,6 +55,7 @@ import org.videolan.vlc.gui.dialogs.AllAccessPermissionDialog
 import org.videolan.vlc.gui.helpers.INavigator
 import org.videolan.vlc.gui.helpers.Navigator
 import org.videolan.vlc.gui.helpers.UiTools
+import org.videolan.vlc.gui.helpers.UiTools.isTablet
 import org.videolan.vlc.gui.video.VideoGridFragment
 import org.videolan.vlc.interfaces.Filterable
 import org.videolan.vlc.interfaces.IRefreshable
@@ -81,7 +82,7 @@ class MainActivity : ContentActivity(),
 
     override fun getSnackAnchorView(overAudioPlayer:Boolean): View? {
         val view = super.getSnackAnchorView(overAudioPlayer)
-        return if (view?.id == android.R.id.content && getScreenWidth() < 600.dp) {if(overAudioPlayer) findViewById(android.R.id.content) else findViewById(R.id.appbar)} else view
+        return if (view?.id == android.R.id.content && !isTablet()) {if(overAudioPlayer) findViewById(android.R.id.content) else findViewById(R.id.appbar)} else view
     }
 
     @SuppressLint("SetTextI18n")
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/helpers/Navigator.kt b/application/vlc-android/src/org/videolan/vlc/gui/helpers/Navigator.kt
index 48481fe1f..66a944946 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/helpers/Navigator.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/helpers/Navigator.kt
@@ -51,6 +51,7 @@ import org.videolan.vlc.gui.audio.AudioBrowserFragment
 import org.videolan.vlc.gui.browser.BaseBrowserFragment
 import org.videolan.vlc.gui.browser.ExtensionBrowser
 import org.videolan.vlc.gui.browser.MainBrowserFragment
+import org.videolan.vlc.gui.helpers.UiTools.isTablet
 import org.videolan.vlc.gui.preferences.PreferencesActivity
 import org.videolan.vlc.gui.video.VideoGridFragment
 import org.videolan.vlc.util.getScreenWidth
@@ -160,8 +161,8 @@ class Navigator : BottomNavigationView.OnNavigationItemSelectedListener, Lifecyc
     override fun configurationChanged(size: Int) {
         navigationView.forEach {
             when (it) {
-                is BottomNavigationView -> if (size > 600.dp) it.setGone() else it.setVisible()
-                else -> if (size <= 600.dp) it.setGone() else it.setVisible()
+                is BottomNavigationView -> if (activity.isTablet()) it.setGone() else it.setVisible()
+                else -> if (!activity.isTablet()) it.setGone() else it.setVisible()
             }
         }
     }
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt b/application/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt
index b53203a44..ad7f7d10b 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt
@@ -422,6 +422,8 @@ object UiTools {
         startActivity(i)
     }
 
+    fun Context.isTablet() = resources.getBoolean(R.bool.is_tablet)
+
     fun getDefaultCover(context: Context, item: MediaLibraryItem): BitmapDrawable {
         return when (item.itemType) {
             MediaLibraryItem.TYPE_ARTIST -> getDefaultArtistDrawable(context)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoStatsDelegate.kt b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoStatsDelegate.kt
index 3b7460b59..55203644d 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoStatsDelegate.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoStatsDelegate.kt
@@ -47,6 +47,7 @@ import org.videolan.tools.readableSize
 import org.videolan.vlc.BuildConfig
 import org.videolan.vlc.R
 import org.videolan.vlc.databinding.PlayerHudBinding
+import org.videolan.vlc.gui.helpers.UiTools.isTablet
 import org.videolan.vlc.util.LocaleUtil
 import org.videolan.vlc.util.getScreenWidth
 import java.lang.Double
@@ -183,7 +184,7 @@ class VideoStatsDelegate(private val player: VideoPlayerActivity, val scrolling:
 
     private fun setupLayout() {
         if (!::constraintSetLarge.isInitialized) return
-        if (player.getScreenWidth() > 600.dp) {
+        if (player.isTablet()) {
             constraintSetLarge.applyTo(binding.statsScrollviewContent)
         } else {
             constraintSet.applyTo(binding.statsScrollviewContent)



More information about the Android mailing list