Found a (or the) duration bug (#5) <- duration was not parcelled correctly -- plus: fixed weird last track loading behavior

This commit is contained in:
y20k 2017-01-10 15:57:03 +01:00
parent 702a2ecd05
commit 892d41a5b3
8 changed files with 44 additions and 32 deletions

View file

@ -479,7 +479,7 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys {
// display and update track tab // display and update track tab
mSelectedTab = FRAGMENT_ID_TRACK; mSelectedTab = FRAGMENT_ID_TRACK;
mViewPager.setCurrentItem(mSelectedTab); mViewPager.setCurrentItem(mSelectedTab);
mMainActivityTrackFragment.refreshTrackView(); // mMainActivityTrackFragment.refreshTrackView();
// dismiss notification // dismiss notification
NotificationHelper.stop(); NotificationHelper.stop();
@ -490,8 +490,6 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys {
// update Floating Action Button icon // update Floating Action Button icon
mFloatingActionButtonState = FAB_STATE_DEFAULT; mFloatingActionButtonState = FAB_STATE_DEFAULT;
setFloatingActionButtonState(); setFloatingActionButtonState();
Toast.makeText(this, getString(R.string.toast_message_track_save), Toast.LENGTH_LONG).show();
} }

View file

@ -407,8 +407,10 @@ public class MainActivityMapFragment extends Fragment implements TrackbookKeys {
saveTrackAsyncHelper.execute(); saveTrackAsyncHelper.execute();
Toast.makeText(mActivity, mActivity.getString(R.string.toast_message_save_track), Toast.LENGTH_LONG).show(); Toast.makeText(mActivity, mActivity.getString(R.string.toast_message_save_track), Toast.LENGTH_LONG).show();
} else { } else {
// clear track object // clear track object and delete temp file
mTrack = null; mTrack = null;
StorageHelper storageHelper = new StorageHelper(mActivity, FILETYPE_TEMP);
storageHelper.deleteTempFile();
} }
// // save track state // // save track state

View file

@ -76,7 +76,6 @@ public class MainActivityTrackFragment extends Fragment implements TrackbookKeys
private BroadcastReceiver mTrackSavedReceiver; private BroadcastReceiver mTrackSavedReceiver;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -87,17 +86,20 @@ public class MainActivityTrackFragment extends Fragment implements TrackbookKeys
// store activity // store activity
mActivity = getActivity(); mActivity = getActivity();
// create receiver for finished save operation // listen for finished save operation
mTrackSavedReceiver = new BroadcastReceiver() { mTrackSavedReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
if (intent.hasExtra(EXTRA_SAVE_FINISHED) && intent.getBooleanExtra(EXTRA_SAVE_FINISHED, false)) { if (intent.hasExtra(EXTRA_SAVE_FINISHED) && intent.getBooleanExtra(EXTRA_SAVE_FINISHED, false)) {
LogHelper.v(LOG_TAG, "Save operation detected. Start loading the new track.");
// load track and display map and statistics // load track and display map and statistics
LoadTrackAsyncHelper loadTrackAsyncHelper = new LoadTrackAsyncHelper(); LoadTrackAsyncHelper loadTrackAsyncHelper = new LoadTrackAsyncHelper();
loadTrackAsyncHelper.execute(); loadTrackAsyncHelper.execute();
} }
} }
}; };
IntentFilter trackSavedReceiverIntentFilter = new IntentFilter(ACTION_TRACK_SAVE);
LocalBroadcastManager.getInstance(mActivity).registerReceiver(mTrackSavedReceiver, trackSavedReceiverIntentFilter);
} }
@ -139,7 +141,7 @@ public class MainActivityTrackFragment extends Fragment implements TrackbookKeys
// get views // get views
View mStaticticsView = mRootView.findViewById(R.id.statistics_view); View mStatisticsView = mRootView.findViewById(R.id.statistics_view);
mDistanceView = (TextView) mRootView.findViewById(R.id.statistics_data_distance); mDistanceView = (TextView) mRootView.findViewById(R.id.statistics_data_distance);
mStepsView = (TextView) mRootView.findViewById(R.id.statistics_data_steps); mStepsView = (TextView) mRootView.findViewById(R.id.statistics_data_steps);
mWaypointsView = (TextView) mRootView.findViewById(R.id.statistics_data_waypoints); mWaypointsView = (TextView) mRootView.findViewById(R.id.statistics_data_waypoints);
@ -148,7 +150,11 @@ public class MainActivityTrackFragment extends Fragment implements TrackbookKeys
mRecordingStopView = (TextView) mRootView.findViewById(R.id.statistics_data_recording_stop); mRecordingStopView = (TextView) mRootView.findViewById(R.id.statistics_data_recording_stop);
View mStatisticsSheet = mRootView.findViewById(R.id.statistics_sheet); View mStatisticsSheet = mRootView.findViewById(R.id.statistics_sheet);
if (mTrack == null) { if (savedInstanceState != null) {
// get track from saved instance and display map and statistics
mTrack = savedInstanceState.getParcelable(INSTANCE_TRACK_TRACK_MAP);
displayTrack();
} else if (mTrack == null) {
// load track and display map and statistics // load track and display map and statistics
LoadTrackAsyncHelper loadTrackAsyncHelper = new LoadTrackAsyncHelper(); LoadTrackAsyncHelper loadTrackAsyncHelper = new LoadTrackAsyncHelper();
loadTrackAsyncHelper.execute(); loadTrackAsyncHelper.execute();
@ -187,7 +193,7 @@ public class MainActivityTrackFragment extends Fragment implements TrackbookKeys
}); });
// react to tap on sheet heading // react to tap on sheet heading
mStaticticsView.setOnClickListener(new View.OnClickListener() { mStatisticsView.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
LogHelper.v(LOG_TAG,"Statistics view tapped"); LogHelper.v(LOG_TAG,"Statistics view tapped");
@ -208,7 +214,6 @@ public class MainActivityTrackFragment extends Fragment implements TrackbookKeys
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
LogHelper.v(LOG_TAG, "TrackFragment: onResume called."); LogHelper.v(LOG_TAG, "TrackFragment: onResume called.");
} }
@ -228,8 +233,18 @@ public class MainActivityTrackFragment extends Fragment implements TrackbookKeys
} }
@Override
public void onDestroy() {
super.onDestroy();
// remove listener
LocalBroadcastManager.getInstance(mActivity).unregisterReceiver(mTrackSavedReceiver);
}
@Override @Override
public void onSaveInstanceState(Bundle outState) { public void onSaveInstanceState(Bundle outState) {
LogHelper.v(LOG_TAG, "TrackFragment: onSaveInstanceState called.");
outState.putDouble(INSTANCE_LATITUDE_TRACK_MAP, mMapView.getMapCenter().getLatitude()); outState.putDouble(INSTANCE_LATITUDE_TRACK_MAP, mMapView.getMapCenter().getLatitude());
outState.putDouble(INSTANCE_LONGITUDE_TRACK_MAP, mMapView.getMapCenter().getLongitude()); outState.putDouble(INSTANCE_LONGITUDE_TRACK_MAP, mMapView.getMapCenter().getLongitude());
outState.putInt(INSTANCE_ZOOM_LEVEL_TRACK_MAP, mMapView.getZoomLevel()); outState.putInt(INSTANCE_ZOOM_LEVEL_TRACK_MAP, mMapView.getZoomLevel());
@ -238,18 +253,18 @@ public class MainActivityTrackFragment extends Fragment implements TrackbookKeys
} }
/* Removes current track display */ // /* Removes current track display */
public void refreshTrackView() { // public void refreshTrackView() {
//
// remove previous track // // remove previous track
if (mMapView != null && mTrackOverlay != null) { // if (mMapView != null && mTrackOverlay != null) {
mMapView.getOverlays().remove(mTrackOverlay); // mMapView.getOverlays().remove(mTrackOverlay);
} // }
//
// listen for finished save // // listen for finished save
IntentFilter trackSavedReceiverIntentFilter = new IntentFilter(ACTION_TRACK_SAVE); // IntentFilter trackSavedReceiverIntentFilter = new IntentFilter(ACTION_TRACK_SAVE);
LocalBroadcastManager.getInstance(mActivity).registerReceiver(mTrackSavedReceiver, trackSavedReceiverIntentFilter); // LocalBroadcastManager.getInstance(mActivity).registerReceiver(mTrackSavedReceiver, trackSavedReceiverIntentFilter);
} // }
/* Displays map and statistics for track */ /* Displays map and statistics for track */
@ -283,8 +298,6 @@ public class MainActivityTrackFragment extends Fragment implements TrackbookKeys
// center map over position // center map over position
mController.setCenter(position); mController.setCenter(position);
} }
@ -295,6 +308,7 @@ public class MainActivityTrackFragment extends Fragment implements TrackbookKeys
mMapView.getOverlays().add(mTrackOverlay); mMapView.getOverlays().add(mTrackOverlay);
} }
/** /**
* Inner class: Loads track from external storage using AsyncTask * Inner class: Loads track from external storage using AsyncTask
*/ */
@ -314,9 +328,6 @@ public class MainActivityTrackFragment extends Fragment implements TrackbookKeys
super.onPostExecute(aVoid); super.onPostExecute(aVoid);
LogHelper.v(LOG_TAG, "Loading finished. Displaying map and statistics of track."); LogHelper.v(LOG_TAG, "Loading finished. Displaying map and statistics of track.");
displayTrack(); displayTrack();
// remove listener
LocalBroadcastManager.getInstance(mActivity).unregisterReceiver(mTrackSavedReceiver);
} }
} }

View file

@ -187,7 +187,8 @@ public class TrackerService extends Service implements TrackbookKeys, SensorEven
@Override @Override
public void onTick(long millisUntilFinished) { public void onTick(long millisUntilFinished) {
// update track duration // update track duration
mTrack.setDuration(EIGHT_HOURS_IN_MILLISECONDS - millisUntilFinished); long duration = EIGHT_HOURS_IN_MILLISECONDS - millisUntilFinished;
mTrack.setDuration(duration);
// try to add WayPoint to Track // try to add WayPoint to Track
addWayPointToTrack(); addWayPointToTrack();
// update notification // update notification

View file

@ -54,6 +54,7 @@ public class Track implements TrackbookKeys, Parcelable {
public Track() { public Track() {
mWayPoints = new ArrayList<WayPoint>(); mWayPoints = new ArrayList<WayPoint>();
mTrackLength = 0f; mTrackLength = 0f;
mDuration = 0;
mStepCount = 0f; mStepCount = 0f;
mRecordingStart = GregorianCalendar.getInstance().getTime(); mRecordingStart = GregorianCalendar.getInstance().getTime();
mRecordingStop = mRecordingStart; mRecordingStop = mRecordingStart;
@ -64,6 +65,7 @@ public class Track implements TrackbookKeys, Parcelable {
protected Track(Parcel in) { protected Track(Parcel in) {
mWayPoints = in.createTypedArrayList(WayPoint.CREATOR); mWayPoints = in.createTypedArrayList(WayPoint.CREATOR);
mTrackLength = in.readFloat(); mTrackLength = in.readFloat();
mDuration = in.readLong();
mStepCount = in.readFloat(); mStepCount = in.readFloat();
mRecordingStart = new Date(in.readLong()); mRecordingStart = new Date(in.readLong());
mRecordingStop = new Date(in.readLong()); mRecordingStop = new Date(in.readLong());
@ -216,6 +218,7 @@ public class Track implements TrackbookKeys, Parcelable {
public void writeToParcel(Parcel parcel, int flags) { public void writeToParcel(Parcel parcel, int flags) {
parcel.writeTypedList(mWayPoints); parcel.writeTypedList(mWayPoints);
parcel.writeFloat(mTrackLength); parcel.writeFloat(mTrackLength);
parcel.writeLong(mDuration);
parcel.writeFloat(mStepCount); parcel.writeFloat(mStepCount);
parcel.writeLong(mRecordingStart.getTime()); parcel.writeLong(mRecordingStart.getTime());
parcel.writeLong(mRecordingStop.getTime()); parcel.writeLong(mRecordingStop.getTime());

View file

@ -48,6 +48,7 @@ public class NotificationHelper implements TrackbookKeys {
private static Notification mNotification; private static Notification mNotification;
private static Service mService; private static Service mService;
/* Create and put up notification */ /* Create and put up notification */
public static void show(final Service service, Track track) { public static void show(final Service service, Track track) {
// save service // save service

View file

@ -43,8 +43,6 @@
<string name="toast_message_save_track">Aufzeichnung wird gespeichert.</string> <string name="toast_message_save_track">Aufzeichnung wird gespeichert.</string>
<string name="toast_message_last_location_age_one_hour">über eine Stunde</string> <string name="toast_message_last_location_age_one_hour">über eine Stunde</string>
<string name="toast_message_track_clear">Aufzeichnung zurückgesetzt.</string> <string name="toast_message_track_clear">Aufzeichnung zurückgesetzt.</string>
<string name="toast_message_track_save">Speichere Aufzeichnung.</string>
<!-- map markers --> <!-- map markers -->
<string name="marker_description_source">Quelle</string> <string name="marker_description_source">Quelle</string>

View file

@ -44,8 +44,6 @@
<string name="toast_message_save_track">Saving current track.</string> <string name="toast_message_save_track">Saving current track.</string>
<string name="toast_message_last_location_age_one_hour">over one hour</string> <string name="toast_message_last_location_age_one_hour">over one hour</string>
<string name="toast_message_track_clear">Current track data removed.</string> <string name="toast_message_track_clear">Current track data removed.</string>
<string name="toast_message_track_save">Saving current track data.</string>
<!-- map markers --> <!-- map markers -->
<string name="marker_description_source">Source</string> <string name="marker_description_source">Source</string>