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.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.material.LinearProgressIndicator
|
||||
import androidx.compose.material.MaterialTheme
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.alpha
|
||||
import androidx.compose.ui.graphics.DefaultAlpha
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.window.*
|
||||
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 isProcessing by gitManager.processing.collectAsState()
|
||||
|
||||
if (repositorySelectionStatus is RepositorySelectionStatus.Open) {
|
||||
tabName.value = gitManager.repositoryName
|
||||
@ -165,21 +168,40 @@ fun App(gitManager: GitManager, repositoryPath: String?, tabName: MutableState<S
|
||||
.background(MaterialTheme.colors.background)
|
||||
.fillMaxSize()
|
||||
) {
|
||||
Crossfade(targetState = repositorySelectionStatus) {
|
||||
|
||||
@Suppress("UnnecessaryVariable") // Don't inline it because smart cast won't work
|
||||
when (repositorySelectionStatus) {
|
||||
RepositorySelectionStatus.None -> {
|
||||
WelcomePage(gitManager = gitManager)
|
||||
}
|
||||
RepositorySelectionStatus.Loading -> {
|
||||
LoadingRepository()
|
||||
}
|
||||
is RepositorySelectionStatus.Open -> {
|
||||
RepositoryOpenPage(gitManager = gitManager)
|
||||
val linearProgressAlpha = if (isProcessing)
|
||||
DefaultAlpha
|
||||
else
|
||||
0f
|
||||
|
||||
LinearProgressIndicator(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.alpha(linearProgressAlpha)
|
||||
)
|
||||
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
Crossfade(targetState = repositorySelectionStatus) {
|
||||
|
||||
@Suppress("UnnecessaryVariable") // Don't inline it because smart cast won't work
|
||||
when (repositorySelectionStatus) {
|
||||
RepositorySelectionStatus.None -> {
|
||||
WelcomePage(gitManager = gitManager)
|
||||
}
|
||||
RepositorySelectionStatus.Loading -> {
|
||||
LoadingRepository()
|
||||
}
|
||||
is RepositorySelectionStatus.Open -> {
|
||||
RepositoryOpenPage(gitManager = gitManager)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isProcessing)
|
||||
Box(modifier = Modifier.fillMaxSize()) //TODO this should block of the mouse/keyboard events while visible
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -82,42 +82,47 @@ class GitManager @Inject constructor(
|
||||
openRepository(File(directory))
|
||||
}
|
||||
|
||||
fun openRepository(directory: File) {
|
||||
println("Trying to open repository ${directory.absoluteFile}")
|
||||
fun openRepository(directory: File) = managerScope.launch(Dispatchers.IO) {
|
||||
safeProcessing {
|
||||
println("Trying to open repository ${directory.absoluteFile}")
|
||||
|
||||
val gitDirectory = if (directory.name == ".git") {
|
||||
directory
|
||||
} else {
|
||||
val gitDir = File(directory, ".git")
|
||||
if (gitDir.exists() && gitDir.isDirectory) {
|
||||
gitDir
|
||||
} else
|
||||
val gitDirectory = if (directory.name == ".git") {
|
||||
directory
|
||||
} else {
|
||||
val gitDir = File(directory, ".git")
|
||||
if (gitDir.exists() && gitDir.isDirectory) {
|
||||
gitDir
|
||||
} else
|
||||
directory
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
val builder = FileRepositoryBuilder()
|
||||
val repository: Repository = builder.setGitDir(gitDirectory)
|
||||
.readEnvironment() // scan environment GIT_* variables
|
||||
.findGitDir() // scan up the file system tree
|
||||
.build()
|
||||
val builder = FileRepositoryBuilder()
|
||||
val repository: Repository = builder.setGitDir(gitDirectory)
|
||||
.readEnvironment() // scan environment GIT_* variables
|
||||
.findGitDir() // scan up the file system tree
|
||||
.build()
|
||||
|
||||
try {
|
||||
repository.workTree // test if repository is valid
|
||||
_repositorySelectionStatus.value = RepositorySelectionStatus.Open(repository)
|
||||
git = Git(repository)
|
||||
try {
|
||||
repository.workTree // test if repository is valid
|
||||
_repositorySelectionStatus.value = RepositorySelectionStatus.Open(repository)
|
||||
git = Git(repository)
|
||||
|
||||
onRepositoryChanged(repository.directory.parent)
|
||||
appStateManager.latestOpenedRepositoryPath = directory.absolutePath
|
||||
refreshRepositoryInfo()
|
||||
} catch (ex: Exception) {
|
||||
ex.printStackTrace()
|
||||
onRepositoryChanged(null)
|
||||
onRepositoryChanged(repository.directory.parent)
|
||||
appStateManager.latestOpenedRepositoryPath = directory.absolutePath
|
||||
refreshRepositoryInfo()
|
||||
} catch (ex: Exception) {
|
||||
ex.printStackTrace()
|
||||
onRepositoryChanged(null)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun loadLog() = managerScope.launch {
|
||||
coLoadLog()
|
||||
}
|
||||
private suspend fun coLoadLog(){
|
||||
logManager.loadLog(safeGit)
|
||||
}
|
||||
|
||||
@ -146,32 +151,40 @@ class GitManager @Inject constructor(
|
||||
}
|
||||
|
||||
fun pull() = managerScope.launch {
|
||||
remoteOperationsManager.pull(safeGit)
|
||||
logManager.loadLog(safeGit)
|
||||
safeProcessing {
|
||||
remoteOperationsManager.pull(safeGit)
|
||||
logManager.loadLog(safeGit)
|
||||
}
|
||||
}
|
||||
|
||||
fun push() = managerScope.launch {
|
||||
remoteOperationsManager.push(safeGit)
|
||||
logManager.loadLog(safeGit)
|
||||
safeProcessing {
|
||||
remoteOperationsManager.push(safeGit)
|
||||
logManager.loadLog(safeGit)
|
||||
}
|
||||
}
|
||||
|
||||
private fun refreshRepositoryInfo() = managerScope.launch {
|
||||
private suspend fun refreshRepositoryInfo() {
|
||||
statusManager.loadHasUncommitedChanges(safeGit)
|
||||
branchesManager.loadBranches(safeGit)
|
||||
stashManager.loadStashList(safeGit)
|
||||
loadLog()
|
||||
coLoadLog()
|
||||
}
|
||||
|
||||
fun stash() = managerScope.launch {
|
||||
stashManager.stash(safeGit)
|
||||
loadStatus()
|
||||
loadLog()
|
||||
safeProcessing {
|
||||
stashManager.stash(safeGit)
|
||||
loadStatus()
|
||||
loadLog()
|
||||
}
|
||||
}
|
||||
|
||||
fun popStash() = managerScope.launch {
|
||||
stashManager.popStash(safeGit)
|
||||
loadStatus()
|
||||
loadLog()
|
||||
safeProcessing {
|
||||
stashManager.popStash(safeGit)
|
||||
loadStatus()
|
||||
loadLog()
|
||||
}
|
||||
}
|
||||
|
||||
fun createBranch(branchName: String) = managerScope.launch {
|
||||
@ -215,6 +228,15 @@ class GitManager @Inject constructor(
|
||||
}
|
||||
|
||||
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