forked from upstream-mirrors/OpenTracks
When deleting all tracks, also disable sync to Google Drive.
This commit is contained in:
@@ -2405,9 +2405,9 @@ limitations under the License.
|
||||
|
||||
<!-- Track List -->
|
||||
<string name="track_list_delete_all_confirm_message"
|
||||
translation_description="When deleting all the tracks, the confirmation dialog message informing
|
||||
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.
|
||||
translation_description="When deleting all the tracks, the confirmation dialog message.">
|
||||
All tracks and markers will be permanently deleted from the device. This will also disable
|
||||
Google Drive sync if it is enabled.
|
||||
</string>
|
||||
<string name="track_list_empty_message"
|
||||
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);
|
||||
if (driveSync) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+11
@@ -17,7 +17,9 @@
|
||||
package com.google.android.apps.mytracks.fragments;
|
||||
|
||||
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.PreferencesUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.app.Dialog;
|
||||
@@ -47,7 +49,16 @@ public class DeleteAllTrackDialogFragment extends DialogFragment {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PreferencesUtils.setBoolean(
|
||||
activity, R.string.drive_sync_key, PreferencesUtils.DRIVE_SYNC_DEFAULT);
|
||||
SyncUtils.disableSync(activity);
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -73,10 +73,6 @@ public class SyncUtils {
|
||||
public static final String DRIVE_ID_TRACKS_QUERY = TracksColumns.DRIVEID + " IS NOT NULL AND "
|
||||
+ 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
|
||||
public static final String NO_DRIVE_ID_TRACKS_QUERY = TracksColumns.DRIVEID + " IS NULL OR "
|
||||
+ TracksColumns.DRIVEID + "=''";
|
||||
@@ -224,12 +220,15 @@ public class SyncUtils {
|
||||
/**
|
||||
* Disables sync.
|
||||
*
|
||||
* @param account the account
|
||||
* @param context the context
|
||||
*/
|
||||
public static void disableSync(Account account) {
|
||||
ContentResolver.cancelSync(account, SYNC_AUTHORITY);
|
||||
ContentResolver.setIsSyncable(account, SYNC_AUTHORITY, 0);
|
||||
ContentResolver.setSyncAutomatically(account, SYNC_AUTHORITY, false);
|
||||
public static void disableSync(Context context) {
|
||||
Account[] accounts = AccountManager.get(context).getAccountsByType(Constants.ACCOUNT_TYPE);
|
||||
for (Account account : accounts) {
|
||||
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.DRIVE_LARGEST_CHANGE_ID_DEFAULT);
|
||||
|
||||
// Clear the driveDeletedList last
|
||||
// Clear the drive_deleted_list_key last
|
||||
PreferencesUtils.setString(
|
||||
this, R.string.drive_deleted_list_key, PreferencesUtils.DRIVE_DELETED_LIST_DEFAULT);
|
||||
}
|
||||
@@ -259,11 +259,7 @@ public class GoogleSettingsActivity extends AbstractSettingsActivity {
|
||||
driveSyncPreference.setChecked(value);
|
||||
|
||||
// Turn off everything
|
||||
Account[] accounts = AccountManager.get(GoogleSettingsActivity.this)
|
||||
.getAccountsByType(Constants.ACCOUNT_TYPE);
|
||||
for (Account account : accounts) {
|
||||
SyncUtils.disableSync(account);
|
||||
}
|
||||
SyncUtils.disableSync(this);
|
||||
|
||||
if (value) {
|
||||
|
||||
@@ -271,8 +267,9 @@ public class GoogleSettingsActivity extends AbstractSettingsActivity {
|
||||
ContentResolver.setMasterSyncAutomatically(true);
|
||||
|
||||
// Enable sync for account
|
||||
String googleAccount = PreferencesUtils.getString(GoogleSettingsActivity.this,
|
||||
R.string.google_account_key, PreferencesUtils.GOOGLE_ACCOUNT_DEFAULT);
|
||||
String googleAccount = PreferencesUtils.getString(
|
||||
this, R.string.google_account_key, PreferencesUtils.GOOGLE_ACCOUNT_DEFAULT);
|
||||
Account[] accounts = AccountManager.get(this).getAccountsByType(Constants.ACCOUNT_TYPE);
|
||||
for (Account account : accounts) {
|
||||
if (account.name.equals(googleAccount)) {
|
||||
SyncUtils.enableSync(account);
|
||||
|
||||
Reference in New Issue
Block a user