OSDN Git Service

Fix new notification showing timestamp "now" after turning off DND
authorshawnlin <shawnlin@google.com>
Wed, 2 May 2018 09:02:54 +0000 (17:02 +0800)
committershawnlin <shawnlin@google.com>
Thu, 3 May 2018 03:06:52 +0000 (11:06 +0800)
DateTimeView won't update timestamp until the view is attached to
window and received TIME_TICK intent.

Update timestamp on onAttachedToWindow().

Test: manual 1) turn on DND 2) send a notification and wait some time 3)
turn off DND and check the timestamp
Fixes: 77970557

Change-Id: Ia8420aacf5b91b0bb9cbec561629ddbfc8de4f67

core/java/android/widget/DateTimeView.java

index 4db3607..a22f345 100644 (file)
@@ -104,8 +104,16 @@ public class DateTimeView extends TextView {
             sReceiverInfo.set(ri);
         }
         ri.addView(this);
+        // The view may not be added to the view hierarchy immediately right after setTime()
+        // is called which means it won't get any update from intents before being added.
+        // In such case, the view might show the incorrect relative time after being added to the
+        // view hierarchy until the next update intent comes.
+        // So we update the time here if mShowRelativeTime is enabled to prevent this case.
+        if (mShowRelativeTime) {
+            update();
+        }
     }
-        
+
     @Override
     protected void onDetachedFromWindow() {
         super.onDetachedFromWindow();