mirror of https://github.com/tasks/tasks
Merge remote-tracking branch 'upstream/master' into 130221_sb_gtasks_new_sync
commit
8d298dda58
@ -0,0 +1,61 @@
|
||||
package com.todoroo.astrid.actfm.sync.messages;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.todoroo.andlib.data.AbstractModel;
|
||||
import com.todoroo.andlib.data.Property;
|
||||
import com.todoroo.andlib.data.Property.LongProperty;
|
||||
import com.todoroo.andlib.data.TodorooCursor;
|
||||
import com.todoroo.andlib.sql.Query;
|
||||
import com.todoroo.andlib.utility.AndroidUtilities;
|
||||
import com.todoroo.andlib.utility.DateUtilities;
|
||||
import com.todoroo.astrid.dao.OutstandingEntryDao;
|
||||
import com.todoroo.astrid.dao.RemoteModelDao;
|
||||
import com.todoroo.astrid.data.OutstandingEntry;
|
||||
import com.todoroo.astrid.data.RemoteModel;
|
||||
|
||||
@SuppressWarnings("nls")
|
||||
public class ConstructOutstandingTableFromMasterTable<TYPE extends RemoteModel, OE extends OutstandingEntry<TYPE>> {
|
||||
|
||||
private final String table;
|
||||
private final RemoteModelDao<TYPE> dao;
|
||||
private final OutstandingEntryDao<OE> outstandingDao;
|
||||
private final LongProperty createdAtProperty;
|
||||
|
||||
public ConstructOutstandingTableFromMasterTable(String table, RemoteModelDao<TYPE> dao,
|
||||
OutstandingEntryDao<OE> outstandingDao, LongProperty createdAtProperty) {
|
||||
this.table = table;
|
||||
this.dao = dao;
|
||||
this.outstandingDao = outstandingDao;
|
||||
this.createdAtProperty = createdAtProperty;
|
||||
}
|
||||
|
||||
public void execute() {
|
||||
Property<?>[] syncableProperties = NameMaps.syncableProperties(table);
|
||||
TodorooCursor<TYPE> items = dao.query(Query.select(AndroidUtilities.addToArray(syncableProperties, AbstractModel.ID_PROPERTY, RemoteModel.UUID_PROPERTY)));
|
||||
try {
|
||||
OE oe = outstandingDao.getModelClass().newInstance();
|
||||
for (items.moveToFirst(); !items.isAfterLast(); items.moveToNext()) {
|
||||
long itemId = items.get(AbstractModel.ID_PROPERTY);
|
||||
for (Property<?> p : syncableProperties) {
|
||||
oe.clear();
|
||||
oe.setValue(OutstandingEntry.ENTITY_ID_PROPERTY, itemId);
|
||||
oe.setValue(OutstandingEntry.COLUMN_STRING_PROPERTY, p.name);
|
||||
oe.setValue(OutstandingEntry.VALUE_STRING_PROPERTY, items.get(p).toString());
|
||||
if (createdAtProperty != null)
|
||||
oe.setValue(OutstandingEntry.CREATED_AT_PROPERTY, items.get(createdAtProperty));
|
||||
else
|
||||
oe.setValue(OutstandingEntry.CREATED_AT_PROPERTY, DateUtilities.now());
|
||||
outstandingDao.createNew(oe);
|
||||
}
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
Log.e("ConstructOutstanding", "Error instantiating outstanding model class", e);
|
||||
} catch (InstantiationException e2) {
|
||||
Log.e("ConstructOutstanding", "Error instantiating outstanding model class", e2);
|
||||
} finally {
|
||||
items.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.todoroo.astrid.actfm.sync.messages;
|
||||
|
||||
import com.todoroo.astrid.dao.TaskListMetadataDao;
|
||||
import com.todoroo.astrid.dao.TaskListMetadataOutstandingDao;
|
||||
import com.todoroo.astrid.data.TaskListMetadata;
|
||||
import com.todoroo.astrid.data.TaskListMetadataOutstanding;
|
||||
|
||||
public class ReplayTaskListMetadataOutstanding extends ReplayOutstandingEntries<TaskListMetadata, TaskListMetadataOutstanding> {
|
||||
|
||||
public ReplayTaskListMetadataOutstanding(TaskListMetadataDao dao, TaskListMetadataOutstandingDao outstandingDao, boolean afterErrors) {
|
||||
super(TaskListMetadata.class, NameMaps.TABLE_ID_TASK_LIST_METADATA, dao, outstandingDao, afterErrors);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldSaveModel(TaskListMetadata model) {
|
||||
if (model.containsNonNullValue(TaskListMetadata.TASK_IDS) &&
|
||||
TaskListMetadata.taskIdsIsEmpty(model.getValue(TaskListMetadata.TASK_IDS)))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void enqueueChangesHappenedMessage(long id) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TextView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/no_members"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:gravity="center_vertical"
|
||||
style="@style/TextAppearance"
|
||||
android:textStyle="bold"
|
||||
android:textColor="#333333"
|
||||
android:text="@string/actfm_TVA_no_members_alert"/>
|
@ -0,0 +1,38 @@
|
||||
package com.todoroo.astrid.sync;
|
||||
|
||||
import com.todoroo.andlib.data.Property;
|
||||
import com.todoroo.andlib.data.TodorooCursor;
|
||||
import com.todoroo.andlib.sql.Query;
|
||||
import com.todoroo.astrid.actfm.sync.messages.ConstructOutstandingTableFromMasterTable;
|
||||
import com.todoroo.astrid.actfm.sync.messages.NameMaps;
|
||||
import com.todoroo.astrid.data.Task;
|
||||
import com.todoroo.astrid.data.TaskOutstanding;
|
||||
|
||||
public class ConstructOutstandingFromMasterTest extends NewSyncTestCase {
|
||||
|
||||
public void testConstructOutstandingConstructsOutstanding() {
|
||||
Task t = createTask(true);
|
||||
TodorooCursor<TaskOutstanding> to = taskOutstandingDao.query(Query.select(TaskOutstanding.PROPERTIES));
|
||||
try {
|
||||
assertEquals(0, to.getCount());
|
||||
} finally {
|
||||
to.close();
|
||||
}
|
||||
|
||||
new ConstructOutstandingTableFromMasterTable<Task, TaskOutstanding>(NameMaps.TABLE_ID_TASKS, taskDao, taskOutstandingDao, Task.CREATION_DATE).execute();
|
||||
|
||||
Property<?>[] syncable = NameMaps.syncableProperties(NameMaps.TABLE_ID_TASKS);
|
||||
for (Property<?> p : syncable) {
|
||||
to = taskOutstandingDao.query(Query.select(TaskOutstanding.PROPERTIES).where(TaskOutstanding.COLUMN_STRING.eq(p.name)));
|
||||
try {
|
||||
assertEquals(1, to.getCount());
|
||||
to.moveToFirst();
|
||||
String value = t.getValue(p).toString();
|
||||
assertEquals(value, to.get(TaskOutstanding.VALUE_STRING));
|
||||
} finally {
|
||||
to.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue