From f3049b51182639ca1107d0271280b36ad0ad4b5b Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 18 May 2024 20:37:13 +0200 Subject: [PATCH] fix: download activity not dismissed when dialog closed --- .../github/libretube/ui/activities/DownloadActivity.kt | 9 ++++++--- .../com/github/libretube/ui/dialogs/DownloadDialog.kt | 10 ++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/activities/DownloadActivity.kt b/app/src/main/java/com/github/libretube/ui/activities/DownloadActivity.kt index 7e5454f36..4d7434275 100644 --- a/app/src/main/java/com/github/libretube/ui/activities/DownloadActivity.kt +++ b/app/src/main/java/com/github/libretube/ui/activities/DownloadActivity.kt @@ -2,18 +2,16 @@ package com.github.libretube.ui.activities import android.content.Intent import android.os.Bundle -import androidx.appcompat.app.AppCompatActivity import androidx.core.net.toUri import androidx.core.os.bundleOf import com.github.libretube.constants.IntentData import com.github.libretube.enums.PlaylistType import com.github.libretube.helpers.IntentHelper -import com.github.libretube.helpers.ThemeHelper import com.github.libretube.ui.base.BaseActivity import com.github.libretube.ui.dialogs.DownloadDialog import com.github.libretube.ui.dialogs.DownloadPlaylistDialog -class DownloadActivity: BaseActivity() { +class DownloadActivity : BaseActivity() { override val isDialogActivity: Boolean = true override fun onCreate(savedInstanceState: Bundle?) { @@ -26,6 +24,11 @@ class DownloadActivity: BaseActivity() { val videoId = intentData?.getStringExtra(IntentData.videoId) val playlistId = intentData?.getStringExtra(IntentData.playlistId) if (videoId != null) { + supportFragmentManager.setFragmentResultListener( + DownloadDialog.DOWNLOAD_DIALOG_DISMISSED_KEY, + this + ) { _, _ -> finish() } + DownloadDialog().apply { arguments = bundleOf(IntentData.videoId to videoId) }.show(supportFragmentManager, null) diff --git a/app/src/main/java/com/github/libretube/ui/dialogs/DownloadDialog.kt b/app/src/main/java/com/github/libretube/ui/dialogs/DownloadDialog.kt index ad5759529..8bdf62964 100644 --- a/app/src/main/java/com/github/libretube/ui/dialogs/DownloadDialog.kt +++ b/app/src/main/java/com/github/libretube/ui/dialogs/DownloadDialog.kt @@ -7,8 +7,10 @@ import android.text.InputFilter import android.text.format.Formatter import android.util.Log import android.widget.Toast +import androidx.core.os.bundleOf import androidx.core.view.isGone import androidx.fragment.app.DialogFragment +import androidx.fragment.app.setFragmentResult import androidx.lifecycle.lifecycleScope import com.github.libretube.R import com.github.libretube.api.RetrofitInstance @@ -253,6 +255,12 @@ class DownloadDialog : DialogFragment() { return null } + override fun onDismiss(dialog: DialogInterface) { + super.onDismiss(dialog) + + setFragmentResult(DOWNLOAD_DIALOG_DISMISSED_KEY, bundleOf()) + } + companion object { /** * 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_FORMAT = "audio_download_format" private const val SUBTITLE_LANGUAGE = "subtitle_download_language" + + const val DOWNLOAD_DIALOG_DISMISSED_KEY = "download_dialog_dismissed_key" } }