From b62996a57c8337259a6ccabe80668673d93fe1e2 Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Sat, 9 Jan 2021 14:29:59 +0100 Subject: [PATCH] Setting to allow or not inline suggestions --- .../keepass/autofill/AutofillHelper.kt | 7 ++++-- .../keepass/autofill/KeeAutofillService.kt | 6 +++-- .../settings/AutofillSettingsFragment.kt | 7 ++++++ .../keepass/settings/PreferencesUtil.kt | 7 +++++- .../main/res/values-v30/donottranslate.xml | 22 +++++++++++++++++++ app/src/main/res/values/donottranslate.xml | 2 ++ app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/preferences_autofill.xml | 5 +++++ 8 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 app/src/main/res/values-v30/donottranslate.xml diff --git a/app/src/main/java/com/kunzisoft/keepass/autofill/AutofillHelper.kt b/app/src/main/java/com/kunzisoft/keepass/autofill/AutofillHelper.kt index 22bfd9344..fb50eaf4f 100644 --- a/app/src/main/java/com/kunzisoft/keepass/autofill/AutofillHelper.kt +++ b/app/src/main/java/com/kunzisoft/keepass/autofill/AutofillHelper.kt @@ -49,6 +49,7 @@ import com.kunzisoft.keepass.icons.assignDatabaseIcon import com.kunzisoft.keepass.icons.createIconFromDatabaseIcon import com.kunzisoft.keepass.model.EntryInfo import com.kunzisoft.keepass.model.SearchInfo +import com.kunzisoft.keepass.settings.PreferencesUtil @RequiresApi(api = Build.VERSION_CODES.O) @@ -171,7 +172,8 @@ object AutofillHelper { // Add inline suggestion for new IME and dataset entriesInfo.forEachIndexed { index, entryInfo -> val inlinePresentation = inlineSuggestionsRequest?.let { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R + && PreferencesUtil.isAutofillInlineSuggestionsEnable(context)) { buildInlinePresentationForEntry(context, inlineSuggestionsRequest, index, entryInfo) } else { null @@ -227,7 +229,8 @@ object AutofillHelper { searchInfo: SearchInfo?) { EntrySelectionHelper.addSpecialModeInIntent(intent, SpecialMode.SELECTION) intent.putExtra(EXTRA_ASSIST_STRUCTURE, autofillComponent.assistStructure) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R + && PreferencesUtil.isAutofillInlineSuggestionsEnable(activity)) { autofillComponent.inlineSuggestionsRequest?.let { intent.putExtra(EXTRA_INLINE_SUGGESTIONS_REQUEST, it) } diff --git a/app/src/main/java/com/kunzisoft/keepass/autofill/KeeAutofillService.kt b/app/src/main/java/com/kunzisoft/keepass/autofill/KeeAutofillService.kt index f4ea3bd7a..663defb1d 100644 --- a/app/src/main/java/com/kunzisoft/keepass/autofill/KeeAutofillService.kt +++ b/app/src/main/java/com/kunzisoft/keepass/autofill/KeeAutofillService.kt @@ -82,7 +82,8 @@ class KeeAutofillService : AutofillService() { } SearchInfo.getConcreteWebDomain(this, searchInfo.webDomain) { webDomainWithoutSubDomain -> searchInfo.webDomain = webDomainWithoutSubDomain - val inlineSuggestionsRequest = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + val inlineSuggestionsRequest = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R + && PreferencesUtil.isAutofillInlineSuggestionsEnable(this)) { request.inlineSuggestionsRequest } else { null @@ -168,7 +169,8 @@ class KeeAutofillService : AutofillService() { // Build inline presentation var inlinePresentation: InlinePresentation? = null - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R + && PreferencesUtil.isAutofillInlineSuggestionsEnable(this)) { inlineSuggestionsRequest?.let { val inlinePresentationSpecs = inlineSuggestionsRequest.inlinePresentationSpecs if (inlineSuggestionsRequest.maxSuggestionCount > 0 diff --git a/app/src/main/java/com/kunzisoft/keepass/settings/AutofillSettingsFragment.kt b/app/src/main/java/com/kunzisoft/keepass/settings/AutofillSettingsFragment.kt index cba9c231d..f3462752b 100644 --- a/app/src/main/java/com/kunzisoft/keepass/settings/AutofillSettingsFragment.kt +++ b/app/src/main/java/com/kunzisoft/keepass/settings/AutofillSettingsFragment.kt @@ -19,10 +19,12 @@ */ package com.kunzisoft.keepass.settings +import android.os.Build import android.os.Bundle import androidx.fragment.app.DialogFragment import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat +import androidx.preference.SwitchPreference import com.kunzisoft.keepass.R import com.kunzisoft.keepass.settings.preferencedialogfragment.AutofillBlocklistAppIdPreferenceDialogFragmentCompat import com.kunzisoft.keepass.settings.preferencedialogfragment.AutofillBlocklistWebDomainPreferenceDialogFragmentCompat @@ -32,6 +34,11 @@ class AutofillSettingsFragment : PreferenceFragmentCompat() { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { // Load the preferences from an XML resource setPreferencesFromResource(R.xml.preferences_autofill, rootKey) + + val autofillInlineSuggestionsPreference: SwitchPreference? = findPreference(getString(R.string.autofill_inline_suggestions_key)) + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { + autofillInlineSuggestionsPreference?.isVisible = false + } } override fun onDisplayPreferenceDialog(preference: Preference?) { diff --git a/app/src/main/java/com/kunzisoft/keepass/settings/PreferencesUtil.kt b/app/src/main/java/com/kunzisoft/keepass/settings/PreferencesUtil.kt index f9c2f415d..f2c166d9e 100644 --- a/app/src/main/java/com/kunzisoft/keepass/settings/PreferencesUtil.kt +++ b/app/src/main/java/com/kunzisoft/keepass/settings/PreferencesUtil.kt @@ -436,13 +436,18 @@ object PreferencesUtil { context.resources.getBoolean(R.bool.autofill_close_database_default)) } - fun isAutofillAutoSearchEnable(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.autofill_auto_search_key), context.resources.getBoolean(R.bool.autofill_auto_search_default)) } + fun isAutofillInlineSuggestionsEnable(context: Context): Boolean { + val prefs = PreferenceManager.getDefaultSharedPreferences(context) + return prefs.getBoolean(context.getString(R.string.autofill_inline_suggestions_key), + context.resources.getBoolean(R.bool.autofill_inline_suggestions_default)) + } + fun isAutofillSaveSearchInfoEnable(context: Context): Boolean { val prefs = PreferenceManager.getDefaultSharedPreferences(context) return prefs.getBoolean(context.getString(R.string.autofill_save_search_info_key), diff --git a/app/src/main/res/values-v30/donottranslate.xml b/app/src/main/res/values-v30/donottranslate.xml new file mode 100644 index 000000000..fc50571b3 --- /dev/null +++ b/app/src/main/res/values-v30/donottranslate.xml @@ -0,0 +1,22 @@ + + + + true + diff --git a/app/src/main/res/values/donottranslate.xml b/app/src/main/res/values/donottranslate.xml index 757f9f374..fd145926f 100644 --- a/app/src/main/res/values/donottranslate.xml +++ b/app/src/main/res/values/donottranslate.xml @@ -151,6 +151,8 @@ false autofill_auto_search_key true + autofill_inline_suggestions_key + false autofill_save_search_info_key true autofill_ask_to_save_data_key diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b1b244d63..295f5dc3d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -432,6 +432,8 @@ Close the database after an autofill selection Auto search Automatically suggest search results from the web domain or application ID + Inline suggestions + Attempt to display autofill suggestions directly from a compatible keyboard Save search info Try to save search information when making a manual entry selection Ask to save data diff --git a/app/src/main/res/xml/preferences_autofill.xml b/app/src/main/res/xml/preferences_autofill.xml index 53f00db66..5ab891b4c 100644 --- a/app/src/main/res/xml/preferences_autofill.xml +++ b/app/src/main/res/xml/preferences_autofill.xml @@ -30,6 +30,11 @@ android:title="@string/autofill_auto_search_title" android:summary="@string/autofill_auto_search_summary" android:defaultValue="@bool/autofill_auto_search_default"/> +