forked from upstream-mirrors/OpenTracks
Code refactor: move managing list of deleted tracks to DeleteAsyncTask
This commit is contained in:
@@ -17,6 +17,7 @@ package com.google.android.apps.mytracks;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
||||||
|
import com.google.android.apps.mytracks.content.Track;
|
||||||
import com.google.android.apps.mytracks.io.sync.SyncUtils;
|
import com.google.android.apps.mytracks.io.sync.SyncUtils;
|
||||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||||
import com.google.android.maps.mytracks.R;
|
import com.google.android.maps.mytracks.R;
|
||||||
@@ -97,7 +98,19 @@ public class DeleteAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
|||||||
if (isCancelled()) {
|
if (isCancelled()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Track track = myTracksProviderUtils.getTrack(id);
|
||||||
myTracksProviderUtils.deleteTrack(id);
|
myTracksProviderUtils.deleteTrack(id);
|
||||||
|
if (track != null) {
|
||||||
|
String driveId = track.getDriveId();
|
||||||
|
if (driveId != null && !driveId.equals("")) {
|
||||||
|
boolean driveSync = PreferencesUtils.getBoolean(
|
||||||
|
context, R.string.drive_sync_key, PreferencesUtils.DRIVE_SYNC_DEFAULT);
|
||||||
|
if (driveSync) {
|
||||||
|
PreferencesUtils.addToList(context, R.string.drive_deleted_list_key,
|
||||||
|
PreferencesUtils.DRIVE_DELETED_LIST_DEFAULT, driveId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,7 +79,6 @@ public class TrackDetailActivity extends AbstractSendToGoogleActivity implements
|
|||||||
public static final String EXTRA_TRACK_ID = "track_id";
|
public static final String EXTRA_TRACK_ID = "track_id";
|
||||||
public static final String EXTRA_MARKER_ID = "marker_id";
|
public static final String EXTRA_MARKER_ID = "marker_id";
|
||||||
|
|
||||||
private static final String TAG = TrackDetailActivity.class.getSimpleName();
|
|
||||||
private static final String CURRENT_TAB_TAG_KEY = "current_tab_tag_key";
|
private static final String CURRENT_TAB_TAG_KEY = "current_tab_tag_key";
|
||||||
private static final String PHOTO_URI_KEY = "photo_uri_key";
|
private static final String PHOTO_URI_KEY = "photo_uri_key";
|
||||||
private static final String HAS_PHOTO_KEY = "has_photo_key";
|
private static final String HAS_PHOTO_KEY = "has_photo_key";
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.google.android.apps.mytracks.content;
|
package com.google.android.apps.mytracks.content;
|
||||||
|
|
||||||
import com.google.android.apps.mytracks.io.sync.SyncUtils;
|
|
||||||
import com.google.android.apps.mytracks.util.FileUtils;
|
import com.google.android.apps.mytracks.util.FileUtils;
|
||||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||||
import com.google.android.maps.mytracks.R;
|
import com.google.android.maps.mytracks.R;
|
||||||
@@ -42,7 +41,6 @@ import android.util.Log;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link ContentProvider} that handles access to track points, tracks, and
|
* A {@link ContentProvider} that handles access to track points, tracks, and
|
||||||
@@ -218,18 +216,6 @@ public class MyTracksProvider extends ContentProvider {
|
|||||||
throw new IllegalArgumentException("Unknown URL " + url);
|
throw new IllegalArgumentException("Unknown URL " + url);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean driveSync = false;
|
|
||||||
String driveIds = "";
|
|
||||||
if (table.equals(TracksColumns.TABLE_NAME)) {
|
|
||||||
driveSync = PreferencesUtils.getBoolean(
|
|
||||||
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_QUERY, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.w(MyTracksProvider.TAG, "Deleting table " + table);
|
Log.w(MyTracksProvider.TAG, "Deleting table " + table);
|
||||||
int count;
|
int count;
|
||||||
try {
|
try {
|
||||||
@@ -241,17 +227,6 @@ public class MyTracksProvider extends ContentProvider {
|
|||||||
}
|
}
|
||||||
getContext().getContentResolver().notifyChange(url, null, false);
|
getContext().getContentResolver().notifyChange(url, null, false);
|
||||||
|
|
||||||
if (driveSync && table.equals(TracksColumns.TABLE_NAME)) {
|
|
||||||
String driveDeletedList = PreferencesUtils.getString(getContext(),
|
|
||||||
R.string.drive_deleted_list_key, PreferencesUtils.DRIVE_DELETED_LIST_DEFAULT);
|
|
||||||
if (driveDeletedList.equals(PreferencesUtils.DRIVE_DELETED_LIST_DEFAULT)) {
|
|
||||||
driveDeletedList = driveIds;
|
|
||||||
} else {
|
|
||||||
driveDeletedList += ";" + driveIds;
|
|
||||||
}
|
|
||||||
PreferencesUtils.setString(getContext(), R.string.drive_deleted_list_key, driveDeletedList);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shouldVacuum) {
|
if (shouldVacuum) {
|
||||||
// If a potentially large amount of data was deleted, reclaim its space.
|
// If a potentially large amount of data was deleted, reclaim its space.
|
||||||
Log.i(TAG, "Vacuuming the database.");
|
Log.i(TAG, "Vacuuming the database.");
|
||||||
@@ -536,33 +511,4 @@ public class MyTracksProvider extends ContentProvider {
|
|||||||
}
|
}
|
||||||
throw new SQLException("Failed to insert a waypoint " + url);
|
throw new SQLException("Failed to insert a waypoint " + url);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a list of dirve ids.
|
|
||||||
*
|
|
||||||
* @param projection the projection
|
|
||||||
* @param where where
|
|
||||||
* @param selectionArgs selection args
|
|
||||||
*/
|
|
||||||
private String getDriveIds(String[] projection, String where, String[] selectionArgs) {
|
|
||||||
ArrayList<String> driveIds = new ArrayList<String>();
|
|
||||||
Cursor cursor = null;
|
|
||||||
try {
|
|
||||||
cursor = query(TracksColumns.CONTENT_URI, projection, where, selectionArgs, null);
|
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
|
||||||
int index = cursor.getColumnIndex(TracksColumns.DRIVEID);
|
|
||||||
do {
|
|
||||||
String driveId = cursor.getString(index);
|
|
||||||
if (driveId != null && !driveId.equals("")) {
|
|
||||||
driveIds.add(driveId);
|
|
||||||
}
|
|
||||||
} while (cursor.moveToNext());
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
if (cursor != null) {
|
|
||||||
cursor.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return TextUtils.join(";", driveIds);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -19,6 +19,7 @@ import com.google.android.apps.mytracks.content.ContentTypeIds;
|
|||||||
import com.google.android.apps.mytracks.util.ApiAdapterFactory;
|
import com.google.android.apps.mytracks.util.ApiAdapterFactory;
|
||||||
import com.google.android.maps.mytracks.R;
|
import com.google.android.maps.mytracks.R;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.SharedPreferences.Editor;
|
import android.content.SharedPreferences.Editor;
|
||||||
@@ -118,6 +119,7 @@ public class PreferenceBackupHelper {
|
|||||||
* @param preferences the shared preferences to edit
|
* @param preferences the shared preferences to edit
|
||||||
* @throws IOException if there are any errors while reading
|
* @throws IOException if there are any errors while reading
|
||||||
*/
|
*/
|
||||||
|
@SuppressLint("CommitPrefEdits")
|
||||||
public void importPreferences(DataInputStream reader, SharedPreferences preferences)
|
public void importPreferences(DataInputStream reader, SharedPreferences preferences)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
Editor editor = preferences.edit();
|
Editor editor = preferences.edit();
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.google.android.apps.mytracks.util;
|
package com.google.android.apps.mytracks.util;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.SharedPreferences.Editor;
|
import android.content.SharedPreferences.Editor;
|
||||||
@@ -94,6 +95,7 @@ public class EulaUtils {
|
|||||||
return sharedPreferences.getBoolean(key, defaultValue);
|
return sharedPreferences.getBoolean(key, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("CommitPrefEdits")
|
||||||
private static void setValue(Context context, String key, boolean value) {
|
private static void setValue(Context context, String key, boolean value) {
|
||||||
SharedPreferences sharedPreferences = context.getSharedPreferences(
|
SharedPreferences sharedPreferences = context.getSharedPreferences(
|
||||||
EULA_PREFERENCE_FILE, Context.MODE_PRIVATE);
|
EULA_PREFERENCE_FILE, Context.MODE_PRIVATE);
|
||||||
|
|||||||
+10
-11
@@ -46,7 +46,7 @@ public class ChartFragmentTest extends AndroidTestCase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the logic to get the incorrect values of sensor in
|
* Tests the logic to get the incorrect values of sensor in
|
||||||
* {@link ChartFragment#fillDataPoint(android.content.Context, Location, double[])}
|
* {@link ChartFragment#fillDataPoint(Location, double[])}
|
||||||
*/
|
*/
|
||||||
public void testFillDataPoint_sensorIncorrect() {
|
public void testFillDataPoint_sensorIncorrect() {
|
||||||
MyTracksLocation myTracksLocation = TrackStubUtils.createMyTracksLocation();
|
MyTracksLocation myTracksLocation = TrackStubUtils.createMyTracksLocation();
|
||||||
@@ -83,7 +83,7 @@ public class ChartFragmentTest extends AndroidTestCase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the logic to get the correct values of sensor in
|
* Tests the logic to get the correct values of sensor in
|
||||||
* {@link ChartFragment#fillDataPoint(android.content.Context, Location, double[])}.
|
* {@link ChartFragment#fillDataPoint(Location, double[])}.
|
||||||
*/
|
*/
|
||||||
public void testFillDataPoint_sensorCorrect() {
|
public void testFillDataPoint_sensorCorrect() {
|
||||||
MyTracksLocation myTracksLocation = TrackStubUtils.createMyTracksLocation();
|
MyTracksLocation myTracksLocation = TrackStubUtils.createMyTracksLocation();
|
||||||
@@ -118,7 +118,7 @@ public class ChartFragmentTest extends AndroidTestCase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the logic to get the value of metric Distance in
|
* Tests the logic to get the value of metric Distance in
|
||||||
* {@link ChartFragment#fillDataPoint(android.content.Context, Location, double[])}.
|
* {@link ChartFragment#fillDataPoint(Location, double[])}.
|
||||||
*/
|
*/
|
||||||
public void testFillDataPoint_distanceMetric() {
|
public void testFillDataPoint_distanceMetric() {
|
||||||
// By distance.
|
// By distance.
|
||||||
@@ -159,7 +159,7 @@ public class ChartFragmentTest extends AndroidTestCase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the logic to get the value of imperial Distance in
|
* Tests the logic to get the value of imperial Distance in
|
||||||
* {@link ChartFragment#fillDataPoint(android.content.Context, Location, double[])}.
|
* {@link ChartFragment#fillDataPoint(Location, double[])}.
|
||||||
*/
|
*/
|
||||||
public void testFillDataPoint_distanceImperial() {
|
public void testFillDataPoint_distanceImperial() {
|
||||||
// By distance.
|
// By distance.
|
||||||
@@ -204,7 +204,7 @@ public class ChartFragmentTest extends AndroidTestCase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the logic to get the values of time in
|
* Tests the logic to get the values of time in
|
||||||
* {@link ChartFragment#fillDataPoint(android.content.Context, Location, double[])}.
|
* {@link ChartFragment#fillDataPoint(Location, double[])}.
|
||||||
*/
|
*/
|
||||||
public void testFillDataPoint_time() {
|
public void testFillDataPoint_time() {
|
||||||
// By time
|
// By time
|
||||||
@@ -221,8 +221,8 @@ public class ChartFragmentTest extends AndroidTestCase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the logic to get the value of elevation in
|
* Tests the logic to get the value of elevation in
|
||||||
* {@link ChartFragment#fillDataPoint(android.content.Context,
|
* {@link ChartFragment#fillDataPoint(Location, double[])} by one and two
|
||||||
* Location, double[])} by one and two points.
|
* points.
|
||||||
*/
|
*/
|
||||||
public void testFillDataPoint_elevation() {
|
public void testFillDataPoint_elevation() {
|
||||||
MyTracksLocation myTracksLocation1 = TrackStubUtils.createMyTracksLocation();
|
MyTracksLocation myTracksLocation1 = TrackStubUtils.createMyTracksLocation();
|
||||||
@@ -247,10 +247,9 @@ public class ChartFragmentTest extends AndroidTestCase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the logic to get the value of speed in
|
* Tests the logic to get the value of speed in
|
||||||
* {@link ChartFragment#fillDataPoint(android.content.Context, Location, double[])}. In this test,
|
* {@link ChartFragment#fillDataPoint(Location, double[])}. In this test,
|
||||||
* firstly remove all points in memory,
|
* firstly remove all points in memory, and then fill in two points one by
|
||||||
* and then fill in two points one by one. The speed values of these points
|
* one. The speed values of these points are 129, 130.
|
||||||
* are 129, 130.
|
|
||||||
*/
|
*/
|
||||||
public void testFillDataPoint_speed() {
|
public void testFillDataPoint_speed() {
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user