Force gtask push when only gtask list changes

pull/413/head
Alex Baker 8 years ago
parent 5e37ad27c8
commit c03493b27a

@ -44,15 +44,13 @@ public class GoogleTaskPushReceiver extends InjectingBroadcastReceiver {
return;
}
final ContentValues setValues = model.getSetValues();
if(setValues == null || !gtasksPreferenceService.isLoggedIn()) {
if(!gtasksPreferenceService.isLoggedIn()) {
return;
}
if (!checkValuesForProperties(setValues, TASK_PROPERTIES)) { //None of the properties we sync were updated
return;
if (checkValuesForProperties(setValues, TASK_PROPERTIES) || model.checkAndClearTransitory(SyncFlags.FORCE_SYNC)) {
Task toPush = taskDao.fetch(model.getId(), TASK_PROPERTIES);
gtasksSyncService.enqueue(new TaskPushOp(toPush));
}
Task toPush = taskDao.fetch(model.getId(), TASK_PROPERTIES);
gtasksSyncService.enqueue(new TaskPushOp(toPush));
}
@Override
@ -82,6 +80,9 @@ public class GoogleTaskPushReceiver extends InjectingBroadcastReceiver {
* @return false if none of the properties we sync were changed, true otherwise
*/
private boolean checkValuesForProperties(ContentValues values, Property<?>[] properties) {
if (values == null) {
return false;
}
for (Property<?> property : properties) {
if (property != Task.ID && values.containsKey(property.name)) {
return true;

@ -11,6 +11,7 @@ import android.widget.TextView;
import com.todoroo.astrid.dao.MetadataDao;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.StoreObject;
import com.todoroo.astrid.data.SyncFlags;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.gtasks.GtasksList;
import com.todoroo.astrid.gtasks.GtasksListService;
@ -117,6 +118,7 @@ public class GoogleTaskListFragment extends TaskEditControlFragment {
if (taskMetadata == null) {
taskMetadata = GtasksMetadata.createEmptyMetadataWithoutList(task.getId());
} else if (!taskMetadata.getValue(GtasksMetadata.LIST_ID).equals(selectedList.getRemoteId())) {
task.putTransitory(SyncFlags.FORCE_SYNC, true);
taskMetadata.setDeletionDate(now());
metadataDao.persist(taskMetadata);
taskMetadata = GtasksMetadata.createEmptyMetadataWithoutList(task.getId());

@ -23,6 +23,7 @@ import android.widget.LinearLayout;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.dao.UserActivityDao;
import com.todoroo.astrid.data.SyncFlags;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.UserActivity;
import com.todoroo.astrid.files.FilesControlSet;
@ -34,6 +35,7 @@ import com.todoroo.astrid.timers.TimerPlugin;
import com.todoroo.astrid.ui.EditTitleControlSet;
import com.todoroo.astrid.utility.Flags;
import org.tasks.Broadcaster;
import org.tasks.R;
import org.tasks.analytics.Tracker;
import org.tasks.analytics.Tracking;
@ -89,6 +91,7 @@ public final class TaskEditFragment extends InjectingFragment implements Toolbar
@Inject CommentsController commentsController;
@Inject Preferences preferences;
@Inject Tracker tracker;
@Inject Broadcaster broadcaster;
@BindView(R.id.toolbar) Toolbar toolbar;
@BindView(R.id.comments) LinearLayout comments;
@ -210,7 +213,10 @@ public final class TaskEditFragment extends InjectingFragment implements Toolbar
for (TaskEditControlFragment fragment : fragments) {
fragment.apply(model);
}
taskService.save(model);
boolean databaseChanged = taskService.save(model);
if (!databaseChanged && model.checkTransitory(SyncFlags.FORCE_SYNC)) {
broadcaster.taskUpdated(model);
}
boolean tagsChanged = Flags.check(Flags.TAGS_CHANGED);

@ -198,30 +198,31 @@ public class TaskDao {
* exist. Returns true on success.
*
*/
public void save(Task task) {
public boolean save(Task task) {
if (task.getId() == Task.NO_ID) {
try {
createNew(task);
return createNew(task);
} catch (SQLiteConstraintException e) {
Timber.e(e, e.getMessage());
handleSQLiteConstraintException(task); // Tried to create task with remote id that already exists
return handleSQLiteConstraintException(task); // Tried to create task with remote id that already exists
}
} else {
saveExisting(task);
return saveExisting(task);
}
}
public void handleSQLiteConstraintException(Task task) {
public boolean handleSQLiteConstraintException(Task task) {
TodorooCursor<Task> cursor = dao.query(Query.select(Task.ID).where(
Task.UUID.eq(task.getUUID())));
if (cursor.getCount() > 0) {
cursor.moveToFirst();
task.setId(cursor.get(Task.ID));
saveExisting(task);
return saveExisting(task);
}
return false;
}
public void createNew(Task item) {
public boolean createNew(Task item) {
if(!item.containsValue(Task.CREATION_DATE)) {
item.setCreationDate(DateUtilities.now());
}
@ -244,7 +245,9 @@ public class TaskDao {
ContentValues values = item.getSetValues();
if(dao.createNew(item)) {
afterSave(item, values);
return true;
}
return false;
}
public static void createDefaultHideUntil(Preferences preferences, Task item) {
@ -269,10 +272,10 @@ public class TaskDao {
}
}
public void saveExisting(Task item) {
public boolean saveExisting(Task item) {
ContentValues values = item.getSetValues();
if(values == null || values.size() == 0) {
return;
return false;
}
if(!TaskApiDao.insignificantChange(values)) {
if(!values.containsKey(Task.MODIFICATION_DATE.name)) {
@ -281,7 +284,9 @@ public class TaskDao {
}
if(dao.saveExisting(item)) {
afterSave(item, values);
return true;
}
return false;
}
private static final Property<?>[] SQL_CONSTRAINT_MERGE_PROPERTIES = new Property<?>[] {

@ -9,6 +9,8 @@ public class SyncFlags {
public static final String GTASKS_SUPPRESS_SYNC = "gtasks_suppress_sync";
public static final String FORCE_SYNC = "force_sync";
public static final String ACTFM_SUPPRESS_OUTSTANDING_ENTRIES = "actfm-suppress-outstanding";
}

@ -102,10 +102,11 @@ public class TaskService {
/**
* Create or save the given action item
*/
public void save(Task item) {
taskDao.save(item);
public boolean save(Task item) {
boolean databaseChanged = taskDao.save(item);
broadcastFilterListUpdated();
refreshScheduler.scheduleRefresh(item);
return databaseChanged;
}
private void saveWithoutPublishingFilterUpdate(Task item) {

Loading…
Cancel
Save