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
mSelectedTab = FRAGMENT_ID_TRACK;
mViewPager.setCurrentItem(mSelectedTab);
mMainActivityTrackFragment.refreshTrackView();
// mMainActivityTrackFragment.refreshTrackView();
// dismiss notification
NotificationHelper.stop();
@ -490,8 +490,6 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys {
// update Floating Action Button icon
mFloatingActionButtonState = FAB_STATE_DEFAULT;
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();
Toast.makeText(mActivity, mActivity.getString(R.string.toast_message_save_track), Toast.LENGTH_LONG).show();
} else {
// clear track object
// clear track object and delete temp file
mTrack = null;
StorageHelper storageHelper = new StorageHelper(mActivity, FILETYPE_TEMP);
storageHelper.deleteTempFile();
}
// // save track state

View file

@ -76,7 +76,6 @@ public class MainActivityTrackFragment extends Fragment implements TrackbookKeys
private BroadcastReceiver mTrackSavedReceiver;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -87,17 +86,20 @@ public class MainActivityTrackFragment extends Fragment implements TrackbookKeys
// store activity
mActivity = getActivity();
// create receiver for finished save operation
// listen for finished save operation
mTrackSavedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
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
LoadTrackAsyncHelper loadTrackAsyncHelper = new LoadTrackAsyncHelper();
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
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);
mStepsView = (TextView) mRootView.findViewById(R.id.statistics_data_steps);
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);
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
LoadTrackAsyncHelper loadTrackAsyncHelper = new LoadTrackAsyncHelper();
loadTrackAsyncHelper.execute();
@ -187,7 +193,7 @@ public class MainActivityTrackFragment extends Fragment implements TrackbookKeys
});
// react to tap on sheet heading
mStaticticsView.setOnClickListener(new View.OnClickListener() {
mStatisticsView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
LogHelper.v(LOG_TAG,"Statistics view tapped");
@ -208,7 +214,6 @@ public class MainActivityTrackFragment extends Fragment implements TrackbookKeys
public void onResume() {
super.onResume();
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
public void onSaveInstanceState(Bundle outState) {
LogHelper.v(LOG_TAG, "TrackFragment: onSaveInstanceState called.");
outState.putDouble(INSTANCE_LATITUDE_TRACK_MAP, mMapView.getMapCenter().getLatitude());
outState.putDouble(INSTANCE_LONGITUDE_TRACK_MAP, mMapView.getMapCenter().getLongitude());
outState.putInt(INSTANCE_ZOOM_LEVEL_TRACK_MAP, mMapView.getZoomLevel());
@ -238,18 +253,18 @@ public class MainActivityTrackFragment extends Fragment implements TrackbookKeys
}
/* Removes current track display */
public void refreshTrackView() {
// remove previous track
if (mMapView != null && mTrackOverlay != null) {
mMapView.getOverlays().remove(mTrackOverlay);
}
// listen for finished save
IntentFilter trackSavedReceiverIntentFilter = new IntentFilter(ACTION_TRACK_SAVE);
LocalBroadcastManager.getInstance(mActivity).registerReceiver(mTrackSavedReceiver, trackSavedReceiverIntentFilter);
}
// /* Removes current track display */
// public void refreshTrackView() {
//
// // remove previous track
// if (mMapView != null && mTrackOverlay != null) {
// mMapView.getOverlays().remove(mTrackOverlay);
// }
//
// // listen for finished save
// IntentFilter trackSavedReceiverIntentFilter = new IntentFilter(ACTION_TRACK_SAVE);
// LocalBroadcastManager.getInstance(mActivity).registerReceiver(mTrackSavedReceiver, trackSavedReceiverIntentFilter);
// }
/* Displays map and statistics for track */
@ -283,8 +298,6 @@ public class MainActivityTrackFragment extends Fragment implements TrackbookKeys
// center map over position
mController.setCenter(position);
}
@ -295,6 +308,7 @@ public class MainActivityTrackFragment extends Fragment implements TrackbookKeys
mMapView.getOverlays().add(mTrackOverlay);
}
/**
* Inner class: Loads track from external storage using AsyncTask
*/
@ -314,9 +328,6 @@ public class MainActivityTrackFragment extends Fragment implements TrackbookKeys
super.onPostExecute(aVoid);
LogHelper.v(LOG_TAG, "Loading finished. Displaying map and statistics of track.");
displayTrack();
// remove listener
LocalBroadcastManager.getInstance(mActivity).unregisterReceiver(mTrackSavedReceiver);
}
}

View file

@ -187,7 +187,8 @@ public class TrackerService extends Service implements TrackbookKeys, SensorEven
@Override
public void onTick(long millisUntilFinished) {
// 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
addWayPointToTrack();
// update notification

View file

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

View file

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

View file

@ -43,8 +43,6 @@
<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_track_clear">Aufzeichnung zurückgesetzt.</string>
<string name="toast_message_track_save">Speichere Aufzeichnung.</string>
<!-- map markers -->
<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_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_save">Saving current track data.</string>
<!-- map markers -->
<string name="marker_description_source">Source</string>