[Android] Any video and group combination can now be added to a group
Nicolas Pomepuy
git at videolan.org
Thu Nov 12 18:23:08 CET 2020
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Nov 12 13:48:58 2020 +0100| [17dd130670c2c4553e8b74f2621cd75bb58d59f4] | committer: Nicolas Pomepuy
Any video and group combination can now be added to a group
Fixes #1505
> https://code.videolan.org/videolan/vlc-android/commit/17dd130670c2c4553e8b74f2621cd75bb58d59f4
---
.../src/org/videolan/vlc/gui/dialogs/AddToGroupDialog.kt | 11 ++++++++++-
.../vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt | 4 ++--
.../src/org/videolan/vlc/gui/video/VideoGridFragment.kt | 9 ++-------
3 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/AddToGroupDialog.kt b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/AddToGroupDialog.kt
index b798e6145..bfe4559dc 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/AddToGroupDialog.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/AddToGroupDialog.kt
@@ -56,6 +56,7 @@ class AddToGroupDialog : VLCBottomSheetDialogFragment(), SimpleAdapter.ClickHand
override fun needToManageOrientation(): Boolean = false
+ private var forbidNewGroup: Boolean = true
lateinit var newGroupListener: () -> Unit
private var isLoading: Boolean = false
set(value) {
@@ -87,6 +88,13 @@ class AddToGroupDialog : VLCBottomSheetDialogFragment(), SimpleAdapter.ClickHand
} catch (e: Exception) {
emptyArray()
}
+
+ forbidNewGroup = try {
+ @Suppress("UNCHECKED_CAST")
+ requireArguments().getBoolean(FORBID_NEW_GROUP)
+ } catch (e: Exception) {
+ true
+ }
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
@@ -108,7 +116,7 @@ class AddToGroupDialog : VLCBottomSheetDialogFragment(), SimpleAdapter.ClickHand
adapter.submitList(it.filter { group -> group is VideoGroup && group.mediaCount() > 1 }.apply {
forEach { mediaLibraryItem -> mediaLibraryItem.description = resources.getQuantityString(R.plurals.media_quantity, mediaLibraryItem.tracksCount, mediaLibraryItem.tracksCount) }
}.toMutableList().apply {
- if (newTrack.size > 1) {
+ if (newTrack.size > 1 && !forbidNewGroup) {
this.add(0, DummyItem(DUMMY_NEW_GROUP, getString(R.string.new_group), getString(R.string.new_group_desc)))
}
})
@@ -161,6 +169,7 @@ class AddToGroupDialog : VLCBottomSheetDialogFragment(), SimpleAdapter.ClickHand
val TAG = "VLC/SavePlaylistDialog"
const val KEY_TRACKS = "ADD_TO_GROUP_TRACKS"
+ const val FORBID_NEW_GROUP = "FORBID_NEW_GROUP"
}
}
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 6402d592c..d2d09ee09 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
@@ -366,10 +366,10 @@ object UiTools {
savePlaylistDialog.show(supportFragmentManager, "fragment_add_to_playlist")
}
- fun FragmentActivity.addToGroup(tracks: List<MediaWrapper>, newGroupListener: ()->Unit) {
+ fun FragmentActivity.addToGroup(tracks: List<MediaWrapper>, forbidNewGroup:Boolean , newGroupListener: ()->Unit) {
if (!isStarted()) return
val addToGroupDialog = AddToGroupDialog()
- addToGroupDialog.arguments = bundleOf(AddToGroupDialog.KEY_TRACKS to tracks.toTypedArray())
+ addToGroupDialog.arguments = bundleOf(AddToGroupDialog.KEY_TRACKS to tracks.toTypedArray(), AddToGroupDialog.FORBID_NEW_GROUP to forbidNewGroup)
addToGroupDialog.show(supportFragmentManager, "fragment_add_to_group")
addToGroupDialog.newGroupListener = newGroupListener
}
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt
index 59a2805e4..272082ffd 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt
@@ -328,7 +328,6 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
menu.findItem(R.id.action_ungroup).isVisible = !multiSelectHelper.getSelection().any { it !is VideoGroup }
menu.findItem(R.id.action_rename).isVisible = count == 1 && !multiSelectHelper.getSelection().any { it !is VideoGroup }
menu.findItem(R.id.action_group_similar).isVisible = count == 1 && multiSelectHelper.getSelection().filterIsInstance<VideoGroup>().isEmpty()
- menu.findItem(R.id.action_add_to_group).isVisible = multiSelectHelper.getSelection().filterIsInstance<VideoGroup>().isEmpty()
}
else -> {}
}
@@ -346,10 +345,6 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
R.id.action_video_append -> MediaUtils.appendMedia(activity, list)
R.id.action_video_share -> requireActivity().share(list)
R.id.action_video_info -> showInfoDialog(list[0])
- // case R.id.action_video_delete:
- // for (int position : rowsAdapter.getSelectedPositions())
- // removeVideo(position, rowsAdapter.getItem(position));
- // break;
R.id.action_video_download_subtitles -> MediaUtils.getSubs(requireActivity(), list)
R.id.action_video_play_audio -> {
for (media in list) media.addFlags(MediaWrapper.MEDIA_FORCE_AUDIO)
@@ -398,7 +393,7 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
}
private fun addToGroup(selection: List<MediaLibraryItem>) {
- requireActivity().addToGroup(selection.getAll()) {
+ requireActivity().addToGroup(selection.getAll(), selection.size == 1) {
lifecycleScope.launch {
viewModel.createGroup(selection.getAll())?.let {
// we already are in a group. Finishing to avoid stacking multiple group activities
@@ -444,7 +439,7 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
}
CTX_SHARE -> lifecycleScope.launch { (requireActivity() as AppCompatActivity).share(media) }
CTX_REMOVE_GROUP -> viewModel.removeFromGroup(media)
- CTX_ADD_GROUP -> requireActivity().addToGroup(listOf(media)) {}
+ CTX_ADD_GROUP -> requireActivity().addToGroup(listOf(media), true) {}
CTX_GROUP_SIMILAR -> lifecycleScope.launch { viewModel.groupSimilar(media) }
CTX_MARK_AS_PLAYED -> lifecycleScope.launch { viewModel.markAsPlayed(media) }
}
More information about the Android
mailing list