feat: add download confirmation and progress dialogs
This commit is contained in:
parent
e15601f4ad
commit
812cd4b23b
|
|
@ -0,0 +1,65 @@
|
||||||
|
package com.syaroful.agrilinkvocpro.core.components
|
||||||
|
|
||||||
|
import androidx.compose.foundation.Image
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.material3.AlertDialog
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextButton
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.MutableState
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.res.painterResource
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import com.syaroful.agrilinkvocpro.R
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun DownloadModuleConfirmationDialog(state: MutableState<Boolean>, onClickConfirm: () -> Unit) {
|
||||||
|
if (!state.value) return
|
||||||
|
|
||||||
|
AlertDialog(
|
||||||
|
icon = {
|
||||||
|
Image(
|
||||||
|
painter = painterResource(R.drawable.play_store),
|
||||||
|
contentDescription = stringResource(id = R.string.play_store_icon_desc),
|
||||||
|
modifier = Modifier.height(70.dp),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
title = { Text(stringResource(id = R.string.download_module_title)) },
|
||||||
|
text = { Text(stringResource(id = R.string.download_module_message)) },
|
||||||
|
onDismissRequest = { state.value = false },
|
||||||
|
confirmButton = {
|
||||||
|
TextButton(
|
||||||
|
onClick = {
|
||||||
|
onClickConfirm.invoke()
|
||||||
|
state.value = false
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
Text(stringResource(id = R.string.download))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
dismissButton = {
|
||||||
|
TextButton(
|
||||||
|
onClick = { state.value = false }
|
||||||
|
) {
|
||||||
|
Text(stringResource(id = R.string.cancel))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Preview(showBackground = true)
|
||||||
|
@Composable
|
||||||
|
fun PreviewDownloadModuleConfirmationDialog() {
|
||||||
|
// Use remember just for preview context
|
||||||
|
val showDialog = remember { mutableStateOf(true) }
|
||||||
|
|
||||||
|
// Provide fake implementation for confirmation click
|
||||||
|
DownloadModuleConfirmationDialog(
|
||||||
|
state = showDialog,
|
||||||
|
onClickConfirm = { /* No-op for preview */ }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,58 @@
|
||||||
|
package com.syaroful.agrilinkvocpro.core.components
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.material3.AlertDialog
|
||||||
|
import androidx.compose.material3.LinearProgressIndicator
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextButton
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import com.syaroful.agrilinkvocpro.ui.theme.MainGreen
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun DownloadProgressDialog(
|
||||||
|
showDialog: Boolean,
|
||||||
|
message: String,
|
||||||
|
progress: Float,
|
||||||
|
onDismiss: () -> Unit
|
||||||
|
) {
|
||||||
|
if (!showDialog) return
|
||||||
|
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = onDismiss,
|
||||||
|
title = { Text(text = "Module Download", style = MaterialTheme.typography.titleMedium) },
|
||||||
|
text = {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
|
) {
|
||||||
|
Text(text = message)
|
||||||
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
|
LinearProgressIndicator(color = MainGreen, trackColor = MainGreen.copy(alpha = 0.1f))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
confirmButton = {
|
||||||
|
TextButton(onClick = onDismiss) {
|
||||||
|
Text(text = "Close", color = MainGreen)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Preview
|
||||||
|
@Composable
|
||||||
|
fun DownloadProgressDialogPreview() {
|
||||||
|
DownloadProgressDialog(
|
||||||
|
showDialog = true,
|
||||||
|
message = "Downloading module...",
|
||||||
|
progress = 0.5f,
|
||||||
|
onDismiss = {}
|
||||||
|
)
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user