-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show the LoaderDialog when syncing the Location data #3598
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,10 +19,9 @@ package org.smartregister.fhircore.engine.ui.components.register | |
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.foundation.layout.wrapContentSize | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material.CircularProgressIndicator | ||
import androidx.compose.material.Surface | ||
|
@@ -35,15 +34,16 @@ import androidx.compose.runtime.remember | |
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.platform.testTag | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.Dp | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import androidx.compose.ui.window.Dialog | ||
import androidx.compose.ui.window.DialogProperties | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.flowOf | ||
import org.smartregister.fhircore.engine.R | ||
import org.smartregister.fhircore.engine.ui.components.LineSpinFadeLoaderProgressIndicator | ||
import org.smartregister.fhircore.engine.util.annotation.PreviewWithBackgroundExcludeGenerated | ||
|
||
const val LOADER_DIALOG_PROGRESS_BAR_TAG = "loaderDialogProgressBarTag" | ||
|
@@ -52,58 +52,113 @@ const val LOADER_DIALOG_PROGRESS_MSG_TAG = "loaderDialogProgressMsgTag" | |
@Composable | ||
fun LoaderDialog( | ||
modifier: Modifier = Modifier, | ||
dialogMessage: String, | ||
dialogMessage: String? = null, | ||
percentageProgressFlow: Flow<Int> = flowOf(0), | ||
showPercentageProgress: Boolean = false, | ||
boxWidth: Dp = 240.dp, | ||
boxHeight: Dp = 180.dp, | ||
progressBarSize: Dp = 40.dp, | ||
showBackground: Boolean = true, | ||
showLineSpinIndicator: Boolean = false, | ||
showOverlay: Boolean = true, | ||
alignment: Alignment = Alignment.Center, | ||
) { | ||
val currentPercentage = percentageProgressFlow.collectAsState(0).value | ||
|
||
if (showOverlay) { | ||
Dialog(onDismissRequest = {}, properties = DialogProperties(dismissOnBackPress = false)) { | ||
LoaderContent( | ||
modifier = modifier, | ||
dialogMessage = dialogMessage, | ||
currentPercentage = currentPercentage, | ||
showPercentageProgress = showPercentageProgress, | ||
boxWidth = boxWidth, | ||
boxHeight = boxHeight, | ||
progressBarSize = progressBarSize, | ||
showBackground = showBackground, | ||
showLineSpinIndicator = showLineSpinIndicator, | ||
) | ||
} | ||
} else { | ||
Box( | ||
modifier = modifier.wrapContentSize(), | ||
contentAlignment = alignment, | ||
) { | ||
LoaderContent( | ||
modifier = modifier, | ||
dialogMessage = dialogMessage, | ||
currentPercentage = currentPercentage, | ||
showPercentageProgress = showPercentageProgress, | ||
boxWidth = boxWidth, | ||
boxHeight = boxHeight, | ||
progressBarSize = progressBarSize, | ||
showBackground = showBackground, | ||
showLineSpinIndicator = showLineSpinIndicator, | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun LoaderContent( | ||
modifier: Modifier, | ||
dialogMessage: String?, | ||
currentPercentage: Int, | ||
showPercentageProgress: Boolean, | ||
boxWidth: Dp, | ||
boxHeight: Dp, | ||
progressBarSize: Dp, | ||
showBackground: Boolean, | ||
showLineSpinIndicator: Boolean, | ||
) { | ||
val openDialog = remember { mutableStateOf(true) } | ||
if (openDialog.value) { | ||
Dialog( | ||
onDismissRequest = { openDialog.value = true }, | ||
properties = DialogProperties(dismissOnBackPress = true), | ||
) { | ||
Box(modifier.size(240.dp, 180.dp)) { | ||
Column( | ||
modifier = modifier.padding(8.dp), | ||
verticalArrangement = Arrangement.Center, | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
Box(modifier.size(boxWidth, boxHeight)) { | ||
Column( | ||
modifier = modifier.padding(8.dp), | ||
verticalArrangement = Arrangement.Center, | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
) { | ||
Surface( | ||
modifier = modifier.size(boxWidth, boxHeight), | ||
shape = RoundedCornerShape(8.dp), | ||
color = if (showBackground) Color.Black.copy(alpha = 0.56f) else Color.Transparent, | ||
) { | ||
Surface( | ||
color = Color.Black.copy(alpha = 0.56f), | ||
modifier = modifier.fillMaxSize(), | ||
shape = RoundedCornerShape(8), | ||
Column( | ||
modifier = modifier.padding(8.dp), | ||
verticalArrangement = Arrangement.Center, | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
) { | ||
Column( | ||
verticalArrangement = Arrangement.Center, | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
) { | ||
if (showLineSpinIndicator) { | ||
LineSpinFadeLoaderProgressIndicator( | ||
color = Color.White, | ||
lineLength = 8f, | ||
innerRadius = 12f, | ||
) | ||
} else { | ||
CircularProgressIndicator( | ||
color = Color.White, | ||
strokeWidth = 3.dp, | ||
modifier = modifier.testTag(LOADER_DIALOG_PROGRESS_BAR_TAG).size(40.dp), | ||
modifier = modifier.size(progressBarSize), | ||
) | ||
Row( | ||
horizontalArrangement = Arrangement.Center, | ||
verticalAlignment = Alignment.CenterVertically, | ||
) { | ||
Text( | ||
fontSize = 16.sp, | ||
color = Color.White, | ||
text = dialogMessage, | ||
modifier = | ||
modifier.testTag(LOADER_DIALOG_PROGRESS_MSG_TAG).padding(vertical = 16.dp), | ||
) | ||
} | ||
|
||
if (showPercentageProgress) { | ||
Text( | ||
fontSize = 15.sp, | ||
color = Color.White, | ||
text = stringResource(id = R.string.percentage_progress, currentPercentage), | ||
modifier = modifier.padding(horizontal = 3.dp, vertical = 16.dp), | ||
) | ||
} | ||
} | ||
dialogMessage?.let { | ||
Text( | ||
text = it, | ||
color = Color.White, | ||
fontSize = 14.sp, | ||
modifier = modifier.padding(top = 8.dp), | ||
) | ||
} | ||
|
||
if (showPercentageProgress) { | ||
Text( | ||
fontSize = 15.sp, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ellykits @qaziabubakar-vd Does this font size align with the default font size in other areas of the app? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't changed any font sizes, we were showing this same font size before in the LoaderDialog class, I just refactored it a little for my implementation. |
||
color = Color.White, | ||
text = "$currentPercentage%", | ||
modifier = modifier.padding(top = 4.dp), | ||
) | ||
} | ||
} | ||
} | ||
|
@@ -122,3 +177,16 @@ fun LoaderDialog( | |
fun LoaderDialogPreview() { | ||
LoaderDialog(dialogMessage = stringResource(id = R.string.syncing)) | ||
} | ||
|
||
@PreviewWithBackgroundExcludeGenerated | ||
@Composable | ||
fun LoaderDialogPreviewTest() { | ||
LoaderDialog( | ||
boxWidth = 50.dp, | ||
boxHeight = 50.dp, | ||
progressBarSize = 25.dp, | ||
showBackground = false, | ||
showLineSpinIndicator = true, | ||
showOverlay = false, | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ellykits @qaziabubakar-vd Does this font size align with the default font size in other areas of the app?