mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-13 22:33:07 +02:00
@@ -1,63 +0,0 @@
|
|||||||
package de.dennisguse.opentracks.util;
|
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class ExportUtilsTest extends TestCase {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testIsExportFileExists_exists() {
|
|
||||||
// given
|
|
||||||
UUID uuid = UUID.randomUUID();
|
|
||||||
String format = "kmz";
|
|
||||||
List<String> fileNames = new ArrayList<>();
|
|
||||||
fileNames.add(uuid.toString().substring(0, 8) + "_name.gpx");
|
|
||||||
fileNames.add(uuid.toString().substring(0, 8) + "_other name name.kmz");
|
|
||||||
|
|
||||||
// when
|
|
||||||
boolean exists = ExportUtils.isExportFileExists(uuid, format, fileNames);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertTrue(exists);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testIsExportFileExists_not_exists1() {
|
|
||||||
// given
|
|
||||||
UUID uuid = UUID.randomUUID();
|
|
||||||
String format = "gpx";
|
|
||||||
List<String> fileNames = new ArrayList<>();
|
|
||||||
fileNames.add(UUID.randomUUID().toString().substring(0, 8) + "_name.gpx");
|
|
||||||
fileNames.add(UUID.randomUUID().toString().substring(0, 8) + "_other name name.gpx");
|
|
||||||
|
|
||||||
// when
|
|
||||||
boolean exists = ExportUtils.isExportFileExists(uuid, format, fileNames);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertFalse(exists);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testIsExportFileExists_not_exists2() {
|
|
||||||
// given
|
|
||||||
UUID uuid = UUID.randomUUID();
|
|
||||||
String format = "kmz";
|
|
||||||
List<String> fileNames = new ArrayList<>();
|
|
||||||
fileNames.add(uuid.toString().substring(0, 8) + "_name.gpx");
|
|
||||||
fileNames.add(UUID.randomUUID().toString().substring(0, 8) + "_other name name.gpx");
|
|
||||||
|
|
||||||
// when
|
|
||||||
boolean exists = ExportUtils.isExportFileExists(uuid, format, fileNames);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertFalse(exists);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -39,6 +39,7 @@ import de.dennisguse.opentracks.data.tables.TracksColumns;
|
|||||||
import de.dennisguse.opentracks.databinding.ExportActivityBinding;
|
import de.dennisguse.opentracks.databinding.ExportActivityBinding;
|
||||||
import de.dennisguse.opentracks.io.file.ErrorListDialog;
|
import de.dennisguse.opentracks.io.file.ErrorListDialog;
|
||||||
import de.dennisguse.opentracks.io.file.TrackFileFormat;
|
import de.dennisguse.opentracks.io.file.TrackFileFormat;
|
||||||
|
import de.dennisguse.opentracks.settings.PreferencesUtils;
|
||||||
import de.dennisguse.opentracks.util.ExportUtils;
|
import de.dennisguse.opentracks.util.ExportUtils;
|
||||||
import de.dennisguse.opentracks.util.FileUtils;
|
import de.dennisguse.opentracks.util.FileUtils;
|
||||||
|
|
||||||
@@ -234,7 +235,7 @@ public class ExportActivity extends FragmentActivity implements ExportServiceRes
|
|||||||
* @param conflictResolution conflict resolution to be applied if needed.
|
* @param conflictResolution conflict resolution to be applied if needed.
|
||||||
*/
|
*/
|
||||||
private void export(Track track, int conflictResolution) {
|
private void export(Track track, int conflictResolution) {
|
||||||
boolean fileExists = ExportUtils.isExportFileExists(track.getUuid(), trackFileFormat.getExtension(), directoryFiles);
|
boolean fileExists = exportFileExists(track);
|
||||||
|
|
||||||
if (fileExists && conflictResolution == CONFLICT_NONE) {
|
if (fileExists && conflictResolution == CONFLICT_NONE) {
|
||||||
conflict(track);
|
conflict(track);
|
||||||
@@ -250,6 +251,11 @@ public class ExportActivity extends FragmentActivity implements ExportServiceRes
|
|||||||
export(track, autoConflict);
|
export(track, autoConflict);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean exportFileExists(Track track) {
|
||||||
|
String filename = PreferencesUtils.getTrackFileformatGenerator().format(track, trackFileFormat);
|
||||||
|
return directoryFiles.stream().anyMatch(filename::equals);
|
||||||
|
}
|
||||||
|
|
||||||
private void setConflictVisibility(int visibility) {
|
private void setConflictVisibility(int visibility) {
|
||||||
viewBinding.exportProgressAlertIcon.setVisibility(visibility);
|
viewBinding.exportProgressAlertIcon.setVisibility(visibility);
|
||||||
viewBinding.exportProgressAlertMsg.setVisibility(visibility);
|
viewBinding.exportProgressAlertMsg.setVisibility(visibility);
|
||||||
@@ -315,7 +321,7 @@ public class ExportActivity extends FragmentActivity implements ExportServiceRes
|
|||||||
public void onExportSuccess(Track.Id trackId) {
|
public void onExportSuccess(Track.Id trackId) {
|
||||||
Track track = contentProviderUtils.getTrack(trackId);
|
Track track = contentProviderUtils.getTrack(trackId);
|
||||||
|
|
||||||
if (ExportUtils.isExportFileExists(track.getUuid(), trackFileFormat.getExtension(), directoryFiles)) {
|
if (exportFileExists(track)) {
|
||||||
trackExportOverwrittenCount++;
|
trackExportOverwrittenCount++;
|
||||||
} else {
|
} else {
|
||||||
trackExportSuccessCount++;
|
trackExportSuccessCount++;
|
||||||
|
|||||||
@@ -85,12 +85,6 @@ public class ExportUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isExportFileExists(UUID uuuid, String trackFileFormatExtension, List<String> filesName) {
|
|
||||||
String word = uuuid.toString().substring(0, 8) + ".*\\." + trackFileFormatExtension;
|
|
||||||
Pattern pattern = Pattern.compile(word);
|
|
||||||
return filesName.stream().anyMatch(w -> pattern.matcher(w).matches());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<String> getAllFiles(Context context, Uri directoryUri) {
|
public static List<String> getAllFiles(Context context, Uri directoryUri) {
|
||||||
List<String> fileNames = new ArrayList<>();
|
List<String> fileNames = new ArrayList<>();
|
||||||
final ContentResolver resolver = context.getContentResolver();
|
final ContentResolver resolver = context.getContentResolver();
|
||||||
|
|||||||
Reference in New Issue
Block a user