Skip to content

Commit

Permalink
Fixed NPE when the RTTV is initially not visible
Browse files Browse the repository at this point in the history
  • Loading branch information
curioustechizen committed Dec 16, 2014
1 parent 6d39759 commit a18341d
Showing 1 changed file with 6 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,8 @@ public class RelativeTimeTextView extends TextView {
private String mPrefix;
private String mSuffix;
private Handler mHandler = new Handler();

/*private Runnable mUpdateTimeTask = new Runnable() {
public void run() {
long difference = Math.abs(System.currentTimeMillis() - mReferenceTime);
long interval = DateUtils.MINUTE_IN_MILLIS;
if (difference > DateUtils.WEEK_IN_MILLIS) {
interval = DateUtils.WEEK_IN_MILLIS;
} else if (difference > DateUtils.DAY_IN_MILLIS) {
interval = DateUtils.DAY_IN_MILLIS;
} else if (difference > DateUtils.HOUR_IN_MILLIS) {
interval = DateUtils.HOUR_IN_MILLIS;
}
updateTextDisplay();
mHandler.postDelayed(this, interval);
}
};*/

private UpdateTimeRunnable mUpdateTimeTask;
private boolean isUpdateTaskRunning = false;

public RelativeTimeTextView(Context context, AttributeSet attrs) {
super(context, attrs);
Expand Down Expand Up @@ -199,10 +183,14 @@ protected void onVisibilityChanged(View changedView, int visibility) {

private void startTaskForPeriodicallyUpdatingRelativeTime() {
mHandler.post(mUpdateTimeTask);
isUpdateTaskRunning = true;
}

private void stopTaskForPeriodicallyUpdatingRelativeTime() {
mHandler.removeCallbacks(mUpdateTimeTask);
if(isUpdateTaskRunning) {
mHandler.removeCallbacks(mUpdateTimeTask);
isUpdateTaskRunning = false;
}
}

@Override
Expand Down

0 comments on commit a18341d

Please sign in to comment.