mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 14:20:30 +05:30
Merge pull request #4752 from Bnyro/master
fix: crash when deleting playlist, playlist description not shown
This commit is contained in:
commit
34261bfe4b
@ -45,6 +45,7 @@ class PlaylistsAdapter(
|
||||
ImageHelper.loadImage(playlist.thumbnail, playlistThumbnail)
|
||||
}
|
||||
playlistTitle.text = playlist.name
|
||||
playlistDescription.text = playlist.shortDescription
|
||||
|
||||
videoCount.text = playlist.videos.toString()
|
||||
|
||||
|
@ -1,10 +1,12 @@
|
||||
package com.github.libretube.ui.dialogs
|
||||
|
||||
import android.app.AlertDialog
|
||||
import android.app.Dialog
|
||||
import android.os.Bundle
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.fragment.app.setFragmentResult
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.api.PlaylistsHelper
|
||||
import com.github.libretube.constants.IntentData
|
||||
@ -16,6 +18,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
class DeletePlaylistDialog : DialogFragment() {
|
||||
private lateinit var playlistId: String
|
||||
@ -31,20 +34,23 @@ class DeletePlaylistDialog : DialogFragment() {
|
||||
return MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(R.string.deletePlaylist)
|
||||
.setMessage(R.string.areYouSure)
|
||||
.setPositiveButton(R.string.yes) { _, _ ->
|
||||
val appContext = context?.applicationContext
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
val success = PlaylistsHelper.deletePlaylist(playlistId, playlistType)
|
||||
appContext?.toastFromMainDispatcher(
|
||||
if (success) R.string.success else R.string.fail
|
||||
)
|
||||
setFragmentResult(
|
||||
PlaylistOptionsBottomSheet.PLAYLIST_OPTIONS_REQUEST_KEY,
|
||||
bundleOf(IntentData.playlistTask to true)
|
||||
)
|
||||
}
|
||||
}
|
||||
.setPositiveButton(R.string.yes, null)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.show()
|
||||
.apply {
|
||||
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
val success = PlaylistsHelper.deletePlaylist(playlistId, playlistType)
|
||||
context.toastFromMainDispatcher(
|
||||
if (success) R.string.success else R.string.fail
|
||||
)
|
||||
setFragmentResult(
|
||||
PlaylistOptionsBottomSheet.PLAYLIST_OPTIONS_REQUEST_KEY,
|
||||
bundleOf(IntentData.playlistTask to true)
|
||||
)
|
||||
withContext(Dispatchers.Main) { dismiss() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user