diff options
author | uabdullah <uabdullah@google.com> | 2018-04-05 09:21:32 -0700 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2018-04-05 09:21:32 -0700 |
commit | bccf3c603a29f1e30d37405772882417aab6db7e (patch) | |
tree | 5562d990e4777461c78870bfc6026eaf8d1202e3 | |
parent | 3690afdf8a8dc506ee9b0e5ecaee39d51aa3b54a (diff) | |
parent | 13ce35c55fc3f4f44fced5183b29081d21e14a96 (diff) |
Merge "Support new voicemail fragment in old peer."
am: 13ce35c55f
Change-Id: I72e7b4dd6b40b0799321f3bb3578225d3cf91441
-rw-r--r-- | java/com/android/dialer/calllog/CallLogFramework.java | 11 | ||||
-rw-r--r-- | java/com/android/dialer/main/impl/OldMainActivityPeer.java | 98 |
2 files changed, 83 insertions, 26 deletions
diff --git a/java/com/android/dialer/calllog/CallLogFramework.java b/java/com/android/dialer/calllog/CallLogFramework.java index b86bfbc10..be4db0675 100644 --- a/java/com/android/dialer/calllog/CallLogFramework.java +++ b/java/com/android/dialer/calllog/CallLogFramework.java @@ -101,12 +101,13 @@ public final class CallLogFramework { return Futures.transform( Futures.allAsList(allFutures), unused -> { - // Send a broadcast to the OldMainActivityPeer to remove the NewCallLogFragment if it is - // currently attached. If this is not done, user interaction with the fragment could cause - // call log framework state to be unexpectedly written. For example scrolling could cause - // the AnnotatedCallLog to be read (which would trigger database creation). + // Send a broadcast to the OldMainActivityPeer to remove the NewCallLogFragment and + // NewVoicemailFragment if it is currently attached. If this is not done, user interaction + // with the fragment could cause call log framework state to be unexpectedly written. For + // example scrolling could cause the AnnotatedCallLog to be read (which would trigger + // database creation). LocalBroadcastManager.getInstance(appContext) - .sendBroadcastSync(new Intent("disableNewCallLogFragment")); + .sendBroadcastSync(new Intent("disableCallLogFramework")); return null; }, uiExecutor); diff --git a/java/com/android/dialer/main/impl/OldMainActivityPeer.java b/java/com/android/dialer/main/impl/OldMainActivityPeer.java index c15d7c1a8..d2a6fd8a4 100644 --- a/java/com/android/dialer/main/impl/OldMainActivityPeer.java +++ b/java/com/android/dialer/main/impl/OldMainActivityPeer.java @@ -111,6 +111,7 @@ import com.android.dialer.telecom.TelecomUtil; import com.android.dialer.util.DialerUtils; import com.android.dialer.util.PermissionsUtil; import com.android.dialer.util.TransactionSafeActivity; +import com.android.dialer.voicemail.listui.NewVoicemailFragment; import com.android.dialer.voicemail.listui.error.VoicemailStatusCorruptionHandler; import com.android.dialer.voicemail.listui.error.VoicemailStatusCorruptionHandler.Source; import com.android.dialer.voicemailstatus.VisualVoicemailEnabledChecker; @@ -141,7 +142,7 @@ public class OldMainActivityPeer implements MainActivityPeer, FragmentUtilListen // TODO(calderwoodra): change to AppCompatActivity once new speed dial ships private final TransactionSafeActivity activity; - private final BroadcastReceiver disableNewCallLogReceiver = + private final BroadcastReceiver disableCallLogFrameworkReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { @@ -149,12 +150,13 @@ public class OldMainActivityPeer implements MainActivityPeer, FragmentUtilListen return; } /* - * Remove the NewCallLogFragment if it is currently attached. If this is not done, user - * interaction with the fragment could cause call log framework state to be unexpectedly - * written. For example scrolling could cause the AnnotatedCallLog to be read (which would - * trigger database creation). + * Remove the NewCallLogFragment and NewVoicemailFragment if it is currently attached. If + * this is not done, user interaction with the fragment could cause call log framework + * state to be unexpectedly written. For example scrolling could cause the + * AnnotatedCallLog to be read (which would trigger database creation). */ bottomNavTabListener.disableNewCallLogFragment(); + bottomNavTabListener.disableNewVoicemailFragment(); } }; @@ -476,14 +478,16 @@ public class OldMainActivityPeer implements MainActivityPeer, FragmentUtilListen * (which would trigger database creation). */ LocalBroadcastManager.getInstance(activity) - .registerReceiver(disableNewCallLogReceiver, new IntentFilter("disableNewCallLogFragment")); + .registerReceiver( + disableCallLogFrameworkReceiver, new IntentFilter("disableCallLogFramework")); /* - * Similar to above, if the new call log is being shown and then the activity is paused, when - * the user returns we need to remove the NewCallLogFragment if the framework has been disabled - * in the meantime. + * Similar to above, if the new call log/new voicemail is being shown and then the activity is + * paused, when the user returns we need to remove the NewCallLogFragment if the framework has + * been disabled in the meantime. */ bottomNavTabListener.ensureCorrectCallLogShown(); + bottomNavTabListener.ensureCorrectVoicemailShown(); if (bottomNavTabListener.newCallLogFragmentActive()) { missedCallCountObserver.onChange(false); // Set the initial value for the badge @@ -509,7 +513,7 @@ public class OldMainActivityPeer implements MainActivityPeer, FragmentUtilListen @Override public void onActivityPause() { searchController.onActivityPause(); - LocalBroadcastManager.getInstance(activity).unregisterReceiver(disableNewCallLogReceiver); + LocalBroadcastManager.getInstance(activity).unregisterReceiver(disableCallLogFrameworkReceiver); activity.getContentResolver().unregisterContentObserver(missedCallCountObserver); } @@ -1000,7 +1004,9 @@ public class OldMainActivityPeer implements MainActivityPeer, FragmentUtilListen public void onActivityResume() { activityIsAlive = true; registerVoicemailStatusContentObserver(context); - callLogQueryHandler.fetchVoicemailStatus(); + if (!bottomNavTabListener.newVoicemailFragmentActive()) { + callLogQueryHandler.fetchVoicemailStatus(); + } if (!bottomNavTabListener.newCallLogFragmentActive()) { callLogQueryHandler.fetchMissedCallsUnreadCount(); } @@ -1267,6 +1273,24 @@ public class OldMainActivityPeer implements MainActivityPeer, FragmentUtilListen } } + void disableNewVoicemailFragment() { + LogUtil.i("MainBottomNavBarBottomNavTabListener.disableNewVoicemailFragment", "disabled"); + android.support.v4.app.Fragment supportFragment = + supportFragmentManager.findFragmentByTag(VOICEMAIL_TAG); + if (supportFragment != null) { + supportFragmentManager.beginTransaction().remove(supportFragment).commit(); + // If the NewVoicemailFragment was showing, immediately show the old voicemail fragment + // instead. + if (selectedTab == TabIndex.VOICEMAIL) { + LogUtil.i( + "MainBottomNavBarBottomNavTabListener.disableNewVoicemailFragment", "showing old"); + Fragment fragment = fragmentManager.findFragmentByTag(VOICEMAIL_TAG); + showFragment( + fragment == null ? new VisualVoicemailCallLogFragment() : fragment, VOICEMAIL_TAG); + } + } + } + void ensureCorrectCallLogShown() { android.support.v4.app.Fragment supportFragment = supportFragmentManager.findFragmentByTag(CALL_LOG_TAG); @@ -1277,6 +1301,18 @@ public class OldMainActivityPeer implements MainActivityPeer, FragmentUtilListen } } + void ensureCorrectVoicemailShown() { + android.support.v4.app.Fragment supportFragment = + supportFragmentManager.findFragmentByTag(VOICEMAIL_TAG); + if (supportFragment != null + && !CallLogConfigComponent.get(activity) + .callLogConfig() + .isNewVoicemailFragmentEnabled()) { + LogUtil.i("MainBottomNavBarBottomNavTabListener.ensureCorrectVoicemailShown", "disabling"); + disableNewVoicemailFragment(); + } + } + boolean newCallLogFragmentActive() { return supportFragmentManager.findFragmentByTag(CALL_LOG_TAG) != null || (fragmentManager.findFragmentByTag(CALL_LOG_TAG) == null @@ -1285,6 +1321,14 @@ public class OldMainActivityPeer implements MainActivityPeer, FragmentUtilListen .isNewCallLogFragmentEnabled()); } + boolean newVoicemailFragmentActive() { + return supportFragmentManager.findFragmentByTag(VOICEMAIL_TAG) != null + || (fragmentManager.findFragmentByTag(VOICEMAIL_TAG) == null + && CallLogConfigComponent.get(activity) + .callLogConfig() + .isNewVoicemailFragmentEnabled()); + } + @Override public void onContactsSelected() { LogUtil.enterBlock("MainBottomNavBarBottomNavTabListener.onContactsSelected"); @@ -1308,15 +1352,22 @@ public class OldMainActivityPeer implements MainActivityPeer, FragmentUtilListen } Logger.get(activity).logScreenView(ScreenEvent.Type.MAIN_VOICEMAIL, activity); selectedTab = TabIndex.VOICEMAIL; - VisualVoicemailCallLogFragment fragment = - (VisualVoicemailCallLogFragment) fragmentManager.findFragmentByTag(VOICEMAIL_TAG); - if (fragment == null) { - fragment = new VisualVoicemailCallLogFragment(); - } - showFragment(fragment, VOICEMAIL_TAG); - fragment.setUserVisibleHint(true); - fragment.onVisible(); + if (CallLogConfigComponent.get(activity).callLogConfig().isNewVoicemailFragmentEnabled()) { + android.support.v4.app.Fragment supportFragment = + supportFragmentManager.findFragmentByTag(VOICEMAIL_TAG); + showSupportFragment( + supportFragment == null ? new NewVoicemailFragment() : supportFragment, VOICEMAIL_TAG); + } else { + VisualVoicemailCallLogFragment fragment = + (VisualVoicemailCallLogFragment) fragmentManager.findFragmentByTag(VOICEMAIL_TAG); + if (fragment == null) { + fragment = new VisualVoicemailCallLogFragment(); + } + showFragment(fragment, VOICEMAIL_TAG); + fragment.setUserVisibleHint(true); + fragment.onVisible(); + } } private void showFragment(@NonNull Fragment fragment, String tag) { @@ -1342,13 +1393,13 @@ public class OldMainActivityPeer implements MainActivityPeer, FragmentUtilListen Fragment speedDial = fragmentManager.findFragmentByTag(SPEED_DIAL_TAG); Fragment oldCallLog = fragmentManager.findFragmentByTag(CALL_LOG_TAG); Fragment contacts = fragmentManager.findFragmentByTag(CONTACTS_TAG); - Fragment voicemail = fragmentManager.findFragmentByTag(VOICEMAIL_TAG); + Fragment oldVoicemail = fragmentManager.findFragmentByTag(VOICEMAIL_TAG); FragmentTransaction transaction = fragmentManager.beginTransaction(); boolean fragmentShown = showIfEqualElseHide(transaction, fragment, speedDial); fragmentShown |= showIfEqualElseHide(transaction, fragment, oldCallLog); fragmentShown |= showIfEqualElseHide(transaction, fragment, contacts); - fragmentShown |= showIfEqualElseHide(transaction, fragment, voicemail); + fragmentShown |= showIfEqualElseHide(transaction, fragment, oldVoicemail); if (!fragmentShown && fragment != null) { LogUtil.i( @@ -1361,11 +1412,16 @@ public class OldMainActivityPeer implements MainActivityPeer, FragmentUtilListen // TODO(calderwoodra): Handle other new fragments. android.support.v4.app.Fragment newCallLog = supportFragmentManager.findFragmentByTag(CALL_LOG_TAG); + android.support.v4.app.Fragment newVoicemail = + supportFragmentManager.findFragmentByTag(VOICEMAIL_TAG); android.support.v4.app.FragmentTransaction supportTransaction = supportFragmentManager.beginTransaction(); boolean supportFragmentShown = showIfEqualElseHideSupport(supportTransaction, supportFragment, newCallLog); + supportFragmentShown |= + showIfEqualElseHideSupport(supportTransaction, supportFragment, newVoicemail); + if (!supportFragmentShown && supportFragment != null) { LogUtil.i( "MainBottomNavBarBottomNavTabListener.showFragment", |