clearing the map now saves the track
This commit is contained in:
parent
e1b01091cb
commit
e3793de0cc
2 changed files with 26 additions and 29 deletions
|
@ -50,6 +50,7 @@ import org.y20k.trackbook.core.Track;
|
||||||
import org.y20k.trackbook.helpers.LocationHelper;
|
import org.y20k.trackbook.helpers.LocationHelper;
|
||||||
import org.y20k.trackbook.helpers.LogHelper;
|
import org.y20k.trackbook.helpers.LogHelper;
|
||||||
import org.y20k.trackbook.helpers.MapHelper;
|
import org.y20k.trackbook.helpers.MapHelper;
|
||||||
|
import org.y20k.trackbook.helpers.StorageHelper;
|
||||||
import org.y20k.trackbook.helpers.TrackbookKeys;
|
import org.y20k.trackbook.helpers.TrackbookKeys;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -390,31 +391,14 @@ public class MainActivityMapFragment extends Fragment implements TrackbookKeys {
|
||||||
Toast.makeText(mActivity, mActivity.getString(R.string.toast_message_clear_map), Toast.LENGTH_LONG).show();
|
Toast.makeText(mActivity, mActivity.getString(R.string.toast_message_clear_map), Toast.LENGTH_LONG).show();
|
||||||
mMapView.getOverlays().remove(mTrackOverlay);
|
mMapView.getOverlays().remove(mTrackOverlay);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// save track object
|
||||||
|
StorageHelper storageHelper = new StorageHelper(mActivity);
|
||||||
|
storageHelper.saveTrack(mTrack);
|
||||||
|
|
||||||
// clear track object
|
// clear track object
|
||||||
mTrack = null;
|
mTrack = null;
|
||||||
|
|
||||||
// // Use the Builder class for convenient dialog construction
|
|
||||||
// AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
|
||||||
// builder.setTitle(R.string.dialog_clear_map_title)
|
|
||||||
// .setMessage(R.string.dialog_clear_map_message)
|
|
||||||
// .setPositiveButton(R.string.dialog_clear_map_okay, new DialogInterface.OnClickListener() {
|
|
||||||
// public void onClick(DialogInterface dialog, int id) {
|
|
||||||
// // clear map
|
|
||||||
// if (mTrackOverlay != null) {
|
|
||||||
// Toast.makeText(mActivity, mActivity.getString(R.string.toast_message_clear_map), Toast.LENGTH_LONG).show();
|
|
||||||
// mMapView.getOverlays().remove(mTrackOverlay);
|
|
||||||
// }
|
|
||||||
// // clear track object
|
|
||||||
// mTrack = null;
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
// .setNegativeButton(R.string.dialog_clear_map_cancel, new DialogInterface.OnClickListener() {
|
|
||||||
// public void onClick(DialogInterface dialog, int id) {
|
|
||||||
// // user clicked cancel - do nothing
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// // Create the AlertDialog object and return it
|
|
||||||
// builder.create().show();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ package org.y20k.trackbook.helpers;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.os.EnvironmentCompat;
|
import android.support.v4.os.EnvironmentCompat;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
@ -61,7 +62,7 @@ public class StorageHelper implements TrackbookKeys {
|
||||||
// store activity
|
// store activity
|
||||||
mActivity = activity;
|
mActivity = activity;
|
||||||
|
|
||||||
// set name sub-directory to "tracks"
|
// get "tracks" folder
|
||||||
mFolder = mActivity.getExternalFilesDir(mDirectoryName);
|
mFolder = mActivity.getExternalFilesDir(mDirectoryName);
|
||||||
// mFolder = getTracksDirectory();
|
// mFolder = getTracksDirectory();
|
||||||
|
|
||||||
|
@ -74,13 +75,17 @@ public class StorageHelper implements TrackbookKeys {
|
||||||
|
|
||||||
|
|
||||||
/* Saves track object to file */
|
/* Saves track object to file */
|
||||||
public boolean saveTrack(Track track) {
|
public boolean saveTrack(@Nullable Track track) {
|
||||||
|
|
||||||
Date recordingStart = track.getRecordingStart();
|
// get "tracks" folder
|
||||||
|
mFolder = mActivity.getExternalFilesDir(mDirectoryName);
|
||||||
|
|
||||||
if (mFolder.exists() && mFolder.isDirectory() && mFolder.canWrite() && recordingStart != null) {
|
Date recordingStart = null;
|
||||||
File lastTrackFile = getMostCurrentTrack();
|
if (track != null) {
|
||||||
|
recordingStart = track.getRecordingStart();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mFolder.exists() && mFolder.isDirectory() && mFolder.canWrite() && recordingStart != null && track != null) {
|
||||||
// construct filename from track recording date
|
// construct filename from track recording date
|
||||||
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.US);
|
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.US);
|
||||||
String fileName = dateFormat.format(recordingStart) + mFileExtension;
|
String fileName = dateFormat.format(recordingStart) + mFileExtension;
|
||||||
|
@ -99,8 +104,8 @@ public class StorageHelper implements TrackbookKeys {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if write was successful delete last file
|
// if write was successful delete old track files
|
||||||
lastTrackFile.delete();
|
deleteOldTracks();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -141,6 +146,10 @@ public class StorageHelper implements TrackbookKeys {
|
||||||
|
|
||||||
/* Gets most current track from directory */
|
/* Gets most current track from directory */
|
||||||
public File getMostCurrentTrack() {
|
public File getMostCurrentTrack() {
|
||||||
|
|
||||||
|
// get "tracks" folder
|
||||||
|
mFolder = mActivity.getExternalFilesDir(mDirectoryName);
|
||||||
|
|
||||||
if (mFolder != null && mFolder.isDirectory()) {
|
if (mFolder != null && mFolder.isDirectory()) {
|
||||||
// get files and sort them
|
// get files and sort them
|
||||||
File[] files = mFolder.listFiles();
|
File[] files = mFolder.listFiles();
|
||||||
|
@ -155,6 +164,10 @@ public class StorageHelper implements TrackbookKeys {
|
||||||
|
|
||||||
/* Gets the last track from directory */
|
/* Gets the last track from directory */
|
||||||
private void deleteOldTracks() {
|
private void deleteOldTracks() {
|
||||||
|
|
||||||
|
// get "tracks" folder
|
||||||
|
mFolder = mActivity.getExternalFilesDir(mDirectoryName);
|
||||||
|
|
||||||
if (mFolder != null && mFolder.isDirectory()) {
|
if (mFolder != null && mFolder.isDirectory()) {
|
||||||
LogHelper.v(LOG_TAG, "Deleting old Track files.");
|
LogHelper.v(LOG_TAG, "Deleting old Track files.");
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue