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,21 +168,40 @@ fun App(gitManager: GitManager, repositoryPath: String?, tabName: MutableState<S
|
|||||||
.background(MaterialTheme.colors.background)
|
.background(MaterialTheme.colors.background)
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
) {
|
) {
|
||||||
Crossfade(targetState = repositorySelectionStatus) {
|
|
||||||
|
|
||||||
@Suppress("UnnecessaryVariable") // Don't inline it because smart cast won't work
|
val linearProgressAlpha = if (isProcessing)
|
||||||
when (repositorySelectionStatus) {
|
DefaultAlpha
|
||||||
RepositorySelectionStatus.None -> {
|
else
|
||||||
WelcomePage(gitManager = gitManager)
|
0f
|
||||||
}
|
|
||||||
RepositorySelectionStatus.Loading -> {
|
LinearProgressIndicator(
|
||||||
LoadingRepository()
|
modifier = Modifier
|
||||||
}
|
.fillMaxWidth()
|
||||||
is RepositorySelectionStatus.Open -> {
|
.alpha(linearProgressAlpha)
|
||||||
RepositoryOpenPage(gitManager = gitManager)
|
)
|
||||||
|
|
||||||
|
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))
|
openRepository(File(directory))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun openRepository(directory: File) {
|
fun openRepository(directory: File) = managerScope.launch(Dispatchers.IO) {
|
||||||
println("Trying to open repository ${directory.absoluteFile}")
|
safeProcessing {
|
||||||
|
println("Trying to open repository ${directory.absoluteFile}")
|
||||||
|
|
||||||
val gitDirectory = if (directory.name == ".git") {
|
val gitDirectory = if (directory.name == ".git") {
|
||||||
directory
|
|
||||||
} else {
|
|
||||||
val gitDir = File(directory, ".git")
|
|
||||||
if (gitDir.exists() && gitDir.isDirectory) {
|
|
||||||
gitDir
|
|
||||||
} else
|
|
||||||
directory
|
directory
|
||||||
|
} else {
|
||||||
|
val gitDir = File(directory, ".git")
|
||||||
|
if (gitDir.exists() && gitDir.isDirectory) {
|
||||||
|
gitDir
|
||||||
|
} else
|
||||||
|
directory
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val builder = FileRepositoryBuilder()
|
val builder = FileRepositoryBuilder()
|
||||||
val repository: Repository = builder.setGitDir(gitDirectory)
|
val repository: Repository = builder.setGitDir(gitDirectory)
|
||||||
.readEnvironment() // scan environment GIT_* variables
|
.readEnvironment() // scan environment GIT_* variables
|
||||||
.findGitDir() // scan up the file system tree
|
.findGitDir() // scan up the file system tree
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
repository.workTree // test if repository is valid
|
repository.workTree // test if repository is valid
|
||||||
_repositorySelectionStatus.value = RepositorySelectionStatus.Open(repository)
|
_repositorySelectionStatus.value = RepositorySelectionStatus.Open(repository)
|
||||||
git = Git(repository)
|
git = Git(repository)
|
||||||
|
|
||||||
onRepositoryChanged(repository.directory.parent)
|
onRepositoryChanged(repository.directory.parent)
|
||||||
appStateManager.latestOpenedRepositoryPath = directory.absolutePath
|
appStateManager.latestOpenedRepositoryPath = directory.absolutePath
|
||||||
refreshRepositoryInfo()
|
refreshRepositoryInfo()
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
ex.printStackTrace()
|
ex.printStackTrace()
|
||||||
onRepositoryChanged(null)
|
onRepositoryChanged(null)
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun loadLog() = managerScope.launch {
|
fun loadLog() = managerScope.launch {
|
||||||
|
coLoadLog()
|
||||||
|
}
|
||||||
|
private suspend fun coLoadLog(){
|
||||||
logManager.loadLog(safeGit)
|
logManager.loadLog(safeGit)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,32 +151,40 @@ class GitManager @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun pull() = managerScope.launch {
|
fun pull() = managerScope.launch {
|
||||||
remoteOperationsManager.pull(safeGit)
|
safeProcessing {
|
||||||
logManager.loadLog(safeGit)
|
remoteOperationsManager.pull(safeGit)
|
||||||
|
logManager.loadLog(safeGit)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun push() = managerScope.launch {
|
fun push() = managerScope.launch {
|
||||||
remoteOperationsManager.push(safeGit)
|
safeProcessing {
|
||||||
logManager.loadLog(safeGit)
|
remoteOperationsManager.push(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 {
|
||||||
stashManager.stash(safeGit)
|
safeProcessing {
|
||||||
loadStatus()
|
stashManager.stash(safeGit)
|
||||||
loadLog()
|
loadStatus()
|
||||||
|
loadLog()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun popStash() = managerScope.launch {
|
fun popStash() = managerScope.launch {
|
||||||
stashManager.popStash(safeGit)
|
safeProcessing {
|
||||||
loadStatus()
|
stashManager.popStash(safeGit)
|
||||||
loadLog()
|
loadStatus()
|
||||||
|
loadLog()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createBranch(branchName: String) = managerScope.launch {
|
fun createBranch(branchName: String) = managerScope.launch {
|
||||||
@ -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