Added log loading screen

This commit is contained in:
Abdelilah El Aissaoui 2023-08-06 12:35:58 +02:00
parent 594e41eda2
commit 0c3ced89b4

View File

@ -26,9 +26,7 @@ import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.clipRect import androidx.compose.ui.graphics.drawscope.clipRect
import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.input.key.KeyEventType
import androidx.compose.ui.input.key.onPreviewKeyEvent import androidx.compose.ui.input.key.onPreviewKeyEvent
import androidx.compose.ui.input.key.type
import androidx.compose.ui.input.pointer.PointerIcon import androidx.compose.ui.input.pointer.PointerIcon
import androidx.compose.ui.input.pointer.pointerHoverIcon import androidx.compose.ui.input.pointer.pointerHoverIcon
import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.LocalDensity
@ -94,28 +92,56 @@ fun Log(
selectedItem: SelectedItem, selectedItem: SelectedItem,
repositoryState: RepositoryState, repositoryState: RepositoryState,
) { ) {
val scope = rememberCoroutineScope()
val logStatusState = logViewModel.logStatus.collectAsState() val logStatusState = logViewModel.logStatus.collectAsState()
val logStatus = logStatusState.value val logStatus = logStatusState.value
val showLogDialog by logViewModel.logDialog.collectAsState() val showLogDialog by logViewModel.logDialog.collectAsState()
when (logStatus) {
is LogStatus.Loaded -> LogLoaded(logViewModel, logStatus, showLogDialog, selectedItem, repositoryState)
LogStatus.Loading -> LogLoading()
}
}
@Composable
private fun LogLoading() {
Column (
modifier = Modifier
.fillMaxSize()
.background(MaterialTheme.colors.background),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally,
) {
CircularProgressIndicator()
Text(
text = "Loading commits history...",
style = MaterialTheme.typography.h4,
modifier = Modifier.padding(top = 8.dp),
)
}
}
@Composable
private fun LogLoaded(
logViewModel: LogViewModel,
logStatus: LogStatus.Loaded,
showLogDialog: LogDialog,
selectedItem: SelectedItem,
repositoryState: RepositoryState
) {
val scope = rememberCoroutineScope()
val hasUncommitedChanges = logStatus.hasUncommittedChanges
val commitList = logStatus.plotCommitList
val verticalScrollState by logViewModel.verticalListState.collectAsState()
val horizontalScrollState by logViewModel.horizontalListState.collectAsState()
val searchFilter = logViewModel.logSearchFilterResults.collectAsState()
val searchFilterValue = searchFilter.value
val selectedCommit = if (selectedItem is SelectedItem.CommitBasedItem) { val selectedCommit = if (selectedItem is SelectedItem.CommitBasedItem) {
selectedItem.revCommit selectedItem.revCommit
} else { } else {
null null
} }
if (logStatus is LogStatus.Loaded) {
val hasUncommitedChanges = logStatus.hasUncommitedChanges
val commitList = logStatus.plotCommitList
val verticalScrollState by logViewModel.verticalListState.collectAsState()
val horizontalScrollState by logViewModel.horizontalListState.collectAsState()
val searchFilter = logViewModel.logSearchFilterResults.collectAsState()
val searchFilterValue = searchFilter.value
// With this method, whenever the scroll changes, the log is recomposed and the graph list is updated with
// the proper scroll position
verticalScrollState.observeScrollChanges()
LaunchedEffect(verticalScrollState, commitList) { LaunchedEffect(verticalScrollState, commitList) {
launch { launch {
logViewModel.focusCommit.collect { commit -> logViewModel.focusCommit.collect { commit ->
@ -277,7 +303,6 @@ fun Log(
} }
} }
} }
}
suspend fun scrollToCommit( suspend fun scrollToCommit(
verticalScrollState: LazyListState, verticalScrollState: LazyListState,