Skip to content

Commit 5ec6c8b

Browse files
committed
wip
1 parent 94fddc3 commit 5ec6c8b

File tree

5 files changed

+29
-8
lines changed

5 files changed

+29
-8
lines changed

app/src/main/java/com/hoc081098/datastoresample/Locator.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.hoc081098.datastoresample.data.UserPreferencesRepositoryImpl
77
import com.hoc081098.datastoresample.domain.ChangeShowCompleted
88
import com.hoc081098.datastoresample.domain.ChangeTheme
99
import com.hoc081098.datastoresample.domain.EnableSortByDeadline
10+
import com.hoc081098.datastoresample.domain.EnableSortByPriority
1011
import com.hoc081098.datastoresample.domain.GetTheme
1112
import com.hoc081098.datastoresample.domain.model.FilterSortTasks
1213
import com.hoc081098.datastoresample.ui.MainViewModel
@@ -27,6 +28,7 @@ object Locator {
2728
getTheme = getTheme,
2829
changeShowCompleted = changeShowCompleted,
2930
enableSortByDeadline = enableSortByDeadline,
31+
enableSortByPriority = enableSortByPriority,
3032
changeTheme = changeTheme,
3133
)
3234

@@ -44,6 +46,8 @@ object Locator {
4446

4547
private val enableSortByDeadline get() = EnableSortByDeadline(userPreferencesRepository)
4648

49+
private val enableSortByPriority get() = EnableSortByPriority(userPreferencesRepository)
50+
4751
private val taskRepository by lazy { TaskRepositoryImpl() }
4852
private val userPreferencesRepository by lazy {
4953
val dataStore = requireApplication.createDataStore(name = "user_preferences")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.hoc081098.datastoresample.domain
2+
3+
import com.hoc081098.datastoresample.domain.repo.UserPreferencesRepository
4+
5+
class EnableSortByPriority(private val userPreferencesRepository: UserPreferencesRepository) {
6+
suspend operator fun invoke(enabled: Boolean) =
7+
userPreferencesRepository.enableSortByPriority(enabled)
8+
}

app/src/main/java/com/hoc081098/datastoresample/ui/MainActivity.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class MainActivity : AppCompatActivity() {
3838
state = state,
3939
changeShowCompleted = viewModel::changeShowCompleted,
4040
enableSortByDeadline = viewModel::enableSortByDeadline,
41+
enableSortByPriority=viewModel::enableSortByPriority,
4142
lightTheme = !darkTheme,
4243
changeTheme = viewModel::changeTheme,
4344
)

app/src/main/java/com/hoc081098/datastoresample/ui/MainScreen.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ fun MainScreen(
4949
state: FilteredSortedTasks?,
5050
changeShowCompleted: (Boolean) -> Unit,
5151
enableSortByDeadline: (Boolean) -> Unit,
52+
enableSortByPriority: (Boolean) -> Unit,
5253
lightTheme: Boolean,
5354
changeTheme: (Boolean) -> Unit,
5455
) {
@@ -121,9 +122,7 @@ fun MainScreen(
121122
text = "Priority",
122123
selected = state.sortOrder == SortOrder.BY_PRIORITY
123124
|| state.sortOrder == SortOrder.BY_DEADLINE_AND_PRIORITY,
124-
setSelected = {
125-
126-
},
125+
setSelected = enableSortByPriority,
127126
shape = RoundedCornerShape(14.dp)
128127
)
129128

@@ -228,11 +227,12 @@ fun SortChip(
228227
fun MainScreenPreview() {
229228
DataStoreSampleTheme {
230229
MainScreen(
231-
null,
232-
{},
233-
{},
234-
false,
235-
{}
230+
state = null,
231+
changeShowCompleted = {},
232+
enableSortByDeadline = {},
233+
enableSortByPriority = {},
234+
lightTheme = false,
235+
changeTheme = {}
236236
)
237237
}
238238
}

app/src/main/java/com/hoc081098/datastoresample/ui/MainViewModel.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import androidx.lifecycle.viewModelScope
77
import com.hoc081098.datastoresample.domain.ChangeShowCompleted
88
import com.hoc081098.datastoresample.domain.ChangeTheme
99
import com.hoc081098.datastoresample.domain.EnableSortByDeadline
10+
import com.hoc081098.datastoresample.domain.EnableSortByPriority
1011
import com.hoc081098.datastoresample.domain.GetTheme
1112
import com.hoc081098.datastoresample.domain.model.FilterSortTasks
1213
import com.hoc081098.datastoresample.domain.model.FilteredSortedTasks
@@ -21,6 +22,7 @@ class MainViewModel(
2122
getTheme: GetTheme,
2223
private val _changeShowCompleted: ChangeShowCompleted,
2324
private val _enableSortByDeadline: EnableSortByDeadline,
25+
private val _enableSortByPriority: EnableSortByPriority,
2426
private val _changeTheme: ChangeTheme,
2527
) : ViewModel() {
2628
val state: StateFlow<FilteredSortedTasks?> = filterSortTasks()
@@ -53,6 +55,10 @@ class MainViewModel(
5355
viewModelScope.launch { _enableSortByDeadline(enabled) }
5456
}
5557

58+
fun enableSortByPriority(enabled: Boolean) {
59+
viewModelScope.launch { _enableSortByPriority(enabled) }
60+
}
61+
5662
fun changeTheme(lightTheme: Boolean) {
5763
viewModelScope.launch { _changeTheme(lightTheme) }
5864
}
@@ -62,6 +68,7 @@ class MainViewModel(
6268
private val getTheme: GetTheme,
6369
private val changeShowCompleted: ChangeShowCompleted,
6470
private val enableSortByDeadline: EnableSortByDeadline,
71+
private val enableSortByPriority: EnableSortByPriority,
6572
private val changeTheme: ChangeTheme,
6673

6774
) : ViewModelProvider.Factory {
@@ -73,6 +80,7 @@ class MainViewModel(
7380
getTheme = getTheme,
7481
_changeShowCompleted = changeShowCompleted,
7582
_enableSortByDeadline = enableSortByDeadline,
83+
_enableSortByPriority = enableSortByPriority,
7684
_changeTheme = changeTheme,
7785
) as T
7886
}

0 commit comments

Comments
 (0)