Added a helper class to construct outstanding tables from master tables after login

pull/14/head
Sam Bosley 12 years ago
parent d145a7ad18
commit 27879460ff

@ -64,7 +64,25 @@ import com.todoroo.astrid.actfm.sync.ActFmInvoker;
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService; import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
import com.todoroo.astrid.actfm.sync.ActFmServiceException; import com.todoroo.astrid.actfm.sync.ActFmServiceException;
import com.todoroo.astrid.actfm.sync.ActFmSyncMonitor; import com.todoroo.astrid.actfm.sync.ActFmSyncMonitor;
import com.todoroo.astrid.actfm.sync.messages.ConstructOutstandingTableFromMasterTable;
import com.todoroo.astrid.actfm.sync.messages.NameMaps;
import com.todoroo.astrid.activity.Eula; import com.todoroo.astrid.activity.Eula;
import com.todoroo.astrid.dao.TagDataDao;
import com.todoroo.astrid.dao.TagOutstandingDao;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.dao.TaskListMetadataDao;
import com.todoroo.astrid.dao.TaskListMetadataOutstandingDao;
import com.todoroo.astrid.dao.TaskOutstandingDao;
import com.todoroo.astrid.dao.UserActivityDao;
import com.todoroo.astrid.dao.UserActivityOutstandingDao;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.TagOutstanding;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.TaskListMetadata;
import com.todoroo.astrid.data.TaskListMetadataOutstanding;
import com.todoroo.astrid.data.TaskOutstanding;
import com.todoroo.astrid.data.UserActivity;
import com.todoroo.astrid.data.UserActivityOutstanding;
import com.todoroo.astrid.gtasks.auth.ModernAuthManager; import com.todoroo.astrid.gtasks.auth.ModernAuthManager;
import com.todoroo.astrid.service.AstridDependencyInjector; import com.todoroo.astrid.service.AstridDependencyInjector;
import com.todoroo.astrid.service.MarketStrategy.AmazonMarketStrategy; import com.todoroo.astrid.service.MarketStrategy.AmazonMarketStrategy;
@ -90,6 +108,25 @@ public class ActFmLoginActivity extends FragmentActivity implements AuthListener
@Autowired @Autowired
protected ActFmPreferenceService actFmPreferenceService; protected ActFmPreferenceService actFmPreferenceService;
@Autowired
private TaskDao taskDao;
@Autowired
private TaskOutstandingDao taskOutstandingDao;
@Autowired
private TagDataDao tagDataDao;
@Autowired
private TagOutstandingDao tagOutstandingDao;
@Autowired
private UserActivityDao userActivityDao;
@Autowired
private UserActivityOutstandingDao userActivityOutstandingDao;
@Autowired
private TaskListMetadataDao taskListMetadataDao;
@Autowired
private TaskListMetadataOutstandingDao taskListMetadataOutstandingDao;
@Autowired protected SyncV2Service syncService; @Autowired protected SyncV2Service syncService;
private final ActFmInvoker actFmInvoker = new ActFmInvoker(); private final ActFmInvoker actFmInvoker = new ActFmInvoker();
private Random rand; private Random rand;
@ -527,6 +564,13 @@ public class ActFmLoginActivity extends FragmentActivity implements AuthListener
if (result.optBoolean("new")) { // Report new user statistic if (result.optBoolean("new")) { // Report new user statistic
StatisticsService.reportEvent(StatisticsConstants.ACTFM_NEW_USER, "provider", provider); StatisticsService.reportEvent(StatisticsConstants.ACTFM_NEW_USER, "provider", provider);
} }
// Successful login, create outstanding entries
if (!TextUtils.isEmpty(token)) {
new ConstructOutstandingTableFromMasterTable<Task, TaskOutstanding>(NameMaps.TABLE_ID_TASKS, taskDao, taskOutstandingDao, Task.CREATION_DATE).execute();
new ConstructOutstandingTableFromMasterTable<TagData, TagOutstanding>(NameMaps.TABLE_ID_TAGS, tagDataDao, tagOutstandingDao, TagData.CREATION_DATE).execute();
new ConstructOutstandingTableFromMasterTable<UserActivity, UserActivityOutstanding>(NameMaps.TABLE_ID_USER_ACTIVITY, userActivityDao, userActivityOutstandingDao, UserActivity.CREATED_AT).execute();
new ConstructOutstandingTableFromMasterTable<TaskListMetadata, TaskListMetadataOutstanding>(NameMaps.TABLE_ID_TASK_LIST_METADATA, taskListMetadataDao, taskListMetadataOutstandingDao, null).execute();
}
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
public void run() { public void run() {
DialogUtilities.dismissDialog(ActFmLoginActivity.this, progressDialog); DialogUtilities.dismissDialog(ActFmLoginActivity.this, progressDialog);

@ -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();
}
}
}
Loading…
Cancel
Save