From 5f735673dac76063cd1c6847b55f9508de84826b Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Thu, 30 Jul 2020 10:11:13 -0500 Subject: [PATCH] Add debug filters --- .../astrid/core/BuiltInFilterExposer.kt | 31 +++++++++++++++++++ .../main/java/org/tasks/data/CaldavTask.kt | 1 + .../main/java/org/tasks/data/GoogleTask.kt | 1 + app/src/main/java/org/tasks/data/TaskDao.kt | 10 +++++- .../java/org/tasks/filters/FilterProvider.kt | 20 ++++++++++++ app/src/main/res/values/keys.xml | 1 + 6 files changed, 63 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/todoroo/astrid/core/BuiltInFilterExposer.kt b/app/src/main/java/com/todoroo/astrid/core/BuiltInFilterExposer.kt index dbbcfe120..0a9f1a5e1 100644 --- a/app/src/main/java/com/todoroo/astrid/core/BuiltInFilterExposer.kt +++ b/app/src/main/java/com/todoroo/astrid/core/BuiltInFilterExposer.kt @@ -7,7 +7,9 @@ package com.todoroo.astrid.core import android.content.Context import android.content.res.Resources +import com.todoroo.andlib.sql.Criterion import com.todoroo.andlib.sql.Criterion.Companion.and +import com.todoroo.andlib.sql.Join import com.todoroo.andlib.sql.QueryTemplate import com.todoroo.andlib.utility.AndroidUtilities import com.todoroo.astrid.api.Filter @@ -16,6 +18,8 @@ import com.todoroo.astrid.data.Task import com.todoroo.astrid.timers.TimerPlugin import dagger.hilt.android.qualifiers.ApplicationContext import org.tasks.R +import org.tasks.data.CaldavTask +import org.tasks.data.GoogleTask import org.tasks.data.TaskDao import org.tasks.data.TaskDao.TaskCriteria.activeAndVisible import org.tasks.filters.RecentlyModifiedFilter @@ -84,6 +88,33 @@ class BuiltInFilterExposer @Inject constructor( todayValues) } + fun getNoListFilter(): Filter { + return Filter( + "No list", + QueryTemplate() + .join(Join.left(GoogleTask.TABLE, and(GoogleTask.TASK.eq(Task.ID), GoogleTask.DELETED.eq(0)))) + .join(Join.left(CaldavTask.TABLE, and(CaldavTask.TASK.eq(Task.ID), CaldavTask.DELETED.eq(0)))) + .where(and( + activeAndVisible(), + GoogleTask.ID.eq(null), + CaldavTask.ID.eq(null)))) + .apply { + icon = R.drawable.ic_outline_cloud_off_24px + } + } + + fun getNoTitleFilter(): Filter { + return Filter( + "No title", + QueryTemplate() + .where(and( + activeAndVisible(), + Criterion.or(Task.TITLE.eq(null), Task.TITLE.eq(""))))) + .apply { + icon = R.drawable.ic_outline_clear_24px + } + } + fun getRecentlyModifiedFilter(r: Resources) = RecentlyModifiedFilter(r.getString(R.string.BFE_Recent)) diff --git a/app/src/main/java/org/tasks/data/CaldavTask.kt b/app/src/main/java/org/tasks/data/CaldavTask.kt index 226a2ab78..44584c66b 100644 --- a/app/src/main/java/org/tasks/data/CaldavTask.kt +++ b/app/src/main/java/org/tasks/data/CaldavTask.kt @@ -70,6 +70,7 @@ class CaldavTask { companion object { const val KEY = "caldav" @JvmField val TABLE = Table("caldav_tasks") + val ID = TABLE.column("cd_id") @JvmField val TASK = TABLE.column("cd_task") @JvmField val DELETED = TABLE.column("cd_deleted") @JvmField val CALENDAR = TABLE.column("cd_calendar") diff --git a/app/src/main/java/org/tasks/data/GoogleTask.kt b/app/src/main/java/org/tasks/data/GoogleTask.kt index caab7a7d4..c4cc4d6cf 100644 --- a/app/src/main/java/org/tasks/data/GoogleTask.kt +++ b/app/src/main/java/org/tasks/data/GoogleTask.kt @@ -99,6 +99,7 @@ class GoogleTask { companion object { const val KEY = "gtasks" @JvmField val TABLE = Table("google_tasks") + val ID = TABLE.column("gt_id") @JvmField val PARENT = TABLE.column("gt_parent") @JvmField val TASK = TABLE.column("gt_task") @JvmField val DELETED = TABLE.column("gt_deleted") diff --git a/app/src/main/java/org/tasks/data/TaskDao.kt b/app/src/main/java/org/tasks/data/TaskDao.kt index 3f4b85b72..a13e77991 100644 --- a/app/src/main/java/org/tasks/data/TaskDao.kt +++ b/app/src/main/java/org/tasks/data/TaskDao.kt @@ -238,7 +238,15 @@ SELECT EXISTS(SELECT 1 FROM tasks WHERE parent > 0 AND deleted = 0) AS hasSubtas return tasks.map(TaskContainer::getTask) } - @Query("SELECT _id FROM tasks LEFT JOIN google_tasks ON _id = gt_task AND gt_deleted = 0 LEFT JOIN caldav_tasks ON _id = cd_task AND cd_deleted = 0 WHERE gt_id IS NULL AND cd_id IS NULL AND parent = 0") + @Query(""" +SELECT _id +FROM tasks + LEFT JOIN google_tasks ON _id = gt_task AND gt_deleted = 0 + LEFT JOIN caldav_tasks ON _id = cd_task AND cd_deleted = 0 +WHERE gt_id IS NULL + AND cd_id IS NULL + AND parent = 0 + """) abstract suspend fun getLocalTasks(): List /** Generates SQL clauses */ diff --git a/app/src/main/java/org/tasks/filters/FilterProvider.kt b/app/src/main/java/org/tasks/filters/FilterProvider.kt index 8545202bf..0e21e4ec1 100644 --- a/app/src/main/java/org/tasks/filters/FilterProvider.kt +++ b/app/src/main/java/org/tasks/filters/FilterProvider.kt @@ -48,6 +48,25 @@ class FilterProvider @Inject constructor( suspend fun drawerCustomizationItems(): List = getAllFilters(showBuiltIn = false) + private fun getDebugFilters(): List = + if (BuildConfig.DEBUG) { + val collapsed = preferences.getBoolean(R.string.p_collapse_debug, false) + listOf(NavigationDrawerSubheader( + context.getString(R.string.debug), + false, + collapsed, + SubheaderType.PREFERENCE, + R.string.p_collapse_debug.toLong())) + .apply { if (collapsed) return this } + .plus(listOf( + BuiltInFilterExposer.getNoListFilter(), + BuiltInFilterExposer.getNoTitleFilter() + )) + + } else { + emptyList() + } + private suspend fun addFilters(showCreate: Boolean, showBuiltIn: Boolean): List = if (!preferences.getBoolean(R.string.p_filters_enabled, true)) { emptyList() @@ -135,6 +154,7 @@ class FilterProvider @Inject constructor( } else { ArrayList() } + .plusAllIf(BuildConfig.DEBUG) { getDebugFilters() } .asSequence() .plus(addFilters(showCreate, showBuiltIn)) .plus(addTags(showCreate)) diff --git a/app/src/main/res/values/keys.xml b/app/src/main/res/values/keys.xml index 445a0154e..8e8860b15 100644 --- a/app/src/main/res/values/keys.xml +++ b/app/src/main/res/values/keys.xml @@ -360,6 +360,7 @@ chips_tag desaturate_colors collapse_filters + collapse_debug collapse_tags collapse_locations auto_dismiss_datetime_edit_screen