Add better dialog formatting for series

This commit is contained in:
Luna712 2024-07-08 18:38:20 -06:00 committed by GitHub
parent 5ed9eee407
commit b5bfc3460b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 40 additions and 10 deletions

View file

@ -10,6 +10,7 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.isEpisodeBased
import com.lagradost.cloudstream3.isMovieType import com.lagradost.cloudstream3.isMovieType
import com.lagradost.cloudstream3.mvvm.launchSafe import com.lagradost.cloudstream3.mvvm.launchSafe
import com.lagradost.cloudstream3.mvvm.logError import com.lagradost.cloudstream3.mvvm.logError
@ -166,19 +167,46 @@ class DownloadViewModel : ViewModel() {
val ids = selectedItemsList.map { it.data.id } val ids = selectedItemsList.map { it.data.id }
val names = selectedItemsList.mapNotNull { val (seriesNames, names) = selectedItemsList.map { item ->
when (it) { when (item) {
is VisualDownloadCached.Header -> it.data.name is VisualDownloadCached.Header -> {
is VisualDownloadCached.Child -> it.data.name 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<Int>, names: List<String>) { private fun showDeleteConfirmationDialog(
context: Context,
ids: List<Int>,
names: List<String>,
seriesNames: List<String>
) {
val formattedNames = names.joinToString(separator = "\n") { "$it" } 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 builder: AlertDialog.Builder = AlertDialog.Builder(context)
val dialogClickListener = val dialogClickListener =

View file

@ -314,7 +314,9 @@
<string name="go_back_30">-30</string> <string name="go_back_30">-30</string>
<string name="go_forward_30">+30</string> <string name="go_forward_30">+30</string>
<string name="delete_message" formatted="true">This will permanently delete %s\nAre you sure?</string> <string name="delete_message" formatted="true">This will permanently delete %s\nAre you sure?</string>
<string name="delete_message_multiple" formatted="true">Are you sure you want to delete the following items?\n\n%s</string> <string name="delete_message_multiple" formatted="true">Are you sure you want to permanently delete the following items?\n\n%s</string>
<string name="delete_message_series_section">You will also permanently delete all episodes in the following series:\n\n%s</string>
<string name="delete_message_series_only">Are you sure you want to permanently delete all episodes in the following series?\n\n%s</string>
<string name="resume_time_left" formatted="true">%dm\nremaining</string> <string name="resume_time_left" formatted="true">%dm\nremaining</string>
<string name="resume_remaining" formatted="true">%s\nremaining</string> <string name="resume_remaining" formatted="true">%s\nremaining</string>
<string name="status_ongoing">Ongoing</string> <string name="status_ongoing">Ongoing</string>