Don't query collapsed caldav/google task lists

pull/996/head
Alex Baker 5 years ago
parent 1f244eae25
commit 889605224d

@ -1,73 +0,0 @@
/*
* Copyright (c) 2012 Todoroo Inc
*
* See the file "LICENSE" for the full license governing this code.
*/
package com.todoroo.astrid.gtasks;
import static com.todoroo.andlib.utility.DateUtilities.now;
import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.api.GtasksFilter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import org.tasks.data.GoogleTaskAccount;
import org.tasks.data.GoogleTaskList;
import org.tasks.data.GoogleTaskListDao;
import org.tasks.filters.AlphanumComparator;
import org.tasks.filters.GoogleTaskFilters;
import org.tasks.sync.SyncAdapters;
/**
* Exposes filters based on lists
*
* @author Tim Su <tim@todoroo.com>
*/
public class GtasksFilterExposer {
private final GtasksListService gtasksListService;
private final SyncAdapters syncAdapters;
private final GoogleTaskListDao googleTaskListDao;
@Inject
public GtasksFilterExposer(
GtasksListService gtasksListService,
SyncAdapters syncAdapters,
GoogleTaskListDao googleTaskListDao) {
this.gtasksListService = gtasksListService;
this.syncAdapters = syncAdapters;
this.googleTaskListDao = googleTaskListDao;
}
public Map<GoogleTaskAccount, List<Filter>> getFilters() {
List<GoogleTaskFilters> googleTaskFilters = googleTaskListDao.getGoogleTaskFilters(now());
LinkedHashMap<GoogleTaskAccount, List<Filter>> filters = new LinkedHashMap<>();
for (GoogleTaskFilters filter : googleTaskFilters) {
if (!filters.containsKey(filter.googleTaskAccount)) {
filters.put(filter.googleTaskAccount, new ArrayList<>());
}
if (filter.googleTaskList != null) {
filters.get(filter.googleTaskAccount).add(filter.toGtasksFilter());
}
}
for (Map.Entry<GoogleTaskAccount, List<Filter>> entry : filters.entrySet()) {
Collections.sort(entry.getValue(), new AlphanumComparator<>(AlphanumComparator.FILTER));
}
return filters;
}
public Filter getFilter(long id) {
if (syncAdapters.isGoogleTaskSyncEnabled()) {
GoogleTaskList list = gtasksListService.getList(id);
if (list != null) {
return new GtasksFilter(list);
}
}
return null;
}
}

@ -1,57 +0,0 @@
package org.tasks.caldav;
import static com.todoroo.andlib.utility.DateUtilities.now;
import com.todoroo.astrid.api.CaldavFilter;
import com.todoroo.astrid.api.Filter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import org.tasks.data.CaldavAccount;
import org.tasks.data.CaldavCalendar;
import org.tasks.data.CaldavDao;
import org.tasks.filters.AlphanumComparator;
import org.tasks.filters.CaldavFilters;
import org.tasks.sync.SyncAdapters;
public class CaldavFilterExposer {
private final SyncAdapters syncAdapters;
private final CaldavDao caldavDao;
@Inject
public CaldavFilterExposer(CaldavDao caldavDao, SyncAdapters syncAdapters) {
this.caldavDao = caldavDao;
this.syncAdapters = syncAdapters;
}
public Map<CaldavAccount, List<Filter>> getFilters() {
List<CaldavFilters> caldavFilters = caldavDao.getCaldavFilters(now());
LinkedHashMap<CaldavAccount, List<Filter>> filters = new LinkedHashMap<>();
for (CaldavFilters filter : caldavFilters) {
if (!filters.containsKey(filter.caldavAccount)) {
filters.put(filter.caldavAccount, new ArrayList<>());
}
if (filter.caldavCalendar != null) {
filters.get(filter.caldavAccount).add(filter.toCaldavFilter());
}
}
for (Map.Entry<CaldavAccount, List<Filter>> entry : filters.entrySet()) {
Collections.sort(entry.getValue(), new AlphanumComparator<>(AlphanumComparator.FILTER));
}
return filters;
}
public Filter getFilterByUuid(String uuid) {
if (syncAdapters.isCaldavSyncEnabled()) {
CaldavCalendar caldavCalendar = caldavDao.getCalendarByUuid(uuid);
if (caldavCalendar != null) {
return new CaldavFilter(caldavCalendar);
}
}
return null;
}
}

@ -146,14 +146,15 @@ public abstract class CaldavDao {
public abstract List<String> getCalendars(List<Long> tasks);
@Query(
"SELECT caldav_lists.*, caldav_accounts.*, COUNT(tasks._id) AS count"
"SELECT caldav_lists.*, COUNT(tasks._id) AS count"
+ " FROM caldav_accounts"
+ " LEFT JOIN caldav_lists ON caldav_lists.cdl_account = caldav_accounts.cda_uuid"
+ " LEFT JOIN caldav_tasks ON caldav_tasks.cd_calendar = caldav_lists.cdl_uuid"
+ " LEFT JOIN tasks ON caldav_tasks.cd_task = tasks._id AND tasks.deleted = 0 AND tasks.completed = 0 AND tasks.hideUntil < :now AND cd_deleted = 0"
+ " WHERE caldav_accounts.cda_id = :accountId"
+ " GROUP BY caldav_lists.cdl_uuid"
+ " ORDER BY caldav_accounts.cda_name COLLATE NOCASE")
public abstract List<CaldavFilters> getCaldavFilters(long now);
public abstract List<CaldavFilters> getCaldavFilters(long accountId, long now);
@Query(
"SELECT tasks._id FROM tasks "

@ -63,12 +63,13 @@ public abstract class GoogleTaskListDao {
public abstract void update(GoogleTaskList list);
@Query(
"SELECT google_task_lists.*, google_task_accounts.*, COUNT(tasks._id) AS count"
"SELECT google_task_lists.*, COUNT(tasks._id) AS count"
+ " FROM google_task_accounts "
+ " LEFT JOIN google_task_lists ON google_task_lists.gtl_account = google_task_accounts.gta_account"
+ " LEFT JOIN google_tasks ON google_tasks.gt_list_id = google_task_lists.gtl_remote_id"
+ " LEFT JOIN tasks ON google_tasks.gt_task = tasks._id AND tasks.deleted = 0 AND tasks.completed = 0 AND tasks.hideUntil < :now AND gt_deleted = 0"
+ " WHERE google_task_accounts.gta_id = :accountId"
+ " GROUP BY google_task_lists.gtl_remote_id"
+ " ORDER BY google_task_lists.gtl_account COLLATE NOCASE")
public abstract List<GoogleTaskFilters> getGoogleTaskFilters(long now);
public abstract List<GoogleTaskFilters> getGoogleTaskFilters(long accountId, long now);
}

@ -2,12 +2,10 @@ package org.tasks.filters;
import androidx.room.Embedded;
import com.todoroo.astrid.api.CaldavFilter;
import org.tasks.data.CaldavAccount;
import org.tasks.data.CaldavCalendar;
public class CaldavFilters {
@Embedded public CaldavCalendar caldavCalendar;
@Embedded public CaldavAccount caldavAccount;
public int count;
public CaldavFilter toCaldavFilter() {
@ -21,7 +19,7 @@ public class CaldavFilters {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (!(o instanceof CaldavFilters)) {
return false;
}
@ -30,33 +28,20 @@ public class CaldavFilters {
if (count != that.count) {
return false;
}
if (caldavCalendar != null
? !caldavCalendar.equals(that.caldavCalendar)
: that.caldavCalendar != null) {
return false;
}
return caldavAccount != null
? caldavAccount.equals(that.caldavAccount)
: that.caldavAccount == null;
return caldavCalendar != null
? caldavCalendar.equals(that.caldavCalendar)
: that.caldavCalendar == null;
}
@Override
public int hashCode() {
int result = caldavCalendar != null ? caldavCalendar.hashCode() : 0;
result = 31 * result + (caldavAccount != null ? caldavAccount.hashCode() : 0);
result = 31 * result + count;
return result;
}
@Override
public String toString() {
return "CaldavFilters{"
+ "caldavCalendar="
+ caldavCalendar
+ ", caldavAccount="
+ caldavAccount
+ ", count="
+ count
+ '}';
return "CaldavFilters{" + "caldavCalendar=" + caldavCalendar + ", count=" + count + '}';
}
}

@ -3,7 +3,9 @@ package org.tasks.filters;
import static com.google.common.base.Strings.isNullOrEmpty;
import static com.google.common.collect.Iterables.concat;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Lists.transform;
import static com.todoroo.andlib.utility.AndroidUtilities.assertNotMainThread;
import static com.todoroo.andlib.utility.DateUtilities.now;
import static org.tasks.caldav.CaldavCalendarSettingsActivity.EXTRA_CALDAV_ACCOUNT;
import static org.tasks.ui.NavigationDrawerFragment.REQUEST_DONATE;
import static org.tasks.ui.NavigationDrawerFragment.REQUEST_PURCHASE;
@ -17,11 +19,11 @@ import com.todoroo.astrid.api.FilterListItem;
import com.todoroo.astrid.core.BuiltInFilterExposer;
import com.todoroo.astrid.core.CustomFilterActivity;
import com.todoroo.astrid.core.CustomFilterExposer;
import com.todoroo.astrid.gtasks.GtasksFilterExposer;
import com.todoroo.astrid.tags.TagFilterExposer;
import com.todoroo.astrid.timers.TimerFilterExposer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@ -34,9 +36,10 @@ import org.tasks.activities.GoogleTaskListSettingsActivity;
import org.tasks.activities.TagSettingsActivity;
import org.tasks.billing.Inventory;
import org.tasks.caldav.CaldavCalendarSettingsActivity;
import org.tasks.caldav.CaldavFilterExposer;
import org.tasks.data.CaldavAccount;
import org.tasks.data.CaldavDao;
import org.tasks.data.GoogleTaskAccount;
import org.tasks.data.GoogleTaskListDao;
import org.tasks.etesync.EteSyncCalendarSettingsActivity;
import org.tasks.filters.NavigationDrawerSubheader.SubheaderType;
import org.tasks.injection.ForApplication;
@ -53,8 +56,8 @@ public class FilterProvider {
private final TimerFilterExposer timerFilterExposer;
private final CustomFilterExposer customFilterExposer;
private final TagFilterExposer tagFilterExposer;
private final GtasksFilterExposer gtasksFilterExposer;
private final CaldavFilterExposer caldavFilterExposer;
private final GoogleTaskListDao googleTaskListDao;
private final CaldavDao caldavDao;
private final Preferences preferences;
@Inject
@ -65,8 +68,8 @@ public class FilterProvider {
TimerFilterExposer timerFilterExposer,
CustomFilterExposer customFilterExposer,
TagFilterExposer tagFilterExposer,
GtasksFilterExposer gtasksFilterExposer,
CaldavFilterExposer caldavFilterExposer,
GoogleTaskListDao googleTaskListDao,
CaldavDao caldavDao,
Preferences preferences) {
this.context = context;
this.inventory = inventory;
@ -74,8 +77,8 @@ public class FilterProvider {
this.timerFilterExposer = timerFilterExposer;
this.customFilterExposer = customFilterExposer;
this.tagFilterExposer = tagFilterExposer;
this.gtasksFilterExposer = gtasksFilterExposer;
this.caldavFilterExposer = caldavFilterExposer;
this.googleTaskListDao = googleTaskListDao;
this.caldavDao = caldavDao;
this.preferences = preferences;
}
@ -242,11 +245,41 @@ public class FilterProvider {
}
private Set<Entry<GoogleTaskAccount, List<Filter>>> getGoogleTaskFilters() {
return gtasksFilterExposer.getFilters().entrySet();
List<GoogleTaskAccount> accounts = googleTaskListDao.getAccounts();
LinkedHashMap<GoogleTaskAccount, List<Filter>> filters = new LinkedHashMap<>();
for (GoogleTaskAccount account : accounts) {
filters.put(
account,
account.isCollapsed()
? Collections.emptyList()
: newArrayList(
transform(
googleTaskListDao.getGoogleTaskFilters(account.getId(), now()),
GoogleTaskFilters::toGtasksFilter)));
}
for (Map.Entry<GoogleTaskAccount, List<Filter>> entry : filters.entrySet()) {
Collections.sort(entry.getValue(), new AlphanumComparator<>(AlphanumComparator.FILTER));
}
return filters.entrySet();
}
private Set<Entry<CaldavAccount, List<Filter>>> getCaldavFilters() {
return caldavFilterExposer.getFilters().entrySet();
List<CaldavAccount> accounts = caldavDao.getAccounts();
LinkedHashMap<CaldavAccount, List<Filter>> filters = new LinkedHashMap<>();
for (CaldavAccount account : accounts) {
filters.put(
account,
account.isCollapsed()
? Collections.emptyList()
: newArrayList(
transform(
caldavDao.getCaldavFilters(account.getId(), now()),
CaldavFilters::toCaldavFilter)));
}
for (Map.Entry<CaldavAccount, List<Filter>> entry : filters.entrySet()) {
Collections.sort(entry.getValue(), new AlphanumComparator<>(AlphanumComparator.FILTER));
}
return filters.entrySet();
}
private List<FilterListItem> getSubmenu(int title, int prefId, Function<List<Filter>> getFilters) {

@ -2,12 +2,10 @@ package org.tasks.filters;
import androidx.room.Embedded;
import com.todoroo.astrid.api.GtasksFilter;
import org.tasks.data.GoogleTaskAccount;
import org.tasks.data.GoogleTaskList;
public class GoogleTaskFilters {
@Embedded public GoogleTaskList googleTaskList;
@Embedded public GoogleTaskAccount googleTaskAccount;
public int count;
public GtasksFilter toGtasksFilter() {
@ -21,7 +19,7 @@ public class GoogleTaskFilters {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (!(o instanceof GoogleTaskFilters)) {
return false;
}
@ -30,33 +28,20 @@ public class GoogleTaskFilters {
if (count != that.count) {
return false;
}
if (googleTaskList != null
? !googleTaskList.equals(that.googleTaskList)
: that.googleTaskList != null) {
return false;
}
return googleTaskAccount != null
? googleTaskAccount.equals(that.googleTaskAccount)
: that.googleTaskAccount == null;
return googleTaskList != null
? googleTaskList.equals(that.googleTaskList)
: that.googleTaskList == null;
}
@Override
public int hashCode() {
int result = googleTaskList != null ? googleTaskList.hashCode() : 0;
result = 31 * result + (googleTaskAccount != null ? googleTaskAccount.hashCode() : 0);
result = 31 * result + count;
return result;
}
@Override
public String toString() {
return "GoogleTaskFilters{"
+ "googleTaskList="
+ googleTaskList
+ ", googleTaskAccount="
+ googleTaskAccount
+ ", count="
+ count
+ '}';
return "GoogleTaskFilters{" + "googleTaskList=" + googleTaskList + ", count=" + count + '}';
}
}

@ -19,11 +19,13 @@ import com.todoroo.astrid.api.GtasksFilter;
import com.todoroo.astrid.api.TagFilter;
import com.todoroo.astrid.core.BuiltInFilterExposer;
import com.todoroo.astrid.core.CustomFilterExposer;
import com.todoroo.astrid.gtasks.GtasksFilterExposer;
import com.todoroo.astrid.tags.TagFilterExposer;
import javax.inject.Inject;
import org.tasks.R;
import org.tasks.caldav.CaldavFilterExposer;
import org.tasks.data.CaldavCalendar;
import org.tasks.data.CaldavDao;
import org.tasks.data.GoogleTaskList;
import org.tasks.data.GoogleTaskListDao;
import org.tasks.injection.ForApplication;
import timber.log.Timber;
@ -44,8 +46,8 @@ public class DefaultFilterProvider {
private final Preferences preferences;
private final CustomFilterExposer customFilterExposer;
private final TagFilterExposer tagFilterExposer;
private final GtasksFilterExposer gtasksFilterExposer;
private final CaldavFilterExposer caldavFilterExposer;
private final GoogleTaskListDao googleTaskListDao;
private final CaldavDao caldavDao;
@Inject
public DefaultFilterProvider(
@ -53,14 +55,14 @@ public class DefaultFilterProvider {
Preferences preferences,
CustomFilterExposer customFilterExposer,
TagFilterExposer tagFilterExposer,
GtasksFilterExposer gtasksFilterExposer,
CaldavFilterExposer caldavFilterExposer) {
GoogleTaskListDao googleTaskListDao,
CaldavDao caldavDao) {
this.context = context;
this.preferences = preferences;
this.customFilterExposer = customFilterExposer;
this.tagFilterExposer = tagFilterExposer;
this.gtasksFilterExposer = gtasksFilterExposer;
this.caldavFilterExposer = caldavFilterExposer;
this.googleTaskListDao = googleTaskListDao;
this.caldavDao = caldavDao;
}
public Filter getDashclockFilter() {
@ -129,9 +131,11 @@ public class DefaultFilterProvider {
case TYPE_TAG:
return tagFilterExposer.getFilterByUuid(split[1]);
case TYPE_GOOGLE_TASKS:
return gtasksFilterExposer.getFilter(Long.parseLong(split[1]));
GoogleTaskList list = googleTaskListDao.getById(Long.parseLong(split[1]));
return list == null ? null : new GtasksFilter(list);
case TYPE_CALDAV:
return caldavFilterExposer.getFilterByUuid(split[1]);
CaldavCalendar caldavCalendar = caldavDao.getCalendarByUuid(split[1]);
return caldavCalendar == null ? null : new CaldavFilter(caldavCalendar);
default:
return null;
}

Loading…
Cancel
Save