Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bccf3c60 authored by uabdullah's avatar uabdullah Committed by android-build-merger
Browse files

Merge "Support new voicemail fragment in old peer."

am: 13ce35c5

Change-Id: I72e7b4dd6b40b0799321f3bb3578225d3cf91441
parents 3690afdf 13ce35c5
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -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);
+77 −21
Original line number Diff line number Diff line
@@ -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);
      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,16 +1352,23 @@ public class OldMainActivityPeer implements MainActivityPeer, FragmentUtilListen
      }
      Logger.get(activity).logScreenView(ScreenEvent.Type.MAIN_VOICEMAIL, activity);
      selectedTab = TabIndex.VOICEMAIL;

      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) {
      showFragment(fragment, null, 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",