From 4218d81c49b0142e9c3686fa0d4a81e9abb87177 Mon Sep 17 00:00:00 2001 From: aayush262 Date: Tue, 23 Jan 2024 17:38:11 +0530 Subject: [PATCH] Download manager fixed now no need to long tap download button to download externally (select external downloader to download from external app) --- .../media/anime/SelectorDialogFragment.kt | 153 ++++++++---------- app/src/main/res/layout/activity_settings.xml | 8 - app/src/main/res/values/strings.xml | 1 - 3 files changed, 71 insertions(+), 91 deletions(-) diff --git a/app/src/main/java/ani/dantotsu/media/anime/SelectorDialogFragment.kt b/app/src/main/java/ani/dantotsu/media/anime/SelectorDialogFragment.kt index 688222c5859..ec8a1234df2 100644 --- a/app/src/main/java/ani/dantotsu/media/anime/SelectorDialogFragment.kt +++ b/app/src/main/java/ani/dantotsu/media/anime/SelectorDialogFragment.kt @@ -300,96 +300,85 @@ class SelectorDialogFragment : BottomSheetDialogFragment() { extractor.server.name media!!.anime!!.episodes!![media!!.anime!!.selectedEpisode!!]!!.selectedVideo = position - binding.urlDownload.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS) - val episode = media!!.anime!!.episodes!![media!!.anime!!.selectedEpisode!!]!! - val selectedVideo = - if (extractor.videos.size > episode.selectedVideo) extractor.videos[episode.selectedVideo] else null - - val subtitles = extractor.subtitles - val subtitleNames = subtitles.map { it.language } - var subtitleToDownload: Subtitle? = null - if (subtitles.isNotEmpty()) { - val alertDialog = AlertDialog.Builder(context, R.style.MyPopup) - .setTitle("Download Subtitle") - .setSingleChoiceItems( - subtitleNames.toTypedArray(), - -1 - ) { dialog, which -> - subtitleToDownload = subtitles[which] - } - .setPositiveButton("Download") { _, _ -> - dialog?.dismiss() - if (selectedVideo != null) { - Helper.startAnimeDownloadService( - currActivity()!!, - media!!.mainName(), - episode.number, - selectedVideo, - subtitleToDownload, - media, - episode.thumb?.url ?: media!!.banner ?: media!!.cover - ) - } else { - snackString("No Video Selected") - } - } - .setNegativeButton("Skip") { dialog, _ -> - subtitleToDownload = null - if (selectedVideo != null) { - Helper.startAnimeDownloadService( - currActivity()!!, - media!!.mainName(), - episode.number, - selectedVideo, - subtitleToDownload, - media, - episode.thumb?.url ?: media!!.banner ?: media!!.cover - ) - } else { - snackString("No Video Selected") - } - dialog.dismiss() - } - .setNeutralButton("Cancel") { dialog, _ -> - subtitleToDownload = null - dialog.dismiss() - } - .show() - alertDialog.window?.setDimAmount(0.8f) - - } else { - if (selectedVideo != null) { - Helper.startAnimeDownloadService( - requireActivity(), - media!!.mainName(), - episode.number, - selectedVideo, - subtitleToDownload, - media, - episode.thumb?.url ?: media!!.banner ?: media!!.cover - ) - } else { - snackString("No Video Selected") - } - } - dismiss() - } - binding.urlDownload.setOnLongClickListener { - binding.urlDownload.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS) if ((loadData("settings_download_manager") ?: 0) != 0) { - media!!.anime!!.episodes!![media!!.anime!!.selectedEpisode!!]!!.selectedExtractor = - extractor.server.name - media!!.anime!!.episodes!![media!!.anime!!.selectedEpisode!!]!!.selectedVideo = - position download( requireActivity(), media!!.anime!!.episodes!![media!!.anime!!.selectedEpisode!!]!!, media!!.userPreferredName ) } else { - snackString("No Download Manager Selected") + val episode = media!!.anime!!.episodes!![media!!.anime!!.selectedEpisode!!]!! + val selectedVideo = + if (extractor.videos.size > episode.selectedVideo) extractor.videos[episode.selectedVideo] else null + val subtitles = extractor.subtitles + val subtitleNames = subtitles.map { it.language } + var subtitleToDownload: Subtitle? = null + if (subtitles.isNotEmpty()) { + val alertDialog = AlertDialog.Builder(context, R.style.MyPopup) + .setTitle("Download Subtitle") + .setSingleChoiceItems( + subtitleNames.toTypedArray(), + -1 + ) { dialog, which -> + subtitleToDownload = subtitles[which] + } + .setPositiveButton("Download") { _, _ -> + dialog?.dismiss() + if (selectedVideo != null) { + Helper.startAnimeDownloadService( + currActivity()!!, + media!!.mainName(), + episode.number, + selectedVideo, + subtitleToDownload, + media, + episode.thumb?.url ?: media!!.banner ?: media!!.cover + ) + } else { + snackString("No Video Selected") + } + } + .setNegativeButton("Skip") { dialog, _ -> + subtitleToDownload = null + if (selectedVideo != null) { + Helper.startAnimeDownloadService( + currActivity()!!, + media!!.mainName(), + episode.number, + selectedVideo, + subtitleToDownload, + media, + episode.thumb?.url ?: media!!.banner ?: media!!.cover + ) + } else { + snackString("No Video Selected") + } + dialog.dismiss() + } + .setNeutralButton("Cancel") { dialog, _ -> + subtitleToDownload = null + dialog.dismiss() + } + .show() + alertDialog.window?.setDimAmount(0.8f) + + } else { + if (selectedVideo != null) { + Helper.startAnimeDownloadService( + requireActivity(), + media!!.mainName(), + episode.number, + selectedVideo, + subtitleToDownload, + media, + episode.thumb?.url ?: media!!.banner ?: media!!.cover + ) + } else { + snackString("No Video Selected") + } + } } - true + dismiss() } if (video.format == VideoType.CONTAINER) { binding.urlSize.visibility = if (video.size != null) View.VISIBLE else View.GONE diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index 1c3d5f805b2..8a8fa7c4dfc 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -719,14 +719,6 @@ app:iconPadding="16dp" app:iconSize="24dp" /> - This is an app widget description Airing Image animeDownloads - Long press the download button to download using the selected download manager Delete all anime downloads Delete all Manga Downloads Delete all Novel Downloads