Skip to content

Commit

Permalink
[Feature] filter by priority #1642 (#1648)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickunterwegs authored Nov 30, 2024
1 parent 05e916c commit 78fabf0
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ data class StoredListSettingData(
var searchResourcesAnyAllNone: AnyAllNone = AnyAllNone.ANY,
var searchStatus: List<Status> = emptyList(),
var searchClassification: List<Classification> = emptyList(),
var searchPriority: List<Int?> = emptyList(),
var searchCollection: List<String> = emptyList(),
var searchAccount: List<String> = emptyList(),
var orderBy: OrderBy = OrderBy.CREATED,
Expand Down Expand Up @@ -115,6 +116,7 @@ data class StoredListSettingData(
searchResourcesAnyAllNone = listSettings.searchResourcesAnyAllNone.value,
searchStatus = listSettings.searchStatus,
searchClassification = listSettings.searchClassification,
searchPriority = listSettings.searchPriority,
searchCollection = listSettings.searchCollection,
searchAccount = listSettings.searchAccount,
orderBy = listSettings.orderBy.value,
Expand Down Expand Up @@ -161,6 +163,7 @@ data class StoredListSettingData(
listSettings.searchResourcesAnyAllNone.value = searchResourcesAnyAllNone
listSettings.searchStatus.addAll(searchStatus)
listSettings.searchClassification.addAll(searchClassification)
listSettings.searchPriority.addAll(searchPriority)
listSettings.searchCollection.addAll(searchCollection)
listSettings.searchAccount.addAll(searchAccount)
listSettings.orderBy.value = orderBy
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/at/techbee/jtx/database/views/ICal4List.kt
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ data class ICal4List(
searchStatus: List<Status> = emptyList(),
searchXStatus: List<String> = emptyList(),
searchClassification: List<Classification> = emptyList(),
searchPriority: List<Int?> = emptyList(),
searchCollection: List<String> = emptyList(),
searchAccount: List<String> = emptyList(),
orderBy: OrderBy = OrderBy.CREATED,
Expand Down Expand Up @@ -516,6 +517,17 @@ data class ICal4List(
queryString += ") "
}

//PRIORITY
if (searchPriority.isNotEmpty()) {
queryString += "AND ("
queryString += searchPriority.joinToString(separator = "OR ", transform = { "$COLUMN_PRIORITY = ? " })
args.addAll(searchPriority.map { it?.toString() ?: "0"})

if(searchPriority.contains(null) || searchPriority.contains(0))
queryString += "OR $COLUMN_PRIORITY IS NULL"
queryString += ") "
}

//Hide biometric protected
hideBiometricProtected.forEach {
if(it == Classification.NO_CLASSIFICATION) {
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/at/techbee/jtx/ui/list/ListActiveFiltersRow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.outlined.Label
import androidx.compose.material.icons.outlined.AccountBalance
import androidx.compose.material.icons.outlined.AssignmentLate
import androidx.compose.material.icons.outlined.FolderOpen
import androidx.compose.material.icons.outlined.PrivacyTip
import androidx.compose.material.icons.outlined.PublishedWithChanges
Expand All @@ -29,6 +30,7 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringArrayResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -157,6 +159,17 @@ fun ListActiveFiltersRow(
isAccessibilityMode = isAccessibilityMode
)
}
listSettings.searchPriority.forEach { priorityInt ->
if(priorityInt in 0..9) {
ListBadge(
icon = Icons.Outlined.AssignmentLate,
iconDesc = stringResource(R.string.priority),
text = stringArrayResource(id = R.array.priority)[priorityInt?:0],
modifier = Modifier.padding(vertical = 2.dp),
isAccessibilityMode = isAccessibilityMode
)
}
}
AnimatedVisibility(listSettings.isExcludeDone.value) {
ListBadge(
text = stringResource(R.string.list_hide_completed_tasks),
Expand Down
39 changes: 39 additions & 0 deletions app/src/main/java/at/techbee/jtx/ui/list/ListOptionsFilter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.outlined.Label
import androidx.compose.material.icons.outlined.AccountBalance
import androidx.compose.material.icons.outlined.AssignmentLate
import androidx.compose.material.icons.outlined.CalendarMonth
import androidx.compose.material.icons.outlined.Close
import androidx.compose.material.icons.outlined.DashboardCustomize
Expand Down Expand Up @@ -44,6 +45,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringArrayResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import at.techbee.jtx.R
Expand Down Expand Up @@ -877,6 +879,43 @@ fun ListOptionsFilter(
}


////// Priority
val priorities = stringArrayResource(id = R.array.priority)
if(module == Module.TODO) {
FilterSection(
icon = Icons.Outlined.AssignmentLate,
headline = stringResource(id = R.string.priority),
onResetSelection = {
listSettings.searchPriority.clear()
onListSettingsChanged()
},
onInvertSelection = {
priorities.forEachIndexed { index, _ ->
if (listSettings.searchPriority.contains(index))
listSettings.searchPriority.remove(index)
else
listSettings.searchPriority.add(index)
}
onListSettingsChanged()
})
{
priorities.forEachIndexed { index, prio ->
FilterChip(
selected = listSettings.searchPriority.contains(index),
onClick = {
if (listSettings.searchPriority.contains(index))
listSettings.searchPriority.remove(index)
else
listSettings.searchPriority.add(index)
onListSettingsChanged()
},
label = { Text(prio) }
)
}
}
}


////// RESOURCES
if (module == Module.TODO) {
FilterSection(
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/at/techbee/jtx/ui/list/ListSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ListSettings {
var searchStatus = mutableStateListOf<Status>()
var searchXStatus = mutableStateListOf<String>()
var searchClassification = mutableStateListOf<Classification>()
var searchPriority = mutableStateListOf<Int?>()
var searchCollection = mutableStateListOf<String>()
var searchAccount = mutableStateListOf<String>()
var orderBy: MutableState<OrderBy> = mutableStateOf(OrderBy.DRAG_AND_DROP)
Expand Down Expand Up @@ -107,6 +108,7 @@ class ListSettings {
private const val PREFS_RESOURCES = "prefsResources"
private const val PREFS_RESOURCES_ANYALLNONE = "prefsResourcesAnyAllNone"
private const val PREFS_CLASSIFICATION = "prefsClassification"
private const val PREFS_PRIORITY = "prefsPriority"
private const val PREFS_STATUS = "prefsStatus"
private const val PREFS_EXTENDED_STATUS = "prefsXStatus"
private const val PREFS_EXCLUDE_DONE = "prefsExcludeDone"
Expand Down Expand Up @@ -208,6 +210,7 @@ class ListSettings {
searchStatus.addAll(Status.getListFromStringList(prefs.getStringSet(PREFS_STATUS, null)))
searchXStatus.addAll(prefs.getStringSet(PREFS_EXTENDED_STATUS, emptySet())?.toList() ?: emptyList())
searchClassification.addAll(Classification.getListFromStringList(prefs.getStringSet(PREFS_CLASSIFICATION, null)))
searchPriority.addAll(prefs.getStringSet(PREFS_PRIORITY, null)?.map { it.toIntOrNull() } ?: emptyList())
searchCollection.addAll(prefs.getStringSet(PREFS_COLLECTION, emptySet())?.toList() ?: emptyList())
searchAccount.addAll(prefs.getStringSet(PREFS_ACCOUNT, emptySet())?.toList() ?: emptyList())

Expand Down Expand Up @@ -277,6 +280,7 @@ class ListSettings {
searchStatus.addAll(listWidgetConfig.searchStatus)
searchXStatus.addAll(listWidgetConfig.searchXStatus)
searchClassification.addAll(listWidgetConfig.searchClassification)
searchPriority.addAll(listWidgetConfig.searchPriority)
searchCollection.addAll(listWidgetConfig.searchCollection)
searchAccount.addAll(listWidgetConfig.searchAccount)

Expand Down Expand Up @@ -367,6 +371,7 @@ class ListSettings {
putStringSet(PREFS_STATUS, Status.getStringSetFromList(searchStatus))
putStringSet(PREFS_EXTENDED_STATUS, searchXStatus.toSet())
putStringSet(PREFS_CLASSIFICATION, Classification.getStringSetFromList(searchClassification))
putStringSet(PREFS_PRIORITY, searchPriority.map { it.toString() }.toSet())
putStringSet(PREFS_COLLECTION, searchCollection.toSet())
putStringSet(PREFS_ACCOUNT, searchAccount.toSet())

Expand Down Expand Up @@ -397,6 +402,7 @@ class ListSettings {
searchStatus.clear()
searchXStatus.clear()
searchClassification.clear()
searchPriority.clear()
searchCollection.clear()
searchAccount.clear()
isExcludeDone.value = false
Expand Down Expand Up @@ -435,6 +441,7 @@ class ListSettings {
|| searchStatus.isNotEmpty()
|| searchXStatus.isNotEmpty()
|| searchClassification.isNotEmpty()
|| searchPriority.isNotEmpty()
|| searchCollection.isNotEmpty()
|| searchAccount.isNotEmpty()
|| isExcludeDone.value
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/at/techbee/jtx/ui/list/ListViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ open class ListViewModel(application: Application, val module: Module) : Android
searchStatus = listSettings.searchStatus,
searchXStatus = listSettings.searchXStatus,
searchClassification = listSettings.searchClassification,
searchPriority = listSettings.searchPriority,
searchCollection = listSettings.searchCollection,
searchAccount = listSettings.searchAccount,
orderBy = listSettings.orderBy.value,
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/at/techbee/jtx/widgets/ListWidget.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class ListWidget : GlanceAppWidget() {
searchResources = listWidgetConfig.searchResources,
searchStatus = listWidgetConfig.searchStatus,
searchClassification = listWidgetConfig.searchClassification,
searchPriority = listWidgetConfig.searchPriority,
searchCollection = listWidgetConfig.searchCollection,
searchAccount = listWidgetConfig.searchAccount,
orderBy = listWidgetConfig.orderBy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
package at.techbee.jtx.widgets

import android.widget.Toast
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
Expand Down Expand Up @@ -64,7 +63,7 @@ import at.techbee.jtx.ui.list.ViewMode
import kotlinx.coroutines.launch


@OptIn(ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class)
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun ListWidgetConfigContent(
initialConfig: ListWidgetConfig,
Expand Down Expand Up @@ -233,6 +232,7 @@ fun ListWidgetConfigContent(
searchStatus = listSettings.searchStatus
searchXStatus = listSettings.searchXStatus
searchClassification = listSettings.searchClassification
searchPriority = listSettings.searchPriority
searchCollection = listSettings.searchCollection
searchAccount = listSettings.searchAccount
orderBy = listSettings.orderBy.value
Expand Down Expand Up @@ -332,6 +332,7 @@ data class ListWidgetConfig(
var searchStatus: List<Status> = emptyList(),
var searchXStatus: List<String> = emptyList(),
var searchClassification: List<Classification> = emptyList(),
var searchPriority: List<Int?> = emptyList(),
var searchCollection: List<String> = emptyList(),
var searchAccount: List<String> = emptyList(),
var orderBy: OrderBy = OrderBy.CREATED,
Expand Down

0 comments on commit 78fabf0

Please sign in to comment.