Fix google task bugs

* Fix manual sort query
* Fix multi-account sync
pull/685/merge 6.0.3
Alex Baker 8 years ago
parent 8a9a97d3ce
commit 021c9bbf35

@ -1,6 +1,11 @@
Change Log Change Log
--- ---
### 6.0.3 (2018-04-25)
* Fix crash when manually sorting Google Task lists
* Fix multi account Google Task sync issue
### 6.0.2 (2018-04-25) ### 6.0.2 (2018-04-25)
* Fix crash caused by missing tag metadata * Fix crash caused by missing tag metadata

@ -20,8 +20,8 @@ android {
defaultConfig { defaultConfig {
testApplicationId "org.tasks.test" testApplicationId "org.tasks.test"
applicationId "org.tasks" applicationId "org.tasks"
versionCode 528 versionCode 529
versionName "6.0.2" versionName "6.0.3"
targetSdkVersion 27 targetSdkVersion 27
minSdkVersion 15 minSdkVersion 15
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

@ -84,6 +84,11 @@ public abstract class Property<TYPE> extends Field implements Cloneable {
super(table, name); super(table, name);
} }
@Override
public IntegerProperty as(String newAlias) {
return (IntegerProperty) super.as(newAlias);
}
IntegerProperty(String name, String expression) { IntegerProperty(String name, String expression) {
super(null, name, expression); super(null, name, expression);
} }

@ -51,7 +51,7 @@ public class GtasksFilter extends Filter {
public static String toManualOrder(String query) { public static String toManualOrder(String query) {
query = query.replaceAll("ORDER BY .*", ""); query = query.replaceAll("ORDER BY .*", "");
query = query + " ORDER BY `order` ASC"; query = query + " ORDER BY `gtasks_order` ASC";
return query.replace( return query.replace(
TaskDao.TaskCriteria.activeAndVisible().toString(), TaskDao.TaskCriteria.activeAndVisible().toString(),
TaskDao.TaskCriteria.notDeleted().toString()); TaskDao.TaskCriteria.notDeleted().toString());

@ -95,9 +95,10 @@ public abstract class TaskDao {
@android.arch.persistence.room.Query( @android.arch.persistence.room.Query(
"SELECT tasks.* FROM tasks " "SELECT tasks.* FROM tasks "
+ "LEFT JOIN google_tasks ON tasks._id = google_tasks.task " + "LEFT JOIN google_tasks ON tasks._id = google_tasks.task "
+ "WHERE tasks.modified > google_tasks.last_sync " + "WHERE list_id IN (SELECT remote_id FROM google_task_lists WHERE account = :account)"
+ "OR google_tasks.remote_id = ''") + "AND (tasks.modified > google_tasks.last_sync "
public abstract List<Task> getGoogleTasksToPush(); + "OR google_tasks.remote_id = '')")
public abstract List<Task> getGoogleTasksToPush(String account);
@android.arch.persistence.room.Query( @android.arch.persistence.room.Query(
"SELECT tasks.* FROM tasks " "SELECT tasks.* FROM tasks "
@ -226,8 +227,12 @@ public abstract class TaskDao {
} }
public Cursor getCursor(String queryTemplate) { public Cursor getCursor(String queryTemplate) {
return getCursor(queryTemplate, Task.PROPERTIES);
}
public Cursor getCursor(String queryTemplate, Property<?>... properties) {
Query query = Query query =
Query.select(Task.PROPERTIES) Query.select(properties)
.withQueryTemplate(PermaSql.replacePlaceholdersForQuery(queryTemplate)); .withQueryTemplate(PermaSql.replacePlaceholdersForQuery(queryTemplate));
String queryString = query.from(Task.TABLE).toString(); String queryString = query.from(Task.TABLE).toString();
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {

@ -49,6 +49,7 @@ public class GtasksSubtaskListFragment extends GtasksListFragment {
public Property<?>[] taskProperties() { public Property<?>[] taskProperties() {
Property<?>[] baseProperties = TaskAdapter.PROPERTIES; Property<?>[] baseProperties = TaskAdapter.PROPERTIES;
ArrayList<Property<?>> properties = new ArrayList<>(Arrays.asList(baseProperties)); ArrayList<Property<?>> properties = new ArrayList<>(Arrays.asList(baseProperties));
properties.add(GoogleTask.ORDER);
properties.add(GoogleTask.INDENT); properties.add(GoogleTask.INDENT);
return properties.toArray(new Property<?>[properties.size()]); return properties.toArray(new Property<?>[properties.size()]);
} }

@ -70,7 +70,7 @@ public abstract class DeletionDao {
return deleted; return deleted;
} }
@Query("UPDATE tasks SET deleted = :timestamp WHERE _id IN(:ids)") @Query("UPDATE tasks SET modified = :timestamp, deleted = :timestamp WHERE _id IN(:ids)")
public abstract void markDeleted(long timestamp, List<Long> ids); public abstract void markDeleted(long timestamp, List<Long> ids);
@Query("SELECT task FROM caldav_tasks WHERE calendar = :calendar AND deleted = 0") @Query("SELECT task FROM caldav_tasks WHERE calendar = :calendar AND deleted = 0")

@ -19,6 +19,10 @@ public class GoogleTask {
public static final Property.IntegerProperty INDENT = public static final Property.IntegerProperty INDENT =
new Property.IntegerProperty(GoogleTask.TABLE, "indent"); new Property.IntegerProperty(GoogleTask.TABLE, "indent");
@Deprecated
public static final Property.IntegerProperty ORDER =
new Property.IntegerProperty(GoogleTask.TABLE, "`order`").as("gtasks_order");
@PrimaryKey(autoGenerate = true) @PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "_id") @ColumnInfo(name = "_id")
private transient long id; private transient long id;

@ -182,7 +182,7 @@ public class GoogleTaskSynchronizer {
} }
GtasksInvoker gtasksInvoker = new GtasksInvoker(context, playServices, account.getAccount()); GtasksInvoker gtasksInvoker = new GtasksInvoker(context, playServices, account.getAccount());
pushLocalChanges(gtasksInvoker); pushLocalChanges(account, gtasksInvoker);
List<TaskList> gtaskLists = new ArrayList<>(); List<TaskList> gtaskLists = new ArrayList<>();
String nextPageToken = null; String nextPageToken = null;
@ -212,8 +212,8 @@ public class GoogleTaskSynchronizer {
account.setError(""); account.setError("");
} }
private void pushLocalChanges(GtasksInvoker gtasksInvoker) throws UserRecoverableAuthIOException { private void pushLocalChanges(GoogleTaskAccount account, GtasksInvoker gtasksInvoker) throws UserRecoverableAuthIOException {
List<Task> tasks = taskDao.getGoogleTasksToPush(); List<Task> tasks = taskDao.getGoogleTasksToPush(account.getAccount());
for (Task task : tasks) { for (Task task : tasks) {
try { try {
pushTask(task, gtasksInvoker); pushTask(task, gtasksInvoker);

@ -14,14 +14,18 @@ import android.text.TextUtils;
import android.view.View; import android.view.View;
import android.widget.RemoteViews; import android.widget.RemoteViews;
import android.widget.RemoteViewsService; import android.widget.RemoteViewsService;
import com.google.common.collect.ObjectArrays;
import com.todoroo.andlib.data.Property;
import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.api.GtasksFilter;
import com.todoroo.astrid.core.SortHelper; import com.todoroo.astrid.core.SortHelper;
import com.todoroo.astrid.dao.TaskDao; import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.subtasks.SubtasksHelper; import com.todoroo.astrid.subtasks.SubtasksHelper;
import org.tasks.BuildConfig; import org.tasks.BuildConfig;
import org.tasks.R; import org.tasks.R;
import org.tasks.data.GoogleTask;
import org.tasks.locale.Locale; import org.tasks.locale.Locale;
import org.tasks.preferences.DefaultFilterProvider; import org.tasks.preferences.DefaultFilterProvider;
import org.tasks.preferences.Preferences; import org.tasks.preferences.Preferences;
@ -199,20 +203,20 @@ class ScrollableViewsFactory implements RemoteViewsService.RemoteViewsFactory {
} }
private Cursor getCursor() { private Cursor getCursor() {
return taskDao.getCursor(getQuery()); updateSettings();
Filter filter = defaultFilterProvider.getFilterFromPreference(filterId);
return taskDao.getCursor(getQuery(filter), getProperties(filter));
} }
private Task getTask(int position) { private Task getTask(int position) {
return cursor.moveToPosition(position) ? new Task(cursor) : null; return cursor.moveToPosition(position) ? new Task(cursor) : null;
} }
private String getQuery() { private String getQuery(Filter filter) {
int sort = preferences.getSortMode(); int sort = preferences.getSortMode();
if (sort == 0) { if (sort == 0) {
sort = SortHelper.SORT_WIDGET; sort = SortHelper.SORT_WIDGET;
} }
updateSettings();
Filter filter = defaultFilterProvider.getFilterFromPreference(filterId);
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.scrollable_widget); RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.scrollable_widget);
rv.setTextViewText(R.id.widget_title, filter.listingTitle); rv.setTextViewText(R.id.widget_title, filter.listingTitle);
@ -226,6 +230,12 @@ class ScrollableViewsFactory implements RemoteViewsService.RemoteViewsFactory {
return subtasksHelper.applySubtasksToWidgetFilter(filter, query); return subtasksHelper.applySubtasksToWidgetFilter(filter, query);
} }
private Property<?>[] getProperties(Filter filter) {
return filter instanceof GtasksFilter
? ObjectArrays.concat(Task.PROPERTIES, new Property<?>[] {GoogleTask.ORDER}, Property.class)
: Task.PROPERTIES;
}
private void formatDueDate(RemoteViews row, Task task) { private void formatDueDate(RemoteViews row, Task task) {
if (task.hasDueDate()) { if (task.hasDueDate()) {
Resources resources = context.getResources(); Resources resources = context.getResources();

Loading…
Cancel
Save