Add built-in Snoozed filter

pull/1811/head
Alex Baker 3 years ago
parent a5e0a06762
commit 3d9835a162

@ -21,6 +21,7 @@ import org.tasks.R
import org.tasks.data.*
import org.tasks.data.TaskDao.TaskCriteria.activeAndVisible
import org.tasks.filters.RecentlyModifiedFilter
import org.tasks.filters.SnoozedFilter
import org.tasks.filters.SortableFilter
import org.tasks.preferences.Preferences
import org.tasks.themes.CustomIcons
@ -57,6 +58,11 @@ class BuiltInFilterExposer @Inject constructor(
recentlyModifiedFilter.icon = CustomIcons.HISTORY
filters.add(recentlyModifiedFilter)
}
if (taskDao.snoozedReminders() > 0) {
val snoozedFilter = SnoozedFilter(r.getString(R.string.filter_snoozed))
snoozedFilter.icon = R.drawable.ic_snooze_white_24dp
filters.add(snoozedFilter)
}
if (taskDao.activeTimers() > 0) {
filters.add(TimerPlugin.createFilter(context))
}

@ -116,8 +116,10 @@ class Alarm : Parcelable {
companion object {
const val TABLE_NAME = "alarms"
val TABLE = Table(TABLE_NAME)
val TASK = TABLE.column("task")
@JvmField val TABLE = Table(TABLE_NAME)
@JvmField val TASK = TABLE.column("task")
@JvmField val TYPE = TABLE.column("type")
const val TYPE_DATE_TIME = 0
const val TYPE_REL_START = 1
const val TYPE_REL_END = 2

@ -19,6 +19,7 @@ import com.todoroo.astrid.data.Task
import com.todoroo.astrid.data.Task.Companion.NO_ID
import com.todoroo.astrid.helper.UUIDHelper
import org.tasks.BuildConfig
import org.tasks.data.Alarm.Companion.TYPE_SNOOZE
import org.tasks.db.SuspendDbUtils.chunkedMap
import org.tasks.db.SuspendDbUtils.eachChunk
import org.tasks.preferences.Preferences
@ -42,6 +43,9 @@ abstract class TaskDao(private val database: Database) {
@Query("SELECT COUNT(1) FROM tasks WHERE timerStart > 0 AND deleted = 0")
abstract suspend fun activeTimers(): Int
@Query("SELECT COUNT(1) FROM tasks INNER JOIN alarms ON tasks._id = alarms.task WHERE type = $TYPE_SNOOZE")
abstract suspend fun snoozedReminders(): Int
@Query("SELECT tasks.* FROM tasks INNER JOIN notification ON tasks._id = notification.task")
abstract suspend fun activeNotifications(): List<Task>

@ -0,0 +1,51 @@
package org.tasks.filters;
import static org.tasks.data.Alarm.TYPE_SNOOZE;
import android.os.Parcel;
import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Join;
import com.todoroo.andlib.sql.QueryTemplate;
import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.data.Task;
import org.tasks.data.Alarm;
public class SnoozedFilter extends Filter {
public static final Creator<SnoozedFilter> CREATOR =
new Creator<SnoozedFilter>() {
/** {@inheritDoc} */
@Override
public SnoozedFilter createFromParcel(Parcel source) {
SnoozedFilter item = new SnoozedFilter();
item.readFromParcel(source);
return item;
}
/** {@inheritDoc} */
@Override
public SnoozedFilter[] newArray(int size) {
return new SnoozedFilter[size];
}
};
public SnoozedFilter(String listingTitle) {
super(listingTitle, getQueryTemplate());
}
private SnoozedFilter() {}
private static QueryTemplate getQueryTemplate() {
return new QueryTemplate()
.join(Join.inner(Alarm.TABLE, Task.ID.eq(Alarm.TASK)))
.where(Criterion.and(Task.DELETION_DATE.lte(0), Alarm.TYPE.eq(TYPE_SNOOZE)));
}
@Override
public boolean supportsHiddenTasks() {
return false;
}
}

@ -730,4 +730,5 @@ File %1$s contained %2$s.\n\n
<string name="alarm_after_due">%s after due</string>
<string name="snoozed_until">Snoozed until %s</string>
<string name="custom_notification">Custom notification</string>
<string name="filter_snoozed">Snoozed</string>
</resources>

Loading…
Cancel
Save