summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/voicemail
diff options
context:
space:
mode:
authorlinyuh <linyuh@google.com>2018-02-20 13:07:49 -0800
committerEric Erfanian <erfanian@google.com>2018-02-22 21:08:55 +0000
commit7e3f39706c2d8ae74ee5613f582daa2946dcc5d4 (patch)
tree6b34e2289f7b3affdd2d333554c44f91c3983d62 /java/com/android/dialer/voicemail
parent43c978b616363bcd364693dde24209384b264319 (diff)
Initialize/Update the UI of New{CallLog|Voicemail}Fragment iff the fragment is truly visible.
Bug: 73347270 Test: NewCallLogFragmentTest, NewVoicemailFragmentTest PiperOrigin-RevId: 186350076 Change-Id: Ib3e320f02a02795acb8b7d2017818b36df3dd49d
Diffstat (limited to 'java/com/android/dialer/voicemail')
-rw-r--r--java/com/android/dialer/voicemail/listui/NewVoicemailFragment.java60
1 files changed, 52 insertions, 8 deletions
diff --git a/java/com/android/dialer/voicemail/listui/NewVoicemailFragment.java b/java/com/android/dialer/voicemail/listui/NewVoicemailFragment.java
index 8d724afe3..9296d04e7 100644
--- a/java/com/android/dialer/voicemail/listui/NewVoicemailFragment.java
+++ b/java/com/android/dialer/voicemail/listui/NewVoicemailFragment.java
@@ -80,22 +80,66 @@ public final class NewVoicemailFragment extends Fragment implements LoaderCallba
public void onResume() {
super.onResume();
- LogUtil.enterBlock("NewCallLogFragment.onResume");
+ boolean isHidden = isHidden();
+ LogUtil.i("NewVoicemailFragment.onResume", "isHidden = %s", isHidden);
+
+ // As a fragment's onResume() is tied to the containing Activity's onResume(), being resumed is
+ // not equivalent to becoming visible.
+ // For example, when an activity with a hidden fragment is resumed, the fragment's onResume()
+ // will be called but it is not visible.
+ if (!isHidden) {
+ onFragmentShown();
+ }
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ LogUtil.enterBlock("NewVoicemailFragment.onPause");
+
+ onFragmentHidden();
+ }
+
+ @Override
+ public void onHiddenChanged(boolean hidden) {
+ super.onHiddenChanged(hidden);
+ LogUtil.i("NewVoicemailFragment.onHiddenChanged", "hidden = %s", hidden);
+ if (hidden) {
+ onFragmentHidden();
+ } else {
+ onFragmentShown();
+ }
+ }
+
+ /**
+ * To be called when the fragment becomes visible.
+ *
+ * <p>Note that for a fragment, being resumed is not equivalent to becoming visible.
+ *
+ * <p>For example, when an activity with a hidden fragment is resumed, the fragment's onResume()
+ * will be called but it is not visible.
+ */
+ private void onFragmentShown() {
registerRefreshAnnotatedCallLogReceiver();
- // TODO(zachh): Consider doing this when fragment becomes visible.
CallLogComponent.get(getContext())
.getRefreshAnnotatedCallLogNotifier()
.notify(/* checkDirty = */ true);
}
- @Override
- public void onPause() {
- super.onPause();
-
- LogUtil.enterBlock("NewVoicemailFragment.onPause");
-
+ /**
+ * To be called when the fragment becomes hidden.
+ *
+ * <p>This can happen in the following two cases:
+ *
+ * <ul>
+ * <li>hide the fragment but keep the parent activity visible (e.g., calling {@link
+ * android.support.v4.app.FragmentTransaction#hide(Fragment)} in an activity, or
+ * <li>the parent activity is paused.
+ * </ul>
+ */
+ private void onFragmentHidden() {
unregisterRefreshAnnotatedCallLogReceiver();
}