[Android] Display the right sort types for files
Nicolas Pomepuy
git at videolan.org
Tue May 21 14:41:04 CEST 2019
vlc-android | branch: master | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Mon May 20 12:05:11 2019 +0200| [6fbc43ca31b76c94c74f91f9e39e56f9b4bfadd4] | committer: Geoffrey Métais
Display the right sort types for files
> https://code.videolan.org/videolan/vlc-android/commit/6fbc43ca31b76c94c74f91f9e39e56f9b4bfadd4
---
.../src/org/videolan/vlc/gui/helpers/ImageLoader.kt | 7 +++++++
.../videolan/vlc/gui/tv/browser/BaseBrowserTvFragment.kt | 14 ++++++++------
.../org/videolan/vlc/viewmodels/browser/BrowserModel.kt | 2 ++
.../src/org/videolan/vlc/viewmodels/tv/TvBrowserModel.kt | 6 ------
4 files changed, 17 insertions(+), 12 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt b/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt
index e74e3a32c..0ac13066e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt
@@ -34,6 +34,7 @@ import org.videolan.vlc.util.ThumbnailsProvider.obtainBitmap
private val sMedialibrary = VLCApplication.mlInstance
@Volatile
private var defaultImageWidth = 0
+private var defaultImageWidthTV = 0
private const val TAG = "ImageLoader"
@ExperimentalCoroutinesApi
@@ -149,6 +150,12 @@ private suspend fun getImage(v: View, item: MediaLibraryItem, binding: ViewDataB
binding.addOnRebindCallback(rebindCallbacks!!)
}
val width = when {
+ isForTV(binding) -> {
+ if (defaultImageWidthTV == 0) {
+ defaultImageWidthTV = v.context.resources.getDimensionPixelSize(R.dimen.tv_grid_card_thumb_width)
+ }
+ defaultImageWidthTV
+ }
v.width > 0 -> v.width
defaultImageWidth > 0 -> defaultImageWidth
else -> {
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseBrowserTvFragment.kt b/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseBrowserTvFragment.kt
index 470567cca..fd8da7d4c 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseBrowserTvFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseBrowserTvFragment.kt
@@ -60,6 +60,7 @@ import org.videolan.vlc.gui.view.RecyclerSectionItemGridDecoration
import org.videolan.vlc.interfaces.IEventsHandler
import org.videolan.vlc.util.RefreshModel
import org.videolan.vlc.util.getScreenWidth
+import org.videolan.vlc.viewmodels.SortableModel
import org.videolan.vlc.viewmodels.tv.TvBrowserModel
private const val TAG = "MediaBrowserTvFragment"
@@ -250,11 +251,12 @@ abstract class BaseBrowserTvFragment : Fragment(), BrowserFragmentInterface, IEv
fun sort(v: View) {
val menu = PopupMenu(v.context, v)
menu.inflate(R.menu.sort_options)
- menu.menu.findItem(R.id.ml_menu_sortby_filename).isVisible = viewModel.canSortByFileNameName()
- menu.menu.findItem(R.id.ml_menu_sortby_length).isVisible = viewModel.canSortByDuration()
- menu.menu.findItem(R.id.ml_menu_sortby_date).isVisible = viewModel.canSortByInsertionDate() || viewModel.canSortByReleaseDate() || viewModel.canSortByLastModified()
- menu.menu.findItem(R.id.ml_menu_sortby_date).isVisible = viewModel.canSortByReleaseDate()
- menu.menu.findItem(R.id.ml_menu_sortby_last_modified).isVisible = viewModel.canSortByLastModified()
+ val canSortByFileNameName = (viewModel as SortableModel).canSortByFileNameName()
+ menu.menu.findItem(R.id.ml_menu_sortby_filename).isVisible = canSortByFileNameName
+ menu.menu.findItem(R.id.ml_menu_sortby_length).isVisible = (viewModel as SortableModel).canSortByDuration()
+ menu.menu.findItem(R.id.ml_menu_sortby_date).isVisible = (viewModel as SortableModel).canSortByInsertionDate() || (viewModel as SortableModel).canSortByReleaseDate() || (viewModel as SortableModel).canSortByLastModified()
+ menu.menu.findItem(R.id.ml_menu_sortby_date).isVisible = (viewModel as SortableModel).canSortByReleaseDate()
+ menu.menu.findItem(R.id.ml_menu_sortby_last_modified).isVisible = (viewModel as SortableModel).canSortByLastModified()
menu.menu.findItem(R.id.ml_menu_sortby_number).isVisible = false
menu.setOnMenuItemClickListener(this)
menu.show()
@@ -299,7 +301,7 @@ abstract class BaseBrowserTvFragment : Fragment(), BrowserFragmentInterface, IEv
}
}
- private fun sortBy(sort: Int) = viewModel.sort(sort)
+ private fun sortBy(sort: Int) = (viewModel as SortableModel).sort(sort)
override fun onHeaderSelected(header: String) {
hideHeaderSelectionScreen()
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserModel.kt
index f12eab185..c44ed1600 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserModel.kt
@@ -92,6 +92,8 @@ open class BrowserModel(context: Context, val url: String?, type: Int, showHidde
return BrowserModel(context.applicationContext, url, type, showHiddenFiles, showDummyCategory = showDummyCategory) as T
}
}
+
+ override fun canSortByFileNameName(): Boolean = true
}
private val ascComp by lazy {
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/tv/TvBrowserModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/tv/TvBrowserModel.kt
index aebd428cf..2a266fb75 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/tv/TvBrowserModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/tv/TvBrowserModel.kt
@@ -4,12 +4,6 @@ import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.vlc.providers.HeaderProvider
interface TvBrowserModel {
- fun canSortByFileNameName(): Boolean
- fun canSortByDuration(): Boolean
- fun canSortByInsertionDate(): Boolean
- fun canSortByReleaseDate(): Boolean
- fun canSortByLastModified(): Boolean
- fun sort(sort: Int)
var currentItem: MediaLibraryItem?
var nbColumns: Int
More information about the Android
mailing list