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