Reduced log flickering by hidding load unless it takes some time (constant)
This commit is contained in:
parent
c28a2834ae
commit
e92a3a5baa
@ -2,6 +2,7 @@ package app.viewmodels
|
|||||||
|
|
||||||
import androidx.compose.foundation.lazy.LazyListState
|
import androidx.compose.foundation.lazy.LazyListState
|
||||||
import app.AppPreferences
|
import app.AppPreferences
|
||||||
|
import app.extensions.delayedStateChange
|
||||||
import app.git.*
|
import app.git.*
|
||||||
import app.git.graph.GraphCommitList
|
import app.git.graph.GraphCommitList
|
||||||
import app.git.graph.GraphNode
|
import app.git.graph.GraphNode
|
||||||
@ -11,12 +12,10 @@ import kotlinx.coroutines.CoroutineScope
|
|||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.*
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import org.eclipse.jgit.lib.Ref
|
import org.eclipse.jgit.lib.Ref
|
||||||
import org.eclipse.jgit.revwalk.RevCommit
|
import org.eclipse.jgit.revwalk.RevCommit
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Provider
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents when the search filter is not being used or the results list is empty
|
* Represents when the search filter is not being used or the results list is empty
|
||||||
@ -29,6 +28,8 @@ private const val NONE_MATCHING_INDEX = 0
|
|||||||
*/
|
*/
|
||||||
private const val FIRST_INDEX = 1
|
private const val FIRST_INDEX = 1
|
||||||
|
|
||||||
|
private const val LOG_MIN_TIME_IN_MS_TO_SHOW_LOAD = 500L
|
||||||
|
|
||||||
class LogViewModel @Inject constructor(
|
class LogViewModel @Inject constructor(
|
||||||
private val logManager: LogManager,
|
private val logManager: LogManager,
|
||||||
private val statusManager: StatusManager,
|
private val statusManager: StatusManager,
|
||||||
@ -78,9 +79,12 @@ class LogViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun loadLog(git: Git) {
|
private suspend fun loadLog(git: Git) = delayedStateChange(
|
||||||
_logStatus.value = LogStatus.Loading
|
delayMs = LOG_MIN_TIME_IN_MS_TO_SHOW_LOAD,
|
||||||
|
onDelayTriggered = {
|
||||||
|
_logStatus.value = LogStatus.Loading
|
||||||
|
}
|
||||||
|
) {
|
||||||
val currentBranch = branchesManager.currentBranchRef(git)
|
val currentBranch = branchesManager.currentBranchRef(git)
|
||||||
|
|
||||||
val statusSummary = statusManager.getStatusSummary(
|
val statusSummary = statusManager.getStatusSummary(
|
||||||
@ -88,24 +92,26 @@ class LogViewModel @Inject constructor(
|
|||||||
)
|
)
|
||||||
|
|
||||||
val hasUncommitedChanges = statusSummary.total > 0
|
val hasUncommitedChanges = statusSummary.total > 0
|
||||||
val commitsLimit = if(appPreferences.commitsLimitEnabled) {
|
val commitsLimit = if (appPreferences.commitsLimitEnabled) {
|
||||||
appPreferences.commitsLimit
|
appPreferences.commitsLimit
|
||||||
} else
|
} else
|
||||||
Int.MAX_VALUE
|
Int.MAX_VALUE
|
||||||
|
|
||||||
val commitsLimitDisplayed = if(appPreferences.commitsLimitEnabled) {
|
val commitsLimitDisplayed = if (appPreferences.commitsLimitEnabled) {
|
||||||
appPreferences.commitsLimit
|
appPreferences.commitsLimit
|
||||||
} else
|
} else
|
||||||
-1
|
-1
|
||||||
|
|
||||||
val log = logManager.loadLog(git, currentBranch, hasUncommitedChanges, commitsLimit)
|
val log = logManager.loadLog(git, currentBranch, hasUncommitedChanges, commitsLimit)
|
||||||
|
|
||||||
_logStatus.value = LogStatus.Loaded(hasUncommitedChanges, log, currentBranch, statusSummary, commitsLimitDisplayed)
|
_logStatus.value =
|
||||||
|
LogStatus.Loaded(hasUncommitedChanges, log, currentBranch, statusSummary, commitsLimitDisplayed)
|
||||||
|
|
||||||
// Remove search filter if the log has been updated
|
// Remove search filter if the log has been updated
|
||||||
_logSearchFilterResults.value = LogSearch.NotSearching
|
_logSearchFilterResults.value = LogSearch.NotSearching
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun pushToRemoteBranch(branch: Ref) = tabState.safeProcessing(
|
fun pushToRemoteBranch(branch: Ref) = tabState.safeProcessing(
|
||||||
refreshType = RefreshType.ALL_DATA,
|
refreshType = RefreshType.ALL_DATA,
|
||||||
) { git ->
|
) { git ->
|
||||||
@ -344,7 +350,7 @@ class LogViewModel @Inject constructor(
|
|||||||
_logSearchFilterResults.value = LogSearch.NotSearching
|
_logSearchFilterResults.value = LogSearch.NotSearching
|
||||||
}
|
}
|
||||||
|
|
||||||
fun rebaseInteractive(revCommit: RevCommit) = tabState.runOperation (
|
fun rebaseInteractive(revCommit: RevCommit) = tabState.runOperation(
|
||||||
refreshType = RefreshType.NONE
|
refreshType = RefreshType.NONE
|
||||||
) {
|
) {
|
||||||
tabState.emitNewTaskEvent(TaskEvent.RebaseInteractive(revCommit))
|
tabState.emitNewTaskEvent(TaskEvent.RebaseInteractive(revCommit))
|
||||||
|
Loading…
Reference in New Issue
Block a user