UpdateDialog
This commit is contained in:
@@ -1,14 +1,20 @@
|
|||||||
package `in`.sminnovations.attendanceapp.screens.home.ui.componets
|
package `in`.sminnovations.attendanceapp.screens.home.ui.componets
|
||||||
|
|
||||||
|
|
||||||
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.width
|
||||||
import androidx.compose.material3.AlertDialog
|
import androidx.compose.material3.AlertDialog
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
import androidx.compose.material3.CircularProgressIndicator
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
|
|
||||||
|
import androidx.compose.material3.LinearProgressIndicator
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
@@ -19,18 +25,21 @@ import androidx.compose.ui.text.font.FontWeight
|
|||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import `in`.sminnovations.attendanceapp.utils.UpdateInfo
|
import `in`.sminnovations.attendanceapp.utils.UpdateInfo
|
||||||
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun UpdateDialog(
|
fun UpdateDialog(
|
||||||
updateInfo: UpdateInfo,
|
updateInfo: UpdateInfo,
|
||||||
isDownloading: Boolean,
|
downloadProgress: Float,
|
||||||
onDismiss: () -> Unit,
|
onDismiss: () -> Unit,
|
||||||
onInstall: (String) -> Unit,
|
onInstall: (String) -> Unit,
|
||||||
modifier: Modifier = Modifier
|
modifier: Modifier = Modifier
|
||||||
) {
|
) {
|
||||||
|
val isinstallPressed = remember { mutableStateOf(false) } //not a smart approach but it works
|
||||||
AlertDialog(
|
AlertDialog(
|
||||||
onDismissRequest = { if (!isDownloading) onDismiss() },
|
|
||||||
|
onDismissRequest = {
|
||||||
|
// Only allow dismissing if not downloading
|
||||||
|
if (downloadProgress == 0f) onDismiss()
|
||||||
|
},
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
title = {
|
title = {
|
||||||
Text(
|
Text(
|
||||||
@@ -53,7 +62,7 @@ fun UpdateDialog(
|
|||||||
modifier = Modifier.padding(vertical = 8.dp)
|
modifier = Modifier.padding(vertical = 8.dp)
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
text = "Release Note :",
|
text = "Release Note:",
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
textAlign = TextAlign.Start,
|
textAlign = TextAlign.Start,
|
||||||
modifier = Modifier.padding(vertical = 8.dp),
|
modifier = Modifier.padding(vertical = 8.dp),
|
||||||
@@ -67,10 +76,9 @@ fun UpdateDialog(
|
|||||||
fontWeight = FontWeight.SemiBold,
|
fontWeight = FontWeight.SemiBold,
|
||||||
fontFamily = FontFamily.Monospace
|
fontFamily = FontFamily.Monospace
|
||||||
)
|
)
|
||||||
if (isDownloading) {
|
if (downloadProgress > 0f) {
|
||||||
CircularProgressIndicator(
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
modifier = Modifier.padding(top = 16.dp)
|
LinearProgressIndicator(progress = downloadProgress)
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -80,19 +88,29 @@ fun UpdateDialog(
|
|||||||
horizontalArrangement = Arrangement.End
|
horizontalArrangement = Arrangement.End
|
||||||
) {
|
) {
|
||||||
Button(
|
Button(
|
||||||
onClick = { onInstall(updateInfo.url) },
|
onClick = {
|
||||||
enabled = !isDownloading
|
onInstall(updateInfo.url)
|
||||||
|
isinstallPressed.value = true },
|
||||||
|
enabled = downloadProgress == 0f || downloadProgress == 1f
|
||||||
) {
|
) {
|
||||||
Text(if (isDownloading) "Downloading..." else "Install")
|
AnimatedVisibility(visible = isinstallPressed.value && downloadProgress ==0f) {
|
||||||
|
CircularProgressIndicator(color = MaterialTheme.colorScheme.surface)
|
||||||
|
}
|
||||||
|
Text(
|
||||||
|
text = if (downloadProgress > 0f && downloadProgress <1f) "Downloading..." else "Install",
|
||||||
|
modifier = Modifier.padding(start = if(isinstallPressed.value && downloadProgress ==0f) 10.dp else 0.dp )
|
||||||
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
dismissButton = {
|
dismissButton = {
|
||||||
// if (!isDownloading) {
|
if (downloadProgress == 0f) {
|
||||||
// Button(onClick = onDismiss) {
|
Button(onClick = onDismiss) {
|
||||||
// Text("Later")
|
Text("Later")
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user