summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSantos Cordon <santoscordon@google.com>2015-09-15 18:08:06 -0700
committerSantos Cordon <santoscordon@google.com>2015-09-15 18:13:06 -0700
commit74e886898a9283cc033c44d2809592e0d85f17e1 (patch)
tree7c3332eda395413f9cc75a52d01fad2322b96786
parent411dd7401997a83a876446261bdf70b3e2c9c4de (diff)
Update "X mins ago" on each minute change.
Reschedule an update when the next minute on the system clock changes. Bug: 2384475 Change-Id: Iead4ba7b0bf234f9e4c209a4e9c5b4f30efe4aa7
-rw-r--r--src/com/android/dialer/calllog/CallLogFragment.java42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/com/android/dialer/calllog/CallLogFragment.java b/src/com/android/dialer/calllog/CallLogFragment.java
index 8762f1822..26e39651b 100644
--- a/src/com/android/dialer/calllog/CallLogFragment.java
+++ b/src/com/android/dialer/calllog/CallLogFragment.java
@@ -34,6 +34,7 @@ import android.database.Cursor;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Handler;
+import android.os.Message;
import android.provider.CallLog;
import android.provider.CallLog.Calls;
import android.provider.ContactsContract;
@@ -89,6 +90,10 @@ public class CallLogFragment extends Fragment implements CallLogQueryHandler.Lis
private static final int READ_CALL_LOG_PERMISSION_REQUEST_CODE = 1;
+ private static final int EVENT_UPDATE_DISPLAY = 1;
+
+ private static final long MILLIS_IN_MINUTE = 60 * 1000;
+
private RecyclerView mRecyclerView;
private LinearLayoutManager mLayoutManager;
private CallLogAdapter mAdapter;
@@ -106,6 +111,18 @@ public class CallLogFragment extends Fragment implements CallLogQueryHandler.Lis
private boolean mCallLogFetched;
private boolean mVoicemailStatusFetched;
+ private final Handler mDisplayUpdateHandler = new Handler() {
+ @Override
+ public void handleMessage(Message msg) {
+ switch (msg.what) {
+ case EVENT_UPDATE_DISPLAY:
+ refreshData();
+ rescheduleDisplayUpdate();
+ break;
+ }
+ }
+ };
+
private final Handler mHandler = new Handler();
private class CustomContentObserver extends ContentObserver {
@@ -343,10 +360,14 @@ public class CallLogFragment extends Fragment implements CallLogQueryHandler.Lis
mHasReadCallLogPermission = hasReadCallLogPermission;
refreshData();
mAdapter.startCache();
+
+ rescheduleDisplayUpdate();
}
@Override
public void onPause() {
+ cancelDisplayUpdate();
+
if (mVoicemailPlaybackPresenter != null) {
mVoicemailPlaybackPresenter.onPause();
}
@@ -517,4 +538,25 @@ public class CallLogFragment extends Fragment implements CallLogQueryHandler.Lis
}
}
}
+
+ /**
+ * Schedules an update to the relative call times (X mins ago).
+ */
+ private void rescheduleDisplayUpdate() {
+ if (!mDisplayUpdateHandler.hasMessages(EVENT_UPDATE_DISPLAY)) {
+ long time = System.currentTimeMillis();
+ // This value allows us to change the display relatively close to when the time changes
+ // from one minute to the next.
+ long millisUtilNextMinute = MILLIS_IN_MINUTE - (time % MILLIS_IN_MINUTE);
+ mDisplayUpdateHandler.sendEmptyMessageDelayed(
+ EVENT_UPDATE_DISPLAY, millisUtilNextMinute);
+ }
+ }
+
+ /**
+ * Cancels any pending update requests to update the relative call times (X mins ago).
+ */
+ private void cancelDisplayUpdate() {
+ mDisplayUpdateHandler.removeMessages(EVENT_UPDATE_DISPLAY);
+ }
}