Skip to content

Commit

Permalink
refactor(gui): box replaced by dialog
Browse files Browse the repository at this point in the history
Signed-off-by: AlperK61 <[email protected]>
  • Loading branch information
AlperK61 committed Jan 23, 2024
1 parent 2789509 commit 8ddcfe7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ import ui.components.general.AutoSizeText
* @param state [AppState] object containing the state of the application.
* @return [Unit]
*/
@OptIn(DelicateCoroutinesApi::class)

@Composable
fun RowScope.ComputeDifferencesButton(
state: MutableState<AppState>,
isLoading: MutableState<Boolean>,
showDialog: MutableState<Boolean>,
isCancelling: MutableState<Boolean>,
) {
val scope = rememberCoroutineScope()
Button(
// fills all available space
modifier = Modifier.weight(0.9f).padding(8.dp).fillMaxSize(1f),
onClick = {
isLoading.value = true
showDialog.value = true
scope.launch(Dispatchers.IO) {
// Generate the differences
val generator = DifferenceGeneratorWrapper(state)
Expand All @@ -44,7 +44,7 @@ fun RowScope.ComputeDifferencesButton(
state.value.copy(sequenceObj = generator.getSequence(), screen = Screen.DiffScreen)
}
isCancelling.value = false
isLoading.value = false
showDialog.value = false
}
},
// enable the button only if all the paths are not empty
Expand Down
48 changes: 44 additions & 4 deletions GUI/src/main/kotlin/ui/screens/SelectVideoScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ import ui.components.selectVideoScreen.FileSelectorButton
* @param state [MutableState]<[AppState]> containing the global state.
* @return [Unit]
*/

@Composable
fun SelectVideoScreen(state: MutableState<AppState>) {
var isLoading = remember { mutableStateOf(false) }
var showDialog = mutableStateOf(false)
var isCancelling = remember { mutableStateOf(false) }
Box(modifier = Modifier.fillMaxSize()) {
Column(modifier = Modifier.fillMaxSize()) {
Expand Down Expand Up @@ -61,16 +62,55 @@ fun SelectVideoScreen(state: MutableState<AppState>) {
}
// screen switch buttons
Row(modifier = Modifier.weight(0.15f)) {
ComputeDifferencesButton(state, isLoading, isCancelling)
ComputeDifferencesButton(state, showDialog, isCancelling)
AdvancedSettingsButton(state)
}
}
if (isLoading.value) {
Loading(isCancelling)
if (showDialog.value) {
ShowDialog(isCancelling)
}
}
}

@OptIn(ExperimentalMaterialApi::class)
@Composable
private fun ShowDialog(isCancelling: MutableState<Boolean>) {
AlertDialog(
modifier = Modifier.fillMaxSize(0.6f),
onDismissRequest = { },
title = {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.fillMaxWidth().fillMaxHeight(),
) {
Text(text = "Computing")
}
},
text = {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.fillMaxWidth().fillMaxHeight(0.8f),
) {
CircularProgressIndicator(modifier = Modifier.size(150.dp))
}
},
confirmButton = {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.fillMaxSize(),
) {
TextButton(onClick = { isCancelling.value = true }) {
if (isCancelling.value) {
CircularProgressIndicator()
} else {
Text("Cancel")
}
}
}
},
)
}

@Composable
private fun Loading(isCancelling: MutableState<Boolean>) {
Box(
Expand Down

0 comments on commit 8ddcfe7

Please sign in to comment.