mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
Merge pull request #4742 from Bnyro/master
fix: issues with fragment result listener
This commit is contained in:
commit
5e2e6069f1
@ -23,7 +23,6 @@ object IntentData {
|
||||
const val currentPosition = "currentPosition"
|
||||
const val duration = "duration"
|
||||
const val updateInfo = "updateInfo"
|
||||
const val requestKey = "requestKey"
|
||||
const val backupFile = "backupFile"
|
||||
const val playlistTask = "playlistTask"
|
||||
const val loginTask = "loginTask"
|
||||
|
@ -54,7 +54,7 @@ class PlaylistsAdapter(
|
||||
|
||||
val fragmentManager = (root.context as BaseActivity).supportFragmentManager
|
||||
fragmentManager.setFragmentResultListener(
|
||||
IntentData.requestKey,
|
||||
PLAYLISTS_ADAPTER_REQUEST_KEY,
|
||||
(root.context as BaseActivity)
|
||||
) { _, resultBundle ->
|
||||
val newPlaylistDescription =
|
||||
@ -102,4 +102,8 @@ class PlaylistsAdapter(
|
||||
notifyItemRangeChanged(position, itemCount)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val PLAYLISTS_ADAPTER_REQUEST_KEY = "playlists_adapter_request_key"
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ class AddToPlaylistDialog : DialogFragment() {
|
||||
val binding = DialogAddToPlaylistBinding.inflate(layoutInflater)
|
||||
|
||||
childFragmentManager.setFragmentResultListener(
|
||||
IntentData.requestKey,
|
||||
ADD_TO_PLAYLIST_DIALOG_REQUEST_KEY,
|
||||
this
|
||||
) { _, resultBundle ->
|
||||
val addedToPlaylist = resultBundle.getBoolean(IntentData.playlistTask)
|
||||
@ -128,4 +128,8 @@ class AddToPlaylistDialog : DialogFragment() {
|
||||
appContext.toastFromMainDispatcher(R.string.fail)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val ADD_TO_PLAYLIST_DIALOG_REQUEST_KEY = "add_to_playlist_dialog_request_key"
|
||||
}
|
||||
}
|
||||
|
@ -102,14 +102,16 @@ class BackupDialog : DialogFragment() {
|
||||
if (selected[index]) option.onSelected(backupFile)
|
||||
}
|
||||
val encodedBackupFile = Json.encodeToString(backupFile)
|
||||
withContext(Dispatchers.Main) {
|
||||
setFragmentResult(
|
||||
IntentData.requestKey,
|
||||
BACKUP_DIALOG_REQUEST_KEY,
|
||||
bundleOf(IntentData.backupFile to encodedBackupFile)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
.create()
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val BACKUP_DIALOG_REQUEST_KEY = "backup_dialog_request_key"
|
||||
}
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ class ColorPickerDialog : DialogFragment(), SeekBar.OnSeekBarChangeListener {
|
||||
.setPositiveButton(R.string.okay) { _, _ ->
|
||||
val color = getColor()
|
||||
setFragmentResult(
|
||||
IntentData.requestKey,
|
||||
COLOR_PICKER_REQUEST_KEY,
|
||||
bundleOf(IntentData.color to color)
|
||||
)
|
||||
}
|
||||
@ -142,4 +142,8 @@ class ColorPickerDialog : DialogFragment(), SeekBar.OnSeekBarChangeListener {
|
||||
private fun colorToString(color: Int): String {
|
||||
return String.format("#%08X", color)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val COLOR_PICKER_REQUEST_KEY = "color_picker_request_key"
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ class CreatePlaylistDialog : DialogFragment() {
|
||||
}
|
||||
if (playlistId != null) {
|
||||
setFragmentResult(
|
||||
IntentData.requestKey,
|
||||
CREATE_PLAYLIST_DIALOG_REQUEST_KEY,
|
||||
bundleOf(IntentData.playlistTask to true)
|
||||
)
|
||||
}
|
||||
@ -72,7 +72,7 @@ class CreatePlaylistDialog : DialogFragment() {
|
||||
)
|
||||
playlistId?.let {
|
||||
setFragmentResult(
|
||||
IntentData.requestKey,
|
||||
CREATE_PLAYLIST_DIALOG_REQUEST_KEY,
|
||||
bundleOf(IntentData.playlistTask to true)
|
||||
)
|
||||
}
|
||||
@ -87,4 +87,8 @@ class CreatePlaylistDialog : DialogFragment() {
|
||||
.setView(binding.root)
|
||||
.show()
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val CREATE_PLAYLIST_DIALOG_REQUEST_KEY = "create_playlist_dialog_request_key"
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import com.github.libretube.constants.IntentData
|
||||
import com.github.libretube.databinding.DialogDeleteAccountBinding
|
||||
import com.github.libretube.extensions.TAG
|
||||
import com.github.libretube.helpers.PreferenceHelper
|
||||
import com.github.libretube.ui.preferences.InstanceSettings
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
@ -61,7 +62,7 @@ class DeleteAccountDialog : DialogFragment() {
|
||||
Toast.makeText(context, R.string.success, Toast.LENGTH_SHORT).show()
|
||||
|
||||
setFragmentResult(
|
||||
IntentData.requestKey,
|
||||
InstanceSettings.INSTANCE_DIALOG_REQUEST_KEY,
|
||||
bundleOf(IntentData.logoutTask to true)
|
||||
)
|
||||
dialog?.dismiss()
|
||||
|
@ -11,6 +11,7 @@ import com.github.libretube.constants.IntentData
|
||||
import com.github.libretube.enums.PlaylistType
|
||||
import com.github.libretube.extensions.serializable
|
||||
import com.github.libretube.extensions.toastFromMainDispatcher
|
||||
import com.github.libretube.ui.sheets.PlaylistOptionsBottomSheet
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@ -38,14 +39,12 @@ class DeletePlaylistDialog : DialogFragment() {
|
||||
appContext?.toastFromMainDispatcher(
|
||||
if (success) R.string.success else R.string.fail
|
||||
)
|
||||
withContext(Dispatchers.Main) {
|
||||
setFragmentResult(
|
||||
IntentData.requestKey,
|
||||
PlaylistOptionsBottomSheet.PLAYLIST_OPTIONS_REQUEST_KEY,
|
||||
bundleOf(IntentData.playlistTask to true)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.show()
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ import com.github.libretube.databinding.DialogLoginBinding
|
||||
import com.github.libretube.extensions.TAG
|
||||
import com.github.libretube.extensions.toastFromMainDispatcher
|
||||
import com.github.libretube.helpers.PreferenceHelper
|
||||
import com.github.libretube.ui.preferences.InstanceSettings.Companion.INSTANCE_DIALOG_REQUEST_KEY
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
@ -100,7 +101,7 @@ class LoginDialog : DialogFragment() {
|
||||
|
||||
withContext(Dispatchers.Main) {
|
||||
setFragmentResult(
|
||||
IntentData.requestKey,
|
||||
INSTANCE_DIALOG_REQUEST_KEY,
|
||||
bundleOf(IntentData.loginTask to true)
|
||||
)
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import com.github.libretube.R
|
||||
import com.github.libretube.constants.IntentData
|
||||
import com.github.libretube.databinding.DialogLogoutBinding
|
||||
import com.github.libretube.helpers.PreferenceHelper
|
||||
import com.github.libretube.ui.preferences.InstanceSettings
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
|
||||
class LogoutDialog : DialogFragment() {
|
||||
@ -25,7 +26,7 @@ class LogoutDialog : DialogFragment() {
|
||||
Toast.makeText(context, R.string.loggedout, Toast.LENGTH_SHORT).show()
|
||||
|
||||
setFragmentResult(
|
||||
IntentData.requestKey,
|
||||
InstanceSettings.INSTANCE_DIALOG_REQUEST_KEY,
|
||||
bundleOf(IntentData.logoutTask to true)
|
||||
)
|
||||
dialog?.dismiss()
|
||||
|
@ -16,6 +16,7 @@ import com.github.libretube.constants.IntentData
|
||||
import com.github.libretube.databinding.DialogTextPreferenceBinding
|
||||
import com.github.libretube.extensions.TAG
|
||||
import com.github.libretube.extensions.toastFromMainDispatcher
|
||||
import com.github.libretube.ui.sheets.PlaylistOptionsBottomSheet.Companion.PLAYLIST_OPTIONS_REQUEST_KEY
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
@ -79,7 +80,7 @@ class PlaylistDescriptionDialog : DialogFragment() {
|
||||
if (success) {
|
||||
appContext.toastFromMainDispatcher(R.string.success)
|
||||
setFragmentResult(
|
||||
IntentData.requestKey,
|
||||
PLAYLIST_OPTIONS_REQUEST_KEY,
|
||||
bundleOf(IntentData.playlistDescription to newDescription)
|
||||
)
|
||||
} else {
|
||||
|
@ -16,6 +16,7 @@ import com.github.libretube.constants.IntentData
|
||||
import com.github.libretube.databinding.DialogTextPreferenceBinding
|
||||
import com.github.libretube.extensions.TAG
|
||||
import com.github.libretube.extensions.toastFromMainDispatcher
|
||||
import com.github.libretube.ui.sheets.PlaylistOptionsBottomSheet.Companion.PLAYLIST_OPTIONS_REQUEST_KEY
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
@ -72,7 +73,7 @@ class RenamePlaylistDialog : DialogFragment() {
|
||||
if (success) {
|
||||
appContext.toastFromMainDispatcher(R.string.success)
|
||||
setFragmentResult(
|
||||
IntentData.requestKey,
|
||||
PLAYLIST_OPTIONS_REQUEST_KEY,
|
||||
bundleOf(IntentData.playlistName to newPlaylistName)
|
||||
)
|
||||
} else {
|
||||
|
@ -32,6 +32,7 @@ import com.github.libretube.helpers.PreferenceHelper
|
||||
import com.github.libretube.ui.adapters.PlaylistBookmarkAdapter
|
||||
import com.github.libretube.ui.adapters.PlaylistsAdapter
|
||||
import com.github.libretube.ui.dialogs.CreatePlaylistDialog
|
||||
import com.github.libretube.ui.dialogs.CreatePlaylistDialog.Companion.CREATE_PLAYLIST_DIALOG_REQUEST_KEY
|
||||
import com.github.libretube.ui.models.PlayerViewModel
|
||||
import com.github.libretube.ui.sheets.BaseBottomSheet
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@ -95,7 +96,7 @@ class LibraryFragment : Fragment() {
|
||||
}
|
||||
|
||||
childFragmentManager.setFragmentResultListener(
|
||||
IntentData.requestKey,
|
||||
CREATE_PLAYLIST_DIALOG_REQUEST_KEY,
|
||||
this
|
||||
) { _, resultBundle ->
|
||||
val isPlaylistCreated = resultBundle.getBoolean(IntentData.playlistTask)
|
||||
|
@ -14,6 +14,7 @@ import com.github.libretube.helpers.ImportHelper
|
||||
import com.github.libretube.obj.BackupFile
|
||||
import com.github.libretube.ui.base.BasePreferenceFragment
|
||||
import com.github.libretube.ui.dialogs.BackupDialog
|
||||
import com.github.libretube.ui.dialogs.BackupDialog.Companion.BACKUP_DIALOG_REQUEST_KEY
|
||||
import com.github.libretube.ui.dialogs.RequireRestartDialog
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import java.time.LocalDateTime
|
||||
@ -178,7 +179,7 @@ class BackupRestoreSettings : BasePreferenceFragment() {
|
||||
}
|
||||
|
||||
childFragmentManager.setFragmentResultListener(
|
||||
IntentData.requestKey,
|
||||
BACKUP_DIALOG_REQUEST_KEY,
|
||||
this
|
||||
) { _, resultBundle ->
|
||||
val encodedBackupFile = resultBundle.getString(IntentData.backupFile)!!
|
||||
|
@ -102,7 +102,7 @@ class InstanceSettings : BasePreferenceFragment() {
|
||||
deleteAccount?.isEnabled = token.isNotEmpty()
|
||||
|
||||
childFragmentManager.setFragmentResultListener(
|
||||
IntentData.requestKey,
|
||||
INSTANCE_DIALOG_REQUEST_KEY,
|
||||
this
|
||||
) { _, resultBundle ->
|
||||
val isLoggedIn = resultBundle.getBoolean(IntentData.loginTask)
|
||||
@ -170,4 +170,8 @@ class InstanceSettings : BasePreferenceFragment() {
|
||||
findPreference<Preference>(PreferenceKeys.LOGOUT)?.isVisible = false
|
||||
findPreference<Preference>(PreferenceKeys.DELETE_ACCOUNT)?.isEnabled = false
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val INSTANCE_DIALOG_REQUEST_KEY = "instance_dialog_request_key"
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import com.github.libretube.extensions.toID
|
||||
import com.github.libretube.extensions.toastFromMainDispatcher
|
||||
import com.github.libretube.helpers.BackgroundHelper
|
||||
import com.github.libretube.obj.ShareData
|
||||
import com.github.libretube.ui.adapters.PlaylistsAdapter.Companion.PLAYLISTS_ADAPTER_REQUEST_KEY
|
||||
import com.github.libretube.ui.base.BaseActivity
|
||||
import com.github.libretube.ui.dialogs.DeletePlaylistDialog
|
||||
import com.github.libretube.ui.dialogs.PlaylistDescriptionDialog
|
||||
@ -93,20 +94,21 @@ class PlaylistOptionsBottomSheet(
|
||||
}
|
||||
// share the playlist
|
||||
getString(R.string.share) -> {
|
||||
val bundle = bundleOf(
|
||||
val newShareDialog = ShareDialog()
|
||||
newShareDialog.arguments = bundleOf(
|
||||
IntentData.id to playlistId,
|
||||
IntentData.shareObjectType to ShareObjectType.PLAYLIST,
|
||||
IntentData.shareData to shareData
|
||||
)
|
||||
val newShareDialog = ShareDialog()
|
||||
newShareDialog.arguments = bundle
|
||||
// using parentFragmentManager, childFragmentManager doesn't work here
|
||||
newShareDialog.show(parentFragmentManager, ShareDialog::class.java.name)
|
||||
}
|
||||
|
||||
getString(R.string.deletePlaylist) -> {
|
||||
mFragmentManager.setFragmentResultListener(IntentData.requestKey, context as BaseActivity) { _, bundle ->
|
||||
mFragmentManager.setFragmentResultListener(PLAYLIST_OPTIONS_REQUEST_KEY, context as BaseActivity) { _, bundle ->
|
||||
if (bundle.getBoolean(IntentData.playlistTask, true)) onDelete()
|
||||
// forward the result the playlists adapter if visible
|
||||
mFragmentManager.setFragmentResult(PLAYLISTS_ADAPTER_REQUEST_KEY, bundle)
|
||||
}
|
||||
val newDeletePlaylistDialog = DeletePlaylistDialog()
|
||||
newDeletePlaylistDialog.arguments = bundleOf(
|
||||
@ -117,8 +119,10 @@ class PlaylistOptionsBottomSheet(
|
||||
}
|
||||
|
||||
getString(R.string.renamePlaylist) -> {
|
||||
mFragmentManager.setFragmentResultListener(IntentData.requestKey, context as BaseActivity) { _, bundle ->
|
||||
mFragmentManager.setFragmentResultListener(PLAYLIST_OPTIONS_REQUEST_KEY, context as BaseActivity) { _, bundle ->
|
||||
onRename(bundle.getString(IntentData.playlistName, ""))
|
||||
// forward the result the playlists adapter if visible
|
||||
mFragmentManager.setFragmentResult(PLAYLISTS_ADAPTER_REQUEST_KEY, bundle)
|
||||
}
|
||||
val newRenamePlaylistDialog = RenamePlaylistDialog()
|
||||
newRenamePlaylistDialog.arguments = bundleOf(
|
||||
@ -129,8 +133,10 @@ class PlaylistOptionsBottomSheet(
|
||||
}
|
||||
|
||||
getString(R.string.change_playlist_description) -> {
|
||||
mFragmentManager.setFragmentResultListener(IntentData.requestKey, context as BaseActivity) { _, bundle ->
|
||||
mFragmentManager.setFragmentResultListener(PLAYLIST_OPTIONS_REQUEST_KEY, context as BaseActivity) { _, bundle ->
|
||||
onChangeDescription(bundle.getString(IntentData.playlistName, ""))
|
||||
// forward the result the playlists adapter if visible
|
||||
mFragmentManager.setFragmentResult(PLAYLISTS_ADAPTER_REQUEST_KEY, bundle)
|
||||
}
|
||||
val newPlaylistDescriptionDialog = PlaylistDescriptionDialog()
|
||||
newPlaylistDescriptionDialog.arguments = bundleOf(
|
||||
@ -158,4 +164,8 @@ class PlaylistOptionsBottomSheet(
|
||||
}
|
||||
super.onCreate(savedInstanceState)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val PLAYLIST_OPTIONS_REQUEST_KEY = "playlist_options_request_key"
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import androidx.preference.PreferenceViewHolder
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.constants.IntentData
|
||||
import com.github.libretube.ui.dialogs.ColorPickerDialog
|
||||
import com.github.libretube.ui.dialogs.ColorPickerDialog.Companion.COLOR_PICKER_REQUEST_KEY
|
||||
|
||||
class ColorPreference(context: Context, attrs: AttributeSet) : Preference(context, attrs) {
|
||||
private lateinit var circleView: View
|
||||
@ -66,7 +67,7 @@ class ColorPreference(context: Context, attrs: AttributeSet) : Preference(contex
|
||||
val dialog = ColorPickerDialog()
|
||||
val fragmentManager = (context as AppCompatActivity).supportFragmentManager
|
||||
fragmentManager.setFragmentResultListener(
|
||||
IntentData.requestKey,
|
||||
COLOR_PICKER_REQUEST_KEY,
|
||||
context as AppCompatActivity
|
||||
) { _, resultBundle ->
|
||||
val newColor = resultBundle.getInt(IntentData.color)
|
||||
|
Loading…
Reference in New Issue
Block a user