mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 17:43:06 +02:00
Delete photo when marker or track is deleted
This commit is contained in:
+4
-2
@@ -88,9 +88,11 @@ public class DeleteMarkerDialogFragment extends DialogFragment {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MyTracksProviderUtils myTracksProviderUtils = MyTracksProviderUtils.Factory.get(
|
||||
fragmentActivity);
|
||||
for (long markerId : markerIds) {
|
||||
MyTracksProviderUtils.Factory.get(fragmentActivity)
|
||||
.deleteWaypoint(markerId, new DescriptionGeneratorImpl(fragmentActivity));
|
||||
myTracksProviderUtils.deleteWaypoint(
|
||||
markerId, new DescriptionGeneratorImpl(fragmentActivity));
|
||||
}
|
||||
caller.onDeleteMarkerDone();
|
||||
}
|
||||
|
||||
+39
@@ -19,6 +19,7 @@ package com.google.android.apps.mytracks.content;
|
||||
import com.google.android.apps.mytracks.content.Sensor.SensorDataSet;
|
||||
import com.google.android.apps.mytracks.content.Waypoint.WaypointType;
|
||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
||||
import com.google.android.apps.mytracks.util.FileUtils;
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
@@ -28,6 +29,7 @@ import android.location.Location;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
@@ -180,6 +182,9 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
||||
contentResolver.delete(WaypointsColumns.CONTENT_URI, null, null);
|
||||
// Delete tracks last since it triggers a database vaccum call
|
||||
contentResolver.delete(TracksColumns.CONTENT_URI, null, null);
|
||||
|
||||
File dir = new File(FileUtils.getPath(FileUtils.PICTURES_DIR));
|
||||
deleteDirectoryRecurse(dir);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -208,6 +213,26 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
||||
}
|
||||
contentResolver.delete(WaypointsColumns.CONTENT_URI, WaypointsColumns.TRACKID + "=?",
|
||||
new String[] { Long.toString(trackId) });
|
||||
|
||||
File dir = new File(
|
||||
FileUtils.getPath(FileUtils.PICTURES_DIR, Long.toString(trackId)));
|
||||
deleteDirectoryRecurse(dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the directory recursively.
|
||||
*
|
||||
* @param dir the directory
|
||||
*/
|
||||
private void deleteDirectoryRecurse(File dir) {
|
||||
if (FileUtils.isDirectory(dir)) {
|
||||
for (File child : dir.listFiles()) {
|
||||
deleteDirectoryRecurse(child);
|
||||
}
|
||||
}
|
||||
if (dir.exists()) {
|
||||
dir.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -499,6 +524,20 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (waypoint != null) {
|
||||
String photoUrl = waypoint.getPhotoUrl();
|
||||
if (photoUrl != null && !photoUrl.equals("")) {
|
||||
Uri uri = Uri.parse(photoUrl);
|
||||
File file = new File(uri.getPath());
|
||||
if (file.exists()) {
|
||||
File parent = file.getParentFile();
|
||||
file.delete();
|
||||
if (parent.listFiles().length == 0) {
|
||||
parent.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
contentResolver.delete(WaypointsColumns.CONTENT_URI, WaypointsColumns._ID + "=?",
|
||||
new String[] { Long.toString(waypointId) });
|
||||
}
|
||||
|
||||
-6
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package com.google.android.apps.mytracks.util;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
import android.os.Environment;
|
||||
|
||||
import java.io.File;
|
||||
@@ -43,14 +41,12 @@ public class FileUtils {
|
||||
/**
|
||||
* The My Tracks external storage directory.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
static final String SDCARD_TOP_DIR = "MyTracks";
|
||||
|
||||
/**
|
||||
* The maximum FAT32 path length. See the FAT32 spec at
|
||||
* http://msdn.microsoft.com/en-us/windows/hardware/gg463080
|
||||
*/
|
||||
@VisibleForTesting
|
||||
static final int MAX_FAT32_PATH_LENGTH = 260;
|
||||
|
||||
/**
|
||||
@@ -206,7 +202,6 @@ public class FileUtils {
|
||||
*
|
||||
* @param name name
|
||||
*/
|
||||
@VisibleForTesting
|
||||
static String sanitizeFileName(String name) {
|
||||
StringBuffer buffer = new StringBuffer(name.length());
|
||||
for (int i = 0; i < name.length(); i++) {
|
||||
@@ -266,7 +261,6 @@ public class FileUtils {
|
||||
* @param name name
|
||||
* @param suffix suffix
|
||||
*/
|
||||
@VisibleForTesting
|
||||
static String truncateFileName(File directory, String name, String suffix) {
|
||||
// 1 at the end accounts for the FAT32 filename trailing NUL character
|
||||
int requiredLength = directory.getPath().length() + suffix.length() + 1;
|
||||
Reference in New Issue
Block a user