fix: restore boundary progress publishes and animate the bar at constant velocity
This commit is contained in:
@@ -195,6 +195,18 @@ class LocalDictionaryRepository(
|
|||||||
val lastEmittedPercent = AtomicInteger(-1)
|
val lastEmittedPercent = AtomicInteger(-1)
|
||||||
val lastProgressEmitMs = AtomicLong(0L)
|
val lastProgressEmitMs = AtomicLong(0L)
|
||||||
|
|
||||||
|
val publishCurrentProgress = {
|
||||||
|
val tracker = progressTracker
|
||||||
|
if (tracker != null) {
|
||||||
|
val progress = tracker.progress()
|
||||||
|
lastEmittedPercent.set((progress * 100f).toInt().coerceIn(0, 100))
|
||||||
|
lastProgressEmitMs.set(SystemClock.elapsedRealtime())
|
||||||
|
mutableIndexingProgress.update { p ->
|
||||||
|
p.copy(progress = progress)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
supervisorScope {
|
supervisorScope {
|
||||||
filesToIndex.map { file ->
|
filesToIndex.map { file ->
|
||||||
async {
|
async {
|
||||||
@@ -228,6 +240,7 @@ class LocalDictionaryRepository(
|
|||||||
|
|
||||||
if (res is OperationResult.Success) {
|
if (res is OperationResult.Success) {
|
||||||
progressTracker?.updateFileProgress(file.name, 1.0f)
|
progressTracker?.updateFileProgress(file.name, 1.0f)
|
||||||
|
publishCurrentProgress()
|
||||||
totalArticlesIndexed.addAndGet(res.data.articleCount)
|
totalArticlesIndexed.addAndGet(res.data.articleCount)
|
||||||
val dictionary = res.data
|
val dictionary = res.data
|
||||||
addDictionary(dictionary)
|
addDictionary(dictionary)
|
||||||
|
|||||||
+19
-5
@@ -1,8 +1,8 @@
|
|||||||
package com.example.research.ui.settings.components
|
package com.example.research.ui.settings.components
|
||||||
|
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
import androidx.compose.animation.core.FastOutSlowInEasing
|
import androidx.compose.animation.core.Animatable
|
||||||
import androidx.compose.animation.core.animateFloatAsState
|
import androidx.compose.animation.core.LinearEasing
|
||||||
import androidx.compose.animation.core.tween
|
import androidx.compose.animation.core.tween
|
||||||
import androidx.compose.animation.expandVertically
|
import androidx.compose.animation.expandVertically
|
||||||
import androidx.compose.animation.fadeIn
|
import androidx.compose.animation.fadeIn
|
||||||
@@ -19,6 +19,10 @@ import androidx.compose.ui.res.stringResource
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.example.research.R
|
import com.example.research.R
|
||||||
|
|
||||||
|
private const val MILLIS_PER_PROGRESS_UNIT = 10_000
|
||||||
|
private const val MIN_PROGRESS_MOTION_MS = 50
|
||||||
|
private const val MAX_PROGRESS_MOTION_MS = 650
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun DictionaryProgressSection(
|
fun DictionaryProgressSection(
|
||||||
visible: Boolean,
|
visible: Boolean,
|
||||||
@@ -58,11 +62,21 @@ fun DictionaryProgressSection(
|
|||||||
displayedTestTag = testTag
|
displayedTestTag = testTag
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val animatedProgress by animateFloatAsState(
|
val animatedState = remember { Animatable(0f) }
|
||||||
|
LaunchedEffect(monotonicTargetProgress) {
|
||||||
|
val delta = monotonicTargetProgress - animatedState.value
|
||||||
|
if (delta > 0f) {
|
||||||
|
animatedState.animateTo(
|
||||||
targetValue = monotonicTargetProgress,
|
targetValue = monotonicTargetProgress,
|
||||||
animationSpec = tween(durationMillis = 650, easing = FastOutSlowInEasing),
|
animationSpec = tween(
|
||||||
label = "dictionary-progress"
|
durationMillis = (delta * MILLIS_PER_PROGRESS_UNIT).toInt()
|
||||||
|
.coerceIn(MIN_PROGRESS_MOTION_MS, MAX_PROGRESS_MOTION_MS),
|
||||||
|
easing = LinearEasing,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val animatedProgress = animatedState.value
|
||||||
|
|
||||||
Column(modifier = Modifier.testTag(displayedTestTag)) {
|
Column(modifier = Modifier.testTag(displayedTestTag)) {
|
||||||
Row(
|
Row(
|
||||||
|
|||||||
Reference in New Issue
Block a user