Skip to content

Commit 50955b1

Browse files
BrayanDSOlukstbit
authored andcommitted
refactor: currentIndex flow configuration
1 parent 715641f commit 50955b1

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

AnkiDroid/src/main/java/com/ichi2/anki/previewer/PreviewerViewModel.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ class PreviewerViewModel(
4949
savedStateHandle: SavedStateHandle,
5050
) : CardViewerViewModel(),
5151
ChangeManager.Subscriber {
52-
val currentIndex = MutableStateFlow<Int>(savedStateHandle.require(PreviewerFragment.CURRENT_INDEX_ARG))
52+
val currentIndex =
53+
savedStateHandle.getMutableStateFlow(
54+
KEY_CURRENT_INDEX,
55+
initialValue = savedStateHandle.require<Int>(PreviewerFragment.CURRENT_INDEX_ARG),
56+
)
5357
val backSideOnly = savedStateHandle.getMutableStateFlow(KEY_BACKSIDE_ONLY, false)
5458
val isMarked = MutableStateFlow(false)
5559
val flag: MutableStateFlow<Flag> = MutableStateFlow(Flag.NONE)
@@ -80,9 +84,6 @@ class PreviewerViewModel(
8084
showingAnswer.collectIn(viewModelScope) {
8185
savedStateHandle[SHOWING_ANSWER_KEY] = it
8286
}
83-
currentIndex.collectIn(viewModelScope) {
84-
savedStateHandle[PreviewerFragment.CURRENT_INDEX_ARG] = it
85-
}
8687
}
8788

8889
/* *********************************************************************************************
@@ -276,6 +277,7 @@ class PreviewerViewModel(
276277

277278
companion object {
278279
private const val KEY_BACKSIDE_ONLY = "backsideOnly"
280+
private const val KEY_CURRENT_INDEX = "currentIndex"
279281
private const val SHOWING_ANSWER_KEY = "showingAnswer"
280282
}
281283
}

0 commit comments

Comments
 (0)