From b5bfc3460bacc0340dbd2031cb963f7e6095ea56 Mon Sep 17 00:00:00 2001 From: Luna712 <142361265+Luna712@users.noreply.github.com> Date: Mon, 8 Jul 2024 18:38:20 -0600 Subject: [PATCH] Add better dialog formatting for series --- .../ui/download/DownloadViewModel.kt | 46 +++++++++++++++---- app/src/main/res/values/strings.xml | 4 +- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadViewModel.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadViewModel.kt index 00c0c673..bb91c0ac 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadViewModel.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadViewModel.kt @@ -10,6 +10,7 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.lagradost.cloudstream3.R +import com.lagradost.cloudstream3.isEpisodeBased import com.lagradost.cloudstream3.isMovieType import com.lagradost.cloudstream3.mvvm.launchSafe import com.lagradost.cloudstream3.mvvm.logError @@ -166,19 +167,46 @@ class DownloadViewModel : ViewModel() { val ids = selectedItemsList.map { it.data.id } - val names = selectedItemsList.mapNotNull { - when (it) { - is VisualDownloadCached.Header -> it.data.name - is VisualDownloadCached.Child -> it.data.name - } - } + val (seriesNames, names) = selectedItemsList.map { item -> + when (item) { + is VisualDownloadCached.Header -> { + if (item.data.type.isEpisodeBased()) { + val episodeInfo = "${item.data.name} (${item.totalDownloads} ${ + context.resources.getQuantityString( + R.plurals.episodes, + item.totalDownloads + ).lowercase() + })" + episodeInfo to null + } else null to item.data.name + } - showDeleteConfirmationDialog(context, ids, names) + is VisualDownloadCached.Child -> null to item.data.name + } + }.unzip() + + showDeleteConfirmationDialog(context, ids, names.filterNotNull(), seriesNames.filterNotNull()) } - private fun showDeleteConfirmationDialog(context: Context, ids: List, names: List) { + private fun showDeleteConfirmationDialog( + context: Context, + ids: List, + names: List, + seriesNames: List + ) { val formattedNames = names.joinToString(separator = "\n") { "• $it" } - val message = context.getString(R.string.delete_message_multiple).format(formattedNames) + val formattedSeriesNames = seriesNames.joinToString(separator = "\n") { "• $it" } + + val message = when { + seriesNames.isNotEmpty() && names.isEmpty() -> { + context.getString(R.string.delete_message_series_only).format(formattedSeriesNames) + } + seriesNames.isNotEmpty() -> { + val seriesSection = context.getString(R.string.delete_message_series_section).format(formattedSeriesNames) + context.getString(R.string.delete_message_multiple).format(formattedNames) + "\n\n" + seriesSection + } + else -> context.getString(R.string.delete_message_multiple).format(formattedNames) + } val builder: AlertDialog.Builder = AlertDialog.Builder(context) val dialogClickListener = diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 71308a75..c94e963e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -314,7 +314,9 @@ -30 +30 This will permanently delete %s\nAre you sure? - Are you sure you want to delete the following items?\n\n%s + Are you sure you want to permanently delete the following items?\n\n%s + You will also permanently delete all episodes in the following series:\n\n%s + Are you sure you want to permanently delete all episodes in the following series?\n\n%s %dm\nremaining %s\nremaining Ongoing