From a7530f84656f1060957b14a4c946fd02cf88f7cd Mon Sep 17 00:00:00 2001 From: uabdullah Date: Fri, 16 Mar 2018 17:32:54 -0700 Subject: 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 --- .../impl/settings/VisualVoicemailSettingsUtil.java | 53 +++++++++++++++------- 1 file changed, 37 insertions(+), 16 deletions(-) (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 e42d56938..3e006988e 100644 --- a/java/com/android/voicemail/impl/settings/VisualVoicemailSettingsUtil.java +++ b/java/com/android/voicemail/impl/settings/VisualVoicemailSettingsUtil.java @@ -33,6 +33,7 @@ public class VisualVoicemailSettingsUtil { @VisibleForTesting public static final String IS_ENABLED_KEY = "is_enabled"; private static final String ARCHIVE_ENABLED_KEY = "archive_is_enabled"; + private static final String TRANSCRIBE_VOICEMAILS_KEY = "transcribe_voicemails"; private static final String DONATE_VOICEMAILS_KEY = "donate_voicemails"; public static void setEnabled( @@ -59,21 +60,6 @@ public class VisualVoicemailSettingsUtil { } } - private static class VoicemailDeleteWorker implements Worker { - private final Context context; - - VoicemailDeleteWorker(Context context) { - this.context = context; - } - - @Override - public Void doInBackground(Void unused) { - int deleted = VoicemailDatabaseUtil.deleteAll(context); - VvmLog.i("VisualVoicemailSettingsUtil.doInBackground", "deleted " + deleted + " voicemails"); - return null; - } - } - private static void onSuccess(Void unused) { VvmLog.i("VisualVoicemailSettingsUtil.onSuccess", "delete voicemails"); } @@ -92,12 +78,24 @@ public class VisualVoicemailSettingsUtil { .apply(); } + public static void setVoicemailTranscriptionEnabled( + Context context, PhoneAccountHandle phoneAccount, boolean isEnabled) { + Assert.checkArgument( + VoicemailComponent.get(context) + .getVoicemailClient() + .isVoicemailTranscriptionAvailable(context, phoneAccount)); + new VisualVoicemailPreferences(context, phoneAccount) + .edit() + .putBoolean(TRANSCRIBE_VOICEMAILS_KEY, isEnabled) + .apply(); + } + public static void setVoicemailDonationEnabled( Context context, PhoneAccountHandle phoneAccount, boolean isEnabled) { Assert.checkArgument( VoicemailComponent.get(context) .getVoicemailClient() - .isVoicemailTranscriptionAvailable(context)); + .isVoicemailTranscriptionAvailable(context, phoneAccount)); new VisualVoicemailPreferences(context, phoneAccount) .edit() .putBoolean(DONATE_VOICEMAILS_KEY, isEnabled) @@ -125,6 +123,14 @@ public class VisualVoicemailSettingsUtil { return prefs.getBoolean(ARCHIVE_ENABLED_KEY, false); } + public static boolean isVoicemailTranscriptionEnabled( + Context context, PhoneAccountHandle phoneAccount) { + Assert.isNotNull(phoneAccount); + + VisualVoicemailPreferences prefs = new VisualVoicemailPreferences(context, phoneAccount); + return prefs.getBoolean(TRANSCRIBE_VOICEMAILS_KEY, false); + } + public static boolean isVoicemailDonationEnabled( Context context, PhoneAccountHandle phoneAccount) { Assert.isNotNull(phoneAccount); @@ -146,4 +152,19 @@ public class VisualVoicemailSettingsUtil { VisualVoicemailPreferences prefs = new VisualVoicemailPreferences(context, phoneAccount); return prefs.contains(IS_ENABLED_KEY); } + + private static class VoicemailDeleteWorker implements Worker { + private final Context context; + + VoicemailDeleteWorker(Context context) { + this.context = context; + } + + @Override + public Void doInBackground(Void unused) { + int deleted = VoicemailDatabaseUtil.deleteAll(context); + VvmLog.i("VisualVoicemailSettingsUtil.doInBackground", "deleted " + deleted + " voicemails"); + return null; + } + } } -- cgit v1.2.3