Skip to content

Commit 4612212

Browse files
committed
TaskListFragment.kt: Temporarily remove sorting functionality for now (#639)
A custom sorting dialog is in the works - it will be Compose-based so we will have to first migrate this entire fragment to Compose (#582) * Remove sorting functionality from `TasksListViewModel`
1 parent 968d256 commit 4612212

2 files changed

Lines changed: 0 additions & 117 deletions

File tree

features/tasks/src/main/kotlin/com/edricchan/studybuddy/features/tasks/list/ui/compat/TaskListFragment.kt

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,6 @@ class TaskListFragment : ViewBindingFragment<FragTodoBinding>(FragTodoBinding::i
109109
}
110110
}
111111
}
112-
item(context.getString(R.string.menu_frag_task_sort_by_title)) {
113-
requestDismissOnClick = false
114-
setIcon(R.drawable.ic_sort_24dp)
115-
setItemClickListener {
116-
showSortByOptions()
117-
}
118-
}
119112
item(context.getString(CoreResR.string.menu_settings_title)) {
120113
setIcon(AppIcons.Compat.Settings.iconRes)
121114
setItemClickListener {
@@ -275,56 +268,6 @@ class TaskListFragment : ViewBindingFragment<FragTodoBinding>(FragTodoBinding::i
275268
}
276269
}
277270

278-
// TODO: Use a more appropriate UI, see tracking issue
279-
// https://github.com/EdricChan03/studybuddy-android/issues/639
280-
private fun showSortByOptions() {
281-
showSingleSelectBottomSheet(
282-
headerTitleRes = R.string.task_sort_dialog_header_title,
283-
onConfirm = {
284-
viewLifecycleOwner.lifecycleScope.launch {
285-
viewModel.updateSort(value = it.id)
286-
}
287-
}
288-
) {
289-
val context = requireContext()
290-
291-
isSelected = { item, _ ->
292-
viewModel.compatQuery.value == item.id
293-
}
294-
295-
addItem(
296-
id = TodoSortValues.NONE,
297-
title = context.getString(R.string.sort_by_bottomsheet_none_title)
298-
) {
299-
iconRes = R.drawable.ic_close_24dp
300-
}
301-
addItem(
302-
id = TodoSortValues.TITLE_ASC,
303-
title = context.getString(R.string.sort_by_bottomsheet_title_asc_title)
304-
) {
305-
iconRes = R.drawable.ic_sort_ascending_24dp
306-
}
307-
addItem(
308-
id = TodoSortValues.TITLE_DESC,
309-
title = context.getString(R.string.sort_by_bottomsheet_title_desc_title)
310-
) {
311-
iconRes = R.drawable.ic_sort_descending_24dp
312-
}
313-
addItem(
314-
id = TodoSortValues.DUE_DATE_NEW_TO_OLD,
315-
title = context.getString(R.string.sort_by_bottomsheet_due_date_newest_title)
316-
) {
317-
iconRes = R.drawable.ic_sort_descending_24dp
318-
}
319-
addItem(
320-
id = TodoSortValues.DUE_DATE_OLD_TO_NEW,
321-
title = context.getString(R.string.sort_by_bottomsheet_due_date_oldest_title)
322-
) {
323-
iconRes = R.drawable.ic_sort_ascending_24dp
324-
}
325-
}
326-
}
327-
328271
private fun newTaskActivity() {
329272
navController.navigateToCreateTask()
330273
}

features/tasks/src/main/kotlin/com/edricchan/studybuddy/features/tasks/vm/TasksListViewModel.kt

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ import androidx.lifecycle.ViewModel
88
import androidx.lifecycle.viewModelScope
99
import com.edricchan.studybuddy.data.common.QueryMapper
1010
import com.edricchan.studybuddy.domain.common.sorting.SortDirection
11-
import com.edricchan.studybuddy.domain.common.sorting.toFirestoreDirection
1211
import com.edricchan.studybuddy.exts.common.TAG
1312
import com.edricchan.studybuddy.features.tasks.constants.sharedprefs.TodoOptionsPrefConstants
1413
import com.edricchan.studybuddy.features.tasks.constants.sharedprefs.TodoOptionsPrefConstants.TodoSortValues
15-
import com.edricchan.studybuddy.features.tasks.data.mapper.toDto
1614
import com.edricchan.studybuddy.features.tasks.data.model.TodoItem
1715
import com.edricchan.studybuddy.features.tasks.data.repo.TaskRepository
1816
import com.edricchan.studybuddy.features.tasks.data.repo.toggleCompleted
@@ -33,20 +31,6 @@ class TasksListViewModel @Inject constructor(
3331
@param:ApplicationContext private val context: Context,
3432
private val savedState: SavedStateHandle
3533
) : ViewModel() {
36-
private val taskOptionsPrefs = context.getSharedPreferences(
37-
TodoOptionsPrefConstants.FILE_TODO_OPTIONS,
38-
Context.MODE_PRIVATE
39-
)
40-
41-
// TODO: Remove when migrated to new UI for sorting preferences
42-
private val sortCompatMap = mapOf(
43-
TodoSortValues.NONE to null,
44-
TodoSortValues.TITLE_ASC to (TaskItem.Field.Title to SortDirection.Ascending),
45-
TodoSortValues.TITLE_DESC to (TaskItem.Field.Title to SortDirection.Descending),
46-
TodoSortValues.DUE_DATE_NEW_TO_OLD to (TaskItem.Field.DueDate to SortDirection.Descending),
47-
TodoSortValues.DUE_DATE_OLD_TO_NEW to (TaskItem.Field.DueDate to SortDirection.Ascending)
48-
)
49-
5034
// A MutableStateFlow but without strict equality comparisons
5135
private val _query =
5236
MutableSharedFlow<QueryMapper?>(replay = 1, onBufferOverflow = BufferOverflow.DROP_OLDEST)
@@ -64,39 +48,6 @@ class TasksListViewModel @Inject constructor(
6448
setQuery(null)
6549
}
6650

67-
/** The (compat) Firestore query to use, in its [TodoSortValues] form. */
68-
val compatQuery = savedState.getStateFlow(
69-
KEY_COMPAT_QUERY,
70-
taskOptionsPrefs.getString(
71-
TodoOptionsPrefConstants.PREF_DEFAULT_SORT, TodoSortValues.NONE
72-
)
73-
)
74-
75-
/** Updates the current Firestore query with the new sorting option to use. */
76-
@Deprecated("For backwards compatibility with existing shared prefs")
77-
suspend fun updateSort(value: String) {
78-
// Persist updated data
79-
taskOptionsPrefs.edit {
80-
putString(
81-
TodoOptionsPrefConstants.PREF_DEFAULT_SORT,
82-
value
83-
)
84-
}
85-
savedState[KEY_COMPAT_QUERY] = value
86-
87-
// Update the query
88-
val sortBy = sortCompatMap[value]
89-
setQuery(
90-
sortBy?.let { (field, dir) ->
91-
{ it.orderBy(field.toDto().fieldName, dir.toFirestoreDirection()) }
92-
} ?: run {
93-
Log.w(TAG, "Unrecognised sort option $value was specified")
94-
// Reset the query used
95-
null
96-
}
97-
)
98-
}
99-
10051
/** The current list of tasks to be shown. */
10152
@OptIn(ExperimentalCoroutinesApi::class)
10253
val tasks = query
@@ -128,15 +79,4 @@ class TasksListViewModel @Inject constructor(
12879
resetQuery()
12980
}
13081
}
131-
132-
companion object {
133-
/**
134-
* Saved-state key used to store the current query.
135-
*
136-
* Its saved-state value represents the compat version as used in the
137-
* task settings UI.
138-
* @see TodoSortValues
139-
*/
140-
const val KEY_COMPAT_QUERY = "tasks:compatQuery"
141-
}
14282
}

0 commit comments

Comments
 (0)