mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-08 04:13:06 +02:00
@@ -33,6 +33,7 @@ import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
||||
import de.dennisguse.opentracks.BuildConfig;
|
||||
import de.dennisguse.opentracks.content.data.Track;
|
||||
|
||||
/**
|
||||
* Utilities for dealing with files.
|
||||
@@ -63,8 +64,8 @@ public class FileUtils {
|
||||
return context.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
|
||||
}
|
||||
|
||||
public static File getPhotoDir(Context context, long trackId) {
|
||||
File photoDirectory = new File(getPhotoDir(context), "" + trackId);
|
||||
public static File getPhotoDir(Context context, Track.Id trackId) {
|
||||
File photoDirectory = new File(getPhotoDir(context), "" + trackId.getId());
|
||||
photoDirectory.mkdirs();
|
||||
return photoDirectory;
|
||||
}
|
||||
@@ -223,7 +224,7 @@ public class FileUtils {
|
||||
* @param context the context.
|
||||
* @param trackId the track id.
|
||||
*/
|
||||
public static String getImageUrl(Context context, long trackId) {
|
||||
public static String getImageUrl(Context context, Track.Id trackId) {
|
||||
File dir = FileUtils.getPhotoDir(context, trackId);
|
||||
|
||||
String fileName = SimpleDateFormat.getDateTimeInstance().format(new Date());
|
||||
@@ -267,7 +268,7 @@ public class FileUtils {
|
||||
* @param uri the uri to check.
|
||||
* @return File object or null.
|
||||
*/
|
||||
public static File getPhotoFileIfExists(Context context, long trackId, Uri uri) {
|
||||
public static File getPhotoFileIfExists(Context context, Track.Id trackId, Uri uri) {
|
||||
if (uri == null) {
|
||||
Log.w(TAG, "URI object is null.");
|
||||
return null;
|
||||
|
||||
@@ -8,7 +8,10 @@ import android.net.Uri;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import de.dennisguse.opentracks.content.data.Track;
|
||||
import de.dennisguse.opentracks.content.data.TrackPointsColumns;
|
||||
import de.dennisguse.opentracks.content.data.TracksColumns;
|
||||
import de.dennisguse.opentracks.content.data.WaypointsColumns;
|
||||
@@ -42,7 +45,7 @@ public class IntentDashboardUtils {
|
||||
* @param context the context
|
||||
* @param trackIds the track ids
|
||||
*/
|
||||
public static void startDashboard(Context context, long[] trackIds, boolean isRecording) {
|
||||
public static void startDashboard(Context context, boolean isRecording, Track.Id... trackIds) {
|
||||
if (trackIds.length == 0) {
|
||||
return;
|
||||
}
|
||||
@@ -73,14 +76,14 @@ public class IntentDashboardUtils {
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
public static long[] extractTrackIdsFromIntent(@NonNull Intent intent) {
|
||||
public static Set<Track.Id> extractTrackIdsFromIntent(@NonNull Intent intent) {
|
||||
final ArrayList<Uri> uris = intent.getParcelableArrayListExtra(ACTION_DASHBOARD_PAYLOAD);
|
||||
final Uri tracksUri = uris.get(TRACK_URI_INDEX);
|
||||
|
||||
String[] trackIdsString = ContentProviderUtils.parseTrackIdsFromUri(tracksUri);
|
||||
long[] trackIds = new long[trackIdsString.length];
|
||||
for (int i = 0; i < trackIdsString.length; i++) {
|
||||
trackIds[i] = Long.parseLong(trackIdsString[i]);
|
||||
Set<Track.Id> trackIds = new HashSet<>(trackIdsString.length);
|
||||
for (String s : trackIdsString) {
|
||||
trackIds.add(new Track.Id(Long.parseLong(s)));
|
||||
}
|
||||
|
||||
return trackIds;
|
||||
|
||||
@@ -67,7 +67,7 @@ public class IntentUtils {
|
||||
* @param context the context
|
||||
* @param trackIds the track ids
|
||||
*/
|
||||
public static Intent newShareFileIntent(Context context, long[] trackIds) {
|
||||
public static Intent newShareFileIntent(Context context, Track.Id... trackIds) {
|
||||
if (trackIds.length == 0) {
|
||||
throw new RuntimeException("Need to share at least one track.");
|
||||
}
|
||||
@@ -84,14 +84,14 @@ public class IntentUtils {
|
||||
String mime = "";
|
||||
|
||||
ArrayList<Uri> uris = new ArrayList<>();
|
||||
for (long trackId : trackIds) {
|
||||
for (Track.Id trackId : trackIds) {
|
||||
Track track = contentProviderUtils.getTrack(trackId);
|
||||
if (track == null) {
|
||||
Log.e(TAG, "TrackId " + trackId + " could not be resolved.");
|
||||
continue;
|
||||
}
|
||||
|
||||
Pair<Uri, String> uriAndMime = ShareContentProvider.createURI(new long[]{trackId}, track.getName(), PreferencesUtils.getExportTrackFileFormat(context));
|
||||
Pair<Uri, String> uriAndMime = ShareContentProvider.createURI(trackId, track.getName(), PreferencesUtils.getExportTrackFileFormat(context));
|
||||
uris.add(uriAndMime.first);
|
||||
mime = uriAndMime.second;
|
||||
}
|
||||
@@ -154,7 +154,6 @@ public class IntentUtils {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sends a take picture request to the camera app.
|
||||
* The picture is then stored in the track's folder.
|
||||
@@ -162,7 +161,7 @@ public class IntentUtils {
|
||||
* @param context the context
|
||||
* @param trackId the track id
|
||||
*/
|
||||
public static Pair<Intent, Uri> createTakePictureIntent(Context context, long trackId) {
|
||||
public static Pair<Intent, Uri> createTakePictureIntent(Context context, Track.Id trackId) {
|
||||
File dir = FileUtils.getPhotoDir(context, trackId);
|
||||
|
||||
String fileName = SimpleDateFormat.getDateTimeInstance().format(new Date());
|
||||
|
||||
@@ -24,6 +24,7 @@ import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import de.dennisguse.opentracks.R;
|
||||
import de.dennisguse.opentracks.content.data.Track;
|
||||
import de.dennisguse.opentracks.io.file.TrackFileFormat;
|
||||
|
||||
/**
|
||||
@@ -54,9 +55,9 @@ public class PreferencesUtils {
|
||||
public static final long RECORDING_TRACK_ID_DEFAULT = -1L;
|
||||
|
||||
@Deprecated //Use the TrackRecordingService
|
||||
public static long getRecordingTrackId(Context context) {
|
||||
public static Track.Id getRecordingTrackId(Context context) {
|
||||
SharedPreferences sharedPreferences = getSharedPreferences(context);
|
||||
return sharedPreferences.getLong(getKey(context, R.string.recording_track_id_key), RECORDING_TRACK_ID_DEFAULT);
|
||||
return new Track.Id(sharedPreferences.getLong(getKey(context, R.string.recording_track_id_key), RECORDING_TRACK_ID_DEFAULT));
|
||||
}
|
||||
|
||||
public static String getDefaultActivity(Context context) {
|
||||
@@ -347,14 +348,13 @@ public class PreferencesUtils {
|
||||
|
||||
@Deprecated //Use TrackRecordingService
|
||||
public static boolean isRecording(Context context) {
|
||||
long recordingTrackId = getRecordingTrackId(context);
|
||||
return isRecording(recordingTrackId);
|
||||
return isRecording(getRecordingTrackId(context));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
//TODO Method is very misleading: it only checks if the provided trackId not the default value (i.e., not recording).
|
||||
public static boolean isRecording(long recordingTrackId) {
|
||||
return recordingTrackId != RECORDING_TRACK_ID_DEFAULT;
|
||||
public static boolean isRecording(Track.Id recordingTrackId) {
|
||||
return recordingTrackId == null || recordingTrackId.getId() != RECORDING_TRACK_ID_DEFAULT;
|
||||
}
|
||||
|
||||
public static void resetPreferences(Context context, boolean readAgain) {
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.Locale;
|
||||
|
||||
import de.dennisguse.opentracks.R;
|
||||
import de.dennisguse.opentracks.content.data.Track;
|
||||
|
||||
/**
|
||||
* Utilities for track name.
|
||||
@@ -46,7 +47,7 @@ public class TrackNameUtils {
|
||||
* @param trackId the track id
|
||||
* @param startTime the track start time
|
||||
*/
|
||||
public static String getTrackName(Context context, long trackId, long startTime) {
|
||||
public static String getTrackName(Context context, Track.Id trackId, long startTime) {
|
||||
String trackName = PreferencesUtils.getString(context, R.string.track_name_key, context.getString(R.string.track_name_default));
|
||||
|
||||
if (trackName.equals(context.getString(R.string.settings_recording_track_name_date_local_value))) {
|
||||
@@ -54,7 +55,7 @@ public class TrackNameUtils {
|
||||
} else if (trackName.equals(context.getString(R.string.settings_recording_track_name_date_iso_8601_value))) {
|
||||
return new SimpleDateFormat(ISO_8601_FORMAT, Locale.US).format(startTime);
|
||||
} else {
|
||||
return context.getString(R.string.track_name_format, trackId);
|
||||
return context.getString(R.string.track_name_format, trackId.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user