diff options
author | linyuh <linyuh@google.com> | 2018-02-20 13:07:49 -0800 |
---|---|---|
committer | Eric Erfanian <erfanian@google.com> | 2018-02-22 21:08:55 +0000 |
commit | 7e3f39706c2d8ae74ee5613f582daa2946dcc5d4 (patch) | |
tree | 6b34e2289f7b3affdd2d333554c44f91c3983d62 | |
parent | 43c978b616363bcd364693dde24209384b264319 (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
-rw-r--r-- | java/com/android/dialer/calllog/ui/NewCallLogFragment.java | 60 | ||||
-rw-r--r-- | java/com/android/dialer/voicemail/listui/NewVoicemailFragment.java | 60 |
2 files changed, 104 insertions, 16 deletions
diff --git a/java/com/android/dialer/calllog/ui/NewCallLogFragment.java b/java/com/android/dialer/calllog/ui/NewCallLogFragment.java index 8e8d55f3a..d0f42d335 100644 --- a/java/com/android/dialer/calllog/ui/NewCallLogFragment.java +++ b/java/com/android/dialer/calllog/ui/NewCallLogFragment.java @@ -73,11 +73,49 @@ public final class NewCallLogFragment extends Fragment implements LoaderCallback public void onResume() { super.onResume(); - LogUtil.enterBlock("NewCallLogFragment.onResume"); + boolean isHidden = isHidden(); + LogUtil.i("NewCallLogFragment.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("NewCallLogFragment.onPause"); + + onFragmentHidden(); + } + + @Override + public void onHiddenChanged(boolean hidden) { + super.onHiddenChanged(hidden); + LogUtil.i("NewCallLogFragment.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); @@ -100,12 +138,18 @@ public final class NewCallLogFragment extends Fragment implements LoaderCallback .postDelayed(setShouldMarkCallsReadTrue, MARK_ALL_CALLS_READ_WAIT_MILLIS); } - @Override - public void onPause() { - super.onPause(); - - LogUtil.enterBlock("NewCallLogFragment.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() { // This is pending work that we don't actually need to follow through with. ThreadUtil.getUiThreadHandler().removeCallbacks(setShouldMarkCallsReadTrue); 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(); } |