[Android] Move grid / list display setting to the video UI

Nicolas Pomepuy git at videolan.org
Mon Sep 23 15:49:58 CEST 2019


vlc-android | branch: master | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Thu Sep 19 11:48:59 2019 +0200| [421af442ea4c11d310daf72e7009ca1b86677f71] | committer: Geoffrey Métais

Move grid / list display setting to the video UI

Fixes #1041

> https://code.videolan.org/videolan/vlc-android/commit/421af442ea4c11d310daf72e7009ca1b86677f71
---

 vlc-android/res/values/strings.xml                     |  2 --
 vlc-android/res/xml/preferences_ui.xml                 |  6 ------
 .../videolan/vlc/gui/tv/preferences/PreferencesUi.kt   |  1 -
 .../org/videolan/vlc/gui/video/VideoGridFragment.kt    | 18 +++++++++++-------
 vlc-android/src/org/videolan/vlc/util/Settings.kt      |  1 -
 5 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index a2964aab7..3d8aae61d 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -324,8 +324,6 @@
     <string name="video_transition_summary">Show new video title on transition</string>
     <string name="media_seen">Show seen video marker</string>
     <string name="media_seen_summary">Mark a video as seen when you play it until the end</string>
-    <string name="force_list_portrait">No grid in portrait mode</string>
-    <string name="force_list_portrait_summary">Show videos in list instead of grid in portrait mode</string>
     <string name="force_play_all_summary">Play all videos, starting with the one you clicked on</string>
     <string name="force_play_all_title">Video playlist mode</string>
     <string name="save_brightness_summary">Remember brightness level in video player</string>
diff --git a/vlc-android/res/xml/preferences_ui.xml b/vlc-android/res/xml/preferences_ui.xml
index 39ed29ade..adceffde8 100644
--- a/vlc-android/res/xml/preferences_ui.xml
+++ b/vlc-android/res/xml/preferences_ui.xml
@@ -50,12 +50,6 @@
                 android:key="force_play_all"
                 android:summary="@string/force_play_all_summary"
                 android:title="@string/force_play_all_title"/>
-        <CheckBoxPreference
-                app:singleLineTitle="false"
-                android:defaultValue="false"
-                android:key="force_list_portrait"
-                android:summary="@string/force_list_portrait_summary"
-                android:title="@string/force_list_portrait"/>
         <CheckBoxPreference
                 app:singleLineTitle="false"
                 android:defaultValue="true"
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/preferences/PreferencesUi.kt b/vlc-android/src/org/videolan/vlc/gui/tv/preferences/PreferencesUi.kt
index 5330f7701..f31aa3d98 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/preferences/PreferencesUi.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/preferences/PreferencesUi.kt
@@ -52,7 +52,6 @@ class PreferencesUi : BasePreferenceFragment(), SharedPreferences.OnSharedPrefer
         }
         super.onCreate(savedInstanceState)
         findPreference<Preference>("ui_audio_category")?.isVisible = false
-        findPreference<Preference>(FORCE_LIST_PORTRAIT)?.isVisible = false
         findPreference<Preference>(PREF_TV_UI)?.isVisible = AndroidDevices.hasTsp
         findPreference<Preference>(KEY_APP_THEME)?.isVisible = false
         prepareLocaleList()
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt
index b41936abc..5bf57724e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt
@@ -22,7 +22,6 @@ package org.videolan.vlc.gui.video
 
 import android.annotation.TargetApi
 import android.content.Intent
-import android.content.res.Configuration
 import android.os.Build
 import android.os.Bundle
 import android.os.Handler
@@ -78,7 +77,6 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
     private lateinit var binding: VideoGridBinding
     private var gridItemDecoration: RecyclerView.ItemDecoration? = null
 
-
     class VideoGridFragmentHandler(private val videoGridFragment: WeakReference<VideoGridFragment>) : Handler() {
 
         override fun handleMessage(msg: Message?) {
@@ -104,7 +102,7 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
             val seenMarkVisible = preferences.getBoolean("media_seen", true)
             videoListAdapter = VideoListAdapter(this, seenMarkVisible)
             multiSelectHelper = videoListAdapter.multiSelectHelper
-            val folder = if (savedInstanceState != null ) savedInstanceState.getParcelable<AbstractFolder>(KEY_FOLDER)
+            val folder = if (savedInstanceState != null) savedInstanceState.getParcelable<AbstractFolder>(KEY_FOLDER)
             else arguments?.getParcelable(KEY_FOLDER)
             viewModel = getViewModel(folder)
             viewModel.provider.pagedList.observe(this, this)
@@ -122,6 +120,9 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
         super.onPrepareOptionsMenu(menu)
         menu.findItem(R.id.ml_menu_last_playlist).isVisible = true
         menu.findItem(R.id.ml_menu_video_group).isVisible = true
+        val displayInCards = Settings.getInstance(requireActivity()).getBoolean("video_display_in_cards", true)
+        menu.findItem(R.id.ml_menu_display_grid).isVisible = displayInCards
+        menu.findItem(R.id.ml_menu_display_list).isVisible = !displayInCards
     }
 
     override fun onOptionsItemSelected(item: MenuItem): Boolean {
@@ -130,6 +131,12 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
                 MediaUtils.loadlastPlaylist(activity, PLAYLIST_TYPE_VIDEO)
                 true
             }
+            R.id.ml_menu_display_list, R.id.ml_menu_display_grid -> {
+                val displayInCards = Settings.getInstance(requireActivity()).getBoolean("video_display_in_cards", true)
+                Settings.getInstance(requireActivity()).edit().putBoolean("video_display_in_cards", !displayInCards).apply()
+                (activity as MainActivity).forceLoadVideoFragment()
+                true
+            }
             else -> super.onOptionsItemSelected(item)
         }
     }
@@ -201,7 +208,7 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
         val res = resources
         if (gridItemDecoration == null)
             gridItemDecoration = ItemOffsetDecoration(resources, R.dimen.left_right_1610_margin, R.dimen.top_bottom_1610_margin)
-        val listMode = res.getBoolean(R.bool.list_mode) || res.configuration.orientation == Configuration.ORIENTATION_PORTRAIT && Settings.getInstance(requireContext()).getBoolean(FORCE_LIST_PORTRAIT, false)
+        val listMode = Settings.getInstance(requireContext()).getBoolean("video_display_in_cards", false)
 
         // Select between grid or list
         binding.videoGrid.removeItemDecoration(gridItemDecoration!!)
@@ -217,7 +224,6 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
         if (videoListAdapter.isListMode != listMode) videoListAdapter.isListMode = listMode
     }
 
-
     private fun playVideo(media: AbstractMediaWrapper, fromStart: Boolean) {
         media.removeFlags(AbstractMediaWrapper.MEDIA_FORCE_AUDIO)
         if (fromStart) media.addFlags(AbstractMediaWrapper.MEDIA_FROM_START)
@@ -336,7 +342,6 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
         return true
     }
 
-
     override fun onImageClick(v: View, position: Int, item: MediaLibraryItem) {}
 
     override fun onCtxClick(v: View, position: Int, item: MediaLibraryItem) {
@@ -348,7 +353,6 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
             showContext(requireActivity(), this, position, item.getTitle(), flags)
     }
 
-
     override fun onMainActionClick(v: View, position: Int, item: MediaLibraryItem) {}
 
     override fun onUpdateFinished(adapter: RecyclerView.Adapter<*>) {
diff --git a/vlc-android/src/org/videolan/vlc/util/Settings.kt b/vlc-android/src/org/videolan/vlc/util/Settings.kt
index 7418dc4e2..9f08aafdf 100644
--- a/vlc-android/src/org/videolan/vlc/util/Settings.kt
+++ b/vlc-android/src/org/videolan/vlc/util/Settings.kt
@@ -35,7 +35,6 @@ const val KEY_APP_THEME = "app_theme"
 const val KEY_BLACK_THEME = "enable_black_theme"
 const val KEY_DAYNIGHT = "daynight"
 const val SHOW_VIDEO_THUMBNAILS = "show_video_thumbnails"
-const val FORCE_LIST_PORTRAIT = "force_list_portrait"
 
 //UI
 const val LIST_TITLE_ELLIPSIZE = "list_title_ellipsize"



More information about the Android mailing list