forked from upstream-mirrors/OpenTracks
Clear sync state when reset settings.
This commit is contained in:
+1
-6
@@ -52,13 +52,8 @@ public class DeleteAllTrackDialogFragment extends DialogFragment {
|
|||||||
PreferencesUtils.setBoolean(
|
PreferencesUtils.setBoolean(
|
||||||
fragmentActivity, R.string.drive_sync_key, PreferencesUtils.DRIVE_SYNC_DEFAULT);
|
fragmentActivity, R.string.drive_sync_key, PreferencesUtils.DRIVE_SYNC_DEFAULT);
|
||||||
SyncUtils.disableSync(fragmentActivity);
|
SyncUtils.disableSync(fragmentActivity);
|
||||||
|
SyncUtils.clearSyncState(fragmentActivity);
|
||||||
MyTracksProviderUtils.Factory.get(fragmentActivity).deleteAllTracks();
|
MyTracksProviderUtils.Factory.get(fragmentActivity).deleteAllTracks();
|
||||||
PreferencesUtils.setLong(fragmentActivity, R.string.drive_largest_change_id_key,
|
|
||||||
PreferencesUtils.DRIVE_LARGEST_CHANGE_ID_DEFAULT);
|
|
||||||
|
|
||||||
// Clear the drive_deleted_list_key last
|
|
||||||
PreferencesUtils.setString(fragmentActivity, R.string.drive_deleted_list_key,
|
|
||||||
PreferencesUtils.DRIVE_DELETED_LIST_DEFAULT);
|
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ import android.accounts.Account;
|
|||||||
import android.accounts.AccountManager;
|
import android.accounts.AccountManager;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.database.Cursor;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@@ -137,6 +138,38 @@ public class SyncUtils {
|
|||||||
ContentResolver.requestSync(account, SYNC_AUTHORITY, new Bundle());
|
ContentResolver.requestSync(account, SYNC_AUTHORITY, new Bundle());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the sync state. Assumes sync is turned off. Do not want clearing the
|
||||||
|
* state to cause sync activities.
|
||||||
|
*/
|
||||||
|
public static void clearSyncState(Context context) {
|
||||||
|
MyTracksProviderUtils myTracksProviderUtils = MyTracksProviderUtils.Factory.get(context);
|
||||||
|
Cursor cursor = null;
|
||||||
|
try {
|
||||||
|
cursor = myTracksProviderUtils.getTrackCursor(SyncUtils.DRIVE_ID_TRACKS_QUERY, null, null);
|
||||||
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
|
do {
|
||||||
|
Track track = myTracksProviderUtils.createTrack(cursor);
|
||||||
|
if (track.isSharedWithMe()) {
|
||||||
|
myTracksProviderUtils.deleteTrack(track.getId());
|
||||||
|
} else {
|
||||||
|
SyncUtils.updateTrackWithDriveFileInfo(myTracksProviderUtils, track, null);
|
||||||
|
}
|
||||||
|
} while (cursor.moveToNext());
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (cursor != null) {
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PreferencesUtils.setLong(context, R.string.drive_largest_change_id_key,
|
||||||
|
PreferencesUtils.DRIVE_LARGEST_CHANGE_ID_DEFAULT);
|
||||||
|
|
||||||
|
// Clear the drive_deleted_list_key last
|
||||||
|
PreferencesUtils.setString(
|
||||||
|
context, R.string.drive_deleted_list_key, PreferencesUtils.DRIVE_DELETED_LIST_DEFAULT);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the drive service.
|
* Gets the drive service.
|
||||||
*
|
*
|
||||||
|
|||||||
+4
@@ -19,6 +19,7 @@ package com.google.android.apps.mytracks.settings;
|
|||||||
import com.google.android.apps.mytracks.Constants;
|
import com.google.android.apps.mytracks.Constants;
|
||||||
import com.google.android.apps.mytracks.io.backup.BackupActivity;
|
import com.google.android.apps.mytracks.io.backup.BackupActivity;
|
||||||
import com.google.android.apps.mytracks.io.backup.RestoreChooserActivity;
|
import com.google.android.apps.mytracks.io.backup.RestoreChooserActivity;
|
||||||
|
import com.google.android.apps.mytracks.io.sync.SyncUtils;
|
||||||
import com.google.android.apps.mytracks.util.DialogUtils;
|
import com.google.android.apps.mytracks.util.DialogUtils;
|
||||||
import com.google.android.apps.mytracks.util.IntentUtils;
|
import com.google.android.apps.mytracks.util.IntentUtils;
|
||||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||||
@@ -189,6 +190,9 @@ public class BackupResetSettingsActivity extends AbstractSettingsActivity {
|
|||||||
// Actually wipe preferences and save synchronously
|
// Actually wipe preferences and save synchronously
|
||||||
sharedPreferences.edit().clear().commit();
|
sharedPreferences.edit().clear().commit();
|
||||||
|
|
||||||
|
SyncUtils.disableSync(BackupResetSettingsActivity.this);
|
||||||
|
SyncUtils.clearSyncState(BackupResetSettingsActivity.this);
|
||||||
|
|
||||||
// Give UI feedback in the UI thread
|
// Give UI feedback in the UI thread
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -17,8 +17,6 @@
|
|||||||
package com.google.android.apps.mytracks.settings;
|
package com.google.android.apps.mytracks.settings;
|
||||||
|
|
||||||
import com.google.android.apps.mytracks.Constants;
|
import com.google.android.apps.mytracks.Constants;
|
||||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
|
||||||
import com.google.android.apps.mytracks.content.Track;
|
|
||||||
import com.google.android.apps.mytracks.io.sendtogoogle.PermissionCallback;
|
import com.google.android.apps.mytracks.io.sendtogoogle.PermissionCallback;
|
||||||
import com.google.android.apps.mytracks.io.sendtogoogle.SendToGoogleUtils;
|
import com.google.android.apps.mytracks.io.sendtogoogle.SendToGoogleUtils;
|
||||||
import com.google.android.apps.mytracks.io.sync.SyncUtils;
|
import com.google.android.apps.mytracks.io.sync.SyncUtils;
|
||||||
@@ -34,7 +32,6 @@ import android.app.Dialog;
|
|||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.database.Cursor;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.CheckBoxPreference;
|
import android.preference.CheckBoxPreference;
|
||||||
import android.preference.ListPreference;
|
import android.preference.ListPreference;
|
||||||
@@ -122,7 +119,6 @@ public class GoogleSettingsActivity extends AbstractSettingsActivity {
|
|||||||
showDialog(DIALOG_CONFIRM_DRIVE_SYNC_ON);
|
showDialog(DIALOG_CONFIRM_DRIVE_SYNC_ON);
|
||||||
} else {
|
} else {
|
||||||
handleSync(false);
|
handleSync(false);
|
||||||
clearSyncState();
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -202,7 +198,6 @@ public class GoogleSettingsActivity extends AbstractSettingsActivity {
|
|||||||
public void onClick(DialogInterface d, int button) {
|
public void onClick(DialogInterface d, int button) {
|
||||||
googleAccountPreference.setValue(newValue);
|
googleAccountPreference.setValue(newValue);
|
||||||
handleSync(false);
|
handleSync(false);
|
||||||
clearSyncState();
|
|
||||||
updateUiByAccountName(newValue);
|
updateUiByAccountName(newValue);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -217,38 +212,6 @@ public class GoogleSettingsActivity extends AbstractSettingsActivity {
|
|||||||
super.onPrepareDialog(id, dialog, bundle);
|
super.onPrepareDialog(id, dialog, bundle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Clears the sync state. Assumes sync is turned off. Do not want clearing the
|
|
||||||
* state to cause sync activities.
|
|
||||||
*/
|
|
||||||
private void clearSyncState() {
|
|
||||||
MyTracksProviderUtils myTracksProviderUtils = MyTracksProviderUtils.Factory.get(this);
|
|
||||||
Cursor cursor = null;
|
|
||||||
try {
|
|
||||||
cursor = myTracksProviderUtils.getTrackCursor(SyncUtils.DRIVE_ID_TRACKS_QUERY, null, null);
|
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
|
||||||
do {
|
|
||||||
Track track = myTracksProviderUtils.createTrack(cursor);
|
|
||||||
if (track.isSharedWithMe()) {
|
|
||||||
myTracksProviderUtils.deleteTrack(track.getId());
|
|
||||||
} else {
|
|
||||||
SyncUtils.updateTrackWithDriveFileInfo(myTracksProviderUtils, track, null);
|
|
||||||
}
|
|
||||||
} while (cursor.moveToNext());
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
if (cursor != null) {
|
|
||||||
cursor.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PreferencesUtils.setLong(this, R.string.drive_largest_change_id_key,
|
|
||||||
PreferencesUtils.DRIVE_LARGEST_CHANGE_ID_DEFAULT);
|
|
||||||
|
|
||||||
// Clear the drive_deleted_list_key last
|
|
||||||
PreferencesUtils.setString(
|
|
||||||
this, R.string.drive_deleted_list_key, PreferencesUtils.DRIVE_DELETED_LIST_DEFAULT);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles sync.
|
* Handles sync.
|
||||||
*
|
*
|
||||||
@@ -275,6 +238,8 @@ public class GoogleSettingsActivity extends AbstractSettingsActivity {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
SyncUtils.clearSyncState(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user