diff --git a/app/src/main/java/com/todoroo/astrid/core/SortHelper.java b/app/src/main/java/com/todoroo/astrid/core/SortHelper.java index 946ece1c0..417caf56a 100644 --- a/app/src/main/java/com/todoroo/astrid/core/SortHelper.java +++ b/app/src/main/java/com/todoroo/astrid/core/SortHelper.java @@ -22,6 +22,9 @@ import org.tasks.preferences.Preferences; */ public class SortHelper { + private static final String ADJUSTED_DUE_DATE = + "(CASE WHEN (dueDate / 1000) % 60 > 0 THEN dueDate ELSE (dueDate + 43140000) END)"; + public static final int SORT_AUTO = 0; public static final int SORT_ALPHA = 1; public static final int SORT_DUE = 2; @@ -76,7 +79,7 @@ public class SortHelper { case SORT_DUE: order = Order.asc( - "(CASE WHEN (dueDate=0) THEN (strftime('%s','now')*1000)*2 ELSE (CASE WHEN (dueDate / 60000) > 0 THEN dueDate ELSE (dueDate + 43140000) END) END)+importance"); + "(CASE WHEN (dueDate=0) THEN (strftime('%s','now')*1000)*2 ELSE " + ADJUSTED_DUE_DATE + " END)+importance"); break; case SORT_IMPORTANCE: order = @@ -95,7 +98,7 @@ public class SortHelper { "THEN (strftime('%s','now')*1000)*2 " + // then now * 2 "ELSE (" - + adjustedDueDateFunction() + + ADJUSTED_DUE_DATE + ") END) " + // else due time "+ 172800000 * importance"); // add 2 days * importance @@ -106,9 +109,4 @@ public class SortHelper { return order; } - - private static String adjustedDueDateFunction() { - // if no due time use 11:59AM - return "(CASE WHEN (dueDate / 60000) > 0 THEN dueDate ELSE (dueDate + 43140000) END)"; - } } diff --git a/app/src/main/java/com/todoroo/astrid/dao/TaskDao.java b/app/src/main/java/com/todoroo/astrid/dao/TaskDao.java index 1df646cfb..5294774ee 100644 --- a/app/src/main/java/com/todoroo/astrid/dao/TaskDao.java +++ b/app/src/main/java/com/todoroo/astrid/dao/TaskDao.java @@ -181,7 +181,7 @@ public abstract class TaskDao { @androidx.room.Query( "SELECT * FROM tasks " + "WHERE completed = 0 AND deleted = 0 AND hideUntil < (strftime('%s','now')*1000) " - + "ORDER BY (CASE WHEN (dueDate=0) THEN (strftime('%s','now')*1000)*2 ELSE ((CASE WHEN (dueDate / 60000) > 0 THEN dueDate ELSE (dueDate + 43140000) END)) END) + 172800000 * importance ASC " + + "ORDER BY (CASE WHEN (dueDate=0) THEN (strftime('%s','now')*1000)*2 ELSE ((CASE WHEN (dueDate / 1000) % 60 > 0 THEN dueDate ELSE (dueDate + 43140000) END)) END) + 172800000 * importance ASC " + "LIMIT 100") public abstract List getAstrid2TaskProviderTasks();