fix: download activity not dismissed when dialog closed

This commit is contained in:
Bnyro 2024-05-18 20:37:13 +02:00
parent 45fbef920a
commit f3049b5118
2 changed files with 16 additions and 3 deletions

View File

@ -2,18 +2,16 @@ package com.github.libretube.ui.activities
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.core.net.toUri import androidx.core.net.toUri
import androidx.core.os.bundleOf import androidx.core.os.bundleOf
import com.github.libretube.constants.IntentData import com.github.libretube.constants.IntentData
import com.github.libretube.enums.PlaylistType import com.github.libretube.enums.PlaylistType
import com.github.libretube.helpers.IntentHelper import com.github.libretube.helpers.IntentHelper
import com.github.libretube.helpers.ThemeHelper
import com.github.libretube.ui.base.BaseActivity import com.github.libretube.ui.base.BaseActivity
import com.github.libretube.ui.dialogs.DownloadDialog import com.github.libretube.ui.dialogs.DownloadDialog
import com.github.libretube.ui.dialogs.DownloadPlaylistDialog import com.github.libretube.ui.dialogs.DownloadPlaylistDialog
class DownloadActivity: BaseActivity() { class DownloadActivity : BaseActivity() {
override val isDialogActivity: Boolean = true override val isDialogActivity: Boolean = true
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
@ -26,6 +24,11 @@ class DownloadActivity: BaseActivity() {
val videoId = intentData?.getStringExtra(IntentData.videoId) val videoId = intentData?.getStringExtra(IntentData.videoId)
val playlistId = intentData?.getStringExtra(IntentData.playlistId) val playlistId = intentData?.getStringExtra(IntentData.playlistId)
if (videoId != null) { if (videoId != null) {
supportFragmentManager.setFragmentResultListener(
DownloadDialog.DOWNLOAD_DIALOG_DISMISSED_KEY,
this
) { _, _ -> finish() }
DownloadDialog().apply { DownloadDialog().apply {
arguments = bundleOf(IntentData.videoId to videoId) arguments = bundleOf(IntentData.videoId to videoId)
}.show(supportFragmentManager, null) }.show(supportFragmentManager, null)

View File

@ -7,8 +7,10 @@ import android.text.InputFilter
import android.text.format.Formatter import android.text.format.Formatter
import android.util.Log import android.util.Log
import android.widget.Toast import android.widget.Toast
import androidx.core.os.bundleOf
import androidx.core.view.isGone import androidx.core.view.isGone
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import androidx.fragment.app.setFragmentResult
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.api.RetrofitInstance import com.github.libretube.api.RetrofitInstance
@ -253,6 +255,12 @@ class DownloadDialog : DialogFragment() {
return null return null
} }
override fun onDismiss(dialog: DialogInterface) {
super.onDismiss(dialog)
setFragmentResult(DOWNLOAD_DIALOG_DISMISSED_KEY, bundleOf())
}
companion object { companion object {
/** /**
* Max file name length at Android systems * Max file name length at Android systems
@ -264,5 +272,7 @@ class DownloadDialog : DialogFragment() {
private const val AUDIO_DOWNLOAD_QUALITY = "audio_download_quality" private const val AUDIO_DOWNLOAD_QUALITY = "audio_download_quality"
private const val AUDIO_DOWNLOAD_FORMAT = "audio_download_format" private const val AUDIO_DOWNLOAD_FORMAT = "audio_download_format"
private const val SUBTITLE_LANGUAGE = "subtitle_download_language" private const val SUBTITLE_LANGUAGE = "subtitle_download_language"
const val DOWNLOAD_DIALOG_DISMISSED_KEY = "download_dialog_dismissed_key"
} }
} }