|
|
|
@ -28,6 +28,7 @@ import com.todoroo.andlib.data.TodorooCursor;
|
|
|
|
|
import com.todoroo.andlib.service.Autowired;
|
|
|
|
|
import com.todoroo.andlib.service.ContextManager;
|
|
|
|
|
import com.todoroo.andlib.service.DependencyInjectionService;
|
|
|
|
|
import com.todoroo.andlib.sql.Criterion;
|
|
|
|
|
import com.todoroo.andlib.utility.AndroidUtilities;
|
|
|
|
|
import com.todoroo.andlib.utility.DateUtilities;
|
|
|
|
|
import com.todoroo.andlib.utility.Preferences;
|
|
|
|
@ -41,10 +42,15 @@ import com.todoroo.astrid.api.PermaSql;
|
|
|
|
|
import com.todoroo.astrid.core.CoreFilterExposer;
|
|
|
|
|
import com.todoroo.astrid.core.SortHelper;
|
|
|
|
|
import com.todoroo.astrid.dao.Database;
|
|
|
|
|
import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
|
|
|
|
|
import com.todoroo.astrid.data.Metadata;
|
|
|
|
|
import com.todoroo.astrid.data.TagData;
|
|
|
|
|
import com.todoroo.astrid.data.Task;
|
|
|
|
|
import com.todoroo.astrid.service.AstridDependencyInjector;
|
|
|
|
|
import com.todoroo.astrid.service.TagDataService;
|
|
|
|
|
import com.todoroo.astrid.service.TaskService;
|
|
|
|
|
import com.todoroo.astrid.service.ThemeService;
|
|
|
|
|
import com.todoroo.astrid.subtasks.SubtasksMetadata;
|
|
|
|
|
import com.todoroo.astrid.utility.AstridPreferences;
|
|
|
|
|
import com.todoroo.astrid.utility.Constants;
|
|
|
|
|
|
|
|
|
@ -114,6 +120,9 @@ public class TasksWidget extends AppWidgetProvider {
|
|
|
|
|
@Autowired
|
|
|
|
|
TaskService taskService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
TagDataService tagDataService;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onStart(final Intent intent, int startId) {
|
|
|
|
|
ContextManager.setContext(this);
|
|
|
|
@ -173,6 +182,39 @@ public class TasksWidget extends AppWidgetProvider {
|
|
|
|
|
String query = SortHelper.adjustQueryForFlagsAndSort(
|
|
|
|
|
filter.getSqlQuery(), flags, sort).replaceAll("LIMIT \\d+", "") + " LIMIT " + numberOfTasks;
|
|
|
|
|
|
|
|
|
|
boolean isTagList = (filter instanceof FilterWithCustomIntent) &&
|
|
|
|
|
((((FilterWithCustomIntent)filter).customTaskList.getShortClassName().equals("com.todoroo.astrid.subtasks.SubtasksTagListFragment")) ||
|
|
|
|
|
(((FilterWithCustomIntent)filter).customTaskList.getShortClassName().equals("com.todoroo.astrid.actfm.TagViewFragment")));
|
|
|
|
|
if (SortHelper.isManualSort(flags) && isTagList) {
|
|
|
|
|
// care for manual ordering
|
|
|
|
|
String tagName = Preferences.getStringValue(WidgetConfigActivity.PREF_TITLE + widgetId);
|
|
|
|
|
if(tagName == null)
|
|
|
|
|
tagName = SubtasksMetadata.LIST_ACTIVE_TASKS;
|
|
|
|
|
else {
|
|
|
|
|
TagData tag = tagDataService.getTag(tagName, TagData.PROPERTIES);
|
|
|
|
|
if (tag != null)
|
|
|
|
|
tagName = "td:"+tag.getId();
|
|
|
|
|
else
|
|
|
|
|
tagName = SubtasksMetadata.LIST_ACTIVE_TASKS;
|
|
|
|
|
}
|
|
|
|
|
String subtaskJoin = String.format("LEFT JOIN %s ON (%s = %s AND %s = '%s' AND %s = '%s') ",
|
|
|
|
|
Metadata.TABLE, Task.ID, Metadata.TASK,
|
|
|
|
|
Metadata.KEY, SubtasksMetadata.METADATA_KEY,
|
|
|
|
|
SubtasksMetadata.TAG, tagName);
|
|
|
|
|
|
|
|
|
|
if(!query.contains(subtaskJoin)) {
|
|
|
|
|
query = subtaskJoin + query;
|
|
|
|
|
query = query.replaceAll("ORDER BY .*", "");
|
|
|
|
|
query = query + String.format(" ORDER BY %s, %s, IFNULL(CAST(%s AS LONG), %s)",
|
|
|
|
|
Task.DELETION_DATE, Task.COMPLETION_DATE,
|
|
|
|
|
SubtasksMetadata.ORDER, Task.CREATION_DATE);
|
|
|
|
|
query = query.replace(TaskCriteria.isVisible().toString(),
|
|
|
|
|
Criterion.all.toString());
|
|
|
|
|
|
|
|
|
|
filter.setFilterQueryOverride(query);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
database.openForReading();
|
|
|
|
|
cursor = taskService.fetchFiltered(query, null, Task.ID, Task.TITLE, Task.DUE_DATE, Task.COMPLETION_DATE);
|
|
|
|
|
Task task = new Task();
|
|
|
|
|