implements save to in share sheet (see #37)
This commit is contained in:
parent
9f8e932b5a
commit
ecc39a2502
4 changed files with 28 additions and 6 deletions
|
@ -56,6 +56,7 @@ import android.widget.Toast;
|
|||
|
||||
import org.osmdroid.config.Configuration;
|
||||
import org.y20k.trackbook.helpers.DialogHelper;
|
||||
import org.y20k.trackbook.helpers.ExportHelper;
|
||||
import org.y20k.trackbook.helpers.LogHelper;
|
||||
import org.y20k.trackbook.helpers.NightModeHelper;
|
||||
import org.y20k.trackbook.helpers.TrackbookKeys;
|
||||
|
@ -108,6 +109,9 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys {
|
|||
// check state of External Storage
|
||||
checkExternalStorageState();
|
||||
|
||||
// empty cache
|
||||
ExportHelper.emptyCacheDirectory(this);
|
||||
|
||||
// load saved state of app
|
||||
loadFloatingActionButtonState(this);
|
||||
|
||||
|
|
|
@ -77,8 +77,8 @@ public final class ExportHelper extends FileProvider implements TrackbookKeys {
|
|||
/* Creates Intent used to bring up an Android share sheet */
|
||||
public static Intent getGpxFileIntent(Context context, Track track) {
|
||||
|
||||
// get file for given track
|
||||
File gpxFile = createFile(track, getDownloadFolder()); // todo use cache folder
|
||||
// create file in Cache directory for given track
|
||||
File gpxFile = createFile(track, context.getCacheDir());
|
||||
|
||||
// get GPX string representation for given track
|
||||
String gpxString = createGpxString(track);
|
||||
|
@ -97,12 +97,23 @@ public final class ExportHelper extends FileProvider implements TrackbookKeys {
|
|||
Intent intent = new Intent();
|
||||
intent.setAction(Intent.ACTION_SEND);
|
||||
intent.setType("application/gpx+xml");
|
||||
intent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(context, authority, gpxFile));
|
||||
intent.setData(FileProvider.getUriForFile(context, authority, gpxFile));
|
||||
|
||||
return intent;
|
||||
}
|
||||
|
||||
|
||||
/* Empties the internal chache directory */
|
||||
public static void emptyCacheDirectory(Context context) {
|
||||
// todo implement a date check - delete only stuff that is a week old
|
||||
File[] cacheFiles = context.getCacheDir().listFiles();
|
||||
for (File file: cacheFiles) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Get "Download" folder */
|
||||
private static File getDownloadFolder() {
|
||||
File folder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
|
||||
|
@ -118,11 +129,12 @@ public final class ExportHelper extends FileProvider implements TrackbookKeys {
|
|||
private static File createFile(Track track, File folder) {
|
||||
Date recordingStart = track.getRecordingStart();
|
||||
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.US);
|
||||
|
||||
return new File(folder, dateFormat.format(recordingStart) + FILE_TYPE_GPX_EXTENSION);
|
||||
}
|
||||
|
||||
|
||||
/* Writes given GPX string to Download folder */
|
||||
/* Writes given GPX string to given file */
|
||||
private static boolean writeGpxToFile (String gpxString, File gpxFile) {
|
||||
// write track
|
||||
try (BufferedWriter bw = new BufferedWriter(new FileWriter(gpxFile))) {
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<paths>
|
||||
<external-path name="external_files" path="Download/"/>
|
||||
|
||||
<!-- Download in External Storage -->
|
||||
<external-path name="external_storage_downloads" path="Download/"/>
|
||||
|
||||
<!-- Cache in Internal Storage -->
|
||||
<cache-path name="external_storage_downloads" path="."/>
|
||||
|
||||
</paths>
|
|
@ -20,8 +20,8 @@ allprojects {
|
|||
}
|
||||
project.ext {
|
||||
applicationId = 'org.y20k.trackbook'
|
||||
versionCode = 25
|
||||
versionName = '1.1.9'
|
||||
versionCode = 26
|
||||
versionName = '1.1.10'
|
||||
minSdkVersion = 22
|
||||
compileSdkVersion = 27
|
||||
targetSdkVersion = 27
|
||||
|
|
Loading…
Reference in a new issue