compose: downloads: Show toast with error when files are not available

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2025-09-16 18:23:28 +05:30
parent 66ed08c502
commit 306dcd92a0
2 changed files with 18 additions and 15 deletions

View File

@@ -61,9 +61,9 @@ fun DownloadComposable(
onClick: () -> Unit = {},
onClear: () -> Unit = {},
onCancel: () -> Unit = {},
onExport: (() -> Unit)? = null,
onInstall: (() -> Unit)? = null,
onShare: (() -> Unit)? = null
onExport: () -> Unit = {},
onInstall: () -> Unit = {},
onShare: () -> Unit = {}
) {
val progress = "${download.progress}%"
val speed = "${Formatter.formatShortFileSize(LocalContext.current, download.speed)}/s"

View File

@@ -92,9 +92,9 @@ private fun ScreenContent(
onNavigateToAppDetails: (packageName: String) -> Unit = {},
onCancel: (packageName: String) -> Unit = {},
onClear: (download: Download) -> Unit = {},
onExport: ((download: Download) -> Unit)? = null,
onInstall: ((download: Download) -> Unit)? = null,
onShare: ((download: Download) -> Unit)? = null,
onExport: (download: Download) -> Unit = {},
onInstall: (download: Download) -> Unit = {},
onShare: (download: Download) -> Unit = {},
onCancelAll: () -> Unit = {},
onForceClearAll: () -> Unit = {},
onClearFinished: () -> Unit = {}
@@ -106,6 +106,7 @@ private fun ScreenContent(
* Save the initial loading state to make sure we don't replay the loading animation again.
*/
var initialLoad by rememberSaveable { mutableStateOf(true) }
val context = LocalContext.current
@Composable
fun SetupMenu() {
@@ -158,17 +159,19 @@ private fun ScreenContent(
download = download,
onClick = { onNavigateToAppDetails(download.packageName) },
onClear = { onClear(download) },
onShare = { onShare!!(download) },
onShare = { onShare(download) },
onCancel = { onCancel(download.packageName) },
onExport = if (download.canInstall(LocalContext.current)) {
{ onExport!!(download) }
} else {
null
onExport = {
when {
download.canInstall(context) -> onExport(download)
else -> context.toast(R.string.purchase_no_file)
}
},
onInstall = if (download.isSuccessful) {
{ onInstall!!(download) }
} else {
null
onInstall = {
when {
download.isSuccessful -> onInstall(download)
else -> context.toast(R.string.purchase_no_file)
}
}
)
}