Add custom order synchronization hack

Workaround for https://issuetracker.google.com/issues/132432317. When
enabled Tasks will synchronize parents and positions for all active
tasks.
pull/820/head
Alex Baker 5 years ago
parent a012ab06bf
commit 9b1e1acc60

@ -103,6 +103,19 @@ public class GtasksInvoker {
GtasksApiUtilities.unixTimeToGtasksCompletionTime(lastSyncDate).toStringRfc3339()));
}
public com.google.api.services.tasks.model.Tasks getAllPositions(
String listId, @Nullable String pageToken) throws IOException {
return execute(
service
.tasks()
.list(listId)
.setMaxResults(100L)
.setShowDeleted(false)
.setShowHidden(true)
.setPageToken(pageToken)
.setFields("items(id,parent,position)"));
}
public @Nullable Task createGtask(
String listId, Task task, @Nullable String parent, @Nullable String previous)
throws IOException {

@ -116,6 +116,10 @@ public abstract class GoogleTaskDao {
"UPDATE google_tasks SET gt_parent = IFNULL((SELECT gt_task FROM google_tasks AS p WHERE p.gt_remote_id = google_tasks.gt_remote_parent), gt_parent) WHERE gt_list_id = :listId AND gt_moved = 0 AND gt_remote_parent IS NOT NULL AND gt_remote_parent != ''")
abstract void updateParents(String listId);
@Query(
"UPDATE google_tasks SET gt_remote_parent = :parent, gt_remote_order = :position WHERE gt_remote_id = :id")
public abstract void updatePosition(String id, String parent, String position);
@Transaction
public void reposition(String listId) {
updateParents(listId);

@ -216,9 +216,36 @@ public class GoogleTaskSynchronizer {
fetchAndApplyRemoteChanges(gtasksInvoker, list);
googleTaskDao.reposition(list.getRemoteId());
}
if (preferences.isPositionHackEnabled()) {
for (TaskList list : gtaskLists) {
List<com.google.api.services.tasks.model.Task> tasks = fetchPositions(gtasksInvoker, list.getId());
for (com.google.api.services.tasks.model.Task task : tasks) {
googleTaskDao.updatePosition(task.getId(), task.getParent(), task.getPosition());
}
googleTaskDao.reposition(list.getId());
}
}
account.setEtag(eTag);
}
private List<com.google.api.services.tasks.model.Task> fetchPositions(GtasksInvoker gtasksInvoker, String listId)
throws IOException {
List<com.google.api.services.tasks.model.Task> tasks = new ArrayList<>();
String nextPageToken = null;
do {
Tasks taskList = gtasksInvoker.getAllPositions(listId, nextPageToken);
if (taskList == null) {
break;
}
List<com.google.api.services.tasks.model.Task> items = taskList.getItems();
if (items != null) {
tasks.addAll(items);
}
nextPageToken = taskList.getNextPageToken();
} while (!Strings.isNullOrEmpty(nextPageToken));
return tasks;
}
private void pushLocalChanges(GoogleTaskAccount account, GtasksInvoker gtasksInvoker)
throws IOException {
List<Task> tasks = taskDao.getGoogleTasksToPush(account.getAccount());

@ -5,6 +5,7 @@ import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Sets.newHashSet;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastKitKat;
import static com.todoroo.andlib.utility.DateUtilities.now;
import static java.util.Collections.emptySet;
import android.content.ContentResolver;
@ -511,4 +512,8 @@ public class Preferences {
public boolean isFlipperEnabled() {
return BuildConfig.DEBUG && getBoolean(R.string.p_flipper, false);
}
public boolean isPositionHackEnabled() {
return getLong(R.string.p_google_tasks_position_hack, 0) > now() - TimeUnit.DAYS.toMillis(7);
}
}

@ -6,11 +6,13 @@
package org.tasks.sync;
import static com.todoroo.andlib.utility.DateUtilities.now;
import static java.util.Arrays.asList;
import static org.tasks.PermissionUtil.verifyPermissions;
import android.content.Intent;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.PreferenceCategory;
import androidx.annotation.NonNull;
@ -98,6 +100,20 @@ public class SynchronizationPreferences extends InjectingPreferenceActivity {
return false;
});
}
CheckBoxPreference positionHack =
(CheckBoxPreference) findPreference(R.string.google_tasks_position_hack);
positionHack.setChecked(preferences.isPositionHackEnabled());
positionHack.setOnPreferenceChangeListener(
(preference, newValue) -> {
if (newValue == null) {
return false;
}
preferences.setLong(
R.string.p_google_tasks_position_hack, ((Boolean) newValue) ? now() : 0);
return true;
});
Preference addCaldavAccount = findPreference(R.string.p_add_caldav_account);
if (inventory.hasPro()) {
addCaldavAccount.setOnPreferenceClickListener(

@ -311,4 +311,7 @@
<string name="p_add_google_task_account">add_google_task_account</string>
<string name="p_add_caldav_account">add_caldav_account</string>
<string name="p_google_tasks_add_to_top">google_tasks_add_to_top</string>
<string name="p_google_tasks_position_hack">google_tasks_position_hack</string>
<string name="google_tasks_position_hack">Custom order synchronization fix</string>
<string name="google_tasks_position_hack_summary">Always perform a full synchronization to workaround https://issuetracker.google.com/issues/132432317. This setting will disable itself after seven days.</string>
</resources>

@ -18,6 +18,11 @@
android:key="@string/p_google_tasks_add_to_top"
android:title="@string/google_tasks_add_to_top"/>
<CheckBoxPreference
android:key="@string/google_tasks_position_hack"
android:title="@string/google_tasks_position_hack"
android:summary="@string/google_tasks_position_hack_summary" />
<PreferenceCategory
android:key="@string/CalDAV"
android:title="@string/CalDAV"/>

Loading…
Cancel
Save