forked from upstream-mirrors/OpenTracks
Fix memory leak in TrackDetailActivity due to TrackController.
This commit is contained in:
@@ -48,18 +48,21 @@ public class TrackController {
|
||||
private final TextView totalTimeTextView;
|
||||
private final ImageButton recordImageButton;
|
||||
private final ImageButton stopImageButton;
|
||||
private final boolean alwaysShow;
|
||||
|
||||
private final boolean alwaysShow;
|
||||
|
||||
private boolean isRecording;
|
||||
private boolean isPaused;
|
||||
private long totalTime = 0;
|
||||
|
||||
// the timestamp for the toal time
|
||||
private long totalTimeTimestamp = 0;
|
||||
|
||||
private boolean isResumed = false;
|
||||
|
||||
// A runnable to update the total time.
|
||||
private final Runnable updateTotalTimeRunnable = new Runnable() {
|
||||
public void run() {
|
||||
if (isRecording && !isPaused) {
|
||||
if (isResumed && isRecording && !isPaused) {
|
||||
totalTimeTextView.setText(StringUtils.formatElapsedTimeWithHour(
|
||||
System.currentTimeMillis() - totalTimeTimestamp + totalTime));
|
||||
handler.postDelayed(this, ONE_SECOND);
|
||||
@@ -84,12 +87,15 @@ public class TrackController {
|
||||
}
|
||||
|
||||
public void update(boolean recording, boolean paused) {
|
||||
if (!isResumed) {
|
||||
return;
|
||||
}
|
||||
isRecording = recording;
|
||||
isPaused = paused;
|
||||
containerView.setVisibility(alwaysShow || isRecording ? View.VISIBLE : View.GONE);
|
||||
|
||||
if (!alwaysShow && !isRecording) {
|
||||
stop();
|
||||
stopTimer();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -108,7 +114,7 @@ public class TrackController {
|
||||
statusTextView.setText(isPaused ? R.string.generic_paused : R.string.generic_recording);
|
||||
}
|
||||
|
||||
stop();
|
||||
stopTimer();
|
||||
totalTime = isRecording ? getTotalTime() : 0L;
|
||||
totalTimeTextView.setText(StringUtils.formatElapsedTimeWithHour(totalTime));
|
||||
if (isRecording && !isPaused) {
|
||||
@@ -117,10 +123,20 @@ public class TrackController {
|
||||
}
|
||||
}
|
||||
|
||||
public void onResume(boolean recording, boolean paused) {
|
||||
isResumed = true;
|
||||
update(recording, paused);
|
||||
}
|
||||
|
||||
public void onPause() {
|
||||
isResumed = false;
|
||||
stopTimer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the timer.
|
||||
*/
|
||||
public void stop() {
|
||||
private void stopTimer() {
|
||||
handler.removeCallbacks(updateTotalTimeRunnable);
|
||||
}
|
||||
|
||||
|
||||
@@ -234,13 +234,13 @@ public class TrackDetailActivity extends AbstractMyTracksActivity implements Del
|
||||
// Update UI
|
||||
boolean isRecording = trackId == recordingTrackId;
|
||||
updateMenuItems(isRecording, recordingTrackPaused);
|
||||
trackController.update(isRecording, recordingTrackPaused);
|
||||
trackController.onResume(isRecording, recordingTrackPaused);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
trackController.stop();
|
||||
trackController.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -463,7 +463,7 @@ public class TrackListActivity extends FragmentActivity implements DeleteOneTrac
|
||||
boolean isRecording = recordingTrackId != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;
|
||||
updateMenuItems(isRecording);
|
||||
sectionResourceCursorAdapter.notifyDataSetChanged();
|
||||
trackController.update(isRecording, recordingTrackPaused);
|
||||
trackController.onResume(isRecording, recordingTrackPaused);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -474,7 +474,7 @@ public class TrackListActivity extends FragmentActivity implements DeleteOneTrac
|
||||
trackDataHub.unregisterTrackDataListener(trackDataListener);
|
||||
|
||||
// Update UI
|
||||
trackController.stop();
|
||||
trackController.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user