From ec1a970dec22d68773f8ae9dbde6f17df6154e03 Mon Sep 17 00:00:00 2001 From: mdooley Date: Fri, 27 Oct 2017 16:20:32 -0700 Subject: internal change Bug: 62423454 Test: manual and updated unit test PiperOrigin-RevId: 173731907 Change-Id: Ic73600197b1c4fa6ac0937a8c38b048cd8faded8 --- .../impl/settings/VisualVoicemailSettingsUtil.java | 21 ++++++++++++ .../impl/settings/VoicemailSettingsFragment.java | 38 ++++++++++++++++++++++ 2 files changed, 59 insertions(+) (limited to 'java/com/android/voicemail/impl/settings') diff --git a/java/com/android/voicemail/impl/settings/VisualVoicemailSettingsUtil.java b/java/com/android/voicemail/impl/settings/VisualVoicemailSettingsUtil.java index ae526d168..6694a5db8 100644 --- a/java/com/android/voicemail/impl/settings/VisualVoicemailSettingsUtil.java +++ b/java/com/android/voicemail/impl/settings/VisualVoicemailSettingsUtil.java @@ -57,6 +57,18 @@ public class VisualVoicemailSettingsUtil { .apply(); } + public static void setVoicemailDonationEnabled( + Context context, PhoneAccountHandle phoneAccount, boolean isEnabled) { + Assert.checkArgument( + VoicemailComponent.get(context) + .getVoicemailClient() + .isVoicemailTranscriptionAvailable(context)); + new VisualVoicemailPreferences(context, phoneAccount) + .edit() + .putBoolean(context.getString(R.string.voicemail_visual_voicemail_donation_key), isEnabled) + .apply(); + } + public static boolean isEnabled(Context context, PhoneAccountHandle phoneAccount) { if (phoneAccount == null) { return false; @@ -79,6 +91,15 @@ public class VisualVoicemailSettingsUtil { context.getString(R.string.voicemail_visual_voicemail_archive_key), false); } + public static boolean isVoicemailDonationEnabled( + Context context, PhoneAccountHandle phoneAccount) { + Assert.isNotNull(phoneAccount); + + VisualVoicemailPreferences prefs = new VisualVoicemailPreferences(context, phoneAccount); + return prefs.getBoolean( + context.getString(R.string.voicemail_visual_voicemail_donation_key), false); + } + /** * Whether the client enabled status is explicitly set by user or by default(Whether carrier VVM * app is installed). This is used to determine whether to disable the client when the carrier VVM diff --git a/java/com/android/voicemail/impl/settings/VoicemailSettingsFragment.java b/java/com/android/voicemail/impl/settings/VoicemailSettingsFragment.java index e2ea72569..465223811 100644 --- a/java/com/android/voicemail/impl/settings/VoicemailSettingsFragment.java +++ b/java/com/android/voicemail/impl/settings/VoicemailSettingsFragment.java @@ -53,6 +53,7 @@ public class VoicemailSettingsFragment extends PreferenceFragment private Preference voicemailNotificationPreference; private SwitchPreference voicemailVisualVoicemail; private SwitchPreference autoArchiveSwitchPreference; + private SwitchPreference donateVoicemailSwitchPreference; private Preference voicemailChangePinPreference; private PreferenceScreen advancedSettings; @@ -102,12 +103,22 @@ public class VoicemailSettingsFragment extends PreferenceFragment (SwitchPreference) findPreference(getString(R.string.voicemail_visual_voicemail_archive_key)); + donateVoicemailSwitchPreference = + (SwitchPreference) + findPreference(getString(R.string.voicemail_visual_voicemail_donation_key)); + if (!VoicemailComponent.get(getContext()) .getVoicemailClient() .isVoicemailArchiveAvailable(getContext())) { getPreferenceScreen().removePreference(autoArchiveSwitchPreference); } + if (!VoicemailComponent.get(getContext()) + .getVoicemailClient() + .isVoicemailDonationEnabled(getContext(), phoneAccountHandle)) { + getPreferenceScreen().removePreference(donateVoicemailSwitchPreference); + } + voicemailChangePinPreference = findPreference(getString(R.string.voicemail_change_pin_key)); if (omtpVvmCarrierConfigHelper.isValid()) { @@ -141,9 +152,15 @@ public class VoicemailSettingsFragment extends PreferenceFragment autoArchiveSwitchPreference.setOnPreferenceChangeListener(this); autoArchiveSwitchPreference.setChecked( VisualVoicemailSettingsUtil.isArchiveEnabled(getContext(), phoneAccountHandle)); + + donateVoicemailSwitchPreference.setOnPreferenceChangeListener(this); + donateVoicemailSwitchPreference.setChecked( + VisualVoicemailSettingsUtil.isVoicemailDonationEnabled(getContext(), phoneAccountHandle)); + updateDonateVoicemail(); } else { prefSet.removePreference(voicemailVisualVoicemail); prefSet.removePreference(autoArchiveSwitchPreference); + prefSet.removePreference(donateVoicemailSwitchPreference); prefSet.removePreference(voicemailChangePinPreference); } @@ -192,10 +209,15 @@ public class VoicemailSettingsFragment extends PreferenceFragment } updateChangePin(); + updateDonateVoicemail(); } else if (preference.getKey().equals(autoArchiveSwitchPreference.getKey())) { logArchiveToggle((boolean) objValue); VisualVoicemailSettingsUtil.setArchiveEnabled( getContext(), phoneAccountHandle, (boolean) objValue); + } else if (preference.getKey().equals(donateVoicemailSwitchPreference.getKey())) { + logArchiveToggle((boolean) objValue); + VisualVoicemailSettingsUtil.setVoicemailDonationEnabled( + getContext(), phoneAccountHandle, (boolean) objValue); } // Always let the preference setting proceed. @@ -217,6 +239,21 @@ public class VoicemailSettingsFragment extends PreferenceFragment } } + private void updateDonateVoicemail() { + if (!VisualVoicemailSettingsUtil.isEnabled(getContext(), phoneAccountHandle)) { + donateVoicemailSwitchPreference.setSummary( + R.string.voicemail_donate_preference_summary_disable); + donateVoicemailSwitchPreference.setEnabled(false); + } else if (!VvmAccountManager.isAccountActivated(getContext(), phoneAccountHandle)) { + donateVoicemailSwitchPreference.setSummary( + R.string.voicemail_donate_preference_summary_not_activated); + donateVoicemailSwitchPreference.setEnabled(false); + } else { + donateVoicemailSwitchPreference.setSummary(R.string.voicemail_donate_preference_summary_info); + donateVoicemailSwitchPreference.setEnabled(true); + } + } + private void logArchiveToggle(boolean userTurnedOn) { if (userTurnedOn) { Logger.get(getContext()) @@ -231,6 +268,7 @@ public class VoicemailSettingsFragment extends PreferenceFragment public void onActivationStateChanged(PhoneAccountHandle phoneAccountHandle, boolean isActivated) { if (this.phoneAccountHandle.equals(phoneAccountHandle)) { updateChangePin(); + updateDonateVoicemail(); } } -- cgit v1.2.3