fix: tie back arrow to pipeline idle state
Computed from operation states in SettingsViewModel instead of a fixed delay; cancel and error release the arrow immediately.
This commit is contained in:
@@ -11,3 +11,6 @@ sealed class DownloadState {
|
|||||||
data class Error(val message: String) : DownloadState()
|
data class Error(val message: String) : DownloadState()
|
||||||
data object Cancelled : DownloadState()
|
data object Cancelled : DownloadState()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val DownloadState.isActive: Boolean
|
||||||
|
get() = this is DownloadState.Loading || this is DownloadState.Extracting || this is DownloadState.Success
|
||||||
|
|||||||
@@ -9,15 +9,11 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
|||||||
import androidx.window.core.layout.WindowSizeClass.Companion.WIDTH_DP_MEDIUM_LOWER_BOUND
|
import androidx.window.core.layout.WindowSizeClass.Companion.WIDTH_DP_MEDIUM_LOWER_BOUND
|
||||||
import com.example.research.feature.search.SearchAction
|
import com.example.research.feature.search.SearchAction
|
||||||
import com.example.research.feature.search.SearchViewModel
|
import com.example.research.feature.search.SearchViewModel
|
||||||
import com.example.research.feature.download.model.DownloadState
|
|
||||||
import com.example.research.ui.about.AboutScreen
|
import com.example.research.ui.about.AboutScreen
|
||||||
import com.example.research.ui.article.ArticleRoute
|
import com.example.research.ui.article.ArticleRoute
|
||||||
import com.example.research.ui.main.MainRoute
|
import com.example.research.ui.main.MainRoute
|
||||||
import com.example.research.ui.settings.ImportState
|
|
||||||
import com.example.research.ui.settings.SettingsRoute
|
import com.example.research.ui.settings.SettingsRoute
|
||||||
import com.example.research.ui.settings.SettingsViewModel
|
import com.example.research.ui.settings.SettingsViewModel
|
||||||
import kotlinx.coroutines.delay
|
|
||||||
import kotlin.time.Duration.Companion.milliseconds
|
|
||||||
|
|
||||||
private data class NavigationState(
|
private data class NavigationState(
|
||||||
val shouldShowSettings: Boolean,
|
val shouldShowSettings: Boolean,
|
||||||
@@ -54,35 +50,10 @@ fun AppNavigation(
|
|||||||
val currentScreen = screenStack.lastOrNull() ?: Screen.Home
|
val currentScreen = screenStack.lastOrNull() ?: Screen.Home
|
||||||
|
|
||||||
val settingsState by settingsViewModel.uiState.collectAsStateWithLifecycle()
|
val settingsState by settingsViewModel.uiState.collectAsStateWithLifecycle()
|
||||||
val progressSnapshot by settingsViewModel.progressSnapshot.collectAsStateWithLifecycle()
|
|
||||||
val isPipelineActiveByState = remember(
|
|
||||||
progressSnapshot,
|
|
||||||
settingsState.indexingProgress.isIndexing,
|
|
||||||
settingsState.downloadState,
|
|
||||||
settingsState.importState,
|
|
||||||
) {
|
|
||||||
progressSnapshot != null ||
|
|
||||||
settingsState.indexingProgress.isIndexing ||
|
|
||||||
settingsState.downloadState is DownloadState.Loading ||
|
|
||||||
settingsState.downloadState is DownloadState.Extracting ||
|
|
||||||
settingsState.downloadState is DownloadState.Success ||
|
|
||||||
settingsState.importState is ImportState.Importing ||
|
|
||||||
settingsState.importState is ImportState.Extracting ||
|
|
||||||
settingsState.importState is ImportState.Success
|
|
||||||
}
|
|
||||||
var stickyPipelineActive by rememberSaveable { mutableStateOf(false) }
|
|
||||||
LaunchedEffect(isPipelineActiveByState) {
|
|
||||||
if (isPipelineActiveByState) {
|
|
||||||
stickyPipelineActive = true
|
|
||||||
} else {
|
|
||||||
delay(1500.milliseconds)
|
|
||||||
stickyPipelineActive = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val navState by remember {
|
val navState by remember {
|
||||||
derivedStateOf {
|
derivedStateOf {
|
||||||
val isOperationActive = stickyPipelineActive
|
val isOperationActive = !settingsState.pipelineIdle
|
||||||
val hasConfirmedNoDictionaries =
|
val hasConfirmedNoDictionaries =
|
||||||
settingsState.hasCompletedStartupScan && settingsState.dictionaries.isEmpty()
|
settingsState.hasCompletedStartupScan && settingsState.dictionaries.isEmpty()
|
||||||
val hasSeededNoDictionaries = seedNoDictionaries && !settingsState.hasCompletedStartupScan
|
val hasSeededNoDictionaries = seedNoDictionaries && !settingsState.hasCompletedStartupScan
|
||||||
|
|||||||
@@ -10,3 +10,6 @@ sealed interface ImportState {
|
|||||||
data object Success : ImportState
|
data object Success : ImportState
|
||||||
data class Error(val message: String) : ImportState
|
data class Error(val message: String) : ImportState
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val ImportState.isActive: Boolean
|
||||||
|
get() = this is ImportState.Importing || this is ImportState.Extracting || this is ImportState.Success
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ data class SettingsUiState(
|
|||||||
val importState: ImportState = ImportState.Idle,
|
val importState: ImportState = ImportState.Idle,
|
||||||
val dictionarySources: List<DictionarySource> = emptyList(),
|
val dictionarySources: List<DictionarySource> = emptyList(),
|
||||||
val hasCompletedStartupScan: Boolean = false,
|
val hasCompletedStartupScan: Boolean = false,
|
||||||
|
val pipelineIdle: Boolean = true,
|
||||||
val appVersion: String = "1.0",
|
val appVersion: String = "1.0",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import com.example.research.data.local.preferences.PreferencesManager
|
|||||||
import com.example.research.data.repository.LocalDictionaryRepository
|
import com.example.research.data.repository.LocalDictionaryRepository
|
||||||
import com.example.research.feature.download.DownloadManager
|
import com.example.research.feature.download.DownloadManager
|
||||||
import com.example.research.feature.download.model.DownloadState
|
import com.example.research.feature.download.model.DownloadState
|
||||||
|
import com.example.research.feature.download.model.isActive
|
||||||
import com.example.research.feature.download.repository.DictionaryRepository
|
import com.example.research.feature.download.repository.DictionaryRepository
|
||||||
import com.example.research.feature.import.DictionaryImportManager
|
import com.example.research.feature.import.DictionaryImportManager
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@@ -225,6 +226,9 @@ class SettingsViewModel(
|
|||||||
importState = operationState.importState,
|
importState = operationState.importState,
|
||||||
dictionaryStatus = operationState.dictionaryStatus,
|
dictionaryStatus = operationState.dictionaryStatus,
|
||||||
hasCompletedStartupScan = operationState.hasCompletedStartupScan,
|
hasCompletedStartupScan = operationState.hasCompletedStartupScan,
|
||||||
|
pipelineIdle = !isIndexing &&
|
||||||
|
!operationState.downloadState.isActive &&
|
||||||
|
!operationState.importState.isActive,
|
||||||
isThemeExpanded = operationState.isThemeExpanded,
|
isThemeExpanded = operationState.isThemeExpanded,
|
||||||
isLanguageExpanded = operationState.isLanguageExpanded,
|
isLanguageExpanded = operationState.isLanguageExpanded,
|
||||||
isDictionariesExpanded = operationState.isDictionariesExpanded,
|
isDictionariesExpanded = operationState.isDictionariesExpanded,
|
||||||
|
|||||||
Reference in New Issue
Block a user