From b87055650930cbaaaeb32788a1d13fde48c9c258 Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Tue, 11 Oct 2016 16:28:23 -0500 Subject: [PATCH] Sort gtask list query results --- .../todoroo/astrid/gtasks/GtasksFilterExposer.java | 2 +- .../todoroo/astrid/gtasks/GtasksListService.java | 11 +++++------ .../activities/SupportGoogleTaskListPicker.java | 2 +- .../java/com/todoroo/astrid/dao/StoreObjectDao.java | 13 ++++--------- .../org/tasks/filters/FilterCriteriaProvider.java | 2 +- 5 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksFilterExposer.java b/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksFilterExposer.java index 032cbfb12..e6b73a28f 100644 --- a/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksFilterExposer.java +++ b/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksFilterExposer.java @@ -41,7 +41,7 @@ public class GtasksFilterExposer { } List listFilters = newArrayList(); - for (GtasksList list : gtasksListService.getSortedGtasksList()) { + for (GtasksList list : gtasksListService.getLists()) { listFilters.add(filterFromList(list)); } return listFilters; diff --git a/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksListService.java b/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksListService.java index c322143d4..15734abdf 100644 --- a/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksListService.java +++ b/src/googleplay/java/com/todoroo/astrid/gtasks/GtasksListService.java @@ -7,8 +7,8 @@ package com.todoroo.astrid.gtasks; import com.google.api.services.tasks.model.TaskList; import com.todoroo.astrid.dao.StoreObjectDao; +import com.todoroo.astrid.data.StoreObject; -import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -18,6 +18,7 @@ import javax.inject.Inject; import timber.log.Timber; import static com.google.common.collect.Lists.newArrayList; +import static com.google.common.collect.Lists.transform; import static org.tasks.time.DateTimeUtils.printTimestamp; public class GtasksListService { @@ -30,13 +31,11 @@ public class GtasksListService { } public List getLists() { - return storeObjectDao.getGtasksLists(); + return toGtasksList(storeObjectDao.getGtasksLists()); } - public List getSortedGtasksList() { - List lists = getLists(); - Collections.sort(lists, (left, right) -> left.getName().compareTo(right.getName())); - return lists; + private static List toGtasksList(List storeObjects) { + return transform(storeObjects, GtasksList::new); } public GtasksList getList(long id) { diff --git a/src/googleplay/java/org/tasks/activities/SupportGoogleTaskListPicker.java b/src/googleplay/java/org/tasks/activities/SupportGoogleTaskListPicker.java index e444c02a3..833a06123 100644 --- a/src/googleplay/java/org/tasks/activities/SupportGoogleTaskListPicker.java +++ b/src/googleplay/java/org/tasks/activities/SupportGoogleTaskListPicker.java @@ -41,7 +41,7 @@ public class SupportGoogleTaskListPicker extends InjectingDialogFragment { } public static AlertDialog createDialog(DialogBuilder dialogBuilder, GtasksListService gtasksListService, final GoogleTaskListSelectionHandler handler) { - final List lists = gtasksListService.getSortedGtasksList(); + final List lists = gtasksListService.getLists(); List listNames = transform(lists, GtasksList::getName); return dialogBuilder.newDialog() .setItems(listNames, (dialog, which) -> { diff --git a/src/main/java/com/todoroo/astrid/dao/StoreObjectDao.java b/src/main/java/com/todoroo/astrid/dao/StoreObjectDao.java index 78ca4259c..1f5f34454 100644 --- a/src/main/java/com/todoroo/astrid/dao/StoreObjectDao.java +++ b/src/main/java/com/todoroo/astrid/dao/StoreObjectDao.java @@ -16,8 +16,6 @@ import java.util.List; import javax.inject.Inject; -import static com.google.common.collect.Iterables.transform; -import static com.google.common.collect.Lists.newArrayList; import static com.todoroo.andlib.sql.Criterion.and; import static com.todoroo.andlib.sql.Query.select; @@ -53,8 +51,10 @@ public class StoreObjectDao { return new GtasksList(result); } - public List getGtasksLists() { - return newArrayList(transform(getByType(GtasksList.TYPE), GtasksList::new)); + public List getGtasksLists() { + return dao.toList(select(StoreObject.PROPERTIES) + .where(and(StoreObject.DELETION_DATE.eq(0), StoreObject.TYPE.eq(GtasksList.TYPE))) + .orderBy(Order.asc(StoreObject.VALUE1))); } public boolean persist(StoreObject storeObject) { @@ -69,11 +69,6 @@ public class StoreObjectDao { dao.saveExisting(storeObject); } - private List getByType(String type) { - return dao.toList(select(StoreObject.PROPERTIES) - .where(StoreObject.TYPE.eq(type))); - } - public StoreObject getSavedFilterByName(String title) { return dao.getFirst(select(StoreObject.ID) .where(and(isSavedFilter, SavedFilter.NAME.eq(title)))); diff --git a/src/main/java/org/tasks/filters/FilterCriteriaProvider.java b/src/main/java/org/tasks/filters/FilterCriteriaProvider.java index 84e9f475f..db50cc332 100644 --- a/src/main/java/org/tasks/filters/FilterCriteriaProvider.java +++ b/src/main/java/org/tasks/filters/FilterCriteriaProvider.java @@ -179,7 +179,7 @@ public class FilterCriteriaProvider { } private CustomFilterCriterion getGtasksFilterCriteria() { - List lists = gtasksListService.getSortedGtasksList(); + List lists = gtasksListService.getLists(); String[] listNames = new String[lists.size()]; String[] listIds = new String[lists.size()];