When deleting all tracks, also disable sync to Google Drive.

This commit is contained in:
Jimmy Shih
2013-02-06 11:01:12 -08:00
parent fdf37bc19d
commit 14f776721c
5 changed files with 29 additions and 21 deletions
+3 -3
View File
@@ -2405,9 +2405,9 @@ limitations under the License.
<!-- Track List --> <!-- Track List -->
<string name="track_list_delete_all_confirm_message" <string name="track_list_delete_all_confirm_message"
translation_description="When deleting all the tracks, the confirmation dialog message informing translation_description="When deleting all the tracks, the confirmation dialog message.">
the user that all tracks and markers will be permanently deleted from the device."> All tracks and markers will be permanently deleted from the device. This will also disable
All tracks and markers will be permanently deleted from the device. Google Drive sync if it is enabled.
</string> </string>
<string name="track_list_empty_message" <string name="track_list_empty_message"
translation_description="When the track list is empty, the message informing the user to click translation_description="When the track list is empty, the message informing the user to click
@@ -208,7 +208,8 @@ public class MyTracksProvider extends ContentProvider {
getContext(), R.string.drive_sync_key, PreferencesUtils.DRIVE_SYNC_DEFAULT); getContext(), R.string.drive_sync_key, PreferencesUtils.DRIVE_SYNC_DEFAULT);
if (driveSync) { if (driveSync) {
driveIds = where != null ? getDriveIds(null, where, selectionArgs) driveIds = where != null ? getDriveIds(null, where, selectionArgs)
: getDriveIds(new String[] { TracksColumns.DRIVEID }, SyncUtils.DRIVE_ID_TRACKS_BY_ME_QUERY, null); : getDriveIds(
new String[] { TracksColumns.DRIVEID }, SyncUtils.DRIVE_ID_TRACKS_QUERY, null);
} }
} }
@@ -17,7 +17,9 @@
package com.google.android.apps.mytracks.fragments; package com.google.android.apps.mytracks.fragments;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
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.PreferencesUtils;
import com.google.android.maps.mytracks.R; import com.google.android.maps.mytracks.R;
import android.app.Dialog; import android.app.Dialog;
@@ -47,7 +49,16 @@ public class DeleteAllTrackDialogFragment extends DialogFragment {
new Thread(new Runnable() { new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
PreferencesUtils.setBoolean(
activity, R.string.drive_sync_key, PreferencesUtils.DRIVE_SYNC_DEFAULT);
SyncUtils.disableSync(activity);
MyTracksProviderUtils.Factory.get(activity).deleteAllTracks(); MyTracksProviderUtils.Factory.get(activity).deleteAllTracks();
PreferencesUtils.setLong(activity, R.string.drive_largest_change_id_key,
PreferencesUtils.DRIVE_LARGEST_CHANGE_ID_DEFAULT);
// Clear the drive_deleted_list_key last
PreferencesUtils.setString(activity, R.string.drive_deleted_list_key,
PreferencesUtils.DRIVE_DELETED_LIST_DEFAULT);
} }
}).start(); }).start();
} }
@@ -73,10 +73,6 @@ public class SyncUtils {
public static final String DRIVE_ID_TRACKS_QUERY = TracksColumns.DRIVEID + " IS NOT NULL AND " public static final String DRIVE_ID_TRACKS_QUERY = TracksColumns.DRIVEID + " IS NOT NULL AND "
+ TracksColumns.DRIVEID + "!=''"; + TracksColumns.DRIVEID + "!=''";
// Get tracks with drive id that are owned by me, not tracks ashared with me.
public static final String DRIVE_ID_TRACKS_BY_ME_QUERY = DRIVE_ID_TRACKS_QUERY + " AND "
+ TracksColumns.SHAREDWITHME + "!=1";
// Get tracks without drive id // Get tracks without drive id
public static final String NO_DRIVE_ID_TRACKS_QUERY = TracksColumns.DRIVEID + " IS NULL OR " public static final String NO_DRIVE_ID_TRACKS_QUERY = TracksColumns.DRIVEID + " IS NULL OR "
+ TracksColumns.DRIVEID + "=''"; + TracksColumns.DRIVEID + "=''";
@@ -224,12 +220,15 @@ public class SyncUtils {
/** /**
* Disables sync. * Disables sync.
* *
* @param account the account * @param context the context
*/ */
public static void disableSync(Account account) { public static void disableSync(Context context) {
ContentResolver.cancelSync(account, SYNC_AUTHORITY); Account[] accounts = AccountManager.get(context).getAccountsByType(Constants.ACCOUNT_TYPE);
ContentResolver.setIsSyncable(account, SYNC_AUTHORITY, 0); for (Account account : accounts) {
ContentResolver.setSyncAutomatically(account, SYNC_AUTHORITY, false); ContentResolver.cancelSync(account, SYNC_AUTHORITY);
ContentResolver.setIsSyncable(account, SYNC_AUTHORITY, 0);
ContentResolver.setSyncAutomatically(account, SYNC_AUTHORITY, false);
}
} }
/** /**
@@ -245,7 +245,7 @@ public class GoogleSettingsActivity extends AbstractSettingsActivity {
PreferencesUtils.setLong(this, R.string.drive_largest_change_id_key, PreferencesUtils.setLong(this, R.string.drive_largest_change_id_key,
PreferencesUtils.DRIVE_LARGEST_CHANGE_ID_DEFAULT); PreferencesUtils.DRIVE_LARGEST_CHANGE_ID_DEFAULT);
// Clear the driveDeletedList last // Clear the drive_deleted_list_key last
PreferencesUtils.setString( PreferencesUtils.setString(
this, R.string.drive_deleted_list_key, PreferencesUtils.DRIVE_DELETED_LIST_DEFAULT); this, R.string.drive_deleted_list_key, PreferencesUtils.DRIVE_DELETED_LIST_DEFAULT);
} }
@@ -259,11 +259,7 @@ public class GoogleSettingsActivity extends AbstractSettingsActivity {
driveSyncPreference.setChecked(value); driveSyncPreference.setChecked(value);
// Turn off everything // Turn off everything
Account[] accounts = AccountManager.get(GoogleSettingsActivity.this) SyncUtils.disableSync(this);
.getAccountsByType(Constants.ACCOUNT_TYPE);
for (Account account : accounts) {
SyncUtils.disableSync(account);
}
if (value) { if (value) {
@@ -271,8 +267,9 @@ public class GoogleSettingsActivity extends AbstractSettingsActivity {
ContentResolver.setMasterSyncAutomatically(true); ContentResolver.setMasterSyncAutomatically(true);
// Enable sync for account // Enable sync for account
String googleAccount = PreferencesUtils.getString(GoogleSettingsActivity.this, String googleAccount = PreferencesUtils.getString(
R.string.google_account_key, PreferencesUtils.GOOGLE_ACCOUNT_DEFAULT); this, R.string.google_account_key, PreferencesUtils.GOOGLE_ACCOUNT_DEFAULT);
Account[] accounts = AccountManager.get(this).getAccountsByType(Constants.ACCOUNT_TYPE);
for (Account account : accounts) { for (Account account : accounts) {
if (account.name.equals(googleAccount)) { if (account.name.equals(googleAccount)) {
SyncUtils.enableSync(account); SyncUtils.enableSync(account);