|
|
@ -1,10 +1,6 @@
|
|
|
|
package org.tasks.filters
|
|
|
|
package org.tasks.filters
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
import org.jetbrains.compose.resources.getString
|
|
|
|
import com.todoroo.astrid.core.BuiltInFilterExposer
|
|
|
|
|
|
|
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
|
|
|
|
|
|
|
import org.tasks.BuildConfig
|
|
|
|
|
|
|
|
import org.tasks.R
|
|
|
|
|
|
|
|
import org.tasks.data.GoogleTaskFilters
|
|
|
|
import org.tasks.data.GoogleTaskFilters
|
|
|
|
import org.tasks.data.LocationFilters
|
|
|
|
import org.tasks.data.LocationFilters
|
|
|
|
import org.tasks.data.NO_ORDER
|
|
|
|
import org.tasks.data.NO_ORDER
|
|
|
@ -14,26 +10,37 @@ import org.tasks.data.dao.FilterDao
|
|
|
|
import org.tasks.data.dao.GoogleTaskListDao
|
|
|
|
import org.tasks.data.dao.GoogleTaskListDao
|
|
|
|
import org.tasks.data.dao.LocationDao
|
|
|
|
import org.tasks.data.dao.LocationDao
|
|
|
|
import org.tasks.data.dao.TagDataDao
|
|
|
|
import org.tasks.data.dao.TagDataDao
|
|
|
|
|
|
|
|
import org.tasks.data.dao.TaskDao
|
|
|
|
import org.tasks.data.entity.CaldavAccount
|
|
|
|
import org.tasks.data.entity.CaldavAccount
|
|
|
|
import org.tasks.data.entity.CaldavAccount.Companion.TYPE_LOCAL
|
|
|
|
import org.tasks.data.entity.CaldavAccount.Companion.TYPE_LOCAL
|
|
|
|
import org.tasks.data.entity.CaldavAccount.Companion.TYPE_OPENTASKS
|
|
|
|
import org.tasks.data.entity.CaldavAccount.Companion.TYPE_OPENTASKS
|
|
|
|
import org.tasks.data.setupLocalAccount
|
|
|
|
import org.tasks.data.setupLocalAccount
|
|
|
|
import org.tasks.data.toGtasksFilter
|
|
|
|
import org.tasks.data.toGtasksFilter
|
|
|
|
|
|
|
|
import org.tasks.filters.NavigationDrawerSubheader.SubheaderType
|
|
|
|
|
|
|
|
import org.tasks.kmp.IS_DEBUG
|
|
|
|
|
|
|
|
import org.tasks.compose.drawer.DrawerConfiguration
|
|
|
|
import org.tasks.data.toLocationFilter
|
|
|
|
import org.tasks.data.toLocationFilter
|
|
|
|
import org.tasks.data.toTagFilter
|
|
|
|
import org.tasks.data.toTagFilter
|
|
|
|
import org.tasks.filters.NavigationDrawerSubheader.SubheaderType
|
|
|
|
import org.tasks.preferences.TasksPreferences
|
|
|
|
import org.tasks.preferences.Preferences
|
|
|
|
import org.tasks.preferences.TasksPreferences.Companion.collapseDebug
|
|
|
|
import javax.inject.Inject
|
|
|
|
import org.tasks.preferences.TasksPreferences.Companion.collapseFilters
|
|
|
|
|
|
|
|
import org.tasks.preferences.TasksPreferences.Companion.collapsePlaces
|
|
|
|
|
|
|
|
import org.tasks.preferences.TasksPreferences.Companion.collapseTags
|
|
|
|
|
|
|
|
import tasks.kmp.generated.resources.Res
|
|
|
|
|
|
|
|
import tasks.kmp.generated.resources.drawer_filters
|
|
|
|
|
|
|
|
import tasks.kmp.generated.resources.drawer_local_lists
|
|
|
|
|
|
|
|
import tasks.kmp.generated.resources.drawer_places
|
|
|
|
|
|
|
|
import tasks.kmp.generated.resources.drawer_tags
|
|
|
|
|
|
|
|
|
|
|
|
class FilterProvider @Inject constructor(
|
|
|
|
class FilterProvider(
|
|
|
|
@param:ApplicationContext private val context: Context,
|
|
|
|
|
|
|
|
private val builtInFilterExposer: BuiltInFilterExposer,
|
|
|
|
|
|
|
|
private val filterDao: FilterDao,
|
|
|
|
private val filterDao: FilterDao,
|
|
|
|
private val tagDataDao: TagDataDao,
|
|
|
|
private val tagDataDao: TagDataDao,
|
|
|
|
private val googleTaskListDao: GoogleTaskListDao,
|
|
|
|
private val googleTaskListDao: GoogleTaskListDao,
|
|
|
|
private val caldavDao: CaldavDao,
|
|
|
|
private val caldavDao: CaldavDao,
|
|
|
|
private val preferences: Preferences,
|
|
|
|
private val configuration: DrawerConfiguration,
|
|
|
|
private val locationDao: LocationDao
|
|
|
|
private val locationDao: LocationDao,
|
|
|
|
|
|
|
|
private val taskDao: TaskDao,
|
|
|
|
|
|
|
|
private val tasksPreferences: TasksPreferences,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
suspend fun listPickerItems(): List<FilterListItem> =
|
|
|
|
suspend fun listPickerItems(): List<FilterListItem> =
|
|
|
|
caldavFilters(showCreate = false, forceExpand = false)
|
|
|
|
caldavFilters(showCreate = false, forceExpand = false)
|
|
|
@ -41,7 +48,6 @@ class FilterProvider @Inject constructor(
|
|
|
|
suspend fun drawerItems(): List<FilterListItem> =
|
|
|
|
suspend fun drawerItems(): List<FilterListItem> =
|
|
|
|
getAllFilters(showCreate = true, hideUnused = true)
|
|
|
|
getAllFilters(showCreate = true, hideUnused = true)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
suspend fun allLists(): List<Filter> =
|
|
|
|
suspend fun allLists(): List<Filter> =
|
|
|
|
caldavFilters(showCreate = false, forceExpand = true)
|
|
|
|
caldavFilters(showCreate = false, forceExpand = true)
|
|
|
|
.filterIsInstance<Filter>()
|
|
|
|
.filterIsInstance<Filter>()
|
|
|
@ -56,27 +62,27 @@ class FilterProvider @Inject constructor(
|
|
|
|
suspend fun drawerCustomizationItems(): List<FilterListItem> =
|
|
|
|
suspend fun drawerCustomizationItems(): List<FilterListItem> =
|
|
|
|
getAllFilters(showBuiltIn = false, showCreate = true)
|
|
|
|
getAllFilters(showBuiltIn = false, showCreate = true)
|
|
|
|
|
|
|
|
|
|
|
|
private fun getDebugFilters(): List<FilterListItem> =
|
|
|
|
private suspend fun getDebugFilters(): List<FilterListItem> =
|
|
|
|
if (BuildConfig.DEBUG) {
|
|
|
|
if (IS_DEBUG) {
|
|
|
|
val collapsed = preferences.getBoolean(R.string.p_collapse_debug, false)
|
|
|
|
val collapsed = tasksPreferences.get(collapseDebug, false)
|
|
|
|
listOf(
|
|
|
|
listOf(
|
|
|
|
NavigationDrawerSubheader(
|
|
|
|
NavigationDrawerSubheader(
|
|
|
|
context.getString(R.string.debug),
|
|
|
|
"Debug",
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
collapsed,
|
|
|
|
collapsed,
|
|
|
|
SubheaderType.PREFERENCE,
|
|
|
|
SubheaderType.PREFERENCE,
|
|
|
|
R.string.p_collapse_debug.toLong(),
|
|
|
|
collapseDebug.name,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.apply { if (collapsed) return this }
|
|
|
|
.apply { if (collapsed) return this }
|
|
|
|
.plus(listOf(
|
|
|
|
.plus(listOf(
|
|
|
|
DebugFilters.getNoListFilter(),
|
|
|
|
DebugFilters.getNoListFilter(),
|
|
|
|
DebugFilters.getNoTitleFilter(),
|
|
|
|
DebugFilters.getNoTitleFilter(),
|
|
|
|
DebugFilters.getMissingListFilter(),
|
|
|
|
DebugFilters.getMissingListFilter(),
|
|
|
|
DebugFilters.getMissingAccountFilter(),
|
|
|
|
DebugFilters.getMissingAccountFilter(),
|
|
|
|
DebugFilters.getNoCreateDateFilter(),
|
|
|
|
DebugFilters.getNoCreateDateFilter(),
|
|
|
|
DebugFilters.getNoModificationDateFilter(),
|
|
|
|
DebugFilters.getNoModificationDateFilter(),
|
|
|
|
DebugFilters.getDeleted()
|
|
|
|
DebugFilters.getDeleted()
|
|
|
|
))
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -88,23 +94,23 @@ class FilterProvider @Inject constructor(
|
|
|
|
showBuiltIn: Boolean,
|
|
|
|
showBuiltIn: Boolean,
|
|
|
|
forceExpand: Boolean,
|
|
|
|
forceExpand: Boolean,
|
|
|
|
): List<FilterListItem> =
|
|
|
|
): List<FilterListItem> =
|
|
|
|
if (!preferences.getBoolean(R.string.p_filters_enabled, true)) {
|
|
|
|
if (!configuration.filtersEnabled) {
|
|
|
|
emptyList()
|
|
|
|
emptyList()
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
val collapsed = !forceExpand && preferences.getBoolean(R.string.p_collapse_filters, false)
|
|
|
|
val collapsed = !forceExpand && tasksPreferences.get(collapseFilters, false)
|
|
|
|
listOf(
|
|
|
|
listOf(
|
|
|
|
NavigationDrawerSubheader(
|
|
|
|
NavigationDrawerSubheader(
|
|
|
|
context.getString(R.string.filters),
|
|
|
|
getString(Res.string.drawer_filters),
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
collapsed,
|
|
|
|
collapsed,
|
|
|
|
SubheaderType.PREFERENCE,
|
|
|
|
SubheaderType.PREFERENCE,
|
|
|
|
R.string.p_collapse_filters.toLong(),
|
|
|
|
collapseFilters.name,
|
|
|
|
if (showCreate) REQUEST_NEW_FILTER else 0,
|
|
|
|
if (showCreate) REQUEST_NEW_FILTER else 0,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.apply { if (collapsed) return this }
|
|
|
|
.apply { if (collapsed) return this }
|
|
|
|
.plusAllIf(showBuiltIn) {
|
|
|
|
.plusAllIf(showBuiltIn) {
|
|
|
|
builtInFilterExposer.filters()
|
|
|
|
builtInFilters()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.plus(filterDao.getFilters().map(::CustomFilter).sort())
|
|
|
|
.plus(filterDao.getFilters().map(::CustomFilter).sort())
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -114,23 +120,23 @@ class FilterProvider @Inject constructor(
|
|
|
|
hideUnused: Boolean,
|
|
|
|
hideUnused: Boolean,
|
|
|
|
forceExpand: Boolean,
|
|
|
|
forceExpand: Boolean,
|
|
|
|
): List<FilterListItem> =
|
|
|
|
): List<FilterListItem> =
|
|
|
|
if (!preferences.getBoolean(R.string.p_tags_enabled, true)) {
|
|
|
|
if (!configuration.tagsEnabled) {
|
|
|
|
emptyList()
|
|
|
|
emptyList()
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
val collapsed = !forceExpand && preferences.getBoolean(R.string.p_collapse_tags, false)
|
|
|
|
val collapsed = !forceExpand && tasksPreferences.get(collapseTags, false)
|
|
|
|
listOf(
|
|
|
|
listOf(
|
|
|
|
NavigationDrawerSubheader(
|
|
|
|
NavigationDrawerSubheader(
|
|
|
|
context.getString(R.string.tags),
|
|
|
|
getString(Res.string.drawer_tags),
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
collapsed,
|
|
|
|
collapsed,
|
|
|
|
SubheaderType.PREFERENCE,
|
|
|
|
SubheaderType.PREFERENCE,
|
|
|
|
R.string.p_collapse_tags.toLong(),
|
|
|
|
collapseTags.name,
|
|
|
|
if (showCreate) REQUEST_NEW_TAGS else 0,
|
|
|
|
if (showCreate) REQUEST_NEW_TAGS else 0,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.apply { if (collapsed) return this }
|
|
|
|
.apply { if (collapsed) return this }
|
|
|
|
.plus(tagDataDao.getTagFilters()
|
|
|
|
.plus(tagDataDao.getTagFilters()
|
|
|
|
.filterIf(hideUnused && preferences.getBoolean(R.string.p_tags_hide_unused, false)) {
|
|
|
|
.filterIf(hideUnused && configuration.hideUnusedTags) {
|
|
|
|
it.count > 0
|
|
|
|
it.count > 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.map(TagFilters::toTagFilter)
|
|
|
|
.map(TagFilters::toTagFilter)
|
|
|
@ -142,23 +148,23 @@ class FilterProvider @Inject constructor(
|
|
|
|
hideUnused: Boolean,
|
|
|
|
hideUnused: Boolean,
|
|
|
|
forceExpand: Boolean,
|
|
|
|
forceExpand: Boolean,
|
|
|
|
): List<FilterListItem> =
|
|
|
|
): List<FilterListItem> =
|
|
|
|
if (!preferences.getBoolean(R.string.p_places_enabled, true)) {
|
|
|
|
if (!configuration.placesEnabled) {
|
|
|
|
emptyList()
|
|
|
|
emptyList()
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
val collapsed = !forceExpand && preferences.getBoolean(R.string.p_collapse_locations, false)
|
|
|
|
val collapsed = !forceExpand && tasksPreferences.get(collapsePlaces, false)
|
|
|
|
listOf(
|
|
|
|
listOf(
|
|
|
|
NavigationDrawerSubheader(
|
|
|
|
NavigationDrawerSubheader(
|
|
|
|
context.getString(R.string.places),
|
|
|
|
getString(Res.string.drawer_places),
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
collapsed,
|
|
|
|
collapsed,
|
|
|
|
SubheaderType.PREFERENCE,
|
|
|
|
SubheaderType.PREFERENCE,
|
|
|
|
R.string.p_collapse_locations.toLong(),
|
|
|
|
collapsePlaces.name,
|
|
|
|
if (showCreate) REQUEST_NEW_PLACE else 0,
|
|
|
|
if (showCreate) REQUEST_NEW_PLACE else 0,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.apply { if (collapsed) return this }
|
|
|
|
.apply { if (collapsed) return this }
|
|
|
|
.plus(locationDao.getPlaceFilters()
|
|
|
|
.plus(locationDao.getPlaceFilters()
|
|
|
|
.filterIf(hideUnused && preferences.getBoolean(R.string.p_places_hide_unused, false)) {
|
|
|
|
.filterIf(hideUnused && configuration.hideUnusedPlaces) {
|
|
|
|
it.count > 0
|
|
|
|
it.count > 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.map(LocationFilters::toLocationFilter)
|
|
|
|
.map(LocationFilters::toLocationFilter)
|
|
|
@ -182,7 +188,7 @@ class FilterProvider @Inject constructor(
|
|
|
|
.plus(addPlaces(showCreate, hideUnused, forceExpand))
|
|
|
|
.plus(addPlaces(showCreate, hideUnused, forceExpand))
|
|
|
|
.plus(caldavFilters(showCreate, forceExpand))
|
|
|
|
.plus(caldavFilters(showCreate, forceExpand))
|
|
|
|
.toList()
|
|
|
|
.toList()
|
|
|
|
.plusAllIf(BuildConfig.DEBUG) { getDebugFilters() }
|
|
|
|
.plusAllIf(IS_DEBUG) { getDebugFilters() }
|
|
|
|
|
|
|
|
|
|
|
|
private suspend fun googleTaskFilter(
|
|
|
|
private suspend fun googleTaskFilter(
|
|
|
|
account: CaldavAccount,
|
|
|
|
account: CaldavAccount,
|
|
|
@ -196,7 +202,7 @@ class FilterProvider @Inject constructor(
|
|
|
|
account.error?.isNotBlank() ?: false,
|
|
|
|
account.error?.isNotBlank() ?: false,
|
|
|
|
collapsed,
|
|
|
|
collapsed,
|
|
|
|
SubheaderType.GOOGLE_TASKS,
|
|
|
|
SubheaderType.GOOGLE_TASKS,
|
|
|
|
account.id,
|
|
|
|
account.id.toString(),
|
|
|
|
if (showCreate) REQUEST_NEW_LIST else 0,
|
|
|
|
if (showCreate) REQUEST_NEW_LIST else 0,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -215,7 +221,7 @@ class FilterProvider @Inject constructor(
|
|
|
|
): List<FilterListItem> =
|
|
|
|
): List<FilterListItem> =
|
|
|
|
caldavDao.getAccounts()
|
|
|
|
caldavDao.getAccounts()
|
|
|
|
.ifEmpty { listOf(caldavDao.setupLocalAccount()) }
|
|
|
|
.ifEmpty { listOf(caldavDao.setupLocalAccount()) }
|
|
|
|
.filter { it.accountType != TYPE_LOCAL || preferences.getBoolean(R.string.p_lists_enabled, true) }
|
|
|
|
.filter { it.accountType != TYPE_LOCAL || configuration.localListsEnabled }
|
|
|
|
.flatMap {
|
|
|
|
.flatMap {
|
|
|
|
if (it.isGoogleTasks) {
|
|
|
|
if (it.isGoogleTasks) {
|
|
|
|
googleTaskFilter(it, showCreate, forceExpand)
|
|
|
|
googleTaskFilter(it, showCreate, forceExpand)
|
|
|
@ -237,7 +243,7 @@ class FilterProvider @Inject constructor(
|
|
|
|
return listOf(
|
|
|
|
return listOf(
|
|
|
|
NavigationDrawerSubheader(
|
|
|
|
NavigationDrawerSubheader(
|
|
|
|
if (account.accountType == TYPE_LOCAL) {
|
|
|
|
if (account.accountType == TYPE_LOCAL) {
|
|
|
|
context.getString(R.string.local_lists)
|
|
|
|
getString(Res.string.drawer_local_lists)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
account.name
|
|
|
|
account.name
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -247,7 +253,7 @@ class FilterProvider @Inject constructor(
|
|
|
|
account.isTasksOrg -> SubheaderType.TASKS
|
|
|
|
account.isTasksOrg -> SubheaderType.TASKS
|
|
|
|
else -> SubheaderType.CALDAV
|
|
|
|
else -> SubheaderType.CALDAV
|
|
|
|
},
|
|
|
|
},
|
|
|
|
account.id,
|
|
|
|
account.id.toString(),
|
|
|
|
if (showCreate) REQUEST_NEW_LIST else 0,
|
|
|
|
if (showCreate) REQUEST_NEW_LIST else 0,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -264,6 +270,26 @@ class FilterProvider @Inject constructor(
|
|
|
|
.sort())
|
|
|
|
.sort())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private suspend fun builtInFilters(): List<Filter> {
|
|
|
|
|
|
|
|
val filters: MutableList<Filter> = ArrayList()
|
|
|
|
|
|
|
|
if (configuration.todayFilter) {
|
|
|
|
|
|
|
|
filters.add(TodayFilter.create())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (configuration.recentlyModifiedFilter) {
|
|
|
|
|
|
|
|
filters.add(RecentlyModifiedFilter.create())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (taskDao.snoozedReminders() > 0) {
|
|
|
|
|
|
|
|
filters.add(SnoozedFilter.create())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (taskDao.activeTimers() > 0) {
|
|
|
|
|
|
|
|
filters.add(TimerFilter.create())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (taskDao.hasNotifications() > 0) {
|
|
|
|
|
|
|
|
filters.add(NotificationsFilter.create())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return filters
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
companion object {
|
|
|
|
const val REQUEST_NEW_LIST = 10100
|
|
|
|
const val REQUEST_NEW_LIST = 10100
|
|
|
|
const val REQUEST_NEW_TAGS = 10101
|
|
|
|
const val REQUEST_NEW_TAGS = 10101
|