File tree Expand file tree Collapse file tree
app/src/main/java/com/commandiron/vacationchecklist Expand file tree Collapse file tree Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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 ,
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package com.commandiron.vacationchecklist.presentation.checklist
33import com.commandiron.vacationchecklist.domain.model.CheckItem
44
55sealed 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
Original file line number Diff line number Diff 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()
You can’t perform that action at this time.
0 commit comments