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