Skip to content

Commit 693d961

Browse files
committed
first visible item index feature prep.
1 parent 9fe945d commit 693d961

5 files changed

Lines changed: 23 additions & 0 deletions

File tree

app/src/main/java/com/commandiron/vacationchecklist/data/preferences/DefaultPreferences.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,17 @@ class DefaultPreferences(
7070
0.5f
7171
)
7272
}
73+
74+
override fun saveListFirstVisibleItemIndex(itemIndex: Int) {
75+
sharedPref.edit()
76+
.putInt(Preferences.KEY_SAVE_LOAD_LIST_FIRST_VISIBLE_ITEM_INDEX, itemIndex)
77+
.apply()
78+
}
79+
80+
override fun loadListFirstVisibleItemIndex(): Int {
81+
return sharedPref.getInt(
82+
Preferences.KEY_SAVE_LOAD_LIST_FIRST_VISIBLE_ITEM_INDEX,
83+
0
84+
)
85+
}
7386
}

app/src/main/java/com/commandiron/vacationchecklist/domain/preferences/Preferences.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@ interface Preferences {
1616
fun saveSliderValue(sliderValue: Float)
1717
fun loadSliderValue(): Float
1818

19+
fun saveListFirstVisibleItemIndex(itemIndex: Int)
20+
fun loadListFirstVisibleItemIndex(): Int
21+
1922
companion object {
2023
const val KEY_SHOULD_SHOW_HOT_SPLASH = "should_show_hotSplash"
2124
const val KEY_SAVE_LOAD_ACTIVE_VACATION = "save_load_active_vacation"
2225
const val KEY_SHOULD_DOUBLE_CHECK = "should_double_check"
2326
const val KEY_SHOULD_SHOW_GRID_VIEW = "should_show_grid_view"
2427
const val KEY_SAVE_LOAD_SLIDER_VALUE = "save_load_slider_value"
28+
const val KEY_SAVE_LOAD_LIST_FIRST_VISIBLE_ITEM_INDEX = "save_load_list_first_visible_item_index"
2529
}
2630
}

app/src/main/java/com/commandiron/vacationchecklist/presentation/checklist/ChecklistState.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ data class ChecklistState(
88
val checkItems: List<CheckItem>? = null,
99
val checkedItem: CheckItem? = null,
1010
val markedItem: CheckItem? = null,
11+
val firstVisibleItemIndex: Int = 0,
1112
val doubleCheckEnabled: Boolean = false,
1213
val isLoading: Boolean = false,
1314
val showCheckAlertDialog: Boolean = false,

app/src/main/java/com/commandiron/vacationchecklist/presentation/checklist/ChecklistUserEvent.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.commandiron.vacationchecklist.presentation.checklist
33
import com.commandiron.vacationchecklist.domain.model.CheckItem
44

55
sealed class ChecklistUserEvent{
6+
data class OnScrollCompleted(val firstVisibleItemIndex: Int): ChecklistUserEvent()
67
data class OnCheck(val checkedItem: CheckItem): ChecklistUserEvent()
78
data class OnMark(val markedItem: CheckItem): ChecklistUserEvent()
89

app/src/main/java/com/commandiron/vacationchecklist/presentation/checklist/ChecklistViewModel.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ class ChecklistViewModel @Inject constructor(
3535

3636
fun onEvent(userEvent: ChecklistUserEvent) {
3737
when (userEvent) {
38+
is ChecklistUserEvent.OnScrollCompleted -> {
39+
preferences.saveListFirstVisibleItemIndex(userEvent.firstVisibleItemIndex)
40+
}
3841
is ChecklistUserEvent.OnCheck -> {
3942
if(!userEvent.checkedItem.isMarked){
4043
if(state.doubleCheckEnabled){
@@ -145,6 +148,7 @@ class ChecklistViewModel @Inject constructor(
145148

146149
private fun loadSettings() {
147150
state = state.copy(
151+
firstVisibleItemIndex = preferences.loadListFirstVisibleItemIndex(),
148152
doubleCheckEnabled = preferences.loadShouldDoubleCheck(),
149153
gridViewEnabled = preferences.loadShouldShowGridView(),
150154
sliderValue = preferences.loadSliderValue()

0 commit comments

Comments
 (0)