Skip to content

Commit 9931eff

Browse files
committed
Jump to Document screen when there's a current scan on startup
1 parent 0b01a83 commit 9931eff

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

app/src/main/java/org/fairscan/app/MainViewModel.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ class MainViewModel(
7373
val liveAnalysisState: StateFlow<LiveAnalysisState> = _liveAnalysisState.asStateFlow()
7474
private var lastSuccessfulLiveAnalysisState: LiveAnalysisState? = null
7575

76-
private val _navigationState = MutableStateFlow(NavigationState.initial())
77-
val currentScreen: StateFlow<Screen> = _navigationState.map { it.current }
78-
.stateIn(viewModelScope, SharingStarted.Eagerly, _navigationState.value.current)
79-
8076
private val _pageIds = MutableStateFlow(imageRepository.imageIds())
8177
val documentUiModel: StateFlow<DocumentUiModel> =
8278
_pageIds.map { ids ->
@@ -87,9 +83,18 @@ class MainViewModel(
8783
}.stateIn(
8884
scope = viewModelScope,
8985
started = SharingStarted.Eagerly,
90-
initialValue = DocumentUiModel(emptyList(), ::getBitmap)
86+
initialValue = DocumentUiModel(_pageIds.value, ::getBitmap)
9187
)
9288

89+
private val _navigationState = MutableStateFlow(value =
90+
if (_pageIds.value.isEmpty())
91+
NavigationState.initial()
92+
else
93+
NavigationState.initial().navigateTo(Screen.Main.Document())
94+
)
95+
val currentScreen: StateFlow<Screen> = _navigationState.map { it.current }
96+
.stateIn(viewModelScope, SharingStarted.Eagerly, _navigationState.value.current)
97+
9398
private val _captureState = MutableStateFlow<CaptureState>(CaptureState.Idle)
9499
val captureState: StateFlow<CaptureState> = _captureState
95100

0 commit comments

Comments
 (0)