Commit 1db14d57 authored by Geoffrey Métais's avatar Geoffrey Métais

Videos: Group by name by default

parent 1f6ffd8f
Pipeline #17236 passed with stage
in 3 minutes and 40 seconds
......@@ -136,6 +136,12 @@ const val KEY_FOLDER = "key_folder"
const val KEY_GROUPING = "key_grouping"
const val FAVORITE_TITLE = "favorite_title"
const val KEY_VIDEOS_CARDS = "video_display_in_cards"
const val KEY_GROUP_VIDEOS = "video_min_group_length"
const val GROUP_VIDEOS_NONE = "-1"
const val GROUP_VIDEOS_FOLDER = "0"
const val GROUP_VIDEOS_NAME = "6"
// Items updates
const val UPDATE_SELECTION = 0
const val UPDATE_THUMB = 1
......
......@@ -13,7 +13,7 @@ import org.videolan.tools.Settings.init
@ExperimentalCoroutinesApi
@ObsoleteCoroutinesApi
object Settings : SingletonHolder<SharedPreferences, Context>({ init(it) }) {
object Settings : SingletonHolder<SharedPreferences, Context>({ init(it.applicationContext) }) {
var showVideoThumbs = true
var tvUI = false
......
......@@ -61,7 +61,7 @@ class Navigator : BottomNavigationView.OnNavigationItemSelectedListener, Lifecyc
private val defaultFragmentId= R.id.nav_video
override var currentFragmentId : Int = 0
var currentFragment: Fragment? = null
private var currentFragment: Fragment? = null
private set
private lateinit var activity: MainActivity
private lateinit var settings: SharedPreferences
......@@ -112,22 +112,7 @@ class Navigator : BottomNavigationView.OnNavigationItemSelectedListener, Lifecyc
R.id.nav_playlists -> PlaylistFragment()
R.id.nav_network -> NetworkBrowserFragment()
R.id.nav_more -> MoreFragment()
else -> {
val group = Integer.valueOf(Settings.getInstance(activity.applicationContext).getString("video_min_group_length", "1")!!)
when {
group > 0 -> VideoGridFragment().apply {
arguments = Bundle(1).apply {
putSerializable(KEY_GROUPING, VideoGroupingType.NAME)
}
}
group == 0 -> VideoGridFragment().apply {
arguments = Bundle(1).apply {
putSerializable(KEY_GROUPING, VideoGroupingType.FOLDER)
}
}
else -> VideoGridFragment()
}
}
else -> VideoGridFragment()
}
}
......
......@@ -98,10 +98,14 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
multiSelectHelper = videoListAdapter.multiSelectHelper
val folder = if (savedInstanceState != null) savedInstanceState.getParcelable<Folder>(KEY_FOLDER)
else arguments?.getParcelable(KEY_FOLDER)
val group = if (savedInstanceState != null) savedInstanceState.getParcelable<VideoGroup>(KEY_GROUP)
else arguments?.getParcelable(KEY_GROUP)
val grouping = arguments?.getSerializable(KEY_GROUPING) as VideoGroupingType? ?: VideoGroupingType.NONE
viewModel = getViewModel(grouping, folder, group)
val parentGroup = if (savedInstanceState != null) savedInstanceState.getParcelable<VideoGroup>(KEY_GROUP)
else arguments?.getParcelable(KEY_GROUP)
val grouping = when (Settings.getInstance(requireContext()).getString(KEY_GROUP_VIDEOS, null) ?: GROUP_VIDEOS_NAME) {
GROUP_VIDEOS_NONE -> VideoGroupingType.NONE
GROUP_VIDEOS_FOLDER -> VideoGroupingType.FOLDER
else -> VideoGroupingType.NAME
}
viewModel = getViewModel(grouping, folder, parentGroup)
setDataObservers()
Medialibrary.lastThumb.observe(this, thumbObs)
videoListAdapter.events.onEach { it.process() }.launchWhenStarted(lifecycleScope)
......@@ -141,54 +145,36 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
when (item.itemId) {
R.id.ml_menu_last_playlist -> {
MediaUtils.loadlastPlaylist(activity, PLAYLIST_TYPE_VIDEO)
true
}
R.id.ml_menu_display_list, R.id.ml_menu_display_grid -> {
val displayInCards = settings.getBoolean("video_display_in_cards", true)
settings.putSingle("video_display_in_cards", !displayInCards)
val displayInCards = settings.getBoolean(KEY_VIDEOS_CARDS, true)
settings.putSingle(KEY_VIDEOS_CARDS, !displayInCards)
(activity as ContentActivity).forceLoadVideoFragment()
true
}
R.id.video_min_group_length_disable -> {
lifecycleScope.launchWhenStarted {
withContext(Dispatchers.IO) {
settings.edit().putString("video_min_group_length", "-1").commit()
}
changeGroupingType(VideoGroupingType.NONE)
}
true
settings.putSingle(KEY_GROUP_VIDEOS, GROUP_VIDEOS_NONE)
changeGroupingType(VideoGroupingType.NONE)
}
R.id.video_min_group_length_folder -> {
lifecycleScope.launchWhenStarted {
withContext(Dispatchers.IO) {
settings.edit().putString("video_min_group_length", "0").commit()
}
changeGroupingType(VideoGroupingType.FOLDER)
}
true
settings.putSingle(KEY_GROUP_VIDEOS, GROUP_VIDEOS_FOLDER)
changeGroupingType(VideoGroupingType.FOLDER)
}
R.id.video_min_group_length_name -> {
lifecycleScope.launchWhenStarted {
withContext(Dispatchers.IO) {
settings.edit().putString("video_min_group_length", "6").commit()
}
changeGroupingType(VideoGroupingType.NAME)
}
true
settings.putSingle(KEY_GROUP_VIDEOS, GROUP_VIDEOS_NAME)
changeGroupingType(VideoGroupingType.NAME)
}
R.id.rename_group -> {
viewModel.group?.let { renameGroup(it) }
true
}
R.id.ungroup -> {
viewModel.group?.let { viewModel.ungroup(it) }
true
}
else -> super.onOptionsItemSelected(item)
else -> return super.onOptionsItemSelected(item)
}
return true
}
override fun sortBy(sort: Int) {
......@@ -270,9 +256,8 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
return
}
val res = resources
if (gridItemDecoration == null)
gridItemDecoration = ItemOffsetDecoration(resources, R.dimen.left_right_1610_margin, R.dimen.top_bottom_1610_margin)
val listMode = !settings.getBoolean("video_display_in_cards", true)
if (gridItemDecoration == null) gridItemDecoration = ItemOffsetDecoration(resources, R.dimen.left_right_1610_margin, R.dimen.top_bottom_1610_margin)
val listMode = !settings.getBoolean(KEY_VIDEOS_CARDS, true)
// Select between grid or list
binding.videoGrid.removeItemDecoration(gridItemDecoration!!)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment