mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 07:50:31 +05:30
Merge pull request #5341 from Bnyro/master
refactor: base option sheets selections on their string resource ids
This commit is contained in:
commit
8a86e60065
@ -37,15 +37,15 @@ class ChannelOptionsBottomSheet : BaseBottomSheet() {
|
||||
|
||||
// List that stores the different menu options. In the future could be add more options here.
|
||||
val optionsList = mutableListOf(
|
||||
getString(R.string.share),
|
||||
getString(R.string.play_latest_videos),
|
||||
getString(R.string.playOnBackground)
|
||||
R.string.share,
|
||||
R.string.play_latest_videos,
|
||||
R.string.playOnBackground
|
||||
)
|
||||
if (subscribed) optionsList.add(getString(R.string.add_to_group))
|
||||
if (subscribed) optionsList.add(R.string.add_to_group)
|
||||
|
||||
setSimpleItems(optionsList) { which ->
|
||||
setSimpleItems(optionsList.map { getString(it) }) { which ->
|
||||
when (optionsList[which]) {
|
||||
getString(R.string.share) -> {
|
||||
R.string.share -> {
|
||||
val bundle = bundleOf(
|
||||
IntentData.id to channelId,
|
||||
IntentData.shareObjectType to ShareObjectType.CHANNEL,
|
||||
@ -56,14 +56,14 @@ class ChannelOptionsBottomSheet : BaseBottomSheet() {
|
||||
newShareDialog.show(parentFragmentManager, null)
|
||||
}
|
||||
|
||||
getString(R.string.add_to_group) -> {
|
||||
R.string.add_to_group -> {
|
||||
val sheet = AddChannelToGroupSheet().apply {
|
||||
arguments = bundleOf(IntentData.channelId to channelId)
|
||||
}
|
||||
sheet.show(parentFragmentManager, null)
|
||||
}
|
||||
|
||||
getString(R.string.play_latest_videos) -> {
|
||||
R.string.play_latest_videos -> {
|
||||
try {
|
||||
val channel = withContext(Dispatchers.IO) {
|
||||
RetrofitInstance.api.getChannel(channelId)
|
||||
@ -80,7 +80,7 @@ class ChannelOptionsBottomSheet : BaseBottomSheet() {
|
||||
}
|
||||
}
|
||||
|
||||
getString(R.string.playOnBackground) -> {
|
||||
R.string.playOnBackground -> {
|
||||
try {
|
||||
val channel = withContext(Dispatchers.IO) {
|
||||
RetrofitInstance.api.getChannel(channelId)
|
||||
|
@ -22,22 +22,22 @@ class DownloadOptionsBottomSheet : BaseBottomSheet() {
|
||||
R.string.go_to_video,
|
||||
R.string.share,
|
||||
R.string.delete
|
||||
).map { getString(it) }
|
||||
)
|
||||
|
||||
setSimpleItems(options) { selectedIndex ->
|
||||
when (selectedIndex) {
|
||||
0 -> {
|
||||
setSimpleItems(options.map { getString(it) }) { which ->
|
||||
when (options[which]) {
|
||||
R.string.playOnBackground -> {
|
||||
val playerIntent = Intent(requireContext(), OfflinePlayerService::class.java)
|
||||
.putExtra(IntentData.videoId, videoId)
|
||||
context?.stopService(playerIntent)
|
||||
ContextCompat.startForegroundService(requireContext(), playerIntent)
|
||||
}
|
||||
|
||||
1 -> {
|
||||
R.string.go_to_video -> {
|
||||
NavigationHelper.navigateVideo(requireContext(), videoId = videoId)
|
||||
}
|
||||
|
||||
2 -> {
|
||||
R.string.share -> {
|
||||
val shareData = ShareData(currentVideo = videoId)
|
||||
val bundle = bundleOf(
|
||||
IntentData.id to videoId,
|
||||
@ -49,7 +49,7 @@ class DownloadOptionsBottomSheet : BaseBottomSheet() {
|
||||
newShareDialog.show(parentFragmentManager, null)
|
||||
}
|
||||
|
||||
3 -> {
|
||||
R.string.delete -> {
|
||||
setFragmentResult(DELETE_DOWNLOAD_REQUEST_KEY, bundleOf())
|
||||
dialog?.dismiss()
|
||||
}
|
||||
|
@ -39,36 +39,32 @@ class PlaylistOptionsBottomSheet : BaseBottomSheet() {
|
||||
setTitle(playlistName)
|
||||
|
||||
// options for the dialog
|
||||
val optionsList = mutableListOf(
|
||||
getString(R.string.playOnBackground)
|
||||
)
|
||||
val optionsList = mutableListOf(R.string.playOnBackground)
|
||||
|
||||
if (PlayingQueue.isNotEmpty()) optionsList.add(getString(R.string.add_to_queue))
|
||||
if (PlayingQueue.isNotEmpty()) optionsList.add(R.string.add_to_queue)
|
||||
|
||||
val isBookmarked = runBlocking(Dispatchers.IO) {
|
||||
DatabaseHolder.Database.playlistBookmarkDao().includes(playlistId)
|
||||
}
|
||||
|
||||
if (playlistType == PlaylistType.PUBLIC) {
|
||||
optionsList.add(getString(R.string.share))
|
||||
optionsList.add(getString(R.string.clonePlaylist))
|
||||
optionsList.add(R.string.share)
|
||||
optionsList.add(R.string.clonePlaylist)
|
||||
|
||||
// only add the bookmark option to the playlist if public
|
||||
optionsList.add(
|
||||
getString(if (isBookmarked) R.string.remove_bookmark else R.string.add_to_bookmarks)
|
||||
)
|
||||
optionsList.add(if (isBookmarked) R.string.remove_bookmark else R.string.add_to_bookmarks)
|
||||
} else {
|
||||
optionsList.add(getString(R.string.renamePlaylist))
|
||||
optionsList.add(getString(R.string.change_playlist_description))
|
||||
optionsList.add(getString(R.string.deletePlaylist))
|
||||
optionsList.add(R.string.renamePlaylist)
|
||||
optionsList.add(R.string.change_playlist_description)
|
||||
optionsList.add(R.string.deletePlaylist)
|
||||
}
|
||||
|
||||
setSimpleItems(optionsList) { which ->
|
||||
setSimpleItems(optionsList.map { getString(it) }) { which ->
|
||||
val mFragmentManager = (context as BaseActivity).supportFragmentManager
|
||||
|
||||
when (optionsList[which]) {
|
||||
// play the playlist in the background
|
||||
getString(R.string.playOnBackground) -> {
|
||||
R.string.playOnBackground -> {
|
||||
val playlist = withContext(Dispatchers.IO) {
|
||||
PlaylistsHelper.getPlaylist(playlistId)
|
||||
}
|
||||
@ -81,11 +77,11 @@ class PlaylistOptionsBottomSheet : BaseBottomSheet() {
|
||||
}
|
||||
}
|
||||
|
||||
getString(R.string.add_to_queue) -> {
|
||||
R.string.add_to_queue -> {
|
||||
PlayingQueue.insertPlaylist(playlistId, null)
|
||||
}
|
||||
// Clone the playlist to the users Piped account
|
||||
getString(R.string.clonePlaylist) -> {
|
||||
R.string.clonePlaylist -> {
|
||||
val context = requireContext()
|
||||
val playlistId = withContext(Dispatchers.IO) {
|
||||
runCatching {
|
||||
@ -97,7 +93,7 @@ class PlaylistOptionsBottomSheet : BaseBottomSheet() {
|
||||
)
|
||||
}
|
||||
// share the playlist
|
||||
getString(R.string.share) -> {
|
||||
R.string.share -> {
|
||||
val newShareDialog = ShareDialog()
|
||||
newShareDialog.arguments = bundleOf(
|
||||
IntentData.id to playlistId,
|
||||
@ -108,7 +104,7 @@ class PlaylistOptionsBottomSheet : BaseBottomSheet() {
|
||||
newShareDialog.show(parentFragmentManager, ShareDialog::class.java.name)
|
||||
}
|
||||
|
||||
getString(R.string.deletePlaylist) -> {
|
||||
R.string.deletePlaylist -> {
|
||||
val newDeletePlaylistDialog = DeletePlaylistDialog()
|
||||
newDeletePlaylistDialog.arguments = bundleOf(
|
||||
IntentData.playlistId to playlistId,
|
||||
@ -117,7 +113,7 @@ class PlaylistOptionsBottomSheet : BaseBottomSheet() {
|
||||
newDeletePlaylistDialog.show(mFragmentManager, null)
|
||||
}
|
||||
|
||||
getString(R.string.renamePlaylist) -> {
|
||||
R.string.renamePlaylist -> {
|
||||
val newRenamePlaylistDialog = RenamePlaylistDialog()
|
||||
newRenamePlaylistDialog.arguments = bundleOf(
|
||||
IntentData.playlistId to playlistId,
|
||||
@ -126,7 +122,7 @@ class PlaylistOptionsBottomSheet : BaseBottomSheet() {
|
||||
newRenamePlaylistDialog.show(mFragmentManager, null)
|
||||
}
|
||||
|
||||
getString(R.string.change_playlist_description) -> {
|
||||
R.string.change_playlist_description -> {
|
||||
val newPlaylistDescriptionDialog = PlaylistDescriptionDialog()
|
||||
newPlaylistDescriptionDialog.arguments = bundleOf(
|
||||
IntentData.playlistId to playlistId,
|
||||
|
@ -46,26 +46,22 @@ class VideoOptionsBottomSheet : BaseBottomSheet() {
|
||||
|
||||
setTitle(streamItem.title)
|
||||
|
||||
val optionsList = mutableListOf<String>()
|
||||
val optionsList = mutableListOf<Int>()
|
||||
if (!isCurrentlyPlaying) {
|
||||
optionsList += getOptionsForNotActivePlayback(videoId)
|
||||
}
|
||||
|
||||
optionsList += listOf(
|
||||
getString(R.string.addToPlaylist),
|
||||
getString(R.string.download),
|
||||
getString(R.string.share)
|
||||
)
|
||||
optionsList += listOf(R.string.addToPlaylist, R.string.download, R.string.share)
|
||||
|
||||
setSimpleItems(optionsList) { which ->
|
||||
setSimpleItems(optionsList.map { getString(it) }) { which ->
|
||||
when (optionsList[which]) {
|
||||
// Start the background mode
|
||||
getString(R.string.playOnBackground) -> {
|
||||
R.string.playOnBackground -> {
|
||||
BackgroundHelper.playOnBackground(requireContext(), videoId)
|
||||
NavigationHelper.startAudioPlayer(requireContext(), true)
|
||||
}
|
||||
// Add Video to Playlist Dialog
|
||||
getString(R.string.addToPlaylist) -> {
|
||||
R.string.addToPlaylist -> {
|
||||
val newAddToPlaylistDialog = AddToPlaylistDialog()
|
||||
newAddToPlaylistDialog.arguments = bundleOf(IntentData.videoId to videoId)
|
||||
newAddToPlaylistDialog.show(
|
||||
@ -74,13 +70,13 @@ class VideoOptionsBottomSheet : BaseBottomSheet() {
|
||||
)
|
||||
}
|
||||
|
||||
getString(R.string.download) -> {
|
||||
R.string.download -> {
|
||||
val newFragment = DownloadDialog()
|
||||
newFragment.arguments = bundleOf(IntentData.videoId to videoId)
|
||||
newFragment.show(parentFragmentManager, DownloadDialog::class.java.name)
|
||||
}
|
||||
|
||||
getString(R.string.share) -> {
|
||||
R.string.share -> {
|
||||
val bundle = bundleOf(
|
||||
IntentData.id to videoId,
|
||||
IntentData.shareObjectType to ShareObjectType.VIDEO,
|
||||
@ -92,15 +88,15 @@ class VideoOptionsBottomSheet : BaseBottomSheet() {
|
||||
newShareDialog.show(parentFragmentManager, ShareDialog::class.java.name)
|
||||
}
|
||||
|
||||
getString(R.string.play_next) -> {
|
||||
R.string.play_next -> {
|
||||
PlayingQueue.addAsNext(streamItem)
|
||||
}
|
||||
|
||||
getString(R.string.add_to_queue) -> {
|
||||
R.string.add_to_queue -> {
|
||||
PlayingQueue.add(streamItem)
|
||||
}
|
||||
|
||||
getString(R.string.mark_as_watched) -> {
|
||||
R.string.mark_as_watched -> {
|
||||
val watchPosition = WatchPosition(videoId, Long.MAX_VALUE)
|
||||
withContext(Dispatchers.IO) {
|
||||
DatabaseHolder.Database.watchPositionDao().insert(watchPosition)
|
||||
@ -120,7 +116,7 @@ class VideoOptionsBottomSheet : BaseBottomSheet() {
|
||||
setFragmentResult(VIDEO_OPTIONS_SHEET_REQUEST_KEY, bundleOf())
|
||||
}
|
||||
|
||||
getString(R.string.mark_as_unwatched) -> {
|
||||
R.string.mark_as_unwatched -> {
|
||||
withContext(Dispatchers.IO) {
|
||||
DatabaseHolder.Database.watchPositionDao().deleteByVideoId(videoId)
|
||||
DatabaseHolder.Database.watchHistoryDao().deleteByVideoId(videoId)
|
||||
@ -133,16 +129,14 @@ class VideoOptionsBottomSheet : BaseBottomSheet() {
|
||||
super.onCreate(savedInstanceState)
|
||||
}
|
||||
|
||||
private fun getOptionsForNotActivePlayback(videoId: String): List<String> {
|
||||
private fun getOptionsForNotActivePlayback(videoId: String): List<Int> {
|
||||
// List that stores the different menu options. In the future could be add more options here.
|
||||
val optionsList = mutableListOf(
|
||||
getString(R.string.playOnBackground)
|
||||
)
|
||||
val optionsList = mutableListOf(R.string.playOnBackground)
|
||||
|
||||
// Check whether the player is running and add queue options
|
||||
if (PlayingQueue.isNotEmpty()) {
|
||||
optionsList += getString(R.string.play_next)
|
||||
optionsList += getString(R.string.add_to_queue)
|
||||
optionsList += R.string.play_next
|
||||
optionsList += R.string.add_to_queue
|
||||
}
|
||||
|
||||
// show the mark as watched or unwatched option if watch positions are enabled
|
||||
@ -158,11 +152,11 @@ class VideoOptionsBottomSheet : BaseBottomSheet() {
|
||||
watchPositionEntry == null ||
|
||||
watchPositionEntry.position < streamItem.duration!! * 1000 * 0.9
|
||||
) {
|
||||
optionsList += getString(R.string.mark_as_watched)
|
||||
optionsList += R.string.mark_as_watched
|
||||
}
|
||||
|
||||
if (watchHistoryEntry != null || watchPositionEntry != null) {
|
||||
optionsList += getString(R.string.mark_as_unwatched)
|
||||
optionsList += R.string.mark_as_unwatched
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user