mirror of https://github.com/tasks/tasks
Don't query collapsed caldav/google task lists
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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue