mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 17:43:06 +02:00
Code cleanup: cleanup callers of FileUtils.buildUniqueFileName
This commit is contained in:
@@ -1008,10 +1008,6 @@ limitations under the License.
|
||||
translation_description="When deleting multiple markers, the confirmation message.">
|
||||
All markers for this track will be permanently deleted from the device.
|
||||
</string>
|
||||
<string name="marker_insert_photo_error"
|
||||
translation_description="The error message when unable to insert a photo marker.">
|
||||
Unable to insert a photo marker. Try again.
|
||||
</string>
|
||||
<string name="marker_label_end"
|
||||
translation_description="When inserting a marker to indicate the end of a track, the marker's
|
||||
name. E.g., 'track_name (End)'.
|
||||
|
||||
@@ -55,7 +55,6 @@ import android.os.Parcelable;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.v4.app.TaskStackBuilder;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
@@ -66,7 +65,6 @@ import android.widget.TabHost.TabSpec;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
@@ -391,32 +389,22 @@ public class TrackDetailActivity extends AbstractSendToGoogleActivity implements
|
||||
startActivity(intent);
|
||||
return true;
|
||||
case R.id.track_detail_insert_photo:
|
||||
try {
|
||||
if (!FileUtils.isExternalStorageWriteable()) {
|
||||
Toast.makeText(this, R.string.external_storage_not_writable, Toast.LENGTH_LONG).show();
|
||||
return false;
|
||||
}
|
||||
|
||||
File dir = new File(
|
||||
FileUtils.getDirectoryPath(FileUtils.PICTURES_DIR, Long.toString(trackId)));
|
||||
FileUtils.ensureDirectoryExists(dir);
|
||||
|
||||
String fileName = SimpleDateFormat.getDateTimeInstance().format(new Date());
|
||||
File file = new File(dir, FileUtils.buildUniqueFileName(dir, fileName, "jpeg"));
|
||||
|
||||
if (file.exists()) {
|
||||
Toast.makeText(this, R.string.marker_insert_photo_error, Toast.LENGTH_LONG).show();
|
||||
return false;
|
||||
}
|
||||
file.createNewFile();
|
||||
photoUri = Uri.fromFile(file);
|
||||
intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE).putExtra(
|
||||
MediaStore.EXTRA_OUTPUT, photoUri);
|
||||
startActivityForResult(intent, CAMERA_REQUEST_CODE);
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Unable to insert photo marker", e);
|
||||
if (!FileUtils.isExternalStorageWriteable()) {
|
||||
Toast.makeText(this, R.string.external_storage_not_writable, Toast.LENGTH_LONG).show();
|
||||
return false;
|
||||
}
|
||||
|
||||
File dir = new File(
|
||||
FileUtils.getDirectoryPath(FileUtils.PICTURES_DIR, Long.toString(trackId)));
|
||||
FileUtils.ensureDirectoryExists(dir);
|
||||
|
||||
String fileName = SimpleDateFormat.getDateTimeInstance().format(new Date());
|
||||
File file = new File(dir, FileUtils.buildUniqueFileName(dir, fileName, "jpeg"));
|
||||
|
||||
photoUri = Uri.fromFile(file);
|
||||
intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE).putExtra(
|
||||
MediaStore.EXTRA_OUTPUT, photoUri);
|
||||
startActivityForResult(intent, CAMERA_REQUEST_CODE);
|
||||
return true;
|
||||
case R.id.track_detail_play:
|
||||
playTrack(new long[] {trackId});
|
||||
|
||||
@@ -183,17 +183,10 @@ public class SaveAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
||||
if (tracks.length == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Track track = tracks[0];
|
||||
boolean useKmz = trackFileFormat == TrackFileFormat.KML && !playTrack;
|
||||
String extension = useKmz ? KmzTrackExporter.KMZ_EXTENSION : trackFileFormat.getExtension();
|
||||
|
||||
// Make sure the file doesn't exist yet (possibly by changing the filename)
|
||||
String fileName = FileUtils.buildUniqueFileName(directory, track.getName(), extension);
|
||||
if (fileName == null) {
|
||||
Log.d(TAG, "Unable to get a unique filename for " + track.getName());
|
||||
return false;
|
||||
}
|
||||
|
||||
FileTrackExporter fileTrackExporter = new FileTrackExporter(myTracksProviderUtils, tracks,
|
||||
trackFileFormat.newTrackWriter(context, playTrack), new TrackExporterListener() {
|
||||
|
||||
@@ -212,6 +205,7 @@ public class SaveAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
||||
trackExporter = useKmz ? new KmzTrackExporter(myTracksProviderUtils, fileTrackExporter, tracks)
|
||||
: fileTrackExporter;
|
||||
|
||||
String fileName = FileUtils.buildUniqueFileName(directory, track.getName(), extension);
|
||||
File file = new File(directory, fileName);
|
||||
FileOutputStream fileOutputStream = null;
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user