Added progress loading animation
This commit is contained in:
parent
894138b39f
commit
8b325b117a
@ -5,10 +5,12 @@ import androidx.compose.foundation.background
|
|||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
|
import androidx.compose.material.LinearProgressIndicator
|
||||||
import androidx.compose.material.MaterialTheme
|
import androidx.compose.material.MaterialTheme
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.alpha
|
import androidx.compose.ui.draw.alpha
|
||||||
|
import androidx.compose.ui.graphics.DefaultAlpha
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.window.*
|
import androidx.compose.ui.window.*
|
||||||
import androidx.compose.ui.zIndex
|
import androidx.compose.ui.zIndex
|
||||||
@ -155,6 +157,7 @@ fun App(gitManager: GitManager, repositoryPath: String?, tabName: MutableState<S
|
|||||||
|
|
||||||
|
|
||||||
val repositorySelectionStatus by gitManager.repositorySelectionStatus.collectAsState()
|
val repositorySelectionStatus by gitManager.repositorySelectionStatus.collectAsState()
|
||||||
|
val isProcessing by gitManager.processing.collectAsState()
|
||||||
|
|
||||||
if (repositorySelectionStatus is RepositorySelectionStatus.Open) {
|
if (repositorySelectionStatus is RepositorySelectionStatus.Open) {
|
||||||
tabName.value = gitManager.repositoryName
|
tabName.value = gitManager.repositoryName
|
||||||
@ -165,6 +168,19 @@ fun App(gitManager: GitManager, repositoryPath: String?, tabName: MutableState<S
|
|||||||
.background(MaterialTheme.colors.background)
|
.background(MaterialTheme.colors.background)
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
val linearProgressAlpha = if (isProcessing)
|
||||||
|
DefaultAlpha
|
||||||
|
else
|
||||||
|
0f
|
||||||
|
|
||||||
|
LinearProgressIndicator(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.alpha(linearProgressAlpha)
|
||||||
|
)
|
||||||
|
|
||||||
|
Box(modifier = Modifier.fillMaxSize()) {
|
||||||
Crossfade(targetState = repositorySelectionStatus) {
|
Crossfade(targetState = repositorySelectionStatus) {
|
||||||
|
|
||||||
@Suppress("UnnecessaryVariable") // Don't inline it because smart cast won't work
|
@Suppress("UnnecessaryVariable") // Don't inline it because smart cast won't work
|
||||||
@ -180,6 +196,12 @@ fun App(gitManager: GitManager, repositoryPath: String?, tabName: MutableState<S
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isProcessing)
|
||||||
|
Box(modifier = Modifier.fillMaxSize()) //TODO this should block of the mouse/keyboard events while visible
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -82,7 +82,8 @@ class GitManager @Inject constructor(
|
|||||||
openRepository(File(directory))
|
openRepository(File(directory))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun openRepository(directory: File) {
|
fun openRepository(directory: File) = managerScope.launch(Dispatchers.IO) {
|
||||||
|
safeProcessing {
|
||||||
println("Trying to open repository ${directory.absoluteFile}")
|
println("Trying to open repository ${directory.absoluteFile}")
|
||||||
|
|
||||||
val gitDirectory = if (directory.name == ".git") {
|
val gitDirectory = if (directory.name == ".git") {
|
||||||
@ -116,8 +117,12 @@ class GitManager @Inject constructor(
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun loadLog() = managerScope.launch {
|
fun loadLog() = managerScope.launch {
|
||||||
|
coLoadLog()
|
||||||
|
}
|
||||||
|
private suspend fun coLoadLog(){
|
||||||
logManager.loadLog(safeGit)
|
logManager.loadLog(safeGit)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,33 +151,41 @@ class GitManager @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun pull() = managerScope.launch {
|
fun pull() = managerScope.launch {
|
||||||
|
safeProcessing {
|
||||||
remoteOperationsManager.pull(safeGit)
|
remoteOperationsManager.pull(safeGit)
|
||||||
logManager.loadLog(safeGit)
|
logManager.loadLog(safeGit)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun push() = managerScope.launch {
|
fun push() = managerScope.launch {
|
||||||
|
safeProcessing {
|
||||||
remoteOperationsManager.push(safeGit)
|
remoteOperationsManager.push(safeGit)
|
||||||
logManager.loadLog(safeGit)
|
logManager.loadLog(safeGit)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun refreshRepositoryInfo() = managerScope.launch {
|
private suspend fun refreshRepositoryInfo() {
|
||||||
statusManager.loadHasUncommitedChanges(safeGit)
|
statusManager.loadHasUncommitedChanges(safeGit)
|
||||||
branchesManager.loadBranches(safeGit)
|
branchesManager.loadBranches(safeGit)
|
||||||
stashManager.loadStashList(safeGit)
|
stashManager.loadStashList(safeGit)
|
||||||
loadLog()
|
coLoadLog()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun stash() = managerScope.launch {
|
fun stash() = managerScope.launch {
|
||||||
|
safeProcessing {
|
||||||
stashManager.stash(safeGit)
|
stashManager.stash(safeGit)
|
||||||
loadStatus()
|
loadStatus()
|
||||||
loadLog()
|
loadLog()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun popStash() = managerScope.launch {
|
fun popStash() = managerScope.launch {
|
||||||
|
safeProcessing {
|
||||||
stashManager.popStash(safeGit)
|
stashManager.popStash(safeGit)
|
||||||
loadStatus()
|
loadStatus()
|
||||||
loadLog()
|
loadLog()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun createBranch(branchName: String) = managerScope.launch {
|
fun createBranch(branchName: String) = managerScope.launch {
|
||||||
branchesManager.createBranch(safeGit, branchName)
|
branchesManager.createBranch(safeGit, branchName)
|
||||||
@ -215,6 +228,15 @@ class GitManager @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
var onRepositoryChanged: (path: String?) -> Unit = {}
|
var onRepositoryChanged: (path: String?) -> Unit = {}
|
||||||
|
|
||||||
|
private suspend fun safeProcessing(callback: suspend () -> Unit) {
|
||||||
|
_processing.value = true
|
||||||
|
try {
|
||||||
|
callback()
|
||||||
|
} finally {
|
||||||
|
_processing.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user