addresses a crash when trying to save an empty recording (see #21)

This commit is contained in:
y20k 2018-09-17 20:07:33 +02:00
parent b44e39667a
commit 2f39017b76

View file

@ -309,11 +309,17 @@ public class MainActivityMapFragment extends Fragment implements TrackbookKeys {
switch(requestCode) { switch(requestCode) {
case RESULT_SAVE_DIALOG: case RESULT_SAVE_DIALOG:
if (resultCode == Activity.RESULT_OK) { if (resultCode == Activity.RESULT_OK) {
// user chose SAVE - clear map AND save track // user chose SAVE
if (mTrack.getSize() > 0) {
// Track is not empty - clear map AND save track
clearMap(true); clearMap(true);
// FloatingActionButton state is already being handled in MainActivity // FloatingActionButton state is already being handled in MainActivity
((MainActivity)mActivity).onFloatingActionButtonResult(requestCode, resultCode); ((MainActivity)mActivity).onFloatingActionButtonResult(requestCode, resultCode);
LogHelper.v(LOG_TAG, "Save dialog result: SAVE"); LogHelper.v(LOG_TAG, "Save dialog result: SAVE");
} else {
// track is empty
handleEmptyRecordingSaveRequest();
}
} else if (resultCode == Activity.RESULT_CANCELED){ } else if (resultCode == Activity.RESULT_CANCELED){
LogHelper.v(LOG_TAG, "Save dialog result: CANCEL"); LogHelper.v(LOG_TAG, "Save dialog result: CANCEL");
} }
@ -446,6 +452,16 @@ public class MainActivityMapFragment extends Fragment implements TrackbookKeys {
} }
/* Handles case when user chose to save recording with zero waypoints */ // todo implement
private void handleEmptyRecordingSaveRequest() {
// todo ask user what to do
Toast.makeText(mActivity, " Error. Empty recording. Clearing Map.", Toast.LENGTH_LONG).show(); // todo user alert (clear track?)
// todo change (solution for now: insta-clear)
clearMap(false);
((MainActivity)mActivity).onFloatingActionButtonResult(RESULT_CLEAR_DIALOG, Activity.RESULT_OK);
}
/* Start preliminary tracking for map */ /* Start preliminary tracking for map */
private void startPreliminaryTracking() { private void startPreliminaryTracking() {
if (mLocationSystemSetting && !mLocalTrackerRunning) { if (mLocationSystemSetting && !mLocalTrackerRunning) {