Commit 60a65906 authored by Geoffrey Métais's avatar Geoffrey Métais

Folders: Implement FAB

parent 9a458796
Pipeline #4333 passed with stage
in 3 minutes and 45 seconds
...@@ -83,13 +83,18 @@ class FoldersFragment : MediaBrowserFragment<PagedFoldersModel>(), CoroutineScop ...@@ -83,13 +83,18 @@ class FoldersFragment : MediaBrowserFragment<PagedFoldersModel>(), CoroutineScop
mSwipeRefreshLayout.setOnRefreshListener { activity?.reload() } mSwipeRefreshLayout.setOnRefreshListener { activity?.reload() }
} }
override fun onStart() {
super.onStart()
setFabPlayVisibility(true);
mFabPlay.setImageResource(R.drawable.ic_fab_play);
}
override fun getTitle() = getString(R.string.video) override fun getTitle() = getString(R.string.video)
override fun onRefresh() { override fun onRefresh() {
viewModel.refresh() viewModel.refresh()
} }
override fun onPrepareOptionsMenu(menu: Menu) { override fun onPrepareOptionsMenu(menu: Menu) {
super.onPrepareOptionsMenu(menu) super.onPrepareOptionsMenu(menu)
menu.findItem(R.id.ml_menu_last_playlist).isVisible = true menu.findItem(R.id.ml_menu_last_playlist).isVisible = true
...@@ -111,6 +116,10 @@ class FoldersFragment : MediaBrowserFragment<PagedFoldersModel>(), CoroutineScop ...@@ -111,6 +116,10 @@ class FoldersFragment : MediaBrowserFragment<PagedFoldersModel>(), CoroutineScop
} }
} }
override fun onFabPlayClick(view: View?) {
MediaUtils.playAllTracks(context, viewModel, 0, false)
}
override fun onCreateActionMode(mode: ActionMode?, menu: Menu?) : Boolean { override fun onCreateActionMode(mode: ActionMode?, menu: Menu?) : Boolean {
mode?.apply { menuInflater.inflate(R.menu.action_mode_folder, menu) } mode?.apply { menuInflater.inflate(R.menu.action_mode_folder, menu) }
return true return true
...@@ -142,8 +151,6 @@ class FoldersFragment : MediaBrowserFragment<PagedFoldersModel>(), CoroutineScop ...@@ -142,8 +151,6 @@ class FoldersFragment : MediaBrowserFragment<PagedFoldersModel>(), CoroutineScop
mActionMode = null mActionMode = null
adapter.multiSelectHelper.clearSelection() adapter.multiSelectHelper.clearSelection()
} }
override fun hasFAB() = false
} }
sealed class FolderAction sealed class FolderAction
......
...@@ -28,6 +28,7 @@ import org.videolan.vlc.gui.DialogActivity ...@@ -28,6 +28,7 @@ import org.videolan.vlc.gui.DialogActivity
import org.videolan.vlc.gui.dialogs.SubtitleDownloaderDialogFragment import org.videolan.vlc.gui.dialogs.SubtitleDownloaderDialogFragment
import org.videolan.vlc.util.* import org.videolan.vlc.util.*
import org.videolan.vlc.viewmodels.paged.MLPagedModel import org.videolan.vlc.viewmodels.paged.MLPagedModel
import org.videolan.vlc.viewmodels.paged.PagedFoldersModel
import java.util.* import java.util.*
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
import kotlin.math.min import kotlin.math.min
...@@ -194,6 +195,39 @@ object MediaUtils : CoroutineScope { ...@@ -194,6 +195,39 @@ object MediaUtils : CoroutineScope {
} }
} }
fun playAllTracks(context: Context?, model: PagedFoldersModel, position: Int, shuffle: Boolean) {
if (context == null) return
SuspendDialogCallback(context) { service ->
val count = withContext(Dispatchers.IO) { model.getTotalCount() }
fun play(list : List<MediaWrapper>) {
service.load(list, if (shuffle) Random().nextInt(min(count, MEDIALIBRARY_PAGE_SIZE)) else position)
if (shuffle && !service.isShuffling) service.shuffle()
}
when (count) {
0 -> return@SuspendDialogCallback
in 1..MEDIALIBRARY_PAGE_SIZE -> play(withContext(Dispatchers.IO) {
model.getAll().flatMap {
it.media(model.type, Medialibrary.SORT_DEFAULT, false, it.mediaCount(model.type), 0).toList()
}
})
else -> {
var index = 0
while (index < count) {
val pageCount = min(MEDIALIBRARY_PAGE_SIZE, count - index)
val list = withContext(Dispatchers.IO) {
model.getPage(pageCount, index).flatMap {
it.media(model.type, Medialibrary.SORT_DEFAULT, false, it.mediaCount(model.type), 0).toList()
}
}
if (index == 0) play(list)
else service.append(list)
index += pageCount
}
}
}
}
}
@JvmOverloads @JvmOverloads
fun openList(context: Context?, list: List<MediaWrapper>, position: Int, shuffle: Boolean = false) { fun openList(context: Context?, list: List<MediaWrapper>, position: Int, shuffle: Boolean = false) {
if (Util.isListEmpty(list) || context == null) return if (Util.isListEmpty(list) || context == null) return
......
...@@ -16,7 +16,7 @@ class PagedFoldersModel(context: Context, val type: Int) : MLPagedModel<Folder>( ...@@ -16,7 +16,7 @@ class PagedFoldersModel(context: Context, val type: Int) : MLPagedModel<Folder>(
if (medialibrary.isStarted) refresh() if (medialibrary.isStarted) refresh()
} }
override fun getAll() = emptyArray<Folder>() override fun getAll() : Array<Folder> = medialibrary.getFolders(type, sort, desc, getTotalCount(), 0)
override fun getTotalCount() = medialibrary.getFoldersCount(type) override fun getTotalCount() = medialibrary.getFoldersCount(type)
......
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