diff --git a/app/src/main/java/dev/patrickgold/florisboard/ime/core/PrefHelper.kt b/app/src/main/java/dev/patrickgold/florisboard/ime/core/PrefHelper.kt index 2a17ce1f..7e48e5bd 100644 --- a/app/src/main/java/dev/patrickgold/florisboard/ime/core/PrefHelper.kt +++ b/app/src/main/java/dev/patrickgold/florisboard/ime/core/PrefHelper.kt @@ -51,6 +51,7 @@ class PrefHelper( val clipboard = Clipboard(this) val correction = Correction(this) val devtools = Devtools(this) + val dictionary = Dictionary(this) val gestures = Gestures(this) val glide = Glide(this) val internal = Internal(this) @@ -240,6 +241,25 @@ class PrefHelper( set(v) = prefHelper.setPref(SHOW_HEAP_MEMORY_STATS, v) } + /** + * Wrapper class for dictionary preferences. + */ + class Dictionary(private val prefHelper: PrefHelper) { + companion object { + const val ENABLE_SYSTEM_USER_DICTIONARY = "suggestion__enable_system_user_dictionary" + const val MANAGE_SYSTEM_USER_DICTIONARY = "suggestion__manage_system_user_dictionary" + const val ENABLE_INTERNAL_USER_DICTIONARY = "suggestion__enable_internal_user_dictionary" + const val MANAGE_INTERNAL_USER_DICTIONARY = "suggestion__manage_internal_user_dictionary" + } + + var enableSystemUserDictionary: Boolean + get() = prefHelper.getPref(ENABLE_SYSTEM_USER_DICTIONARY, true) + set(v) = prefHelper.setPref(ENABLE_SYSTEM_USER_DICTIONARY, v) + var enableInternalUserDictionary: Boolean + get() = prefHelper.getPref(ENABLE_INTERNAL_USER_DICTIONARY, true) + set(v) = prefHelper.setPref(ENABLE_INTERNAL_USER_DICTIONARY, v) + } + /** * Wrapper class for gestures preferences. */ diff --git a/app/src/main/java/dev/patrickgold/florisboard/settings/fragments/TypingFragment.kt b/app/src/main/java/dev/patrickgold/florisboard/settings/fragments/TypingFragment.kt index 34ec5552..cb81830f 100644 --- a/app/src/main/java/dev/patrickgold/florisboard/settings/fragments/TypingFragment.kt +++ b/app/src/main/java/dev/patrickgold/florisboard/settings/fragments/TypingFragment.kt @@ -60,7 +60,7 @@ class TypingFragment : SettingsMainActivity.SettingsFragment() { .beginTransaction() .replace( binding.prefsFrame.id, - SettingsMainActivity.PrefFragment.createFromResource(R.xml.prefs_typing) + TypingInnerFragment() ) .commit() diff --git a/app/src/main/java/dev/patrickgold/florisboard/settings/fragments/TypingInnerFragment.kt b/app/src/main/java/dev/patrickgold/florisboard/settings/fragments/TypingInnerFragment.kt new file mode 100644 index 00000000..abbf99c3 --- /dev/null +++ b/app/src/main/java/dev/patrickgold/florisboard/settings/fragments/TypingInnerFragment.kt @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2021 Patrick Goldinger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.patrickgold.florisboard.settings.fragments + +import android.content.Intent +import android.os.Bundle +import androidx.preference.Preference +import androidx.preference.PreferenceFragmentCompat +import dev.patrickgold.florisboard.R +import dev.patrickgold.florisboard.ime.core.PrefHelper + +class TypingInnerFragment : PreferenceFragmentCompat() { + companion object { + private const val USER_DICTIONARY_SETTINGS_INTENT_ACTION: String = + "android.settings.USER_DICTIONARY_SETTINGS" + } + + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + addPreferencesFromResource(R.xml.prefs_typing) + } + + override fun onPreferenceTreeClick(preference: Preference?): Boolean { + return when (preference?.key) { + PrefHelper.Dictionary.MANAGE_SYSTEM_USER_DICTIONARY -> { + val intent = Intent(USER_DICTIONARY_SETTINGS_INTENT_ACTION) + startActivity(intent) + true + } + PrefHelper.Dictionary.MANAGE_INTERNAL_USER_DICTIONARY -> { + // NYI + true + } + else -> super.onPreferenceTreeClick(preference) + } + } +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3656cd48..7c3ccc18 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -240,6 +240,15 @@ Classic (3 columns) Dynamic width Dynamic width & scrollable + Dictionary + Enable system user dictionary + Suggest words stored in the system user dictionary + Manage system user dictionary + Add, view, and remove entries for the system user dictionary + Enable internal user dictionary + Suggest words stored in the internal user dictionary + Manage internal user dictionary + Add, view, and remove entries for the internal user dictionary Corrections Auto-capitalization Capitalize words based on the current input context diff --git a/app/src/main/res/xml/prefs_typing.xml b/app/src/main/res/xml/prefs_typing.xml index e30d41df..180d92df 100644 --- a/app/src/main/res/xml/prefs_typing.xml +++ b/app/src/main/res/xml/prefs_typing.xml @@ -69,6 +69,42 @@ + + + + + + + + + + + +