Hide readPropertiesFromCursor

pull/189/head
Alex Baker 11 years ago
parent 1274f69d38
commit 34511b83ff

@ -76,6 +76,13 @@ public abstract class AbstractModel implements Parcelable, Cloneable {
/** Transitory Metadata (not saved in database) */ /** Transitory Metadata (not saved in database) */
protected HashMap<String, Object> transitoryData = null; protected HashMap<String, Object> transitoryData = null;
public AbstractModel() {
}
public AbstractModel(TodorooCursor<? extends AbstractModel> cursor) {
readPropertiesFromCursor(cursor);
}
/** Get database-read values for this object */ /** Get database-read values for this object */
public ContentValues getDatabaseValues() { public ContentValues getDatabaseValues() {
return values; return values;
@ -165,12 +172,10 @@ public abstract class AbstractModel implements Parcelable, Cloneable {
return clone; return clone;
} }
// --- data retrieval
/** /**
* Reads all properties from the supplied cursor and store * Reads all properties from the supplied cursor and store
*/ */
public synchronized void readPropertiesFromCursor(TodorooCursor<? extends AbstractModel> cursor) { private void readPropertiesFromCursor(TodorooCursor<? extends AbstractModel> cursor) {
if (values == null) { if (values == null) {
values = new ContentValues(); values = new ContentValues();
} }

@ -106,12 +106,7 @@ public class Metadata extends AbstractModel {
} }
public Metadata(TodorooCursor<Metadata> cursor) { public Metadata(TodorooCursor<Metadata> cursor) {
this(); super(cursor);
readPropertiesFromCursor(cursor);
}
public void readFromCursor(TodorooCursor<Metadata> cursor) {
super.readPropertiesFromCursor(cursor);
} }
@Override @Override

@ -11,6 +11,7 @@ import android.text.TextUtils;
import com.todoroo.andlib.data.AbstractModel; import com.todoroo.andlib.data.AbstractModel;
import com.todoroo.andlib.data.Property.StringProperty; import com.todoroo.andlib.data.Property.StringProperty;
import com.todoroo.andlib.data.TodorooCursor;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
@ -27,6 +28,14 @@ import java.io.File;
*/ */
abstract public class RemoteModel extends AbstractModel { abstract public class RemoteModel extends AbstractModel {
public RemoteModel() {
super();
}
public RemoteModel(TodorooCursor<? extends AbstractModel> cursor) {
super(cursor);
}
private static final Logger log = LoggerFactory.getLogger(RemoteModel.class); private static final Logger log = LoggerFactory.getLogger(RemoteModel.class);
/** remote id property common to all remote models */ /** remote id property common to all remote models */

@ -80,12 +80,7 @@ public class StoreObject extends AbstractModel {
} }
public StoreObject(TodorooCursor<StoreObject> cursor) { public StoreObject(TodorooCursor<StoreObject> cursor) {
this(); super(cursor);
readPropertiesFromCursor(cursor);
}
public void readFromCursor(TodorooCursor<StoreObject> cursor) {
super.readPropertiesFromCursor(cursor);
} }
@Override @Override

@ -83,12 +83,7 @@ public final class TagData extends RemoteModel {
} }
public TagData(TodorooCursor<TagData> cursor) { public TagData(TodorooCursor<TagData> cursor) {
this(); super(cursor);
readPropertiesFromCursor(cursor);
}
public void readFromCursor(TodorooCursor<TagData> cursor) {
super.readPropertiesFromCursor(cursor);
} }
@Override @Override

@ -219,12 +219,7 @@ public class Task extends RemoteModel {
} }
public Task(TodorooCursor<Task> cursor) { public Task(TodorooCursor<Task> cursor) {
this(); super(cursor);
readPropertiesFromCursor(cursor);
}
public void readFromCursor(TodorooCursor<Task> cursor) {
super.readPropertiesFromCursor(cursor);
} }
@Override @Override

@ -123,12 +123,7 @@ public final class TaskAttachment extends RemoteModel {
} }
public TaskAttachment(TodorooCursor<TaskAttachment> cursor) { public TaskAttachment(TodorooCursor<TaskAttachment> cursor) {
this(); super(cursor);
readPropertiesFromCursor(cursor);
}
public void readFromCursor(TodorooCursor<TaskAttachment> cursor) {
super.readPropertiesFromCursor(cursor);
} }
@Override @Override

@ -79,8 +79,7 @@ public final class TaskListMetadata extends RemoteModel {
} }
public TaskListMetadata(TodorooCursor<TaskListMetadata> cursor) { public TaskListMetadata(TodorooCursor<TaskListMetadata> cursor) {
this(); super(cursor);
readPropertiesFromCursor(cursor);
} }
@Override @Override

@ -63,8 +63,7 @@ public class UserActivity extends RemoteModel {
public static final String ACTION_TASK_COMMENT = "task_comment"; public static final String ACTION_TASK_COMMENT = "task_comment";
public UserActivity(TodorooCursor<UserActivity> cursor) { public UserActivity(TodorooCursor<UserActivity> cursor) {
this(); super(cursor);
readPropertiesFromCursor(cursor);
} }
// --- helpers // --- helpers

@ -75,7 +75,7 @@ public class MetadataDaoTests extends DatabaseTestCase {
Query.select(KEYS)); Query.select(KEYS));
assertEquals(1, cursor.getCount()); assertEquals(1, cursor.getCount());
cursor.moveToFirst(); cursor.moveToFirst();
metadata.readFromCursor(cursor); metadata = new Metadata(cursor);
assertEquals("happy", metadata.getKey()); assertEquals("happy", metadata.getKey());
cursor.close(); cursor.close();
} }
@ -105,10 +105,10 @@ public class MetadataDaoTests extends DatabaseTestCase {
Query.select(KEYS).where(MetadataCriteria.byTask(1))); Query.select(KEYS).where(MetadataCriteria.byTask(1)));
assertEquals(2, cursor.getCount()); assertEquals(2, cursor.getCount());
cursor.moveToFirst(); cursor.moveToFirst();
metadata.readFromCursor(cursor); metadata = new Metadata(cursor);
assertEquals("with1", metadata.getKey()); assertEquals("with1", metadata.getKey());
cursor.moveToNext(); cursor.moveToNext();
metadata.readFromCursor(cursor); metadata = new Metadata(cursor);
assertEquals("with1", metadata.getKey()); assertEquals("with1", metadata.getKey());
cursor.close(); cursor.close();
@ -185,7 +185,7 @@ public class MetadataDaoTests extends DatabaseTestCase {
cursor = metadataDao.fetchDangling(KEYS); cursor = metadataDao.fetchDangling(KEYS);
assertEquals(1, cursor.getCount()); assertEquals(1, cursor.getCount());
cursor.moveToFirst(); cursor.moveToFirst();
metadata.readFromCursor(cursor); metadata = new Metadata(cursor);
assertEquals("with2", metadata.getKey()); assertEquals("with2", metadata.getKey());
cursor.close(); cursor.close();
} }

@ -144,7 +144,7 @@ public class NewRepeatTests extends DatabaseTestCase {
} }
assertEquals(1, cursor.getCount()); assertEquals(1, cursor.getCount());
cursor.moveToFirst(); cursor.moveToFirst();
t.readFromCursor(cursor); t = new Task(cursor);
assertEquals(title, t.getTitle()); assertEquals(title, t.getTitle());
assertFalse(t.isCompleted()); assertFalse(t.isCompleted());

@ -125,14 +125,14 @@ public class TagViewFragment extends TaskListFragment {
} }
try { try {
tagData = new TagData();
if(cursor.getCount() == 0) { if(cursor.getCount() == 0) {
tagData = new TagData();
tagData.setName(tag); tagData.setName(tag);
tagData.setUUID(uuid); tagData.setUUID(uuid);
tagDataService.save(tagData); tagDataService.save(tagData);
} else { } else {
cursor.moveToFirst(); cursor.moveToFirst();
tagData.readFromCursor(cursor); tagData = new TagData(cursor);
} }
} finally { } finally {
cursor.close(); cursor.close();

@ -360,12 +360,11 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
viewHolder.hasNotes = cursor.get(HAS_NOTES_PROPERTY) > 0; viewHolder.hasNotes = cursor.get(HAS_NOTES_PROPERTY) > 0;
} }
Task task = viewHolder.task; // TODO: see if this is a performance issue
task.clear(); viewHolder.task = new Task(cursor);
task.readFromCursor(cursor);
setFieldContentsAndVisibility(view); setFieldContentsAndVisibility(view);
setTaskAppearance(viewHolder, task); setTaskAppearance(viewHolder, viewHolder.task);
} }
public String getItemUuid(int position) { public String getItemUuid(int position) {
@ -686,11 +685,8 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
try { try {
Random random = new Random(); Random random = new Random();
Task task = new Task();
for(fetchCursor.moveToFirst(); !fetchCursor.isAfterLast(); fetchCursor.moveToNext()) { for(fetchCursor.moveToFirst(); !fetchCursor.isAfterLast(); fetchCursor.moveToNext()) {
task.clear(); Task task = new Task(fetchCursor);
task.readFromCursor(fetchCursor);
if(task.isCompleted()) { if(task.isCompleted()) {
continue; continue;
} }

@ -128,9 +128,8 @@ public class AlarmService {
public void scheduleAllAlarms() { public void scheduleAllAlarms() {
TodorooCursor<Metadata> cursor = getActiveAlarms(); TodorooCursor<Metadata> cursor = getActiveAlarms();
try { try {
Metadata alarm = new Metadata();
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
alarm.readFromCursor(cursor); Metadata alarm = new Metadata(cursor);
scheduleAlarm(alarm); scheduleAlarm(alarm);
} }
} catch (Exception e) { } catch (Exception e) {
@ -149,9 +148,8 @@ public class AlarmService {
public void scheduleAlarms(long taskId) { public void scheduleAlarms(long taskId) {
TodorooCursor<Metadata> cursor = getActiveAlarmsForTask(taskId); TodorooCursor<Metadata> cursor = getActiveAlarmsForTask(taskId);
try { try {
Metadata alarm = new Metadata();
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
alarm.readFromCursor(cursor); Metadata alarm = new Metadata(cursor);
scheduleAlarm(alarm); scheduleAlarm(alarm);
} }
} catch (Exception e) { } catch (Exception e) {

@ -49,10 +49,9 @@ public class AlarmTaskRepeatListener extends InjectingBroadcastReceiver {
return; return;
} }
Metadata metadata = new Metadata();
LinkedHashSet<Long> alarms = new LinkedHashSet<>(cursor.getCount()); LinkedHashSet<Long> alarms = new LinkedHashSet<>(cursor.getCount());
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
metadata.readFromCursor(cursor); Metadata metadata = new Metadata(cursor);
alarms.add(metadata.getValue(AlarmFields.TIME) + (newDueDate - oldDueDate)); alarms.add(metadata.getValue(AlarmFields.TIME) + (newDueDate - oldDueDate));
} }
alarmService.synchronizeAlarms(taskId, alarms); alarmService.synchronizeAlarms(taskId, alarms);

@ -176,11 +176,10 @@ public class TasksXmlExporter {
TagData.PROPERTIES).orderBy(Order.asc(TagData.ID))); TagData.PROPERTIES).orderBy(Order.asc(TagData.ID)));
try { try {
TagData tag = new TagData();
int length = cursor.getCount(); int length = cursor.getCount();
for(int i = 0; i < length; i++) { for(int i = 0; i < length; i++) {
cursor.moveToNext(); cursor.moveToNext();
tag.readFromCursor(cursor); TagData tag = new TagData(cursor);
//TODO setProgress(i, length); //TODO setProgress(i, length);
@ -199,11 +198,10 @@ public class TasksXmlExporter {
cursor = taskService.query(Query.select( cursor = taskService.query(Query.select(
Task.PROPERTIES).orderBy(Order.asc(Task.ID))); Task.PROPERTIES).orderBy(Order.asc(Task.ID)));
try { try {
Task task = new Task();
int length = cursor.getCount(); int length = cursor.getCount();
for(int i = 0; i < length; i++) { for(int i = 0; i < length; i++) {
cursor.moveToNext(); cursor.moveToNext();
task.readFromCursor(cursor); Task task = new Task(cursor);
setProgress(i, length); setProgress(i, length);
@ -222,9 +220,8 @@ public class TasksXmlExporter {
TodorooCursor<Metadata> cursor = metadataService.query(Query.select( TodorooCursor<Metadata> cursor = metadataService.query(Query.select(
Metadata.PROPERTIES).where(MetadataCriteria.byTask(task.getId()))); Metadata.PROPERTIES).where(MetadataCriteria.byTask(task.getId())));
try { try {
Metadata metadata = new Metadata();
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
metadata.readFromCursor(cursor); Metadata metadata = new Metadata(cursor);
xml.startTag(null, BackupConstants.METADATA_TAG); xml.startTag(null, BackupConstants.METADATA_TAG);
serializeModel(metadata, Metadata.PROPERTIES, Metadata.ID, Metadata.TASK); serializeModel(metadata, Metadata.PROPERTIES, Metadata.ID, Metadata.TASK);

@ -88,9 +88,8 @@ public final class CustomFilterExposer extends InjectingBroadcastReceiver implem
} }
if (cursor != null) { if (cursor != null) {
StoreObject savedFilter = new StoreObject();
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
savedFilter.readFromCursor(cursor); StoreObject savedFilter = new StoreObject(cursor);
Filter f = SavedFilter.load(savedFilter); Filter f = SavedFilter.load(savedFilter);
Intent deleteIntent = new Intent(context, DeleteActivity.class); Intent deleteIntent = new Intent(context, DeleteActivity.class);

@ -147,11 +147,10 @@ public class OldTaskPreferences extends TodorooPreferenceActivity {
TodorooCursor<Task> cursor = taskService.query(Query.select(Task.ID, Task.CALENDAR_URI).where( TodorooCursor<Task> cursor = taskService.query(Query.select(Task.ID, Task.CALENDAR_URI).where(
Criterion.and(Task.COMPLETION_DATE.gt(0), Task.CALENDAR_URI.isNotNull()))); Criterion.and(Task.COMPLETION_DATE.gt(0), Task.CALENDAR_URI.isNotNull())));
try { try {
Task task = new Task();
int length = cursor.getCount(); int length = cursor.getCount();
for(int i = 0; i < length; i++) { for(int i = 0; i < length; i++) {
cursor.moveToNext(); cursor.moveToNext();
task.readFromCursor(cursor); Task task = new Task(cursor);
gcalHelper.deleteTaskEvent(task); gcalHelper.deleteTaskEvent(task);
} }
} finally { } finally {
@ -186,11 +185,10 @@ public class OldTaskPreferences extends TodorooPreferenceActivity {
TodorooCursor<Task> cursor = taskService.query(Query.select(Task.ID, Task.TITLE, Task.CALENDAR_URI).where( TodorooCursor<Task> cursor = taskService.query(Query.select(Task.ID, Task.TITLE, Task.CALENDAR_URI).where(
Criterion.and(Task.DELETION_DATE.gt(0), Task.CALENDAR_URI.isNotNull()))); Criterion.and(Task.DELETION_DATE.gt(0), Task.CALENDAR_URI.isNotNull())));
try { try {
Task task = new Task();
int length = cursor.getCount(); int length = cursor.getCount();
for(int i = 0; i < length; i++) { for(int i = 0; i < length; i++) {
cursor.moveToNext(); cursor.moveToNext();
task.readFromCursor(cursor); Task task = new Task(cursor);
gcalHelper.deleteTaskEvent(task); gcalHelper.deleteTaskEvent(task);
} }
} finally { } finally {
@ -221,11 +219,10 @@ public class OldTaskPreferences extends TodorooPreferenceActivity {
TodorooCursor<Task> cursor = taskService.query(Query.select(Task.ID, Task.CALENDAR_URI).where( TodorooCursor<Task> cursor = taskService.query(Query.select(Task.ID, Task.CALENDAR_URI).where(
Criterion.and(Task.COMPLETION_DATE.gt(0), Task.CALENDAR_URI.isNotNull()))); Criterion.and(Task.COMPLETION_DATE.gt(0), Task.CALENDAR_URI.isNotNull())));
try { try {
Task task = new Task();
int length = cursor.getCount(); int length = cursor.getCount();
for(int i = 0; i < length; i++) { for(int i = 0; i < length; i++) {
cursor.moveToNext(); cursor.moveToNext();
task.readFromCursor(cursor); Task task = new Task(cursor);
if (gcalHelper.deleteTaskEvent(task)) { if (gcalHelper.deleteTaskEvent(task)) {
deletedEventCount++; deletedEventCount++;
} }
@ -263,11 +260,10 @@ public class OldTaskPreferences extends TodorooPreferenceActivity {
TodorooCursor<Task> cursor = taskService.query(Query.select(Task.ID, Task.CALENDAR_URI).where( TodorooCursor<Task> cursor = taskService.query(Query.select(Task.ID, Task.CALENDAR_URI).where(
Task.CALENDAR_URI.isNotNull())); Task.CALENDAR_URI.isNotNull()));
try { try {
Task task = new Task();
int length = cursor.getCount(); int length = cursor.getCount();
for(int i = 0; i < length; i++) { for(int i = 0; i < length; i++) {
cursor.moveToNext(); cursor.moveToNext();
task.readFromCursor(cursor); Task task = new Task(cursor);
if (gcalHelper.deleteTaskEvent(task)) { if (gcalHelper.deleteTaskEvent(task)) {
deletedEventCount++; deletedEventCount++;
} }

@ -57,12 +57,14 @@ public class SavedFilter {
} }
// if filter of this name exists, edit it // if filter of this name exists, edit it
StoreObject storeObject = new StoreObject(); StoreObject storeObject;
TodorooCursor<StoreObject> cursor = dao.query(Query.select(StoreObject.ID).where(NAME.eq(title))); TodorooCursor<StoreObject> cursor = dao.query(Query.select(StoreObject.ID).where(NAME.eq(title)));
try { try {
if(!cursor.isAfterLast()) { if (cursor.isAfterLast()) {
storeObject = new StoreObject();
} else {
cursor.moveToNext(); cursor.moveToNext();
storeObject.readFromCursor(cursor); storeObject = new StoreObject(cursor);
} }
} finally { } finally {
cursor.close(); cursor.close();

@ -84,13 +84,12 @@ public class MetadataDao extends DatabaseDao<Metadata> {
newMetadataValues.add(metadatum.getMergedValues()); newMetadataValues.add(metadatum.getMergedValues());
} }
Metadata item = new Metadata();
TodorooCursor<Metadata> cursor = query(Query.select(Metadata.PROPERTIES).where(Criterion.and(MetadataCriteria.byTask(taskId), TodorooCursor<Metadata> cursor = query(Query.select(Metadata.PROPERTIES).where(Criterion.and(MetadataCriteria.byTask(taskId),
metadataCriteria))); metadataCriteria)));
try { try {
// try to find matches within our metadata list // try to find matches within our metadata list
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
item.readFromCursor(cursor); Metadata item = new Metadata(cursor);
long id = item.getId(); long id = item.getId();
// clear item id when matching with incoming values // clear item id when matching with incoming values
@ -110,7 +109,7 @@ public class MetadataDao extends DatabaseDao<Metadata> {
// everything that remains shall be written // everything that remains shall be written
for(ContentValues values : newMetadataValues) { for(ContentValues values : newMetadataValues) {
item.clear(); Metadata item = new Metadata();
item.mergeWith(values); item.mergeWith(values);
persist(item); persist(item);
} }

@ -258,10 +258,8 @@ public class TaskDao extends RemoteModelDao<Task> {
Task.UUID.eq(uuid))); Task.UUID.eq(uuid)));
try { try {
if (tasksWithUUID.getCount() > 0) { if (tasksWithUUID.getCount() > 0) {
Task curr = new Task(); for (tasksWithUUID.moveToFirst(); !tasksWithUUID.isAfterLast(); tasksWithUUID.moveToNext()) {
for (tasksWithUUID.moveToFirst(); Task curr = new Task(tasksWithUUID);
!tasksWithUUID.isAfterLast(); tasksWithUUID.moveToNext()) {
curr.readFromCursor(tasksWithUUID);
if (curr.getId() == item.getId()) { if (curr.getId() == item.getId()) {
continue; continue;
} }

@ -96,8 +96,7 @@ public class FilesControlSet extends PopupControlSet {
try { try {
files.clear(); files.clear();
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
TaskAttachment attachment = new TaskAttachment(); TaskAttachment attachment = new TaskAttachment(cursor);
attachment.readFromCursor(cursor);
files.add(attachment); files.add(attachment);
} }
} finally { } finally {

@ -161,9 +161,8 @@ public class GtasksTaskListUpdater extends OrderedMetadataListUpdater<StoreObjec
.orderBy(Order.asc(Functions.cast(GtasksMetadata.GTASKS_ORDER, "INTEGER")))); //$NON-NLS-1$ .orderBy(Order.asc(Functions.cast(GtasksMetadata.GTASKS_ORDER, "INTEGER")))); //$NON-NLS-1$
try { try {
if (metadata.getCount() > 0) { if (metadata.getCount() > 0) {
Metadata curr = new Metadata();
for (metadata.moveToFirst(); !metadata.isAfterLast(); metadata.moveToNext()) { for (metadata.moveToFirst(); !metadata.isAfterLast(); metadata.moveToNext()) {
curr.readFromCursor(metadata); Metadata curr = new Metadata(metadata);
if(alreadyChecked.contains(curr.getTask())) { if(alreadyChecked.contains(curr.getTask())) {
continue; continue;
} }

@ -161,9 +161,8 @@ public class GtasksSyncV2Provider extends SyncV2Provider {
private synchronized void pushTasks(TodorooCursor<Task> queued, GtasksInvoker invoker) { private synchronized void pushTasks(TodorooCursor<Task> queued, GtasksInvoker invoker) {
try { try {
Task task = new Task();
for (queued.moveToFirst(); !queued.isAfterLast(); queued.moveToNext()) { for (queued.moveToFirst(); !queued.isAfterLast(); queued.moveToNext()) {
task.readFromCursor(queued); Task task = new Task(queued);
try { try {
gtasksSyncService.pushTaskOnSave(task, task.getMergedValues(), invoker); gtasksSyncService.pushTaskOnSave(task, task.getMergedValues(), invoker);
} catch (IOException e) { } catch (IOException e) {

@ -283,9 +283,8 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene
MetadataCriteria.byTaskAndwithKey(task.getId(), MetadataCriteria.byTaskAndwithKey(task.getId(),
NoteMetadata.METADATA_KEY))); NoteMetadata.METADATA_KEY)));
try { try {
Metadata metadata = new Metadata();
for(notes.moveToFirst(); !notes.isAfterLast(); notes.moveToNext()) { for(notes.moveToFirst(); !notes.isAfterLast(); notes.moveToNext()) {
metadata.readFromCursor(notes); Metadata metadata = new Metadata(notes);
items.add(NoteOrUpdate.fromMetadata(metadata)); items.add(NoteOrUpdate.fromMetadata(metadata));
} }
} finally { } finally {

@ -88,10 +88,9 @@ public class NotesDetailExposer extends InjectingBroadcastReceiver {
Query.select(Metadata.PROPERTIES).where( Query.select(Metadata.PROPERTIES).where(
MetadataCriteria.byTaskAndwithKey(task.getId(), MetadataCriteria.byTaskAndwithKey(task.getId(),
NoteMetadata.METADATA_KEY)).orderBy(Order.asc(Metadata.CREATION_DATE))); NoteMetadata.METADATA_KEY)).orderBy(Order.asc(Metadata.CREATION_DATE)));
Metadata metadata = new Metadata();
try { try {
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
metadata.readFromCursor(cursor); Metadata metadata = new Metadata(cursor);
if(notesBuilder.length() > 0) { if(notesBuilder.length() > 0) {
notesBuilder.append("\n"); notesBuilder.append("\n");

@ -123,10 +123,9 @@ public final class ReminderService {
public void scheduleAllAlarms(TaskDao taskDao) { public void scheduleAllAlarms(TaskDao taskDao) {
TodorooCursor<Task> cursor = getTasksWithReminders(taskDao, NOTIFICATION_PROPERTIES); TodorooCursor<Task> cursor = getTasksWithReminders(taskDao, NOTIFICATION_PROPERTIES);
try { try {
Task task = new Task();
now = DateUtilities.now(); // Before mass scheduling, initialize now variable now = DateUtilities.now(); // Before mass scheduling, initialize now variable
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
task.readFromCursor(cursor); Task task = new Task(cursor);
scheduleAlarm(task, null); scheduleAlarm(task, null);
} }
} catch (Exception e) { } catch (Exception e) {

@ -113,13 +113,12 @@ public class MetadataService {
newMetadataValues.add(values); newMetadataValues.add(values);
} }
Metadata item = new Metadata();
TodorooCursor<Metadata> cursor = metadataDao.query(Query.select(Metadata.PROPERTIES).where(Criterion.and(MetadataCriteria.byTask(taskId), TodorooCursor<Metadata> cursor = metadataDao.query(Query.select(Metadata.PROPERTIES).where(Criterion.and(MetadataCriteria.byTask(taskId),
metadataCriterion))); metadataCriterion)));
try { try {
// try to find matches within our metadata list // try to find matches within our metadata list
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
item.readFromCursor(cursor); Metadata item = new Metadata(cursor);
long id = item.getId(); long id = item.getId();
// clear item id when matching with incoming values // clear item id when matching with incoming values
@ -146,7 +145,7 @@ public class MetadataService {
// everything that remains shall be written // everything that remains shall be written
for(ContentValues values : newMetadataValues) { for(ContentValues values : newMetadataValues) {
item.clear(); Metadata item = new Metadata();
item.setCreationDate(DateUtilities.now()); item.setCreationDate(DateUtilities.now());
item.mergeWith(values); item.mergeWith(values);
metadataDao.persist(item); metadataDao.persist(item);

@ -54,12 +54,11 @@ public class TaskDuplicator {
Query.select(Metadata.PROPERTIES).where(MetadataDao.MetadataCriteria.byTask(task.getId()))); Query.select(Metadata.PROPERTIES).where(MetadataDao.MetadataCriteria.byTask(task.getId())));
try { try {
if(cursor.getCount() > 0) { if(cursor.getCount() > 0) {
Metadata metadata = new Metadata();
newTask.putTransitory(SyncFlags.GTASKS_SUPPRESS_SYNC, true); newTask.putTransitory(SyncFlags.GTASKS_SUPPRESS_SYNC, true);
taskService.save(newTask); taskService.save(newTask);
long newId = newTask.getId(); long newId = newTask.getId();
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
metadata.readFromCursor(cursor); Metadata metadata = new Metadata(cursor);
if(!metadata.containsNonNullValue(Metadata.KEY)) { if(!metadata.containsNonNullValue(Metadata.KEY)) {
continue; continue;

@ -247,11 +247,9 @@ public class AstridOrderedListFragmentHelper<LIST> implements OrderedListFragmen
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 {
Task t = new Task();
boolean madeChanges = false; boolean madeChanges = false;
for (recurring.moveToFirst(); !recurring.isAfterLast(); recurring.moveToNext()) { for (recurring.moveToFirst(); !recurring.isAfterLast(); recurring.moveToNext()) {
t.clear(); Task t = new Task(recurring);
t.readFromCursor(recurring);
if (!TextUtils.isEmpty(t.getRecurrence())) { if (!TextUtils.isEmpty(t.getRecurrence())) {
updater.moveToParentOf(t.getUuid(), itemId); updater.moveToParentOf(t.getUuid(), itemId);
madeChanges = true; madeChanges = true;

@ -240,10 +240,9 @@ public final class TagService {
TodorooCursor<Metadata> tags = getTags(taskId); TodorooCursor<Metadata> tags = getTags(taskId);
try { try {
int length = tags.getCount(); int length = tags.getCount();
Metadata metadata = new Metadata();
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
tags.moveToNext(); tags.moveToNext();
metadata.readFromCursor(tags); Metadata metadata = new Metadata(tags);
tagBuilder.append(metadata.getValue(TaskToTagMetadata.TAG_NAME)); tagBuilder.append(metadata.getValue(TaskToTagMetadata.TAG_NAME));
if (i < length - 1) { if (i < length - 1) {
tagBuilder.append(separator); tagBuilder.append(separator);
@ -264,9 +263,8 @@ public final class TagService {
TagData.DELETION_DATE.eq(0), TagData.DELETION_DATE.eq(0),
TagData.NAME.isNotNull())).orderBy(Order.asc(Functions.upper(TagData.NAME)))); TagData.NAME.isNotNull())).orderBy(Order.asc(Functions.upper(TagData.NAME))));
try { try {
TagData tagData = new TagData();
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
tagData.readFromCursor(cursor); TagData tagData = new TagData(cursor);
Tag tag = new Tag(tagData); Tag tag = new Tag(tagData);
if(TextUtils.isEmpty(tag.tag)) { if(TextUtils.isEmpty(tag.tag)) {
continue; continue;

@ -118,11 +118,10 @@ public class WidgetUpdateService extends InjectingService {
database.openForReading(); database.openForReading();
cursor = taskService.fetchFiltered(query, null, Task.ID, Task.TITLE, Task.DUE_DATE, Task.COMPLETION_DATE); cursor = taskService.fetchFiltered(query, null, Task.ID, Task.TITLE, Task.DUE_DATE, Task.COMPLETION_DATE);
Task task = new Task();
int i; int i;
for (i = 0; i < cursor.getCount() && i < numberOfTasks; i++) { for (i = 0; i < cursor.getCount() && i < numberOfTasks; i++) {
cursor.moveToPosition(i); cursor.moveToPosition(i);
task.readFromCursor(cursor); Task task = new Task(cursor);
String textContent; String textContent;
Resources r = context.getResources(); Resources r = context.getResources();

@ -41,9 +41,8 @@ public class RefreshScheduler {
public void scheduleAllAlarms() { public void scheduleAllAlarms() {
TodorooCursor<Task> cursor = getTasks(); TodorooCursor<Task> cursor = getTasks();
try { try {
Task task = new Task();
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
task.readFromCursor(cursor); Task task = new Task(cursor);
scheduleRefresh(task); scheduleRefresh(task);
} }
} finally { } finally {

Loading…
Cancel
Save