Added ability to sync individual gtasks immediately on save. Properties synced--all relevant task data e.g. title, due date, parent indentation. Properties ignored--ordering in a list. Also fixed several major bugs related to normal syncing.

Various bugfixes and improvements to exception handling during migration
pull/14/head
Sam Bosley 15 years ago committed by Tim Su
parent 365608f4c6
commit b96ef92f9c

@ -24,6 +24,7 @@
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<!-- for google tasks -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="com.google.android.googleapps.permission.GOOGLE_AUTH" />
<!-- for task sharing -->
<uses-permission android:name="android.permission.READ_CONTACTS" />
@ -63,7 +64,6 @@
<uses-sdk android:targetSdkVersion="10"
android:minSdkVersion="4" />
<supports-screens />
<uses-permission android:name="android.permission.USE_CREDENTIALS"></uses-permission>
<application android:icon="@drawable/icon" android:label="@string/app_name"
android:theme="@style/Theme"

@ -1,6 +1,7 @@
package com.todoroo.astrid.gtasks;
import com.timsu.astrid.R;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.sync.SyncProviderUtilities;
/**
@ -28,6 +29,10 @@ public class GtasksPreferenceService extends SyncProviderUtilities {
return R.string.gtasks_GPr_sync_on_save_key;
}
public boolean migrationHasOccurred() {
return Preferences.getBoolean(PREF_MIGRATION_HAS_OCCURRED, false);
}
/** GTasks user's default list id */
public static final String PREF_DEFAULT_LIST = IDENTIFIER + "_defaultlist"; //$NON-NLS-1$
@ -40,4 +45,6 @@ public class GtasksPreferenceService extends SyncProviderUtilities {
/** GTasks whether we have shown list help boolean */
public static final String PREF_SHOWN_LIST_HELP = IDENTIFIER + "_list_help"; //$NON-NLS-1$
}
public static final String PREF_MIGRATION_HAS_OCCURRED = IDENTIFIER + "_migrated";
}

@ -15,8 +15,6 @@ import com.todoroo.astrid.gtasks.api.GtasksService;
public class GtasksTokenValidator {
private static GoogleAccountManager accountManager = new GoogleAccountManager(ContextManager.getContext());
/**
* Invalidates and then revalidates the auth token for the currently logged in user
* Shouldn't be called from the main thread--will block on network calls
@ -24,6 +22,8 @@ public class GtasksTokenValidator {
* @return valid token on success, null on failure
*/
public static String validateAuthToken(String token) {
GoogleAccountManager accountManager = new GoogleAccountManager(ContextManager.getContext());
GtasksService testService = new GtasksService(token);
try {
testService.ping();

@ -33,8 +33,7 @@ public class GtasksLegacyMigrator {
@Autowired TaskService taskService;
@Autowired MetadataService metadataService;
@Autowired GtasksListService gtasksListService;
private static final String MIGRATION_HAS_OCCURRED = "gtasksLegacySyncMigrated"; //$NON-NLS-1$
@Autowired GtasksPreferenceService gtasksPreferenceService;
private final GtasksService gtasksService;
private final GtasksListService listService;
@ -52,7 +51,7 @@ public class GtasksLegacyMigrator {
}
public void checkAndMigrateLegacy() throws IOException {
if (!Preferences.getBoolean(MIGRATION_HAS_OCCURRED, false)) {
if (!gtasksPreferenceService.migrationHasOccurred()) {
listService.migrateListIds(allLists);
@ -107,13 +106,16 @@ public class GtasksLegacyMigrator {
}
}
}
if (defaultListId == null) defaultListId = "@default"; //$NON-NLS-1$
if (defaultListId == null) {
com.google.api.services.tasks.v1.model.TaskList defaultList = gtasksService.getGtaskList("@default"); //$NON-NLS-1$
defaultListId = defaultList.id;
}
Preferences.setString(GtasksPreferenceService.PREF_DEFAULT_LIST, defaultListId);
}
} finally {
allTasksWithGtaskData.close();
}
Preferences.setBoolean(MIGRATION_HAS_OCCURRED, true); //Record successful migration
Preferences.setBoolean(GtasksPreferenceService.PREF_MIGRATION_HAS_OCCURRED, true); //Record successful migration
}
}

@ -121,6 +121,9 @@ public class GtasksSyncProvider extends SyncProvider<GtasksTaskContainer> {
try {
String authToken = gtasksPreferenceService.getToken();
authToken = GtasksTokenValidator.validateAuthToken(authToken);
if (authToken == null) {
throw new GoogleTasksException(ContextManager.getContext().getString(R.string.gtasks_GLA_errorAuth));
}
gtasksPreferenceService.setToken(authToken);
taskService = new GtasksService(authToken);

@ -138,8 +138,12 @@ public class StartupService {
// invoke upgrade service
boolean justUpgraded = latestSetVersion != version;
if(justUpgraded && version > 0) {
if(latestSetVersion > 0)
if(latestSetVersion > 0) {
upgradeService.performUpgrade(context, latestSetVersion);
if (!gtasksPreferenceService.migrationHasOccurred()) {
gtasksPreferenceService.setToken(null);
}
}
AstridPreferences.setCurrentVersion(version);
}
if(latestSetVersion == 0) {

Loading…
Cancel
Save