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

Commit a7530f84 authored by uabdullah's avatar uabdullah Committed by Copybara-Service
Browse files

Refactor VM Settings and add support for voicemail transcription

This CL refactors the existing voicemail settings fragment and adds UI support for voicemail transcription. It mainly deals with the following:
- ensuring that when the VVM toggle is turned off, transcription and donations are gone.
- when transcription is off, donation preference is gone.
- donation is only available when transcription is available and enabled
- as part of the refactor, fixes existing logging bugs
- breaks preferences and its associated methods into helper methods when possible
- groups relevant preferences together when possible

Bug: 74033229
Test: Unit tests
PiperOrigin-RevId: 189418217
Change-Id: I3442cb5752a235cfca643ba55df3fb75171e3fe4
parent fce3a793
Loading
Loading
Loading
Loading
+47 −46
Original line number Diff line number Diff line
@@ -94,6 +94,49 @@ public class PhoneCallDetailsHelper
    calendar = Calendar.getInstance();
  }

  static boolean shouldShowVoicemailDonationPromo(
      Context context, PhoneAccountHandle accountHandle) {
    VoicemailClient client = VoicemailComponent.get(context).getVoicemailClient();
    return client.isVoicemailDonationAvailable(context, accountHandle)
        && !hasSeenVoicemailDonationPromo(context);
  }

  static boolean hasSeenVoicemailDonationPromo(Context context) {
    return StorageComponent.get(context.getApplicationContext())
        .unencryptedSharedPrefs()
        .getBoolean(PREF_VOICEMAIL_DONATION_PROMO_SHOWN_KEY, false);
  }

  private static int dpsToPixels(Context context, int dps) {
    return (int)
        (TypedValue.applyDimension(
            TypedValue.COMPLEX_UNIT_DIP, dps, context.getResources().getDisplayMetrics()));
  }

  private static void recordPromoShown(Context context) {
    StorageComponent.get(context.getApplicationContext())
        .unencryptedSharedPrefs()
        .edit()
        .putBoolean(PREF_VOICEMAIL_DONATION_PROMO_SHOWN_KEY, true)
        .apply();
  }

  /** Returns true if primary name is empty or the data is from Cequint Caller ID. */
  private static boolean shouldShowLocation(PhoneCallDetails details) {
    if (TextUtils.isEmpty(details.geocode)) {
      return false;
    }
    // For caller ID provided by Cequint we want to show the geo location.
    if (details.sourceType == ContactSource.Type.SOURCE_TYPE_CEQUINT_CALLER_ID) {
      return true;
    }
    // Don't bother showing geo location for contacts.
    if (!TextUtils.isEmpty(details.namePrimary)) {
      return false;
    }
    return true;
  }

  /** Fills the call details views with content. */
  public void setPhoneCallDetails(PhoneCallDetailsViews views, PhoneCallDetails details) {
    // Display up to a given number of icons.
@@ -250,9 +293,10 @@ public class PhoneCallDetailsHelper
      return true;
    }

    // Also show the rating option if voicemail transcription is available (but not enabled)
    // Also show the rating option if voicemail donation is available (but not enabled)
    // and the donation promo has not yet been shown.
    if (client.isVoicemailDonationAvailable(context) && !hasSeenVoicemailDonationPromo(context)) {
    if (client.isVoicemailDonationAvailable(context, account)
        && !hasSeenVoicemailDonationPromo(context)) {
      return true;
    }

@@ -263,7 +307,7 @@ public class PhoneCallDetailsHelper
      TranscriptionRatingValue ratingValue, PhoneCallDetails details, View ratingView) {
    LogUtil.enterBlock("PhoneCallDetailsHelper.recordTranscriptionRating");

    if (shouldShowVoicemailDonationPromo(context)) {
    if (shouldShowVoicemailDonationPromo(context, details.accountHandle)) {
      showVoicemailDonationPromo(ratingValue, details, ratingView);
    } else {
      TranscriptionRatingHelper.sendRating(
@@ -275,19 +319,6 @@ public class PhoneCallDetailsHelper
    }
  }

  static boolean shouldShowVoicemailDonationPromo(Context context) {
    VoicemailClient client = VoicemailComponent.get(context).getVoicemailClient();
    return client.isVoicemailTranscriptionAvailable(context)
        && client.isVoicemailDonationAvailable(context)
        && !hasSeenVoicemailDonationPromo(context);
  }

  static boolean hasSeenVoicemailDonationPromo(Context context) {
    return StorageComponent.get(context.getApplicationContext())
        .unencryptedSharedPrefs()
        .getBoolean(PREF_VOICEMAIL_DONATION_PROMO_SHOWN_KEY, false);
  }

  private void showVoicemailDonationPromo(
      TranscriptionRatingValue ratingValue, PhoneCallDetails details, View ratingView) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
@@ -360,20 +391,6 @@ public class PhoneCallDetailsHelper
    }
  }

  private static int dpsToPixels(Context context, int dps) {
    return (int)
        (TypedValue.applyDimension(
            TypedValue.COMPLEX_UNIT_DIP, dps, context.getResources().getDisplayMetrics()));
  }

  private static void recordPromoShown(Context context) {
    StorageComponent.get(context.getApplicationContext())
        .unencryptedSharedPrefs()
        .edit()
        .putBoolean(PREF_VOICEMAIL_DONATION_PROMO_SHOWN_KEY, true)
        .apply();
  }

  private SpannableString getVoicemailDonationPromoContent() {
    return new ContentWithLearnMoreSpanner(context)
        .create(
@@ -462,22 +479,6 @@ public class PhoneCallDetailsHelper
    return numberFormattedLabel;
  }

  /** Returns true if primary name is empty or the data is from Cequint Caller ID. */
  private static boolean shouldShowLocation(PhoneCallDetails details) {
    if (TextUtils.isEmpty(details.geocode)) {
      return false;
    }
    // For caller ID provided by Cequint we want to show the geo location.
    if (details.sourceType == ContactSource.Type.SOURCE_TYPE_CEQUINT_CALLER_ID) {
      return true;
    }
    // Don't bother showing geo location for contacts.
    if (!TextUtils.isEmpty(details.namePrimary)) {
      return false;
    }
    return true;
  }

  public void setPhoneTypeLabelForTest(CharSequence phoneTypeLabel) {
    this.phoneTypeLabelForTest = phoneTypeLabel;
  }
+10 −6
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@ message DialerImpression {
  // Event enums to be used for Impression Logging in Dialer.
  // It's perfectly acceptable for this enum to be large
  // Values should be from 1000 to 100000.
  // Next Tag: 1361
  // Next Tag: 1366
  enum Type {
    UNKNOWN_AOSP_EVENT_TYPE = 1000;

@@ -372,7 +372,7 @@ message DialerImpression {
    VVM_SETTINGS_VIEWED = 1148;
    VVM_CHANGE_PIN_CLICKED = 1149;
    VVM_CHANGE_PIN_COMPLETED = 1150;
    VVM_CHANGE_RINGTONE_CLICKED = 1151;
    VVM_CHANGE_RINGTONE_CLICKED = 1151 [deprecated = true];
    VVM_CHANGE_VIBRATION_CLICKED = 1152;
    VVM_USER_ENABLED_IN_SETTINGS = 1153;
    VVM_USER_DISABLED_IN_SETTINGS = 1154;
@@ -594,14 +594,12 @@ message DialerImpression {
    ASSISTED_DIALING_FEATURE_DISABLED_BY_USER = 1292;

    // User reports a same prefix call as spam from call history
    REPORT_SAME_PREFIX_CALL_AS_SPAM_VIA_CALL_HISTORY =
        1290
    REPORT_SAME_PREFIX_CALL_AS_SPAM_VIA_CALL_HISTORY = 1290

        ;

    // User reports a same prefix call as not spam from call history
    REPORT_SAME_PREFIX_CALL_AS_NOT_SPAM_VIA_CALL_HISTORY =
        1291
    REPORT_SAME_PREFIX_CALL_AS_NOT_SPAM_VIA_CALL_HISTORY = 1291

        ;

@@ -715,5 +713,11 @@ message DialerImpression {
    SPAM_BLOCKING_DISABLED_THROUGH_SETTING = 1359;
    // Failure happened while modifying spam blocking setting.
    SPAM_BLOCKING_MODIFY_FAILURE_THROUGH_SETTING = 1360;

    VVM_NOTIFICATIONS_SETTING_CLICKED = 1361;
    VVM_USER_TURNED_TRANSCRIBE_ON_FROM_SETTINGS = 1362;
    VVM_USER_TURNED_TRANSCRIBE_OFF_FROM_SETTINGS = 1363;
    VVM_USER_TURNED_DONATION_ON_FROM_SETTINGS = 1364;
    VVM_USER_TURNED_DONATION_OFF_FROM_SETTINGS = 1365;
  }
}
+212 −99
Original line number Diff line number Diff line
@@ -51,8 +51,6 @@ import com.google.common.base.Optional;
public class VoicemailSettingsFragment extends PreferenceFragment
    implements Preference.OnPreferenceChangeListener, ActivationStateListener {

  private static final String TAG = "VmSettingsActivity";

  // Extras copied from com.android.phone.settings.VoicemailSettingsActivity,
  // it does not recognize EXTRA_PHONE_ACCOUNT_HANDLE in O.
  @VisibleForTesting
@@ -63,21 +61,26 @@ public class VoicemailSettingsFragment extends PreferenceFragment
  static final String SUB_LABEL_EXTRA =
      "com.android.phone.settings.SubscriptionInfoHelper.SubscriptionLabel";

  private static final String TAG = "VmSettingsActivity";
  @Nullable private PhoneAccountHandle phoneAccountHandle;

  private VoicemailClient voicemailClient;

  // Settings that are independent of the carrier configurations
  private Preference voicemailNotificationPreference;
  private SwitchPreference voicemailVisualVoicemail;
  private SwitchPreference autoArchiveSwitchPreference;
  private SwitchPreference donateVoicemailSwitchPreference;
  private PreferenceScreen advancedSettingsPreference;

  // Settings that are supported by dialer only if the carrier configurations are valid.
  private SwitchPreference visualVoicemailPreference;
  private SwitchPreference voicemailAutoArchivePreference;
  private SwitchPreference transcribeVoicemailPreference;
  // Voicemail transcription analysis toggle
  private SwitchPreference donateTranscribedVoicemailPreference;
  private Preference voicemailChangePinPreference;
  private PreferenceScreen advancedSettings;

  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    phoneAccountHandle =
        Assert.isNotNull(getArguments().getParcelable(VoicemailClient.PARAM_PHONE_ACCOUNT_HANDLE));
    voicemailClient = VoicemailComponent.get(getContext()).getVoicemailClient();
@@ -95,52 +98,140 @@ public class VoicemailSettingsFragment extends PreferenceFragment

    addPreferencesFromResource(R.xml.voicemail_settings);

    PreferenceScreen prefSet = getPreferenceScreen();
    initializePreferences();

    voicemailNotificationPreference =
        findPreference(getString(R.string.voicemail_notifications_key));
    voicemailNotificationPreference.setIntent(getNotificationSettingsIntent());
    setupVisualVoicemailPreferences();

    voicemailNotificationPreference.setOnPreferenceClickListener(
        new OnPreferenceClickListener() {
          @Override
          public boolean onPreferenceClick(Preference preference) {
            Logger.get(getContext())
                .logImpression(DialerImpression.Type.VVM_CHANGE_RINGTONE_CLICKED);
            // Let the preference handle the click.
            return false;
    setupNotificationsPreference();
    setupAdvancedSettingsPreference();
  }
        });

    voicemailVisualVoicemail =
        (SwitchPreference) findPreference(getString(R.string.voicemail_visual_voicemail_key));
  private void setupVisualVoicemailPreferences() {
    if (!voicemailClient.hasCarrierSupport(getContext(), phoneAccountHandle)) {
      removeAllVisualVoicemailPreferences();
      return;
    }

    autoArchiveSwitchPreference =
        (SwitchPreference)
            findPreference(getString(R.string.voicemail_visual_voicemail_archive_key));
    setupVisualVoicemailPreference();

    donateVoicemailSwitchPreference =
        (SwitchPreference)
            findPreference(getString(R.string.voicemail_visual_voicemail_donation_key));
    setupVisualVoicemailFeaturePreferences();

    setupVoicemailChangePinPreference();
  }

  private void setupVisualVoicemailFeaturePreferences() {
    if (!voicemailClient.isVoicemailEnabled(getContext(), phoneAccountHandle)
        || !voicemailClient.isActivated(getContext(), phoneAccountHandle)) {
      removeAllTranscriptionPreferences();
      getPreferenceScreen().removePreference(voicemailAutoArchivePreference);
      return;
    }
    setupAutoArchivePreference();
    updateTranscriptionPreferences();
  }

  private void updateTranscriptionPreferences() {
    if (!VoicemailComponent.get(getContext())
        .getVoicemailClient()
        .isVoicemailArchiveAvailable(getContext())) {
      getPreferenceScreen().removePreference(autoArchiveSwitchPreference);
        .isVoicemailTranscriptionAvailable(getContext(), phoneAccountHandle)) {
      removeAllTranscriptionPreferences();
      return;
    } else {
      showTranscriptionEnabledPreference();
      updateTranscriptionDonationPreference();
    }
  }

  private void showTranscriptionEnabledPreference() {
    transcribeVoicemailPreference.setOnPreferenceChangeListener(this);
    transcribeVoicemailPreference.setChecked(
        voicemailClient.isVoicemailTranscriptionEnabled(getContext(), phoneAccountHandle));
    transcribeVoicemailPreference.setSummary(
        R.string.voicemail_transcription_preference_summary_info);
    transcribeVoicemailPreference.setEnabled(true);
    getPreferenceScreen().addPreference(transcribeVoicemailPreference);
  }

  private void updateTranscriptionDonationPreference() {
    if (!VoicemailComponent.get(getContext())
        .getVoicemailClient()
        .isVoicemailDonationAvailable(getContext())) {
      getPreferenceScreen().removePreference(donateVoicemailSwitchPreference);
        .isVoicemailDonationAvailable(getContext(), phoneAccountHandle)) {
      getPreferenceScreen().removePreference(donateTranscribedVoicemailPreference);
    } else {
      showTranscriptionDonationEnabledPreferences();
    }
  }

  private void showTranscriptionDonationEnabledPreferences() {
    donateTranscribedVoicemailPreference.setOnPreferenceChangeListener(this);
    donateTranscribedVoicemailPreference.setChecked(
        voicemailClient.isVoicemailDonationEnabled(getContext(), phoneAccountHandle));
    donateTranscribedVoicemailPreference.setSummary(
        R.string.voicemail_donate_preference_summary_info);
    donateTranscribedVoicemailPreference.setEnabled(true);
    getPreferenceScreen().addPreference(donateTranscribedVoicemailPreference);
  }

  private void removeAllTranscriptionPreferences() {
    getPreferenceScreen().removePreference(transcribeVoicemailPreference);
    getPreferenceScreen().removePreference(donateTranscribedVoicemailPreference);
  }

  private void setupAutoArchivePreference() {
    if (!VoicemailComponent.get(getContext())
        .getVoicemailClient()
        .isVoicemailArchiveAvailable(getContext())) {
      getPreferenceScreen().removePreference(voicemailAutoArchivePreference);
    } else {
      voicemailAutoArchivePreference.setOnPreferenceChangeListener(this);
      voicemailAutoArchivePreference.setChecked(
          voicemailClient.isVoicemailArchiveEnabled(getContext(), phoneAccountHandle));
    }
  }

  private void setupVisualVoicemailPreference() {
    visualVoicemailPreference.setOnPreferenceChangeListener(this);
    visualVoicemailPreference.setChecked(
        voicemailClient.isVoicemailEnabled(getContext(), phoneAccountHandle));
  }

  private void initializePreferences() {
    voicemailNotificationPreference =
        findPreference(getString(R.string.voicemail_notifications_key));

    advancedSettingsPreference =
        (PreferenceScreen) findPreference(getString(R.string.voicemail_advanced_settings_key));

    visualVoicemailPreference =
        (SwitchPreference) findPreference(getString(R.string.voicemail_visual_voicemail_key));

    voicemailAutoArchivePreference =
        (SwitchPreference)
            findPreference(getString(R.string.voicemail_visual_voicemail_archive_key));

    transcribeVoicemailPreference =
        (SwitchPreference)
            findPreference(getString(R.string.voicemail_visual_voicemail_transcription_key));

    donateTranscribedVoicemailPreference =
        (SwitchPreference)
            findPreference(getString(R.string.voicemail_visual_voicemail_donation_key));

    voicemailChangePinPreference = findPreference(getString(R.string.voicemail_change_pin_key));
  }

    if (voicemailClient.hasCarrierSupport(getContext(), phoneAccountHandle)) {
      Assert.isNotNull(phoneAccountHandle);
      Intent changePinIntent =
          new Intent(new Intent(getContext(), VoicemailChangePinActivity.class));
  /** Removes vvm settings since the carrier setup is not supported by Dialer */
  private void removeAllVisualVoicemailPreferences() {
    PreferenceScreen prefSet = getPreferenceScreen();
    prefSet.removePreference(visualVoicemailPreference);
    prefSet.removePreference(voicemailAutoArchivePreference);
    prefSet.removePreference(transcribeVoicemailPreference);
    prefSet.removePreference(donateTranscribedVoicemailPreference);
    prefSet.removePreference(voicemailChangePinPreference);
  }

  private void setupVoicemailChangePinPreference() {
    Intent changePinIntent = new Intent(new Intent(getContext(), VoicemailChangePinActivity.class));
    changePinIntent.putExtra(VoicemailClient.PARAM_PHONE_ACCOUNT_HANDLE, phoneAccountHandle);

    voicemailChangePinPreference.setIntent(changePinIntent);
@@ -158,29 +249,26 @@ public class VoicemailSettingsFragment extends PreferenceFragment
    } else {
      voicemailChangePinPreference.setTitle(R.string.voicemail_change_pin_preference_title);
    }
      updateChangePin();
    updateChangePinPreference();
  }

      voicemailVisualVoicemail.setOnPreferenceChangeListener(this);
      voicemailVisualVoicemail.setChecked(
          voicemailClient.isVoicemailEnabled(getContext(), phoneAccountHandle));
  private void setupNotificationsPreference() {

      autoArchiveSwitchPreference.setOnPreferenceChangeListener(this);
      autoArchiveSwitchPreference.setChecked(
          voicemailClient.isVoicemailArchiveEnabled(getContext(), phoneAccountHandle));
    voicemailNotificationPreference.setIntent(getNotificationSettingsIntent());

      donateVoicemailSwitchPreference.setOnPreferenceChangeListener(this);
      donateVoicemailSwitchPreference.setChecked(
          voicemailClient.isVoicemailDonationEnabled(getContext(), phoneAccountHandle));
      updateDonateVoicemail();
    } else {
      prefSet.removePreference(voicemailVisualVoicemail);
      prefSet.removePreference(autoArchiveSwitchPreference);
      prefSet.removePreference(donateVoicemailSwitchPreference);
      prefSet.removePreference(voicemailChangePinPreference);
    voicemailNotificationPreference.setOnPreferenceClickListener(
        new OnPreferenceClickListener() {
          @Override
          public boolean onPreferenceClick(Preference preference) {
            Logger.get(getContext())
                .logImpression(DialerImpression.Type.VVM_NOTIFICATIONS_SETTING_CLICKED);
            // Let the preference handle the click.
            return false;
          }
        });
  }

    advancedSettings =
        (PreferenceScreen) findPreference(getString(R.string.voicemail_advanced_settings_key));
  private void setupAdvancedSettingsPreference() {
    Intent advancedSettingsIntent = new Intent(TelephonyManager.ACTION_CONFIGURE_VOICEMAIL);
    advancedSettingsIntent.putExtra(TelephonyManager.EXTRA_HIDE_PUBLIC_SETTINGS, true);
    advancedSettingsIntent.putExtra(
@@ -198,8 +286,9 @@ public class VoicemailSettingsFragment extends PreferenceFragment
      }
    }

    advancedSettings.setIntent(advancedSettingsIntent);
    voicemailChangePinPreference.setOnPreferenceClickListener(
    advancedSettingsPreference.setIntent(advancedSettingsIntent);

    advancedSettingsPreference.setOnPreferenceClickListener(
        new OnPreferenceClickListener() {
          @Override
          public boolean onPreferenceClick(Preference preference) {
@@ -226,7 +315,7 @@ public class VoicemailSettingsFragment extends PreferenceFragment
  @Override
  public boolean onPreferenceChange(Preference preference, Object objValue) {
    LogUtil.d(TAG, "onPreferenceChange: \"" + preference + "\" changed to \"" + objValue + "\"");
    if (preference.getKey().equals(voicemailVisualVoicemail.getKey())) {
    if (preference.getKey().equals(visualVoicemailPreference.getKey())) {
      boolean isEnabled = (boolean) objValue;
      if (!isEnabled) {
        showDisableConfirmationDialog();
@@ -235,12 +324,17 @@ public class VoicemailSettingsFragment extends PreferenceFragment
      } else {
        updateVoicemailEnabled(true);
      }
    } else if (preference.getKey().equals(autoArchiveSwitchPreference.getKey())) {
    } else if (preference.getKey().equals(voicemailAutoArchivePreference.getKey())) {
      logArchiveToggle((boolean) objValue);
      voicemailClient.setVoicemailArchiveEnabled(
          getContext(), phoneAccountHandle, (boolean) objValue);
    } else if (preference.getKey().equals(donateVoicemailSwitchPreference.getKey())) {
      logArchiveToggle((boolean) objValue);
    } else if (preference.getKey().equals(transcribeVoicemailPreference.getKey())) {
      logTranscribeToggle((boolean) objValue);
      voicemailClient.setVoicemailTranscriptionEnabled(
          getContext(), phoneAccountHandle, (boolean) objValue);
      updateTranscriptionDonationPreference();
    } else if (preference.getKey().equals(donateTranscribedVoicemailPreference.getKey())) {
      logDonationToggle((boolean) objValue);
      voicemailClient.setVoicemailDonationEnabled(
          getContext(), phoneAccountHandle, (boolean) objValue);
    }
@@ -251,19 +345,19 @@ public class VoicemailSettingsFragment extends PreferenceFragment

  private void updateVoicemailEnabled(boolean isEnabled) {
    voicemailClient.setVoicemailEnabled(getContext(), phoneAccountHandle, isEnabled);
    voicemailVisualVoicemail.setChecked(isEnabled);
    visualVoicemailPreference.setChecked(isEnabled);

    if (isEnabled) {
      Logger.get(getContext()).logImpression(DialerImpression.Type.VVM_USER_ENABLED_IN_SETTINGS);
    } else {
      Logger.get(getContext()).logImpression(DialerImpression.Type.VVM_USER_DISABLED_IN_SETTINGS);
    }

    updateChangePin();
    updateDonateVoicemail();
    updateVoicemailSummaryMessage();
    updateTranscriptionPreferences();
    updateChangePinPreference();
  }

  private void updateChangePin() {
  private void updateChangePinPreference() {
    if (!voicemailClient.isVoicemailEnabled(getContext(), phoneAccountHandle)) {
      voicemailChangePinPreference.setSummary(
          R.string.voicemail_change_pin_preference_summary_disable);
@@ -278,36 +372,55 @@ public class VoicemailSettingsFragment extends PreferenceFragment
    }
  }

  private void updateDonateVoicemail() {
    if (!voicemailClient.isVoicemailEnabled(getContext(), phoneAccountHandle)) {
      donateVoicemailSwitchPreference.setSummary(
          R.string.voicemail_donate_preference_summary_disable);
      donateVoicemailSwitchPreference.setEnabled(false);
    } else if (!voicemailClient.isActivated(getContext(), phoneAccountHandle)) {
      donateVoicemailSwitchPreference.setSummary(
          R.string.voicemail_donate_preference_summary_not_activated);
      donateVoicemailSwitchPreference.setEnabled(false);
  private void logArchiveToggle(boolean userTurnedOn) {
    if (userTurnedOn) {
      Logger.get(getContext())
          .logImpression(DialerImpression.Type.VVM_USER_TURNED_ARCHIVE_ON_FROM_SETTINGS);
    } else {
      donateVoicemailSwitchPreference.setSummary(R.string.voicemail_donate_preference_summary_info);
      donateVoicemailSwitchPreference.setEnabled(true);
      Logger.get(getContext())
          .logImpression(DialerImpression.Type.VVM_USER_TURNED_ARCHIVE_OFF_FROM_SETTINGS);
    }
  }

  private void logArchiveToggle(boolean userTurnedOn) {
  private void logTranscribeToggle(boolean userTurnedOn) {
    if (userTurnedOn) {
      Logger.get(getContext())
          .logImpression(DialerImpression.Type.VVM_USER_TURNED_ARCHIVE_ON_FROM_SETTINGS);
          .logImpression(DialerImpression.Type.VVM_USER_TURNED_TRANSCRIBE_ON_FROM_SETTINGS);
    } else {
      Logger.get(getContext())
          .logImpression(DialerImpression.Type.VVM_USER_TURNED_ARCHIVE_OFF_FROM_SETTINGS);
          .logImpression(DialerImpression.Type.VVM_USER_TURNED_TRANSCRIBE_OFF_FROM_SETTINGS);
    }
  }

  private void logDonationToggle(boolean userTurnedOn) {
    if (userTurnedOn) {
      Logger.get(getContext())
          .logImpression(DialerImpression.Type.VVM_USER_TURNED_TRANSCRIBE_ON_FROM_SETTINGS);
    } else {
      Logger.get(getContext())
          .logImpression(DialerImpression.Type.VVM_USER_TURNED_TRANSCRIBE_OFF_FROM_SETTINGS);
    }
  }

  @Override
  public void onActivationStateChanged(PhoneAccountHandle phoneAccountHandle, boolean isActivated) {
    if (this.phoneAccountHandle.equals(phoneAccountHandle)) {
      updateChangePin();
      updateDonateVoicemail();
      updateVoicemailSummaryMessage();
      updateTranscriptionPreferences();
      updateChangePinPreference();
    }
  }

  /**
   * Shows the activating message while visual voicemail is being activated. This is useful, since
   * some toggles do not show up, until voicemail is activated e.g transcription and rating.
   */
  private void updateVoicemailSummaryMessage() {
    if (voicemailClient.isVoicemailEnabled(getContext(), phoneAccountHandle)
        && !voicemailClient.isActivated(getContext(), phoneAccountHandle)) {
      visualVoicemailPreference.setSummary(R.string.voicemail_activating_summary_info);
    } else {
      visualVoicemailPreference.setSummary("");
    }
  }

+13 −8

File changed.

Preview size limit exceeded, changes collapsed.

+5 −1
Original line number Diff line number Diff line
@@ -31,8 +31,12 @@
    android:title="@string/voicemail_visual_voicemail_auto_archive_switch_title"/>"

  <SwitchPreference
    android:key="@string/voicemail_visual_voicemail_donation_key"
      android:key="@string/voicemail_visual_voicemail_transcription_key"
      android:dependency="@string/voicemail_visual_voicemail_key"
      android:title="@string/voicemail_visual_voicemail_transcription_switch_title"/>"
  <SwitchPreference
    android:key="@string/voicemail_visual_voicemail_donation_key"
    android:dependency="@string/voicemail_visual_voicemail_transcription_key"
    android:title="@string/voicemail_visual_voicemail_donation_switch_title"/>"

  <Preference
Loading