Loading android/app/src/main/java/foundation/e/stt/ConsentActivity.kt +3 −19 Original line number Diff line number Diff line Loading @@ -7,30 +7,14 @@ import android.os.Build import android.os.Bundle import android.os.LocaleList import android.widget.TextView import androidx.annotation.IntDef import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity import androidx.core.net.toUri import com.google.android.material.dialog.MaterialAlertDialogBuilder @IntDef(ConsentActivity.CONSENT_NOT_YET_GIVEN, ConsentActivity.CONSENT_GIVEN, ConsentActivity.CONSENT_REFUSED) @Retention(AnnotationRetention.SOURCE) annotation class ConsentStatus class ConsentActivity : AppCompatActivity() { companion object { const val CONSENT_NOT_YET_GIVEN = 0 const val CONSENT_GIVEN = 1 const val CONSENT_REFUSED = 2 @ConsentStatus fun hasGivenConsent(): Int = UserPreference.hasGivenConsentForSTT fun setConsentGiven(@ConsentStatus given: Int) { UserPreference.hasGivenConsentForSTT = given } private val SUPPORTED_LANGUAGES = setOf("fr", "es", "de", "it") fun getTermsOfServiceLanguage(): String { Loading @@ -49,7 +33,7 @@ class ConsentActivity : AppCompatActivity() { UserPreference.init(this) if (hasGivenConsent() != CONSENT_NOT_YET_GIVEN) { if (UserPreference.hasGivenConsentForSTT) { finish() return } Loading @@ -70,11 +54,11 @@ class ConsentActivity : AppCompatActivity() { .setTitle(R.string.consent_dialog_title) .setView(messageTextView) .setPositiveButton(R.string.consent_dialog_yes) { _, _ -> setConsentGiven(CONSENT_GIVEN) UserPreference.hasGivenConsentForSTT = true finish() } .setNegativeButton(R.string.consent_dialog_no) { _, _ -> setConsentGiven(CONSENT_REFUSED) UserPreference.hasGivenConsentForSTT = false finish() } .setNeutralButton(R.string.consent_dialog_terms_of_service, null) Loading android/app/src/main/java/foundation/e/stt/MurenaWhisperInputService.kt +7 −7 Original line number Diff line number Diff line Loading @@ -352,7 +352,11 @@ class MurenaWhisperInputService : InputMethodService() { UserPreference.init(this@MurenaWhisperInputService) if (ConsentActivity.hasGivenConsent() == ConsentActivity.CONSENT_NOT_YET_GIVEN) { if (UserPreference.hasGivenConsentForSTT) { showKeyboard() attachRecorderCallbacks() initApp() } else { consentPrefs = applicationContext .getSharedPreferences(UserPreference.PREF_NAME, Context.MODE_PRIVATE) consentPrefs.registerOnSharedPreferenceChangeListener(consentListener) Loading @@ -360,10 +364,6 @@ class MurenaWhisperInputService : InputMethodService() { val intent = Intent(applicationContext, ConsentActivity::class.java) intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK startActivity(intent) } else { showKeyboard() attachRecorderCallbacks() initApp() } } } Loading Loading @@ -454,8 +454,8 @@ class MurenaWhisperInputService : InputMethodService() { if (key == UserPreference.PREF_CONSENT_STT) { sp.unregisterOnSharedPreferenceChangeListener(consentListener) val granted = sp.getInt(key, ConsentActivity.CONSENT_NOT_YET_GIVEN) if (granted == ConsentActivity.CONSENT_GIVEN) { val granted = sp.getBoolean(key, false) if (granted) { showKeyboard() initApp() } else { Loading android/app/src/main/java/foundation/e/stt/StartupReceiver.kt +2 −1 Original line number Diff line number Diff line Loading @@ -47,8 +47,9 @@ class StartupReceiver : BroadcastReceiver() { var enabledImes: String? = Settings.Secure.getString(cr, Settings.Secure.ENABLED_INPUT_METHODS) val accountIsPremium = AccountManagerHelper.accountIsPremium(context.applicationContext) val sttKeyboardActivated = !enabledImes.isNullOrEmpty() && enabledImes.contains(imeId) val sttNotActivated = !sttKeyboardActivated && !UserPreference.isSttFeatureActivated if (accountIsPremium && !sttKeyboardActivated && !UserPreference.isSttFeatureActivated && UserPreference.hasGivenConsentForSTT != ConsentActivity.CONSENT_REFUSED) { if (accountIsPremium && sttNotActivated && UserPreference.hasGivenConsentForSTT) { SttKeyboardManager.enabledSttKeyboard(context) } else if (!accountIsPremium && sttKeyboardActivated) { // Remove the STT keyboard if it's enabled for a non-premium account Loading android/app/src/main/java/foundation/e/stt/UserPreference.kt +3 −5 Original line number Diff line number Diff line Loading @@ -46,11 +46,9 @@ object UserPreference { get() = sharedPreferences.getBoolean(PREF_AUTO_ACTIVATED, false) set(value) = sharedPreferences.edit() { putBoolean(PREF_AUTO_ACTIVATED, value) } @get:ConsentStatus @setparam:ConsentStatus var hasGivenConsentForSTT: Int get() = sharedPreferences.getInt(PREF_CONSENT_STT, ConsentActivity.CONSENT_NOT_YET_GIVEN) set(value) = sharedPreferences.edit() { putInt(PREF_CONSENT_STT, value) } var hasGivenConsentForSTT: Boolean get() = sharedPreferences.getBoolean(PREF_CONSENT_STT, false) set(value) = sharedPreferences.edit() { putBoolean(PREF_CONSENT_STT, value) } var isVoiceAnonymizerEnabled: Boolean get() = sharedPreferences.getBoolean(PREF_VOICE_ANONYMIZER_ENABLED, true) Loading Loading
android/app/src/main/java/foundation/e/stt/ConsentActivity.kt +3 −19 Original line number Diff line number Diff line Loading @@ -7,30 +7,14 @@ import android.os.Build import android.os.Bundle import android.os.LocaleList import android.widget.TextView import androidx.annotation.IntDef import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity import androidx.core.net.toUri import com.google.android.material.dialog.MaterialAlertDialogBuilder @IntDef(ConsentActivity.CONSENT_NOT_YET_GIVEN, ConsentActivity.CONSENT_GIVEN, ConsentActivity.CONSENT_REFUSED) @Retention(AnnotationRetention.SOURCE) annotation class ConsentStatus class ConsentActivity : AppCompatActivity() { companion object { const val CONSENT_NOT_YET_GIVEN = 0 const val CONSENT_GIVEN = 1 const val CONSENT_REFUSED = 2 @ConsentStatus fun hasGivenConsent(): Int = UserPreference.hasGivenConsentForSTT fun setConsentGiven(@ConsentStatus given: Int) { UserPreference.hasGivenConsentForSTT = given } private val SUPPORTED_LANGUAGES = setOf("fr", "es", "de", "it") fun getTermsOfServiceLanguage(): String { Loading @@ -49,7 +33,7 @@ class ConsentActivity : AppCompatActivity() { UserPreference.init(this) if (hasGivenConsent() != CONSENT_NOT_YET_GIVEN) { if (UserPreference.hasGivenConsentForSTT) { finish() return } Loading @@ -70,11 +54,11 @@ class ConsentActivity : AppCompatActivity() { .setTitle(R.string.consent_dialog_title) .setView(messageTextView) .setPositiveButton(R.string.consent_dialog_yes) { _, _ -> setConsentGiven(CONSENT_GIVEN) UserPreference.hasGivenConsentForSTT = true finish() } .setNegativeButton(R.string.consent_dialog_no) { _, _ -> setConsentGiven(CONSENT_REFUSED) UserPreference.hasGivenConsentForSTT = false finish() } .setNeutralButton(R.string.consent_dialog_terms_of_service, null) Loading
android/app/src/main/java/foundation/e/stt/MurenaWhisperInputService.kt +7 −7 Original line number Diff line number Diff line Loading @@ -352,7 +352,11 @@ class MurenaWhisperInputService : InputMethodService() { UserPreference.init(this@MurenaWhisperInputService) if (ConsentActivity.hasGivenConsent() == ConsentActivity.CONSENT_NOT_YET_GIVEN) { if (UserPreference.hasGivenConsentForSTT) { showKeyboard() attachRecorderCallbacks() initApp() } else { consentPrefs = applicationContext .getSharedPreferences(UserPreference.PREF_NAME, Context.MODE_PRIVATE) consentPrefs.registerOnSharedPreferenceChangeListener(consentListener) Loading @@ -360,10 +364,6 @@ class MurenaWhisperInputService : InputMethodService() { val intent = Intent(applicationContext, ConsentActivity::class.java) intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK startActivity(intent) } else { showKeyboard() attachRecorderCallbacks() initApp() } } } Loading Loading @@ -454,8 +454,8 @@ class MurenaWhisperInputService : InputMethodService() { if (key == UserPreference.PREF_CONSENT_STT) { sp.unregisterOnSharedPreferenceChangeListener(consentListener) val granted = sp.getInt(key, ConsentActivity.CONSENT_NOT_YET_GIVEN) if (granted == ConsentActivity.CONSENT_GIVEN) { val granted = sp.getBoolean(key, false) if (granted) { showKeyboard() initApp() } else { Loading
android/app/src/main/java/foundation/e/stt/StartupReceiver.kt +2 −1 Original line number Diff line number Diff line Loading @@ -47,8 +47,9 @@ class StartupReceiver : BroadcastReceiver() { var enabledImes: String? = Settings.Secure.getString(cr, Settings.Secure.ENABLED_INPUT_METHODS) val accountIsPremium = AccountManagerHelper.accountIsPremium(context.applicationContext) val sttKeyboardActivated = !enabledImes.isNullOrEmpty() && enabledImes.contains(imeId) val sttNotActivated = !sttKeyboardActivated && !UserPreference.isSttFeatureActivated if (accountIsPremium && !sttKeyboardActivated && !UserPreference.isSttFeatureActivated && UserPreference.hasGivenConsentForSTT != ConsentActivity.CONSENT_REFUSED) { if (accountIsPremium && sttNotActivated && UserPreference.hasGivenConsentForSTT) { SttKeyboardManager.enabledSttKeyboard(context) } else if (!accountIsPremium && sttKeyboardActivated) { // Remove the STT keyboard if it's enabled for a non-premium account Loading
android/app/src/main/java/foundation/e/stt/UserPreference.kt +3 −5 Original line number Diff line number Diff line Loading @@ -46,11 +46,9 @@ object UserPreference { get() = sharedPreferences.getBoolean(PREF_AUTO_ACTIVATED, false) set(value) = sharedPreferences.edit() { putBoolean(PREF_AUTO_ACTIVATED, value) } @get:ConsentStatus @setparam:ConsentStatus var hasGivenConsentForSTT: Int get() = sharedPreferences.getInt(PREF_CONSENT_STT, ConsentActivity.CONSENT_NOT_YET_GIVEN) set(value) = sharedPreferences.edit() { putInt(PREF_CONSENT_STT, value) } var hasGivenConsentForSTT: Boolean get() = sharedPreferences.getBoolean(PREF_CONSENT_STT, false) set(value) = sharedPreferences.edit() { putBoolean(PREF_CONSENT_STT, value) } var isVoiceAnonymizerEnabled: Boolean get() = sharedPreferences.getBoolean(PREF_VOICE_ANONYMIZER_ENABLED, true) Loading