Add option to store snoozed filter in preference

pull/1811/head
Alex Baker 3 years ago
parent 52a902c51a
commit 62931a5c70

@ -59,7 +59,7 @@ class BuiltInFilterExposer @Inject constructor(
filters.add(recentlyModifiedFilter)
}
if (taskDao.snoozedReminders() > 0) {
val snoozedFilter = SnoozedFilter(r.getString(R.string.filter_snoozed))
val snoozedFilter = getSnoozedFilter(r)
snoozedFilter.icon = R.drawable.ic_snooze_white_24dp
filters.add(snoozedFilter)
}
@ -158,15 +158,20 @@ class BuiltInFilterExposer @Inject constructor(
fun getRecentlyModifiedFilter(r: Resources) =
RecentlyModifiedFilter(r.getString(R.string.BFE_Recent))
fun getSnoozedFilter(r: Resources) = SnoozedFilter(r.getString(R.string.filter_snoozed))
@JvmStatic
fun isInbox(context: Context, filter: Filter?) =
filter != null && filter == getMyTasksFilter(context.resources)
filter == getMyTasksFilter(context.resources)
@JvmStatic
fun isTodayFilter(context: Context, filter: Filter?) =
filter != null && filter == getTodayFilter(context.resources)
filter == getTodayFilter(context.resources)
fun isRecentlyModifiedFilter(context: Context, filter: Filter?) =
filter != null && filter == getRecentlyModifiedFilter(context.resources)
filter == getRecentlyModifiedFilter(context.resources)
fun isSnoozedFilter(context: Context, filter: Filter?) =
filter == getSnoozedFilter(context.resources)
}
}

@ -1,8 +1,11 @@
package org.tasks.preferences
import android.content.Context
import com.todoroo.astrid.api.*
import com.todoroo.astrid.api.CaldavFilter
import com.todoroo.astrid.api.CustomFilter
import com.todoroo.astrid.api.Filter
import com.todoroo.astrid.api.GtasksFilter
import com.todoroo.astrid.api.TagFilter
import com.todoroo.astrid.core.BuiltInFilterExposer
import com.todoroo.astrid.core.BuiltInFilterExposer.Companion.getMyTasksFilter
import com.todoroo.astrid.data.Task
@ -10,7 +13,14 @@ import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.runBlocking
import org.tasks.R
import org.tasks.Strings.isNullOrEmpty
import org.tasks.data.*
import org.tasks.data.CaldavDao
import org.tasks.data.CaldavTask
import org.tasks.data.FilterDao
import org.tasks.data.GoogleTask
import org.tasks.data.GoogleTaskDao
import org.tasks.data.GoogleTaskListDao
import org.tasks.data.LocationDao
import org.tasks.data.TagDataDao
import org.tasks.filters.PlaceFilter
import timber.log.Timber
import javax.inject.Inject
@ -131,16 +141,17 @@ class DefaultFilterProvider @Inject constructor(
private fun getBuiltInFilter(id: Int): Filter = when (id) {
FILTER_TODAY -> BuiltInFilterExposer.getTodayFilter(context.resources)
FILTER_RECENTLY_MODIFIED -> BuiltInFilterExposer.getRecentlyModifiedFilter(context.resources)
FILTER_SNOOZED -> BuiltInFilterExposer.getSnoozedFilter(context.resources)
else -> getMyTasksFilter(context.resources)
}
private fun getBuiltInFilterId(filter: Filter): Int {
if (BuiltInFilterExposer.isTodayFilter(context, filter)) {
return FILTER_TODAY
} else if (BuiltInFilterExposer.isRecentlyModifiedFilter(context, filter)) {
return FILTER_RECENTLY_MODIFIED
private fun getBuiltInFilterId(filter: Filter) = with(filter) {
when {
isToday() -> FILTER_TODAY
isRecentlyModified() -> FILTER_RECENTLY_MODIFIED
isSnoozed() -> FILTER_SNOOZED
else -> FILTER_MY_TASKS
}
return FILTER_MY_TASKS
}
suspend fun getList(task: Task): Filter {
@ -176,6 +187,15 @@ class DefaultFilterProvider @Inject constructor(
return originalList ?: getDefaultList()
}
private fun Filter.isToday() =
BuiltInFilterExposer.isTodayFilter(context, this)
private fun Filter.isRecentlyModified() =
BuiltInFilterExposer.isRecentlyModifiedFilter(context, this)
private fun Filter.isSnoozed() =
BuiltInFilterExposer.isSnoozedFilter(context, this)
companion object {
private const val TYPE_FILTER = 0
private const val TYPE_CUSTOM_FILTER = 1
@ -187,5 +207,6 @@ class DefaultFilterProvider @Inject constructor(
private const val FILTER_TODAY = 1
@Suppress("unused") private const val FILTER_UNCATEGORIZED = 2
private const val FILTER_RECENTLY_MODIFIED = 3
private const val FILTER_SNOOZED = 4
}
}
Loading…
Cancel
Save