Skip to content

Commit a20518b

Browse files
committed
Reverts saved state to enums
1 parent 32539bf commit a20518b

File tree

1 file changed

+6
-4
lines changed
  • app/src/main/java/com/example/android/architecture/blueprints/todoapp/tasks

1 file changed

+6
-4
lines changed

app/src/main/java/com/example/android/architecture/blueprints/todoapp/tasks/TasksViewModel.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ import com.example.android.architecture.blueprints.todoapp.data.Result.Success
3232
import com.example.android.architecture.blueprints.todoapp.data.Task
3333
import com.example.android.architecture.blueprints.todoapp.data.source.TasksDataSource
3434
import com.example.android.architecture.blueprints.todoapp.data.source.TasksRepository
35-
import com.example.android.architecture.blueprints.todoapp.tasks.TasksFilterType.*
35+
import com.example.android.architecture.blueprints.todoapp.tasks.TasksFilterType.ACTIVE_TASKS
36+
import com.example.android.architecture.blueprints.todoapp.tasks.TasksFilterType.ALL_TASKS
37+
import com.example.android.architecture.blueprints.todoapp.tasks.TasksFilterType.COMPLETED_TASKS
3638
import kotlinx.coroutines.launch
3739

3840
/**
@@ -106,7 +108,7 @@ class TasksViewModel(
106108
* [TasksFilterType.ACTIVE_TASKS]
107109
*/
108110
fun setFiltering(requestType: TasksFilterType) {
109-
savedStateHandle.set(TASKS_FILTER_SAVED_STATE_KEY, requestType.ordinal)
111+
savedStateHandle.set(TASKS_FILTER_SAVED_STATE_KEY, requestType)
110112

111113
// Depending on the filter type, set the filtering label, icon drawables, etc.
112114
when (requestType) {
@@ -237,8 +239,8 @@ class TasksViewModel(
237239
}
238240

239241
private fun getSavedFilterType() : TasksFilterType {
240-
return TasksFilterType
241-
.values()[savedStateHandle.get(TASKS_FILTER_SAVED_STATE_KEY) ?: ALL_TASKS.ordinal]
242+
val get: TasksFilterType? = savedStateHandle.get(TASKS_FILTER_SAVED_STATE_KEY)
243+
return get ?: ALL_TASKS
242244
}
243245
}
244246

0 commit comments

Comments
 (0)