Remove type from database and todoroocursor

pull/618/head
Alex Baker 7 years ago
parent bc5f441a50
commit c8bff28a07

@ -16,6 +16,7 @@ public class GtaskListMaker {
public static final Property<GoogleTaskList, String> REMOTE_ID = newProperty(); public static final Property<GoogleTaskList, String> REMOTE_ID = newProperty();
public static final Property<GoogleTaskList, Long> LAST_SYNC = newProperty(); public static final Property<GoogleTaskList, Long> LAST_SYNC = newProperty();
public static final Property<GoogleTaskList, String> NAME = newProperty(); public static final Property<GoogleTaskList, String> NAME = newProperty();
public static final Property<GoogleTaskList, Integer> COLOR = newProperty();
public static GoogleTaskList newGtaskList(PropertyValue<? super GoogleTaskList, ?>... properties) { public static GoogleTaskList newGtaskList(PropertyValue<? super GoogleTaskList, ?>... properties) {
return make(instantiator, properties); return make(instantiator, properties);
@ -28,5 +29,6 @@ public class GtaskListMaker {
setTitle(lookup.valueOf(NAME, "Default")); setTitle(lookup.valueOf(NAME, "Default"));
setRemoteOrder(lookup.valueOf(ORDER, 0)); setRemoteOrder(lookup.valueOf(ORDER, 0));
setLastSync(lookup.valueOf(LAST_SYNC, 0L)); setLastSync(lookup.valueOf(LAST_SYNC, 0L));
setColor(lookup.valueOf(COLOR, -1));
}}; }};
} }

@ -79,7 +79,7 @@ public class GtasksSubtaskListFragment extends GtasksListFragment {
} }
@Override @Override
protected TaskAdapter createTaskAdapter(TodorooCursor<Task> cursor) { protected TaskAdapter createTaskAdapter(TodorooCursor cursor) {
return helper.createTaskAdapter(theme.wrap(context), cursor); return helper.createTaskAdapter(theme.wrap(context), cursor);
} }

@ -56,7 +56,7 @@ class OrderedMetadataListFragmentHelper {
updater.initialize(filter); updater.initialize(filter);
} }
TaskAdapter createTaskAdapter(Context context, TodorooCursor<Task> cursor) { TaskAdapter createTaskAdapter(Context context, TodorooCursor cursor) {
taskAdapter = new DraggableTaskAdapter(context, cursor); taskAdapter = new DraggableTaskAdapter(context, cursor);
taskAdapter.setOnCompletedTaskListener(this::setCompletedForItemAndSubtasks); taskAdapter.setOnCompletedTaskListener(this::setCompletedForItemAndSubtasks);

@ -80,7 +80,7 @@ public abstract class AbstractModel implements Parcelable, Cloneable {
protected AbstractModel() { protected AbstractModel() {
} }
protected AbstractModel(TodorooCursor<? extends AbstractModel> cursor) { protected AbstractModel(TodorooCursor cursor) {
readPropertiesFromCursor(cursor); readPropertiesFromCursor(cursor);
} }
@ -187,7 +187,7 @@ public abstract class AbstractModel implements Parcelable, Cloneable {
/** /**
* Reads all properties from the supplied cursor and store * Reads all properties from the supplied cursor and store
*/ */
void readPropertiesFromCursor(TodorooCursor<? extends AbstractModel> cursor) { void readPropertiesFromCursor(TodorooCursor cursor) {
if (values == null) { if (values == null) {
values = new ContentValues(); values = new ContentValues();
} }

@ -11,6 +11,7 @@ import android.database.Cursor;
import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Query; import com.todoroo.andlib.sql.Query;
import com.todoroo.astrid.dao.Database; import com.todoroo.astrid.dao.Database;
import com.todoroo.astrid.data.Task;
import org.tasks.BuildConfig; import org.tasks.BuildConfig;
@ -27,49 +28,34 @@ import timber.log.Timber;
* @author Tim Su <tim@todoroo.com> * @author Tim Su <tim@todoroo.com>
* *
*/ */
public class DatabaseDao<TYPE extends AbstractModel> { public class DatabaseDao {
private final Class<TYPE> modelClass; private final Table table = Task.TABLE;
private final Table table;
private final Database database; private final Database database;
public DatabaseDao(Database database, Class<TYPE> modelClass) { public DatabaseDao(Database database) {
this.modelClass = modelClass;
this.database = database; this.database = database;
table = database.getTable(this.modelClass);
try {
modelClass.getConstructor(); // check for default constructor
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}
}
/** Gets table associated with this DAO */
public Table getTable() {
return table;
} }
// --- dao methods public List<Task> toList(Query query) {
public List<TYPE> toList(Query query) {
return query(query).toList(); return query(query).toList();
} }
private TYPE getFirst(Query query) { private Task getFirst(Query query) {
return query(query).first(); return query(query).first();
} }
/** /**
* Construct a query with SQL DSL objects * Construct a query with SQL DSL objects
*/ */
public TodorooCursor<TYPE> query(Query query) { public TodorooCursor query(Query query) {
query.from(table); query.from(table);
String queryString = query.toString(); String queryString = query.toString();
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {
Timber.v(queryString); Timber.v(queryString);
} }
Cursor cursor = database.rawQuery(queryString); Cursor cursor = database.rawQuery(queryString);
return new TodorooCursor<>(modelClass, cursor, query.getFields()); return new TodorooCursor(cursor, query.getFields());
} }
/** /**
@ -80,7 +66,7 @@ public class DatabaseDao<TYPE extends AbstractModel> {
* id of item * id of item
* @return null if no item found * @return null if no item found
*/ */
public TYPE fetch(long id, Property<?>... properties) { public Task fetch(long id, Property<?>... properties) {
return getFirst(Query.select(properties).where(AbstractModel.ID_PROPERTY.eq(id))); return getFirst(Query.select(properties).where(AbstractModel.ID_PROPERTY.eq(id)));
} }
@ -117,7 +103,7 @@ public class DatabaseDao<TYPE extends AbstractModel> {
* @param template set fields on this object in order to set them in the db. * @param template set fields on this object in order to set them in the db.
* @return # of updated items * @return # of updated items
*/ */
public int update(Criterion where, TYPE template) { public int update(Criterion where, Task template) {
return database.update(table.name, template.getSetValues(), return database.update(table.name, template.getSetValues(),
where.toString()); where.toString());
} }
@ -128,7 +114,7 @@ public class DatabaseDao<TYPE extends AbstractModel> {
* *
* @return true on success. * @return true on success.
*/ */
public boolean persist(TYPE item) { public boolean persist(Task item) {
if (item.getId() == AbstractModel.NO_ID) { if (item.getId() == AbstractModel.NO_ID) {
return createNew(item); return createNew(item);
} else { } else {
@ -147,7 +133,7 @@ public class DatabaseDao<TYPE extends AbstractModel> {
boolean makeChange(); boolean makeChange();
} }
private boolean insertOrUpdateAndRecordChanges(TYPE item, DatabaseChangeOp op) { private boolean insertOrUpdateAndRecordChanges(Task item, DatabaseChangeOp op) {
final AtomicBoolean result = new AtomicBoolean(false); final AtomicBoolean result = new AtomicBoolean(false);
synchronized(database) { synchronized(database) {
result.set(op.makeChange()); result.set(op.makeChange());
@ -167,7 +153,7 @@ public class DatabaseDao<TYPE extends AbstractModel> {
* item model * item model
* @return returns true on success. * @return returns true on success.
*/ */
public boolean createNew(final TYPE item) { public boolean createNew(final Task item) {
item.clearValue(AbstractModel.ID_PROPERTY); item.clearValue(AbstractModel.ID_PROPERTY);
DatabaseChangeOp insert = new DatabaseChangeOp() { DatabaseChangeOp insert = new DatabaseChangeOp() {
@ -195,7 +181,7 @@ public class DatabaseDao<TYPE extends AbstractModel> {
* item model * item model
* @return returns true on success. * @return returns true on success.
*/ */
public boolean saveExisting(final TYPE item) { public boolean saveExisting(final Task item) {
final ContentValues values = item.getSetValues(); final ContentValues values = item.getSetValues();
if(values == null || values.size() == 0) // nothing changed if(values == null || values.size() == 0) // nothing changed
{ {

@ -16,33 +16,19 @@ import com.todoroo.andlib.sql.SqlTable;
*/ */
public final class Table extends SqlTable { public final class Table extends SqlTable {
public final String name; public final String name;
public final Class<? extends AbstractModel> modelClass; private final Class<? extends AbstractModel> modelClass;
public Table(String name, Class<? extends AbstractModel> modelClass) { public Table(String name, Class<? extends AbstractModel> modelClass) {
this(name, modelClass, null); this(name, modelClass, null);
} }
public Table(String name, Class<? extends AbstractModel> modelClass, String alias) { private Table(String name, Class<? extends AbstractModel> modelClass, String alias) {
super(name); super(name);
this.name = name; this.name = name;
this.alias = alias; this.alias = alias;
this.modelClass = modelClass; this.modelClass = modelClass;
} }
/**
* Reads a list of properties from model class by reflection
* @return property array
*/
public Property<?>[] getProperties() {
try {
return (Property<?>[])modelClass.getField("PROPERTIES").get(null);
} catch (IllegalArgumentException | NoSuchFieldException | IllegalAccessException | SecurityException e) {
throw new RuntimeException(e);
}
}
// --- for sql-dsl
/** /**
* Create a new join table based on this table, but with an alias * Create a new join table based on this table, but with an alias
*/ */

@ -9,6 +9,7 @@ import android.database.Cursor;
import android.database.CursorWrapper; import android.database.CursorWrapper;
import com.todoroo.andlib.data.Property.PropertyVisitor; import com.todoroo.andlib.data.Property.PropertyVisitor;
import com.todoroo.astrid.data.Task;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -21,11 +22,9 @@ import java.util.WeakHashMap;
* *
* @author Tim Su <tim@todoroo.com> * @author Tim Su <tim@todoroo.com>
* *
* @param <TYPE> a model type that is returned by this cursor
*/ */
public class TodorooCursor<TYPE extends AbstractModel> extends CursorWrapper { public class TodorooCursor extends CursorWrapper {
private final Class<TYPE> modelClass;
/** Properties read by this cursor */ /** Properties read by this cursor */
private final Property<?>[] properties; private final Property<?>[] properties;
@ -42,16 +41,15 @@ public class TodorooCursor<TYPE extends AbstractModel> extends CursorWrapper {
* *
* @param properties properties read from this cursor * @param properties properties read from this cursor
*/ */
public TodorooCursor(Class<TYPE> modelClass, Cursor cursor, Property<?>[] properties) { public TodorooCursor(Cursor cursor, Property<?>[] properties) {
super(cursor); super(cursor);
this.modelClass = modelClass;
this.properties = properties; this.properties = properties;
columnIndexCache = new WeakHashMap<>(); columnIndexCache = new WeakHashMap<>();
} }
public List<TYPE> toList() { public List<Task> toList() {
List<TYPE> result = new ArrayList<>(); List<Task> result = new ArrayList<>();
try { try {
for (moveToFirst() ; !isAfterLast() ; moveToNext()) { for (moveToFirst() ; !isAfterLast() ; moveToNext()) {
result.add(toModel()); result.add(toModel());
@ -62,17 +60,8 @@ public class TodorooCursor<TYPE extends AbstractModel> extends CursorWrapper {
return result; return result;
} }
public TYPE toModel() { public Task toModel() {
TYPE instance; return new Task(this);
try {
instance = modelClass.newInstance();
} catch (InstantiationException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
instance.readPropertiesFromCursor(this);
return instance;
} }
public int count() { public int count() {
@ -83,7 +72,7 @@ public class TodorooCursor<TYPE extends AbstractModel> extends CursorWrapper {
} }
} }
public TYPE first() { public Task first() {
try { try {
return moveToFirst() ? toModel() : null; return moveToFirst() ? toModel() : null;
} finally { } finally {
@ -127,11 +116,10 @@ public class TodorooCursor<TYPE extends AbstractModel> extends CursorWrapper {
* @author Tim Su <tim@todoroo.com> * @author Tim Su <tim@todoroo.com>
* *
*/ */
public static class CursorReadingVisitor implements PropertyVisitor<Object, TodorooCursor<?>> { public static class CursorReadingVisitor implements PropertyVisitor<Object, TodorooCursor> {
@Override @Override
public Object visitInteger(Property<Integer> property, public Object visitInteger(Property<Integer> property, TodorooCursor cursor) {
TodorooCursor<?> cursor) {
int column = columnIndex(property, cursor); int column = columnIndex(property, cursor);
if(property.checkFlag(Property.PROP_FLAG_NULLABLE) && cursor.isNull(column)) { if(property.checkFlag(Property.PROP_FLAG_NULLABLE) && cursor.isNull(column)) {
return null; return null;
@ -140,7 +128,7 @@ public class TodorooCursor<TYPE extends AbstractModel> extends CursorWrapper {
} }
@Override @Override
public Object visitLong(Property<Long> property, TodorooCursor<?> cursor) { public Object visitLong(Property<Long> property, TodorooCursor cursor) {
int column = columnIndex(property, cursor); int column = columnIndex(property, cursor);
if(property.checkFlag(Property.PROP_FLAG_NULLABLE) && cursor.isNull(column)) { if(property.checkFlag(Property.PROP_FLAG_NULLABLE) && cursor.isNull(column)) {
return null; return null;
@ -149,7 +137,7 @@ public class TodorooCursor<TYPE extends AbstractModel> extends CursorWrapper {
} }
@Override @Override
public Object visitDouble(Property<Double> property, TodorooCursor<?> cursor) { public Object visitDouble(Property<Double> property, TodorooCursor cursor) {
int column = columnIndex(property, cursor); int column = columnIndex(property, cursor);
if (property.checkFlag(Property.PROP_FLAG_NULLABLE) && cursor.isNull(column)) { if (property.checkFlag(Property.PROP_FLAG_NULLABLE) && cursor.isNull(column)) {
return null; return null;
@ -158,8 +146,7 @@ public class TodorooCursor<TYPE extends AbstractModel> extends CursorWrapper {
} }
@Override @Override
public Object visitString(Property<String> property, public Object visitString(Property<String> property, TodorooCursor cursor) {
TodorooCursor<?> cursor) {
int column = columnIndex(property, cursor); int column = columnIndex(property, cursor);
if(property.checkFlag(Property.PROP_FLAG_NULLABLE) && cursor.isNull(column)) { if(property.checkFlag(Property.PROP_FLAG_NULLABLE) && cursor.isNull(column)) {
return null; return null;
@ -167,10 +154,8 @@ public class TodorooCursor<TYPE extends AbstractModel> extends CursorWrapper {
return cursor.getString(column); return cursor.getString(column);
} }
private int columnIndex(Property<?> property, TodorooCursor<?> cursor) { private int columnIndex(Property<?> property, TodorooCursor cursor) {
return cursor.getColumnIndexFromCache(property.getColumnName()); return cursor.getColumnIndexFromCache(property.getColumnName());
} }
} }
} }

@ -425,7 +425,7 @@ public class TaskListFragment extends InjectingFragment implements
} }
} }
protected TaskAdapter createTaskAdapter(TodorooCursor<Task> cursor) { protected TaskAdapter createTaskAdapter(TodorooCursor cursor) {
return new TaskAdapter(context, cursor); return new TaskAdapter(context, cursor);
} }
@ -441,7 +441,7 @@ public class TaskListFragment extends InjectingFragment implements
return; return;
} }
TodorooCursor<Task> currentCursor = taskListDataProvider.constructCursor(filter, taskProperties()); TodorooCursor currentCursor = taskListDataProvider.constructCursor(filter, taskProperties());
if (currentCursor == null) { if (currentCursor == null) {
return; return;
} }
@ -461,7 +461,7 @@ public class TaskListFragment extends InjectingFragment implements
} }
public void reconstructCursor() { public void reconstructCursor() {
TodorooCursor<Task> cursor = taskListDataProvider.constructCursor(filter, taskProperties()); TodorooCursor cursor = taskListDataProvider.constructCursor(filter, taskProperties());
if (cursor == null || taskAdapter == null) { if (cursor == null || taskAdapter == null) {
return; return;
} }

@ -37,7 +37,7 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
public List<Integer> getTaskPositions(List<Long> longs) { public List<Integer> getTaskPositions(List<Long> longs) {
List<Integer> result = new ArrayList<>(); List<Integer> result = new ArrayList<>();
TodorooCursor<Task> taskCursor = getTaskCursor(); TodorooCursor taskCursor = getTaskCursor();
for (taskCursor.moveToFirst() ; !taskCursor.isAfterLast() ; taskCursor.moveToNext()) { for (taskCursor.moveToFirst() ; !taskCursor.isAfterLast() ; taskCursor.moveToNext()) {
if (longs.contains(taskCursor.get(Task.ID))) { if (longs.contains(taskCursor.get(Task.ID))) {
result.add(taskCursor.getPosition()); result.add(taskCursor.getPosition());
@ -114,12 +114,12 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
} }
private TodorooCursor<Task> getTaskCursor() { private TodorooCursor getTaskCursor() {
return (TodorooCursor<Task>) getCursor(); return (TodorooCursor) getCursor();
} }
public long getTaskId(int position) { public long getTaskId(int position) {
TodorooCursor<Task> c = getTaskCursor(); TodorooCursor c = getTaskCursor();
if (c != null) { if (c != null) {
if (c.moveToPosition(position)) { if (c.moveToPosition(position)) {
return c.get(Task.ID); return c.get(Task.ID);
@ -129,7 +129,7 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
} }
public Task getTask(int position) { public Task getTask(int position) {
TodorooCursor<Task> c = getTaskCursor(); TodorooCursor c = getTaskCursor();
if (c != null) { if (c != null) {
if (c.moveToPosition(position)) { if (c.moveToPosition(position)) {
return c.toModel(); return c.toModel();
@ -139,7 +139,7 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
} }
protected String getItemUuid(int position) { protected String getItemUuid(int position) {
TodorooCursor<Task> c = getTaskCursor(); TodorooCursor c = getTaskCursor();
if (c != null) { if (c != null) {
if (c.moveToPosition(position)) { if (c.moveToPosition(position)) {
return c.get(Task.UUID); return c.get(Task.UUID);

@ -12,32 +12,28 @@ import android.database.Cursor;
import android.database.sqlite.SQLiteConstraintException; import android.database.sqlite.SQLiteConstraintException;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import com.todoroo.andlib.data.AbstractModel;
import com.todoroo.andlib.data.Table;
import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.AndroidUtilities;
import org.tasks.data.Filter;
import org.tasks.data.FilterDao;
import org.tasks.data.GoogleTaskList;
import org.tasks.data.GoogleTaskListDao;
import org.tasks.data.TagData;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import org.tasks.data.TaskAttachment;
import org.tasks.data.TaskListMetadata;
import org.tasks.data.UserActivity;
import org.tasks.data.Alarm; import org.tasks.data.Alarm;
import org.tasks.data.AlarmDao; import org.tasks.data.AlarmDao;
import org.tasks.data.Filter;
import org.tasks.data.FilterDao;
import org.tasks.data.GoogleTask; import org.tasks.data.GoogleTask;
import org.tasks.data.GoogleTaskDao; import org.tasks.data.GoogleTaskDao;
import org.tasks.data.GoogleTaskList;
import org.tasks.data.GoogleTaskListDao;
import org.tasks.data.Location; import org.tasks.data.Location;
import org.tasks.data.LocationDao; import org.tasks.data.LocationDao;
import org.tasks.data.Tag; import org.tasks.data.Tag;
import org.tasks.data.TagDao; import org.tasks.data.TagDao;
import org.tasks.data.TagData;
import org.tasks.data.TagDataDao; import org.tasks.data.TagDataDao;
import org.tasks.data.TaskAttachment;
import org.tasks.data.TaskAttachmentDao; import org.tasks.data.TaskAttachmentDao;
import org.tasks.data.TaskListMetadata;
import org.tasks.data.TaskListMetadataDao; import org.tasks.data.TaskListMetadataDao;
import org.tasks.data.UserActivity;
import org.tasks.data.UserActivityDao; import org.tasks.data.UserActivityDao;
import org.tasks.notifications.Notification; import org.tasks.notifications.Notification;
import org.tasks.notifications.NotificationDao; import org.tasks.notifications.NotificationDao;
@ -84,10 +80,6 @@ public abstract class Database extends RoomDatabase {
public static final String NAME = "database"; public static final String NAME = "database";
private static final Table[] TABLES = new Table[] {
Task.TABLE
};
private SupportSQLiteDatabase database; private SupportSQLiteDatabase database;
private Runnable onDatabaseUpdated; private Runnable onDatabaseUpdated;
@ -108,18 +100,6 @@ public abstract class Database extends RoomDatabase {
} }
} }
/**
* Return the name of the table containing these models
*/
public final Table getTable(Class<? extends AbstractModel> modelType) {
for(Table table : TABLES) {
if(table.modelClass.equals(modelType)) {
return table;
}
}
throw new UnsupportedOperationException("Unknown model class " + modelType); //$NON-NLS-1$
}
/** /**
* Open the database for writing. Must be closed afterwards. If user is * Open the database for writing. Must be closed afterwards. If user is
* out of disk space, database may be opened for reading instead * out of disk space, database may be opened for reading instead

@ -2,6 +2,7 @@ package com.todoroo.astrid.dao;
import com.todoroo.andlib.data.DatabaseDao; import com.todoroo.andlib.data.DatabaseDao;
import com.todoroo.astrid.data.RemoteModel; import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.helper.UUIDHelper; import com.todoroo.astrid.helper.UUIDHelper;
/** /**
@ -11,16 +12,15 @@ import com.todoroo.astrid.helper.UUIDHelper;
* created model if one doesn't already exist. * created model if one doesn't already exist.
* @author Sam * @author Sam
* *
* @param <RTYPE>
*/ */
public class RemoteModelDao<RTYPE extends RemoteModel> extends DatabaseDao<RTYPE> { public class RemoteModelDao extends DatabaseDao {
public RemoteModelDao(Database database, Class<RTYPE> modelClass) { public RemoteModelDao(Database database) {
super(database, modelClass); super(database);
} }
@Override @Override
public boolean createNew(RTYPE item) { public boolean createNew(Task item) {
if (!item.containsValue(RemoteModel.UUID_PROPERTY) || RemoteModel.isUuidEmpty(item.getUuidProperty())) { if (!item.containsValue(RemoteModel.UUID_PROPERTY) || RemoteModel.isUuidEmpty(item.getUuidProperty())) {
item.setUuidProperty(UUIDHelper.newUUID()); item.setUuidProperty(UUIDHelper.newUUID());
} }

@ -52,7 +52,7 @@ public class TaskDao {
public static final String TRANS_SUPPRESS_REFRESH = "suppress-refresh"; public static final String TRANS_SUPPRESS_REFRESH = "suppress-refresh";
private final RemoteModelDao<Task> dao; private final RemoteModelDao dao;
private final LocalBroadcastManager localBroadcastManager; private final LocalBroadcastManager localBroadcastManager;
private final Preferences preferences; private final Preferences preferences;
@ -73,10 +73,10 @@ public class TaskDao {
this.locationDao = locationDao; this.locationDao = locationDao;
this.googleTaskDao = googleTaskDao; this.googleTaskDao = googleTaskDao;
this.localBroadcastManager = localBroadcastManager; this.localBroadcastManager = localBroadcastManager;
dao = new RemoteModelDao<>(database, Task.class); dao = new RemoteModelDao(database);
} }
public TodorooCursor<Task> query(Query query) { public TodorooCursor query(Query query) {
return dao.query(query); return dao.query(query);
} }
@ -172,7 +172,7 @@ public class TaskDao {
} }
public String uuidFromLocalId(long localId) { public String uuidFromLocalId(long localId) {
TodorooCursor<Task> cursor = dao.query(Query.select(RemoteModel.UUID_PROPERTY).where(AbstractModel.ID_PROPERTY.eq(localId))); TodorooCursor cursor = dao.query(Query.select(RemoteModel.UUID_PROPERTY).where(AbstractModel.ID_PROPERTY.eq(localId)));
try { try {
if (cursor.getCount() == 0) { if (cursor.getCount() == 0) {
return RemoteModel.NO_UUID; return RemoteModel.NO_UUID;
@ -238,7 +238,7 @@ public class TaskDao {
} }
private ContentValues handleSQLiteConstraintException(Task task) { private ContentValues handleSQLiteConstraintException(Task task) {
TodorooCursor<Task> cursor = dao.query(Query.select(Task.ID).where( TodorooCursor cursor = dao.query(Query.select(Task.ID).where(
Task.UUID.eq(task.getUUID()))); Task.UUID.eq(task.getUUID())));
if (cursor.getCount() > 0) { if (cursor.getCount() > 0) {
cursor.moveToFirst(); cursor.moveToFirst();
@ -332,7 +332,7 @@ public class TaskDao {
} catch (SQLiteConstraintException e) { } catch (SQLiteConstraintException e) {
Timber.e(e, e.getMessage()); Timber.e(e, e.getMessage());
String uuid = item.getUUID(); String uuid = item.getUUID();
TodorooCursor<Task> tasksWithUUID = dao.query(Query.select( TodorooCursor tasksWithUUID = dao.query(Query.select(
SQL_CONSTRAINT_MERGE_PROPERTIES).where( SQL_CONSTRAINT_MERGE_PROPERTIES).where(
Task.UUID.eq(uuid))); Task.UUID.eq(uuid)));
try { try {
@ -396,7 +396,7 @@ public class TaskDao {
save(item); save(item);
} }
public TodorooCursor<Task> fetchFiltered(String queryTemplate, Property<?>... properties) { public TodorooCursor fetchFiltered(String queryTemplate, Property<?>... properties) {
return query(queryTemplate == null return query(queryTemplate == null
? Query.selectDistinct(properties) ? Query.selectDistinct(properties)
: Query.select(properties).withQueryTemplate(PermaSql.replacePlaceholders(queryTemplate))); : Query.select(properties).withQueryTemplate(PermaSql.replacePlaceholders(queryTemplate)));

@ -32,7 +32,7 @@ abstract public class RemoteModel extends AbstractModel {
super(); super();
} }
RemoteModel(TodorooCursor<? extends AbstractModel> cursor) { RemoteModel(TodorooCursor cursor) {
super(cursor); super(cursor);
} }

@ -234,7 +234,7 @@ public class Task extends RemoteModel {
} }
@Ignore @Ignore
public Task(TodorooCursor<Task> cursor) { public Task(TodorooCursor cursor) {
super(cursor); super(cursor);
} }

@ -49,7 +49,7 @@ class AstridOrderedListFragmentHelper {
updater.initialize(list, filter); updater.initialize(list, filter);
} }
TaskAdapter createTaskAdapter(Context context, TodorooCursor<Task> cursor) { TaskAdapter createTaskAdapter(Context context, TodorooCursor cursor) {
taskAdapter = new DraggableTaskAdapter(context, cursor); taskAdapter = new DraggableTaskAdapter(context, cursor);
taskAdapter.setOnCompletedTaskListener(this::setCompletedForItemAndSubtasks); taskAdapter.setOnCompletedTaskListener(this::setCompletedForItemAndSubtasks);
@ -152,7 +152,7 @@ class AstridOrderedListFragmentHelper {
if(chained.size() > 0) { if(chained.size() > 0) {
// move recurring items to item parent // move recurring items to item parent
TodorooCursor<Task> recurring = taskDao.query(Query.select(Task.UUID, Task.RECURRENCE).where( TodorooCursor recurring = taskDao.query(Query.select(Task.UUID, Task.RECURRENCE).where(
Criterion.and(Task.UUID.in(chained.toArray(new String[chained.size()])), Criterion.and(Task.UUID.in(chained.toArray(new String[chained.size()])),
Task.RECURRENCE.isNotNull(), Functions.length(Task.RECURRENCE).gt(0)))); Task.RECURRENCE.isNotNull(), Functions.length(Task.RECURRENCE).gt(0))));
try { try {

@ -120,7 +120,7 @@ public class SubtasksFilterUpdater {
sql = sql.replace( sql = sql.replace(
TaskDao.TaskCriteria.activeAndVisible().toString(), TaskDao.TaskCriteria.activeAndVisible().toString(),
TaskDao.TaskCriteria.notDeleted().toString()); TaskDao.TaskCriteria.notDeleted().toString());
TodorooCursor<Task> tasks = taskDao.fetchFiltered(sql, Task.UUID); TodorooCursor tasks = taskDao.fetchFiltered(sql, Task.UUID);
try { try {
for (tasks.moveToFirst(); !tasks.isAfterLast(); tasks.moveToNext()) { for (tasks.moveToFirst(); !tasks.isAfterLast(); tasks.moveToNext()) {
String id = tasks.getString(0); String id = tasks.getString(0);

@ -171,7 +171,7 @@ public class SubtasksHelper {
private static <A, B> HashMap<A, B> getIdMap(TaskDao taskDao, Iterable<A> keys, Property<A> keyProperty, Property<B> valueProperty) { private static <A, B> HashMap<A, B> getIdMap(TaskDao taskDao, Iterable<A> keys, Property<A> keyProperty, Property<B> valueProperty) {
HashMap<A, B> map = new HashMap<>(); HashMap<A, B> map = new HashMap<>();
TodorooCursor<Task> tasks = taskDao.query(Query.select(keyProperty, valueProperty).where(keyProperty.in(keys))); TodorooCursor tasks = taskDao.query(Query.select(keyProperty, valueProperty).where(keyProperty.in(keys)));
try { try {
for (tasks.moveToFirst(); !tasks.isAfterLast(); tasks.moveToNext()) { for (tasks.moveToFirst(); !tasks.isAfterLast(); tasks.moveToNext()) {
A key = tasks.get(keyProperty); A key = tasks.get(keyProperty);

@ -102,7 +102,7 @@ public class SubtasksListFragment extends TaskListFragment {
} }
@Override @Override
protected TaskAdapter createTaskAdapter(TodorooCursor<Task> cursor) { protected TaskAdapter createTaskAdapter(TodorooCursor cursor) {
return helper.createTaskAdapter(theme.wrap(context), cursor); return helper.createTaskAdapter(theme.wrap(context), cursor);
} }

@ -73,7 +73,7 @@ public class SubtasksTagListFragment extends TagListFragment {
} }
@Override @Override
protected TaskAdapter createTaskAdapter(TodorooCursor<Task> cursor) { protected TaskAdapter createTaskAdapter(TodorooCursor cursor) {
return helper.createTaskAdapter(theme.wrap(context), cursor); return helper.createTaskAdapter(theme.wrap(context), cursor);
} }

@ -36,7 +36,7 @@ public class TaskListDataProvider {
this.preferences = preferences; this.preferences = preferences;
} }
public TodorooCursor<Task> constructCursor(Filter filter, Property<?>[] properties) { public TodorooCursor constructCursor(Filter filter, Property<?>[] properties) {
Criterion tagsJoinCriterion = Criterion.and( Criterion tagsJoinCriterion = Criterion.and(
Task.ID.eq(Field.field(TAGS_METADATA_JOIN + ".task"))); Task.ID.eq(Field.field(TAGS_METADATA_JOIN + ".task")));

@ -108,7 +108,7 @@ public class TaskListRecyclerAdapter extends RecyclerView.Adapter<ViewHolder> im
public void onBindViewHolder(ViewHolder holder, int position) { public void onBindViewHolder(ViewHolder holder, int position) {
Cursor cursor = adapter.getCursor(); Cursor cursor = adapter.getCursor();
cursor.moveToPosition(position); cursor.moveToPosition(position);
holder.bindView((TodorooCursor<Task>) cursor); holder.bindView((TodorooCursor) cursor);
holder.setMoving(false); holder.setMoving(false);
holder.setIndent(adapter.getIndent(holder.task)); holder.setIndent(adapter.getIndent(holder.task));
} }

@ -194,7 +194,7 @@ class ViewHolder extends MultiSelectorBindingHolder {
return indent > 0; return indent > 0;
} }
void bindView(TodorooCursor<Task> cursor) { void bindView(TodorooCursor cursor) {
tagsString = cursor.get(TaskAdapter.TAGS); tagsString = cursor.get(TaskAdapter.TAGS);
hasFiles = cursor.get(TaskAdapter.FILE_ID_PROPERTY) > 0; hasFiles = cursor.get(TaskAdapter.FILE_ID_PROPERTY) > 0;
hasNotes = cursor.get(TaskAdapter.HAS_NOTES_PROPERTY) > 0; hasNotes = cursor.get(TaskAdapter.HAS_NOTES_PROPERTY) > 0;

@ -55,7 +55,7 @@ class ScrollableViewsFactory implements RemoteViewsService.RemoteViewsFactory {
private int textColorPrimary; private int textColorPrimary;
private int textColorSecondary; private int textColorSecondary;
private TodorooCursor<Task> cursor; private TodorooCursor cursor;
ScrollableViewsFactory( ScrollableViewsFactory(
SubtasksHelper subtasksHelper, SubtasksHelper subtasksHelper,
@ -199,7 +199,7 @@ class ScrollableViewsFactory implements RemoteViewsService.RemoteViewsFactory {
return null; return null;
} }
private TodorooCursor<Task> getCursor() { private TodorooCursor getCursor() {
String query = getQuery(); String query = getQuery();
return taskDao.fetchFiltered(query, Task.ID, Task.TITLE, Task.DUE_DATE, Task.COMPLETION_DATE, Task.IMPORTANCE, Task.RECURRENCE); return taskDao.fetchFiltered(query, Task.ID, Task.TITLE, Task.DUE_DATE, Task.COMPLETION_DATE, Task.IMPORTANCE, Task.RECURRENCE);
} }

Loading…
Cancel
Save