Save track name inside gpx
This commit is contained in:
parent
c6094c456f
commit
81c6a8f437
1 changed files with 35 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
package net.osmand;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
@ -8,6 +9,8 @@ import androidx.fragment.app.Fragment;
|
|||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
import net.osmand.GPXUtilities.GPXFile;
|
||||
import net.osmand.GPXUtilities.Metadata;
|
||||
import net.osmand.plus.GpxSelectionHelper;
|
||||
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
|
@ -109,6 +112,8 @@ public class FileUtils {
|
|||
selected.getGpxFile().path = dest.getAbsolutePath();
|
||||
helper.updateSelectedGpxFile(selected);
|
||||
}
|
||||
RenameGpxAsyncTask renameGpxAsyncTask = new RenameGpxAsyncTask(app, dest);
|
||||
renameGpxAsyncTask.execute();
|
||||
return dest;
|
||||
}
|
||||
return null;
|
||||
|
@ -196,4 +201,34 @@ public class FileUtils {
|
|||
public interface RenameCallback {
|
||||
void renamedTo(File file);
|
||||
}
|
||||
|
||||
private static class RenameGpxAsyncTask extends AsyncTask<Void, Void, Exception> {
|
||||
|
||||
private OsmandApplication app;
|
||||
private File file;
|
||||
|
||||
private RenameGpxAsyncTask(@NonNull OsmandApplication app, @NonNull File file) {
|
||||
this.app = app;
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Exception doInBackground(Void... voids) {
|
||||
GpxSelectionHelper helper = app.getSelectedGpxHelper();
|
||||
SelectedGpxFile selected = helper.getSelectedFileByPath(file.getAbsolutePath());
|
||||
|
||||
GPXFile gpxFile;
|
||||
if (selected != null && selected.getGpxFile() != null) {
|
||||
gpxFile = selected.getGpxFile();
|
||||
} else {
|
||||
gpxFile = GPXUtilities.loadGPXFile(file);
|
||||
}
|
||||
if (gpxFile.metadata == null) {
|
||||
gpxFile.metadata = new Metadata();
|
||||
}
|
||||
gpxFile.metadata.name = Algorithms.getFileNameWithoutExtension(file.getName());
|
||||
|
||||
return GPXUtilities.writeGpxFile(file, gpxFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue