Added clone progress and changed clone button to PrimaryButton
This commit is contained in:
parent
df638defb8
commit
c1fdd891c6
@ -224,9 +224,13 @@ class RemoteOperationsManager @Inject constructor(
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
fun clone(directory: File, url: String): Flow<CloneStatus> = callbackFlow {
|
||||
var lastTitle: String = ""
|
||||
var lastTotalWork = 0
|
||||
var progress = 0
|
||||
|
||||
try {
|
||||
ensureActive()
|
||||
this.trySend(CloneStatus.Cloning(0))
|
||||
trySend(CloneStatus.Cloning("Starting...", progress, lastTotalWork))
|
||||
|
||||
Git.cloneRepository()
|
||||
.setDirectory(directory)
|
||||
@ -239,18 +243,22 @@ class RemoteOperationsManager @Inject constructor(
|
||||
|
||||
override fun beginTask(title: String?, totalWork: Int) {
|
||||
println("ProgressMonitor Begin task with title: $title")
|
||||
lastTitle = title.orEmpty()
|
||||
lastTotalWork = totalWork
|
||||
progress = 0
|
||||
trySend(CloneStatus.Cloning(lastTitle, progress, lastTotalWork))
|
||||
}
|
||||
|
||||
override fun update(completed: Int) {
|
||||
println("ProgressMonitor Update $completed")
|
||||
ensureActive()
|
||||
trySend(CloneStatus.Cloning(completed))
|
||||
|
||||
progress += completed
|
||||
trySend(CloneStatus.Cloning(lastTitle, progress, lastTotalWork))
|
||||
}
|
||||
|
||||
override fun endTask() {
|
||||
println("ProgressMonitor End task")
|
||||
ensureActive()
|
||||
trySend(CloneStatus.CheckingOut)
|
||||
}
|
||||
|
||||
override fun isCancelled(): Boolean {
|
||||
@ -282,9 +290,8 @@ class RemoteOperationsManager @Inject constructor(
|
||||
|
||||
sealed class CloneStatus {
|
||||
object None : CloneStatus()
|
||||
data class Cloning(val progress: Int) : CloneStatus()
|
||||
data class Cloning(val taskName: String, val progress: Int, val total: Int) : CloneStatus()
|
||||
object Cancelling : CloneStatus()
|
||||
object CheckingOut : CloneStatus()
|
||||
data class Fail(val reason: String) : CloneStatus()
|
||||
data class Completed(val repoDir: File) : CloneStatus()
|
||||
}
|
@ -19,6 +19,7 @@ import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import app.git.CloneStatus
|
||||
import app.theme.primaryTextColor
|
||||
import app.ui.components.PrimaryButton
|
||||
import app.viewmodels.CloneViewModel
|
||||
import openDirectoryDialog
|
||||
import java.io.File
|
||||
@ -39,11 +40,8 @@ fun CloneDialog(
|
||||
.animateContentSize()
|
||||
) {
|
||||
when (cloneStatusValue) {
|
||||
CloneStatus.CheckingOut -> {
|
||||
Cloning(cloneViewModel)
|
||||
}
|
||||
is CloneStatus.Cloning -> {
|
||||
Cloning(cloneViewModel)
|
||||
Cloning(cloneViewModel, cloneStatusValue)
|
||||
}
|
||||
is CloneStatus.Cancelling -> {
|
||||
onClose()
|
||||
@ -197,7 +195,7 @@ private fun CloneInput(
|
||||
) {
|
||||
Text("Cancel")
|
||||
}
|
||||
Button(
|
||||
PrimaryButton(
|
||||
onClick = {
|
||||
cloneViewModel.clone(directory, url)
|
||||
},
|
||||
@ -205,23 +203,42 @@ private fun CloneInput(
|
||||
.focusOrder(cloneButtonFocusRequester) {
|
||||
previous = directoryButtonFocusRequester
|
||||
next = cancelButtonFocusRequester
|
||||
}
|
||||
) {
|
||||
Text("Clone")
|
||||
}
|
||||
},
|
||||
text = "Clone"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun Cloning(cloneViewModel: CloneViewModel) {
|
||||
private fun Cloning(cloneViewModel: CloneViewModel, cloneStatusValue: CloneStatus.Cloning) {
|
||||
Column (
|
||||
modifier = Modifier
|
||||
.fillMaxWidth(),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
|
||||
CircularProgressIndicator(modifier = Modifier.padding(horizontal = 16.dp))
|
||||
|
||||
val progress = remember(cloneStatusValue) {
|
||||
val total = cloneStatusValue.total
|
||||
|
||||
if(total == 0) // Prevent division by 0
|
||||
-1f
|
||||
else
|
||||
cloneStatusValue.progress / total.toFloat()
|
||||
}
|
||||
|
||||
if(progress >= 0f)
|
||||
CircularProgressIndicator(
|
||||
modifier = Modifier.padding(vertical = 16.dp),
|
||||
progress = progress
|
||||
)
|
||||
else // Show indeterminate if we do not know the total (aka total == 0 or progress == -1)
|
||||
CircularProgressIndicator(
|
||||
modifier = Modifier.padding(vertical = 16.dp),
|
||||
)
|
||||
|
||||
Text(cloneStatusValue.taskName, color = MaterialTheme.colors.primaryTextColor)
|
||||
|
||||
TextButton(
|
||||
modifier = Modifier
|
||||
|
Loading…
Reference in New Issue
Block a user