mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-04-20 06:09:09 +00:00
rename some stuff
This commit is contained in:
parent
b62eaba3e4
commit
efc7f1842b
26 changed files with 415 additions and 429 deletions
|
@ -74,7 +74,7 @@ SPDX-License-Identifier: Apache-2.0 AND GPL-3.0-only
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity android:name="helium314.keyboard.settings.SettingsActivity2"
|
<activity android:name="helium314.keyboard.settings.SettingsActivity"
|
||||||
android:theme="@style/platformActivityTheme"
|
android:theme="@style/platformActivityTheme"
|
||||||
android:windowSoftInputMode="adjustResize"
|
android:windowSoftInputMode="adjustResize"
|
||||||
android:label="@string/ime_settings"
|
android:label="@string/ime_settings"
|
||||||
|
|
|
@ -88,7 +88,7 @@ import helium314.keyboard.latin.utils.StatsUtilsManager;
|
||||||
import helium314.keyboard.latin.utils.SubtypeLocaleUtils;
|
import helium314.keyboard.latin.utils.SubtypeLocaleUtils;
|
||||||
import helium314.keyboard.latin.utils.SubtypeSettingsKt;
|
import helium314.keyboard.latin.utils.SubtypeSettingsKt;
|
||||||
import helium314.keyboard.latin.utils.ViewLayoutUtils;
|
import helium314.keyboard.latin.utils.ViewLayoutUtils;
|
||||||
import helium314.keyboard.settings.SettingsActivity2;
|
import helium314.keyboard.settings.SettingsActivity;
|
||||||
import helium314.keyboard.settings.SettingsActivityKt;
|
import helium314.keyboard.settings.SettingsActivityKt;
|
||||||
import kotlin.collections.CollectionsKt;
|
import kotlin.collections.CollectionsKt;
|
||||||
|
|
||||||
|
@ -1879,7 +1879,7 @@ public class LatinIME extends InputMethodService implements
|
||||||
mainKeyboardView.closing();
|
mainKeyboardView.closing();
|
||||||
}
|
}
|
||||||
final Intent intent = new Intent();
|
final Intent intent = new Intent();
|
||||||
intent.setClass(LatinIME.this, SettingsActivity2.class);
|
intent.setClass(LatinIME.this, SettingsActivity.class);
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
|
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
|
||||||
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
|
|
|
@ -21,7 +21,7 @@ import androidx.appcompat.app.ActionBar;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.core.app.ActivityCompat;
|
import androidx.core.app.ActivityCompat;
|
||||||
|
|
||||||
public final class SettingsActivity extends AppCompatActivity
|
public final class OldSettingsActivity extends AppCompatActivity
|
||||||
implements ActivityCompat.OnRequestPermissionsResultCallback {
|
implements ActivityCompat.OnRequestPermissionsResultCallback {
|
||||||
private static final String DEFAULT_FRAGMENT = SettingsFragment.class.getName();
|
private static final String DEFAULT_FRAGMENT = SettingsFragment.class.getName();
|
||||||
|
|
|
@ -26,13 +26,12 @@ import androidx.core.content.res.ResourcesCompat;
|
||||||
import androidx.core.graphics.drawable.DrawableCompat;
|
import androidx.core.graphics.drawable.DrawableCompat;
|
||||||
|
|
||||||
import helium314.keyboard.latin.R;
|
import helium314.keyboard.latin.R;
|
||||||
import helium314.keyboard.latin.settings.SettingsActivity;
|
|
||||||
import helium314.keyboard.latin.utils.ActivityThemeUtils;
|
import helium314.keyboard.latin.utils.ActivityThemeUtils;
|
||||||
import helium314.keyboard.latin.utils.JniUtils;
|
import helium314.keyboard.latin.utils.JniUtils;
|
||||||
import helium314.keyboard.latin.utils.LeakGuardHandlerWrapper;
|
import helium314.keyboard.latin.utils.LeakGuardHandlerWrapper;
|
||||||
import helium314.keyboard.latin.utils.ResourceUtils;
|
import helium314.keyboard.latin.utils.ResourceUtils;
|
||||||
import helium314.keyboard.latin.utils.UncachedInputMethodManagerUtils;
|
import helium314.keyboard.latin.utils.UncachedInputMethodManagerUtils;
|
||||||
import helium314.keyboard.settings.SettingsActivity2;
|
import helium314.keyboard.settings.SettingsActivity;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
@ -166,7 +165,7 @@ public final class SetupWizardActivity extends AppCompatActivity implements View
|
||||||
0 /* finishedInstruction */, R.drawable.sym_keyboard_language_switch,
|
0 /* finishedInstruction */, R.drawable.sym_keyboard_language_switch,
|
||||||
R.string.setup_step3_action);
|
R.string.setup_step3_action);
|
||||||
step3.setAction(() -> {
|
step3.setAction(() -> {
|
||||||
final Intent intent = new Intent(getApplicationContext(), SettingsActivity2.class);
|
final Intent intent = new Intent(getApplicationContext(), SettingsActivity.class);
|
||||||
intent.setAction(Intent.ACTION_VIEW);
|
intent.setAction(Intent.ACTION_VIEW);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
finish();
|
finish();
|
||||||
|
@ -224,11 +223,11 @@ public final class SetupWizardActivity extends AppCompatActivity implements View
|
||||||
|
|
||||||
private void invokeSettingsOfThisIme() {
|
private void invokeSettingsOfThisIme() {
|
||||||
final Intent intent = new Intent();
|
final Intent intent = new Intent();
|
||||||
intent.setClass(this, SettingsActivity2.class);
|
intent.setClass(this, SettingsActivity.class);
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
|
intent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
|
||||||
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
intent.putExtra(SettingsActivity.EXTRA_ENTRY_KEY,
|
// intent.putExtra(OldSettingsActivity.EXTRA_ENTRY_KEY,
|
||||||
SettingsActivity.EXTRA_ENTRY_VALUE_APP_ICON);
|
// OldSettingsActivity.EXTRA_ENTRY_VALUE_APP_ICON);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,80 +0,0 @@
|
||||||
// SPDX-License-Identifier: GPL-3.0-only
|
|
||||||
package helium314.keyboard.settings
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import androidx.annotation.StringRes
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import helium314.keyboard.settings.screens.createAboutPrefs
|
|
||||||
import helium314.keyboard.settings.screens.createAdvancedPrefs
|
|
||||||
import helium314.keyboard.settings.screens.createAppearancePrefs
|
|
||||||
import helium314.keyboard.settings.screens.createCorrectionPrefs
|
|
||||||
import helium314.keyboard.settings.screens.createDebugPrefs
|
|
||||||
import helium314.keyboard.settings.screens.createGestureTypingPrefs
|
|
||||||
import helium314.keyboard.settings.screens.createPreferencesPrefs
|
|
||||||
import helium314.keyboard.settings.screens.createToolbarPrefs
|
|
||||||
|
|
||||||
class AllPrefs(context: Context) {
|
|
||||||
private val list = createPrefDefs(context)
|
|
||||||
|
|
||||||
val map: Map<String, PrefDef> = HashMap<String, PrefDef>(list.size).apply {
|
|
||||||
list.forEach {
|
|
||||||
if (put(it.key, it) != null)
|
|
||||||
throw IllegalArgumentException("key $it added twice")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// could be more elaborate, but should be good enough for a start
|
|
||||||
fun filter(searchTerm: String): List<PrefDef> {
|
|
||||||
val term = searchTerm.lowercase()
|
|
||||||
val results = mutableSetOf<PrefDef>()
|
|
||||||
list.forEach { def -> if (def.title.lowercase().startsWith(term)) results.add(def) }
|
|
||||||
list.forEach { def -> if (def.title.lowercase().split(' ').any { it.startsWith(term) }) results.add(def) }
|
|
||||||
list.forEach { def ->
|
|
||||||
if (def.description?.lowercase()?.split(' ')?.any { it.startsWith(term) } == true)
|
|
||||||
results.add(def)
|
|
||||||
}
|
|
||||||
return results.toList()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class PrefDef(
|
|
||||||
context: Context,
|
|
||||||
val key: String,
|
|
||||||
@StringRes titleId: Int,
|
|
||||||
@StringRes descriptionId: Int? = null,
|
|
||||||
private val compose: @Composable (PrefDef) -> Unit
|
|
||||||
) {
|
|
||||||
val title = context.getString(titleId)
|
|
||||||
val description = descriptionId?.let { context.getString(it) }
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun Preference() {
|
|
||||||
compose(this)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun createPrefDefs(context: Context) = createAboutPrefs(context) +
|
|
||||||
createCorrectionPrefs(context) + createPreferencesPrefs(context) + createToolbarPrefs(context) +
|
|
||||||
createGestureTypingPrefs(context) + createAdvancedPrefs(context) + createDebugPrefs(context) +
|
|
||||||
createAppearancePrefs(context)
|
|
||||||
|
|
||||||
object NonSettingsPrefs {
|
|
||||||
const val EDIT_PERSONAL_DICTIONARY = "edit_personal_dictionary"
|
|
||||||
const val APP = "app"
|
|
||||||
const val VERSION = "version"
|
|
||||||
const val LICENSE = "license"
|
|
||||||
const val HIDDEN_FEATURES = "hidden_features"
|
|
||||||
const val GITHUB = "github"
|
|
||||||
const val SAVE_LOG = "save_log"
|
|
||||||
const val CUSTOM_KEY_CODES = "customize_key_codes"
|
|
||||||
const val CUSTOM_SYMBOLS_NUMBER_LAYOUTS = "custom_symbols_number_layouts"
|
|
||||||
const val CUSTOM_FUNCTIONAL_LAYOUTS = "custom_functional_key_layouts"
|
|
||||||
const val BACKUP_RESTORE = "backup_restore"
|
|
||||||
const val DEBUG_SETTINGS = "screen_debug"
|
|
||||||
const val LOAD_GESTURE_LIB = "load_gesture_library"
|
|
||||||
const val ADJUST_COLORS = "adjust_colors"
|
|
||||||
const val ADJUST_COLORS_NIGHT = "adjust_colors_night"
|
|
||||||
const val BACKGROUND_IMAGE = "background_image"
|
|
||||||
const val BACKGROUND_IMAGE_LANDSCAPE = "background_image_landscape"
|
|
||||||
const val CUSTOM_FONT = "custom_font"
|
|
||||||
}
|
|
|
@ -63,13 +63,13 @@ fun SearchPrefScreen(
|
||||||
if (it is Int)
|
if (it is Int)
|
||||||
PreferenceCategory(stringResource(it))
|
PreferenceCategory(stringResource(it))
|
||||||
else
|
else
|
||||||
SettingsActivity2.allPrefs.map[it]!!.Preference()
|
SettingsActivity.settingsContainer[it]!!.Preference()
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
filteredItems = { SettingsActivity2.allPrefs.filter(it) },
|
filteredItems = { SettingsActivity.settingsContainer.filter(it) },
|
||||||
itemContent = { it.Preference() }
|
itemContent = { it.Preference() }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,13 +14,10 @@ import helium314.keyboard.latin.utils.prefs
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
|
||||||
// todo (roughly in order)
|
// todo (roughly in order)
|
||||||
// use better / more structured and clear names and arrangement of files
|
|
||||||
// the prefDef and AllPrefs, also be clear about pref <-> key <-> prefKey (all used, probably should be latter)
|
|
||||||
// there is a lot more ambiguous naming...
|
|
||||||
// dialogs should be rememberSaveable to survive display orientation change and stuff?
|
// dialogs should be rememberSaveable to survive display orientation change and stuff?
|
||||||
// check dark and light theme (don't have dynamic)
|
// check dark and light theme (don't have dynamic)
|
||||||
// any way to get rid of the "old" background on starting settings? probably comes from app theme, can we avoid it?
|
// any way to get rid of the "old" background on starting settings? probably comes from app theme, can we avoid it?
|
||||||
// rename both settingsActivities
|
// try making old fragment back stuff work better, and try the different themes (with and without top bar, it should only appear for old fragments)
|
||||||
// calling KeyboardSwitcher.getInstance().forceUpdateKeyboardTheme(requireContext()) while keyboard is showing shows just full screen background
|
// calling KeyboardSwitcher.getInstance().forceUpdateKeyboardTheme(requireContext()) while keyboard is showing shows just full screen background
|
||||||
// but reload while keyboard is showing would be great (isn't it at least semi-done when changing one-handed mode?)
|
// but reload while keyboard is showing would be great (isn't it at least semi-done when changing one-handed mode?)
|
||||||
// bg image inconsistent about being on toolbar or not (is this new?)
|
// bg image inconsistent about being on toolbar or not (is this new?)
|
||||||
|
@ -28,7 +25,6 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
// find a nice way of testing (probably add logs for measuring time and recompositions)
|
// find a nice way of testing (probably add logs for measuring time and recompositions)
|
||||||
// consider that stuff in composables can get called quite often on any changes
|
// consider that stuff in composables can get called quite often on any changes
|
||||||
// -> use remember for things that are slow, but be careful they don't change from outside the composable
|
// -> use remember for things that are slow, but be careful they don't change from outside the composable
|
||||||
// try making old fragment back stuff work better, and try the different themes (with and without top bar, it should only appear for old fragments)
|
|
||||||
// PRs adding prefs -> need to finish and merge main before finishing this PR
|
// PRs adding prefs -> need to finish and merge main before finishing this PR
|
||||||
// 1263 (no response for several weeks now...)
|
// 1263 (no response for several weeks now...)
|
||||||
// really use the restart dialog for debug settings stuff?
|
// really use the restart dialog for debug settings stuff?
|
||||||
|
@ -65,6 +61,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
// actually lenient json parsing is not good in a certain way: we should show an error if a json property is unknown
|
// actually lenient json parsing is not good in a certain way: we should show an error if a json property is unknown
|
||||||
// syntax highlighting for json? should show basic json errors
|
// syntax highlighting for json? should show basic json errors
|
||||||
// does restore prefs not delete dictionaries?
|
// does restore prefs not delete dictionaries?
|
||||||
|
// don't require to switch keyboard when entering settings
|
||||||
|
|
||||||
// preliminary results:
|
// preliminary results:
|
||||||
// looks ok (ugly M3 switches)
|
// looks ok (ugly M3 switches)
|
||||||
|
@ -83,7 +80,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
// -> too much, but still ok if we can get nicer preference stuff
|
// -> too much, but still ok if we can get nicer preference stuff
|
||||||
// meh, and using a TextField adds another 300 kb... huge chunks for sth that seems so small
|
// meh, and using a TextField adds another 300 kb... huge chunks for sth that seems so small
|
||||||
|
|
||||||
class SettingsActivity2 : AppCompatActivity(), SharedPreferences.OnSharedPreferenceChangeListener {
|
class SettingsActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
private val prefs by lazy { this.prefs() }
|
private val prefs by lazy { this.prefs() }
|
||||||
val prefChanged = MutableStateFlow(0) // simple counter, as the only relevant information is that something changed
|
val prefChanged = MutableStateFlow(0) // simple counter, as the only relevant information is that something changed
|
||||||
|
|
||||||
|
@ -92,7 +89,7 @@ class SettingsActivity2 : AppCompatActivity(), SharedPreferences.OnSharedPrefere
|
||||||
if (Settings.getInstance().current == null)
|
if (Settings.getInstance().current == null)
|
||||||
Settings.init(this)
|
Settings.init(this)
|
||||||
|
|
||||||
allPrefs = AllPrefs(this)
|
settingsContainer = SettingsContainer(this)
|
||||||
|
|
||||||
// todo: when removing old settings completely, remove settings_activity.xml and supportFragmentManager stuff
|
// todo: when removing old settings completely, remove settings_activity.xml and supportFragmentManager stuff
|
||||||
// val cv = ComposeView(context = this)
|
// val cv = ComposeView(context = this)
|
||||||
|
@ -133,8 +130,8 @@ class SettingsActivity2 : AppCompatActivity(), SharedPreferences.OnSharedPrefere
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
// public write so compose previews can show the pref screens
|
// public write so compose previews can show the screens
|
||||||
lateinit var allPrefs: AllPrefs
|
lateinit var settingsContainer: SettingsContainer
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSharedPreferenceChanged(prefereces: SharedPreferences?, key: String?) {
|
override fun onSharedPreferenceChanged(prefereces: SharedPreferences?, key: String?) {
|
||||||
|
|
|
@ -0,0 +1,81 @@
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
package helium314.keyboard.settings
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.annotation.StringRes
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import helium314.keyboard.settings.screens.createAboutSettings
|
||||||
|
import helium314.keyboard.settings.screens.createAdvancedSettings
|
||||||
|
import helium314.keyboard.settings.screens.createAppearanceSettings
|
||||||
|
import helium314.keyboard.settings.screens.createCorrectionSettings
|
||||||
|
import helium314.keyboard.settings.screens.createDebugSettings
|
||||||
|
import helium314.keyboard.settings.screens.createGestureTypingSettings
|
||||||
|
import helium314.keyboard.settings.screens.createPreferencesSettings
|
||||||
|
import helium314.keyboard.settings.screens.createToolbarSettingss
|
||||||
|
|
||||||
|
class SettingsContainer(context: Context) {
|
||||||
|
private val list = createSettings(context)
|
||||||
|
private val map: Map<String, Setting> = HashMap<String, Setting>(list.size).apply {
|
||||||
|
list.forEach {
|
||||||
|
if (put(it.key, it) != null)
|
||||||
|
throw IllegalArgumentException("key $it added twice")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
operator fun get(key: Any): Setting? = map[key]
|
||||||
|
|
||||||
|
// could be more elaborate, but should be good enough for a start
|
||||||
|
fun filter(searchTerm: String): List<Setting> {
|
||||||
|
val term = searchTerm.lowercase()
|
||||||
|
val results = mutableSetOf<Setting>()
|
||||||
|
list.forEach { setting -> if (setting.title.lowercase().startsWith(term)) results.add(setting) }
|
||||||
|
list.forEach { setting -> if (setting.title.lowercase().split(' ').any { it.startsWith(term) }) results.add(setting) }
|
||||||
|
list.forEach { setting ->
|
||||||
|
if (setting.description?.lowercase()?.split(' ')?.any { it.startsWith(term) } == true)
|
||||||
|
results.add(setting)
|
||||||
|
}
|
||||||
|
return results.toList()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Setting(
|
||||||
|
context: Context,
|
||||||
|
val key: String,
|
||||||
|
@StringRes titleId: Int,
|
||||||
|
@StringRes descriptionId: Int? = null,
|
||||||
|
private val content: @Composable (Setting) -> Unit
|
||||||
|
) {
|
||||||
|
val title = context.getString(titleId)
|
||||||
|
val description = descriptionId?.let { context.getString(it) }
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun Preference() {
|
||||||
|
content(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createSettings(context: Context) = createAboutSettings(context) +
|
||||||
|
createCorrectionSettings(context) + createPreferencesSettings(context) + createToolbarSettingss(context) +
|
||||||
|
createGestureTypingSettings(context) + createAdvancedSettings(context) + createDebugSettings(context) +
|
||||||
|
createAppearanceSettings(context)
|
||||||
|
|
||||||
|
object SettingsWithoutKey {
|
||||||
|
const val EDIT_PERSONAL_DICTIONARY = "edit_personal_dictionary"
|
||||||
|
const val APP = "app"
|
||||||
|
const val VERSION = "version"
|
||||||
|
const val LICENSE = "license"
|
||||||
|
const val HIDDEN_FEATURES = "hidden_features"
|
||||||
|
const val GITHUB = "github"
|
||||||
|
const val SAVE_LOG = "save_log"
|
||||||
|
const val CUSTOM_KEY_CODES = "customize_key_codes"
|
||||||
|
const val CUSTOM_SYMBOLS_NUMBER_LAYOUTS = "custom_symbols_number_layouts"
|
||||||
|
const val CUSTOM_FUNCTIONAL_LAYOUTS = "custom_functional_key_layouts"
|
||||||
|
const val BACKUP_RESTORE = "backup_restore"
|
||||||
|
const val DEBUG_SETTINGS = "screen_debug"
|
||||||
|
const val LOAD_GESTURE_LIB = "load_gesture_library"
|
||||||
|
const val ADJUST_COLORS = "adjust_colors"
|
||||||
|
const val ADJUST_COLORS_NIGHT = "adjust_colors_night"
|
||||||
|
const val BACKGROUND_IMAGE = "background_image"
|
||||||
|
const val BACKGROUND_IMAGE_LANDSCAPE = "background_image_landscape"
|
||||||
|
const val CUSTOM_FONT = "custom_font"
|
||||||
|
}
|
|
@ -23,8 +23,8 @@ import helium314.keyboard.latin.settings.Settings
|
||||||
import helium314.keyboard.latin.utils.Log
|
import helium314.keyboard.latin.utils.Log
|
||||||
import helium314.keyboard.latin.utils.getActivity
|
import helium314.keyboard.latin.utils.getActivity
|
||||||
import helium314.keyboard.latin.utils.prefs
|
import helium314.keyboard.latin.utils.prefs
|
||||||
import helium314.keyboard.settings.PrefDef
|
import helium314.keyboard.settings.Setting
|
||||||
import helium314.keyboard.settings.SettingsActivity2
|
import helium314.keyboard.settings.SettingsActivity
|
||||||
import helium314.keyboard.settings.dialogs.ConfirmationDialog
|
import helium314.keyboard.settings.dialogs.ConfirmationDialog
|
||||||
import helium314.keyboard.settings.dialogs.InfoDialog
|
import helium314.keyboard.settings.dialogs.InfoDialog
|
||||||
import helium314.keyboard.settings.keyboardNeedsReload
|
import helium314.keyboard.settings.keyboardNeedsReload
|
||||||
|
@ -32,14 +32,14 @@ import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun BackgroundImagePref(def: PrefDef, isLandscape: Boolean) {
|
fun BackgroundImagePref(setting: Setting, isLandscape: Boolean) {
|
||||||
var showDayNightDialog by remember { mutableStateOf(false) }
|
var showDayNightDialog by remember { mutableStateOf(false) }
|
||||||
var showSelectionDialog by remember { mutableStateOf(false) }
|
var showSelectionDialog by remember { mutableStateOf(false) }
|
||||||
var showErrorDialog by remember { mutableStateOf(false) }
|
var showErrorDialog by remember { mutableStateOf(false) }
|
||||||
var isNight by remember { mutableStateOf(false) }
|
var isNight by remember { mutableStateOf(false) }
|
||||||
val ctx = LocalContext.current
|
val ctx = LocalContext.current
|
||||||
fun getFile() = Settings.getCustomBackgroundFile(ctx, isNight, isLandscape)
|
fun getFile() = Settings.getCustomBackgroundFile(ctx, isNight, isLandscape)
|
||||||
val b = (ctx.getActivity() as? SettingsActivity2)?.prefChanged?.collectAsState()
|
val b = (ctx.getActivity() as? SettingsActivity)?.prefChanged?.collectAsState()
|
||||||
if ((b?.value ?: 0) < 0) // necessary to reload dayNightPref
|
if ((b?.value ?: 0) < 0) // necessary to reload dayNightPref
|
||||||
Log.v("irrelevant", "stupid way to trigger recomposition on preference change")
|
Log.v("irrelevant", "stupid way to trigger recomposition on preference change")
|
||||||
val dayNightPref = Settings.readDayNightPref(ctx.prefs(), ctx.resources)
|
val dayNightPref = Settings.readDayNightPref(ctx.prefs(), ctx.resources)
|
||||||
|
@ -60,7 +60,7 @@ fun BackgroundImagePref(def: PrefDef, isLandscape: Boolean) {
|
||||||
.addCategory(Intent.CATEGORY_OPENABLE)
|
.addCategory(Intent.CATEGORY_OPENABLE)
|
||||||
.setType("image/*")
|
.setType("image/*")
|
||||||
Preference(
|
Preference(
|
||||||
name = def.title,
|
name = setting.title,
|
||||||
onClick = {
|
onClick = {
|
||||||
if (dayNightPref) {
|
if (dayNightPref) {
|
||||||
showDayNightDialog = true
|
showDayNightDialog = true
|
||||||
|
|
|
@ -39,8 +39,8 @@ import helium314.keyboard.latin.utils.onCustomLayoutFileListChanged
|
||||||
import helium314.keyboard.latin.utils.prefs
|
import helium314.keyboard.latin.utils.prefs
|
||||||
import helium314.keyboard.latin.utils.reloadEnabledSubtypes
|
import helium314.keyboard.latin.utils.reloadEnabledSubtypes
|
||||||
import helium314.keyboard.latin.utils.updateAdditionalSubtypes
|
import helium314.keyboard.latin.utils.updateAdditionalSubtypes
|
||||||
import helium314.keyboard.settings.PrefDef
|
import helium314.keyboard.settings.Setting
|
||||||
import helium314.keyboard.settings.SettingsActivity2
|
import helium314.keyboard.settings.SettingsActivity
|
||||||
import helium314.keyboard.settings.dialogs.ConfirmationDialog
|
import helium314.keyboard.settings.dialogs.ConfirmationDialog
|
||||||
import helium314.keyboard.settings.dialogs.InfoDialog
|
import helium314.keyboard.settings.dialogs.InfoDialog
|
||||||
import helium314.keyboard.settings.keyboardNeedsReload
|
import helium314.keyboard.settings.keyboardNeedsReload
|
||||||
|
@ -54,7 +54,7 @@ import java.util.zip.ZipInputStream
|
||||||
import java.util.zip.ZipOutputStream
|
import java.util.zip.ZipOutputStream
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun BackupRestorePreference(def: PrefDef) {
|
fun BackupRestorePreference(setting: Setting) {
|
||||||
var showDialog by remember { mutableStateOf(false) }
|
var showDialog by remember { mutableStateOf(false) }
|
||||||
val ctx = LocalContext.current
|
val ctx = LocalContext.current
|
||||||
val prefs = ctx.prefs()
|
val prefs = ctx.prefs()
|
||||||
|
@ -180,13 +180,10 @@ fun BackupRestorePreference(def: PrefDef) {
|
||||||
val newDictBroadcast = Intent(DictionaryPackConstants.NEW_DICTIONARY_INTENT_ACTION)
|
val newDictBroadcast = Intent(DictionaryPackConstants.NEW_DICTIONARY_INTENT_ACTION)
|
||||||
ctx.getActivity()?.sendBroadcast(newDictBroadcast)
|
ctx.getActivity()?.sendBroadcast(newDictBroadcast)
|
||||||
onCustomLayoutFileListChanged()
|
onCustomLayoutFileListChanged()
|
||||||
(ctx.getActivity() as? SettingsActivity2)?.prefChanged?.value = 210 // for settings reload
|
(ctx.getActivity() as? SettingsActivity)?.prefChanged?.value = 210 // for settings reload
|
||||||
keyboardNeedsReload = true
|
keyboardNeedsReload = true
|
||||||
}
|
}
|
||||||
Preference(
|
Preference(name = setting.title, onClick = { showDialog = true })
|
||||||
name = def.title,
|
|
||||||
onClick = { showDialog = true }
|
|
||||||
)
|
|
||||||
if (showDialog) {
|
if (showDialog) {
|
||||||
ConfirmationDialog(
|
ConfirmationDialog(
|
||||||
onDismissRequest = { showDialog = false },
|
onDismissRequest = { showDialog = false },
|
||||||
|
|
|
@ -17,14 +17,14 @@ import helium314.keyboard.latin.R
|
||||||
import helium314.keyboard.latin.common.FileUtils
|
import helium314.keyboard.latin.common.FileUtils
|
||||||
import helium314.keyboard.latin.settings.Settings
|
import helium314.keyboard.latin.settings.Settings
|
||||||
import helium314.keyboard.latin.utils.DeviceProtectedUtils
|
import helium314.keyboard.latin.utils.DeviceProtectedUtils
|
||||||
import helium314.keyboard.settings.PrefDef
|
import helium314.keyboard.settings.Setting
|
||||||
import helium314.keyboard.settings.dialogs.ConfirmationDialog
|
import helium314.keyboard.settings.dialogs.ConfirmationDialog
|
||||||
import helium314.keyboard.settings.dialogs.InfoDialog
|
import helium314.keyboard.settings.dialogs.InfoDialog
|
||||||
import helium314.keyboard.settings.keyboardNeedsReload
|
import helium314.keyboard.settings.keyboardNeedsReload
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun CustomFontPreference(def: PrefDef) {
|
fun CustomFontPreference(setting: Setting) {
|
||||||
val ctx = LocalContext.current
|
val ctx = LocalContext.current
|
||||||
var showDialog by remember { mutableStateOf(false) }
|
var showDialog by remember { mutableStateOf(false) }
|
||||||
var showErrorDialog by remember { mutableStateOf(false) }
|
var showErrorDialog by remember { mutableStateOf(false) }
|
||||||
|
@ -49,7 +49,7 @@ fun CustomFontPreference(def: PrefDef) {
|
||||||
.addCategory(Intent.CATEGORY_OPENABLE)
|
.addCategory(Intent.CATEGORY_OPENABLE)
|
||||||
.setType("*/*")
|
.setType("*/*")
|
||||||
Preference(
|
Preference(
|
||||||
name = def.title,
|
name = setting.title,
|
||||||
onClick = {
|
onClick = {
|
||||||
if (fontFile.exists())
|
if (fontFile.exists())
|
||||||
showDialog = true
|
showDialog = true
|
||||||
|
|
|
@ -9,14 +9,14 @@ import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import helium314.keyboard.latin.utils.CUSTOM_LAYOUT_PREFIX
|
import helium314.keyboard.latin.utils.CUSTOM_LAYOUT_PREFIX
|
||||||
import helium314.keyboard.latin.utils.getCustomLayoutFiles
|
import helium314.keyboard.latin.utils.getCustomLayoutFiles
|
||||||
import helium314.keyboard.settings.PrefDef
|
import helium314.keyboard.settings.Setting
|
||||||
import helium314.keyboard.settings.dialogs.LayoutEditDialog
|
import helium314.keyboard.settings.dialogs.LayoutEditDialog
|
||||||
import helium314.keyboard.settings.dialogs.ListPickerDialog
|
import helium314.keyboard.settings.dialogs.ListPickerDialog
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun LayoutEditPreference(
|
fun LayoutEditPreference(
|
||||||
def: PrefDef,
|
setting: Setting,
|
||||||
items: List<String>,
|
items: List<String>,
|
||||||
getItemName: @Composable (String) -> String,
|
getItemName: @Composable (String) -> String,
|
||||||
getDefaultLayout: @Composable (String?) -> String?,
|
getDefaultLayout: @Composable (String?) -> String?,
|
||||||
|
@ -25,7 +25,7 @@ fun LayoutEditPreference(
|
||||||
val ctx = LocalContext.current
|
val ctx = LocalContext.current
|
||||||
var layout: String? by remember { mutableStateOf(null) }
|
var layout: String? by remember { mutableStateOf(null) }
|
||||||
Preference(
|
Preference(
|
||||||
name = def.title,
|
name = setting.title,
|
||||||
onClick = { showDialog = true }
|
onClick = { showDialog = true }
|
||||||
)
|
)
|
||||||
if (showDialog) {
|
if (showDialog) {
|
||||||
|
@ -36,7 +36,7 @@ fun LayoutEditPreference(
|
||||||
items = items,
|
items = items,
|
||||||
getItemName = getItemName,
|
getItemName = getItemName,
|
||||||
onItemSelected = { layout = it },
|
onItemSelected = { layout = it },
|
||||||
title = { Text(def.title) }
|
title = { Text(setting.title) }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (layout != null) {
|
if (layout != null) {
|
||||||
|
|
|
@ -20,7 +20,7 @@ import helium314.keyboard.latin.settings.Settings
|
||||||
import helium314.keyboard.latin.utils.ChecksumCalculator
|
import helium314.keyboard.latin.utils.ChecksumCalculator
|
||||||
import helium314.keyboard.latin.utils.JniUtils
|
import helium314.keyboard.latin.utils.JniUtils
|
||||||
import helium314.keyboard.latin.utils.prefs
|
import helium314.keyboard.latin.utils.prefs
|
||||||
import helium314.keyboard.settings.PrefDef
|
import helium314.keyboard.settings.Setting
|
||||||
import helium314.keyboard.settings.dialogs.ConfirmationDialog
|
import helium314.keyboard.settings.dialogs.ConfirmationDialog
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileInputStream
|
import java.io.FileInputStream
|
||||||
|
@ -28,7 +28,7 @@ import java.io.FileOutputStream
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun LoadGestureLibPreference(def: PrefDef) {
|
fun LoadGestureLibPreference(setting: Setting) {
|
||||||
var showDialog by remember { mutableStateOf(false) }
|
var showDialog by remember { mutableStateOf(false) }
|
||||||
val ctx = LocalContext.current
|
val ctx = LocalContext.current
|
||||||
val prefs = ctx.prefs()
|
val prefs = ctx.prefs()
|
||||||
|
@ -74,7 +74,7 @@ fun LoadGestureLibPreference(def: PrefDef) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Preference(
|
Preference(
|
||||||
name = def.title,
|
name = setting.title,
|
||||||
onClick = { showDialog = true }
|
onClick = { showDialog = true }
|
||||||
)
|
)
|
||||||
if (showDialog) {
|
if (showDialog) {
|
||||||
|
|
|
@ -119,7 +119,7 @@ private fun PreferencePreview() {
|
||||||
)
|
)
|
||||||
SliderPreference(
|
SliderPreference(
|
||||||
name = "SliderPreference",
|
name = "SliderPreference",
|
||||||
pref = "",
|
key = "",
|
||||||
default = 1,
|
default = 1,
|
||||||
description = { it.toString() },
|
description = { it.toString() },
|
||||||
range = -5f..5f
|
range = -5f..5f
|
||||||
|
@ -138,7 +138,7 @@ private fun PreferencePreview() {
|
||||||
}
|
}
|
||||||
SwitchPreference(
|
SwitchPreference(
|
||||||
name = "SwitchPreference",
|
name = "SwitchPreference",
|
||||||
pref = "none",
|
key = "none",
|
||||||
default = true
|
default = true
|
||||||
)
|
)
|
||||||
Preference(
|
Preference(
|
||||||
|
|
|
@ -16,37 +16,37 @@ import helium314.keyboard.keyboard.internal.KeyboardIconsSet
|
||||||
import helium314.keyboard.latin.R
|
import helium314.keyboard.latin.R
|
||||||
import helium314.keyboard.latin.utils.getStringResourceOrName
|
import helium314.keyboard.latin.utils.getStringResourceOrName
|
||||||
import helium314.keyboard.latin.utils.prefs
|
import helium314.keyboard.latin.utils.prefs
|
||||||
import helium314.keyboard.settings.PrefDef
|
import helium314.keyboard.settings.Setting
|
||||||
import helium314.keyboard.settings.dialogs.ReorderDialog
|
import helium314.keyboard.settings.dialogs.ReorderDialog
|
||||||
import helium314.keyboard.settings.keyboardNeedsReload
|
import helium314.keyboard.settings.keyboardNeedsReload
|
||||||
import helium314.keyboard.settings.screens.GetIcon
|
import helium314.keyboard.settings.screens.GetIcon
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ReorderSwitchPreference(def: PrefDef, default: String) {
|
fun ReorderSwitchPreference(setting: Setting, default: String) {
|
||||||
var showDialog by remember { mutableStateOf(false) }
|
var showDialog by remember { mutableStateOf(false) }
|
||||||
Preference(
|
Preference(
|
||||||
name = def.title,
|
name = setting.title,
|
||||||
description = def.description,
|
description = setting.description,
|
||||||
onClick = { showDialog = true },
|
onClick = { showDialog = true },
|
||||||
)
|
)
|
||||||
if (showDialog) {
|
if (showDialog) {
|
||||||
val ctx = LocalContext.current
|
val ctx = LocalContext.current
|
||||||
val prefs = ctx.prefs()
|
val prefs = ctx.prefs()
|
||||||
val items = prefs.getString(def.key, default)!!.split(";").mapTo(ArrayList()) {
|
val items = prefs.getString(setting.key, default)!!.split(";").mapTo(ArrayList()) {
|
||||||
val both = it.split(",")
|
val both = it.split(",")
|
||||||
KeyAndState(both.first(), both.last().toBoolean())
|
KeyAndState(both.first(), both.last().toBoolean())
|
||||||
}
|
}
|
||||||
ReorderDialog(
|
ReorderDialog(
|
||||||
onConfirmed = { reorderedItems ->
|
onConfirmed = { reorderedItems ->
|
||||||
val value = reorderedItems.joinToString(";") { it.name + "," + it.state }
|
val value = reorderedItems.joinToString(";") { it.name + "," + it.state }
|
||||||
prefs.edit().putString(def.key, value).apply()
|
prefs.edit().putString(setting.key, value).apply()
|
||||||
keyboardNeedsReload = true
|
keyboardNeedsReload = true
|
||||||
},
|
},
|
||||||
onDismissRequest = { showDialog = false },
|
onDismissRequest = { showDialog = false },
|
||||||
onNeutral = { prefs.edit().remove(def.key).apply() },
|
onNeutral = { prefs.edit().remove(setting.key).apply() },
|
||||||
neutralButtonText = if (prefs.contains(def.key)) stringResource(R.string.button_default) else null,
|
neutralButtonText = if (prefs.contains(setting.key)) stringResource(R.string.button_default) else null,
|
||||||
items = items,
|
items = items,
|
||||||
title = { Text(def.title) },
|
title = { Text(setting.title) },
|
||||||
displayItem = { item ->
|
displayItem = { item ->
|
||||||
var checked by remember { mutableStateOf(item.state) }
|
var checked by remember { mutableStateOf(item.state) }
|
||||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||||
|
|
|
@ -14,8 +14,8 @@ import androidx.core.content.edit
|
||||||
import helium314.keyboard.latin.utils.Log
|
import helium314.keyboard.latin.utils.Log
|
||||||
import helium314.keyboard.latin.utils.getActivity
|
import helium314.keyboard.latin.utils.getActivity
|
||||||
import helium314.keyboard.latin.utils.prefs
|
import helium314.keyboard.latin.utils.prefs
|
||||||
import helium314.keyboard.settings.PrefDef
|
import helium314.keyboard.settings.Setting
|
||||||
import helium314.keyboard.settings.SettingsActivity2
|
import helium314.keyboard.settings.SettingsActivity
|
||||||
import helium314.keyboard.settings.dialogs.ListPickerDialog
|
import helium314.keyboard.settings.dialogs.ListPickerDialog
|
||||||
import helium314.keyboard.settings.dialogs.SliderDialog
|
import helium314.keyboard.settings.dialogs.SliderDialog
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
@ -25,7 +25,7 @@ import kotlin.math.roundToInt
|
||||||
fun <T: Number> SliderPreference(
|
fun <T: Number> SliderPreference(
|
||||||
name: String,
|
name: String,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
pref: String,
|
key: String,
|
||||||
description: @Composable (T) -> String,
|
description: @Composable (T) -> String,
|
||||||
default: T,
|
default: T,
|
||||||
range: ClosedFloatingPointRange<Float>,
|
range: ClosedFloatingPointRange<Float>,
|
||||||
|
@ -34,11 +34,11 @@ fun <T: Number> SliderPreference(
|
||||||
) {
|
) {
|
||||||
val ctx = LocalContext.current
|
val ctx = LocalContext.current
|
||||||
val prefs = ctx.prefs()
|
val prefs = ctx.prefs()
|
||||||
val b = (ctx.getActivity() as? SettingsActivity2)?.prefChanged?.collectAsState()
|
val b = (ctx.getActivity() as? SettingsActivity)?.prefChanged?.collectAsState()
|
||||||
if ((b?.value ?: 0) < 0)
|
if ((b?.value ?: 0) < 0)
|
||||||
Log.v("irrelevant", "stupid way to trigger recomposition on preference change")
|
Log.v("irrelevant", "stupid way to trigger recomposition on preference change")
|
||||||
val initialValue = if (default is Int || default is Float)
|
val initialValue = if (default is Int || default is Float)
|
||||||
getPrefOfType(prefs, pref, default)
|
getPrefOfType(prefs, key, default)
|
||||||
else throw IllegalArgumentException("only float and int are supported")
|
else throw IllegalArgumentException("only float and int are supported")
|
||||||
|
|
||||||
var showDialog by remember { mutableStateOf(false) }
|
var showDialog by remember { mutableStateOf(false) }
|
||||||
|
@ -52,8 +52,8 @@ fun <T: Number> SliderPreference(
|
||||||
SliderDialog(
|
SliderDialog(
|
||||||
onDismissRequest = { showDialog = false },
|
onDismissRequest = { showDialog = false },
|
||||||
onDone = {
|
onDone = {
|
||||||
if (default is Int) prefs.edit().putInt(pref, it.toInt()).apply()
|
if (default is Int) prefs.edit().putInt(key, it.toInt()).apply()
|
||||||
else prefs.edit().putFloat(pref, it).apply()
|
else prefs.edit().putFloat(key, it).apply()
|
||||||
},
|
},
|
||||||
initialValue = initialValue.toFloat(),
|
initialValue = initialValue.toFloat(),
|
||||||
range = range,
|
range = range,
|
||||||
|
@ -63,7 +63,7 @@ fun <T: Number> SliderPreference(
|
||||||
},
|
},
|
||||||
onValueChanged = onValueChanged,
|
onValueChanged = onValueChanged,
|
||||||
showDefault = true,
|
showDefault = true,
|
||||||
onDefault = { prefs.edit().remove(pref).apply() },
|
onDefault = { prefs.edit().remove(key).apply() },
|
||||||
intermediateSteps = stepSize?.let {
|
intermediateSteps = stepSize?.let {
|
||||||
// this is not nice, but slider wants it like this...
|
// this is not nice, but slider wants it like this...
|
||||||
((range.endInclusive - range.start) / it - 1).toInt()
|
((range.endInclusive - range.start) / it - 1).toInt()
|
||||||
|
@ -74,16 +74,16 @@ fun <T: Number> SliderPreference(
|
||||||
@Composable
|
@Composable
|
||||||
// just in here so we can keep getPrefOfType private... rename file?
|
// just in here so we can keep getPrefOfType private... rename file?
|
||||||
fun <T: Any> ListPreference(
|
fun <T: Any> ListPreference(
|
||||||
def: PrefDef,
|
setting: Setting,
|
||||||
items: List<Pair<String, T>>,
|
items: List<Pair<String, T>>,
|
||||||
default: T,
|
default: T,
|
||||||
onChanged: (T) -> Unit = { }
|
onChanged: (T) -> Unit = { }
|
||||||
) {
|
) {
|
||||||
var showDialog by remember { mutableStateOf(false) }
|
var showDialog by remember { mutableStateOf(false) }
|
||||||
val prefs = LocalContext.current.prefs()
|
val prefs = LocalContext.current.prefs()
|
||||||
val selected = items.firstOrNull { it.second == getPrefOfType(prefs, def.key, default) }
|
val selected = items.firstOrNull { it.second == getPrefOfType(prefs, setting.key, default) }
|
||||||
Preference(
|
Preference(
|
||||||
name = def.title,
|
name = setting.title,
|
||||||
description = selected?.first,
|
description = selected?.first,
|
||||||
onClick = { showDialog = true }
|
onClick = { showDialog = true }
|
||||||
)
|
)
|
||||||
|
@ -93,11 +93,11 @@ fun <T: Any> ListPreference(
|
||||||
items = items,
|
items = items,
|
||||||
onItemSelected = {
|
onItemSelected = {
|
||||||
if (it == selected) return@ListPickerDialog
|
if (it == selected) return@ListPickerDialog
|
||||||
putPrefOfType(prefs, def.key, it.second)
|
putPrefOfType(prefs, setting.key, it.second)
|
||||||
onChanged(it.second)
|
onChanged(it.second)
|
||||||
},
|
},
|
||||||
selectedItem = selected,
|
selectedItem = selected,
|
||||||
title = { Text(def.title) },
|
title = { Text(setting.title) },
|
||||||
getItemName = { it.first }
|
getItemName = { it.first }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,15 +8,31 @@ import androidx.compose.ui.platform.LocalContext
|
||||||
import helium314.keyboard.latin.utils.Log
|
import helium314.keyboard.latin.utils.Log
|
||||||
import helium314.keyboard.latin.utils.getActivity
|
import helium314.keyboard.latin.utils.getActivity
|
||||||
import helium314.keyboard.latin.utils.prefs
|
import helium314.keyboard.latin.utils.prefs
|
||||||
import helium314.keyboard.settings.PrefDef
|
import helium314.keyboard.settings.Setting
|
||||||
import helium314.keyboard.settings.SettingsActivity2
|
import helium314.keyboard.settings.SettingsActivity
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun SwitchPreference(
|
||||||
|
setting: Setting,
|
||||||
|
default: Boolean,
|
||||||
|
allowCheckedChange: (Boolean) -> Boolean = { true },
|
||||||
|
onCheckedChange: (Boolean) -> Unit = { }
|
||||||
|
) {
|
||||||
|
SwitchPreference(
|
||||||
|
name = setting.title,
|
||||||
|
description = setting.description,
|
||||||
|
key = setting.key,
|
||||||
|
default = default,
|
||||||
|
allowCheckedChange = allowCheckedChange,
|
||||||
|
onCheckedChange = onCheckedChange
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun SwitchPreference(
|
fun SwitchPreference(
|
||||||
name: String,
|
name: String,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
pref: String,
|
key: String,
|
||||||
default: Boolean,
|
default: Boolean,
|
||||||
description: String? = null,
|
description: String? = null,
|
||||||
allowCheckedChange: (Boolean) -> Boolean = { true }, // true means ok, usually for showing some dialog
|
allowCheckedChange: (Boolean) -> Boolean = { true }, // true means ok, usually for showing some dialog
|
||||||
|
@ -24,17 +40,17 @@ fun SwitchPreference(
|
||||||
) {
|
) {
|
||||||
val ctx = LocalContext.current
|
val ctx = LocalContext.current
|
||||||
val prefs = ctx.prefs()
|
val prefs = ctx.prefs()
|
||||||
val b = (ctx.getActivity() as? SettingsActivity2)?.prefChanged?.collectAsState()
|
val b = (ctx.getActivity() as? SettingsActivity)?.prefChanged?.collectAsState()
|
||||||
if ((b?.value ?: 0) < 0)
|
if ((b?.value ?: 0) < 0)
|
||||||
Log.v("irrelevant", "stupid way to trigger recomposition on preference change")
|
Log.v("irrelevant", "stupid way to trigger recomposition on preference change")
|
||||||
var value = prefs.getBoolean(pref, default)
|
var value = prefs.getBoolean(key, default)
|
||||||
fun switched(newValue: Boolean) {
|
fun switched(newValue: Boolean) {
|
||||||
if (!allowCheckedChange(newValue)) {
|
if (!allowCheckedChange(newValue)) {
|
||||||
value = !newValue
|
value = !newValue
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
value = newValue
|
value = newValue
|
||||||
prefs.edit().putBoolean(pref, newValue).apply()
|
prefs.edit().putBoolean(key, newValue).apply()
|
||||||
onCheckedChange(newValue)
|
onCheckedChange(newValue)
|
||||||
}
|
}
|
||||||
Preference(
|
Preference(
|
||||||
|
@ -49,20 +65,3 @@ fun SwitchPreference(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun SwitchPreference(
|
|
||||||
def: PrefDef,
|
|
||||||
default: Boolean,
|
|
||||||
allowCheckedChange: (Boolean) -> Boolean = { true },
|
|
||||||
onCheckedChange: (Boolean) -> Unit = { }
|
|
||||||
) {
|
|
||||||
SwitchPreference(
|
|
||||||
name = def.title,
|
|
||||||
description = def.description,
|
|
||||||
pref = def.key,
|
|
||||||
default = default,
|
|
||||||
allowCheckedChange = allowCheckedChange,
|
|
||||||
onCheckedChange = onCheckedChange
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
|
@ -29,12 +29,12 @@ import helium314.keyboard.latin.utils.Log
|
||||||
import helium314.keyboard.latin.utils.SpannableStringUtils
|
import helium314.keyboard.latin.utils.SpannableStringUtils
|
||||||
import helium314.keyboard.latin.utils.getActivity
|
import helium314.keyboard.latin.utils.getActivity
|
||||||
import helium314.keyboard.latin.utils.prefs
|
import helium314.keyboard.latin.utils.prefs
|
||||||
import helium314.keyboard.settings.AllPrefs
|
import helium314.keyboard.settings.SettingsContainer
|
||||||
import helium314.keyboard.settings.NonSettingsPrefs
|
import helium314.keyboard.settings.SettingsWithoutKey
|
||||||
import helium314.keyboard.settings.PrefDef
|
import helium314.keyboard.settings.Setting
|
||||||
import helium314.keyboard.settings.preferences.Preference
|
import helium314.keyboard.settings.preferences.Preference
|
||||||
import helium314.keyboard.settings.SearchPrefScreen
|
import helium314.keyboard.settings.SearchPrefScreen
|
||||||
import helium314.keyboard.settings.SettingsActivity2
|
import helium314.keyboard.settings.SettingsActivity
|
||||||
import helium314.keyboard.settings.Theme
|
import helium314.keyboard.settings.Theme
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
@ -44,12 +44,12 @@ fun AboutScreen(
|
||||||
onClickBack: () -> Unit,
|
onClickBack: () -> Unit,
|
||||||
) {
|
) {
|
||||||
val items = listOf(
|
val items = listOf(
|
||||||
NonSettingsPrefs.APP,
|
SettingsWithoutKey.APP,
|
||||||
NonSettingsPrefs.VERSION,
|
SettingsWithoutKey.VERSION,
|
||||||
NonSettingsPrefs.LICENSE,
|
SettingsWithoutKey.LICENSE,
|
||||||
NonSettingsPrefs.HIDDEN_FEATURES,
|
SettingsWithoutKey.HIDDEN_FEATURES,
|
||||||
NonSettingsPrefs.GITHUB,
|
SettingsWithoutKey.GITHUB,
|
||||||
NonSettingsPrefs.SAVE_LOG
|
SettingsWithoutKey.SAVE_LOG
|
||||||
)
|
)
|
||||||
SearchPrefScreen(
|
SearchPrefScreen(
|
||||||
onClickBack = onClickBack,
|
onClickBack = onClickBack,
|
||||||
|
@ -58,8 +58,8 @@ fun AboutScreen(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createAboutPrefs(context: Context) = listOf(
|
fun createAboutSettings(context: Context) = listOf(
|
||||||
PrefDef(context, NonSettingsPrefs.APP, R.string.english_ime_name, R.string.app_slogan) {
|
Setting(context, SettingsWithoutKey.APP, R.string.english_ime_name, R.string.app_slogan) {
|
||||||
Preference(
|
Preference(
|
||||||
name = it.title,
|
name = it.title,
|
||||||
description = it.description,
|
description = it.description,
|
||||||
|
@ -67,7 +67,7 @@ fun createAboutPrefs(context: Context) = listOf(
|
||||||
icon = R.drawable.ic_launcher_foreground // use the bitmap trick here if we really want the colored icon
|
icon = R.drawable.ic_launcher_foreground // use the bitmap trick here if we really want the colored icon
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
PrefDef(context, NonSettingsPrefs.VERSION, R.string.version) {
|
Setting(context, SettingsWithoutKey.VERSION, R.string.version) {
|
||||||
var count by rememberSaveable { mutableIntStateOf(0) }
|
var count by rememberSaveable { mutableIntStateOf(0) }
|
||||||
val ctx = LocalContext.current
|
val ctx = LocalContext.current
|
||||||
val prefs = ctx.prefs()
|
val prefs = ctx.prefs()
|
||||||
|
@ -85,7 +85,7 @@ fun createAboutPrefs(context: Context) = listOf(
|
||||||
icon = R.drawable.ic_settings_about_foreground
|
icon = R.drawable.ic_settings_about_foreground
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
PrefDef(context, NonSettingsPrefs.LICENSE, R.string.license, R.string.gnu_gpl) {
|
Setting(context, SettingsWithoutKey.LICENSE, R.string.license, R.string.gnu_gpl) {
|
||||||
val ctx = LocalContext.current
|
val ctx = LocalContext.current
|
||||||
Preference(
|
Preference(
|
||||||
name = it.title,
|
name = it.title,
|
||||||
|
@ -99,7 +99,7 @@ fun createAboutPrefs(context: Context) = listOf(
|
||||||
icon = R.drawable.ic_settings_about_license_foreground
|
icon = R.drawable.ic_settings_about_license_foreground
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
PrefDef(context, NonSettingsPrefs.HIDDEN_FEATURES, R.string.hidden_features_title, R.string.hidden_features_summary) {
|
Setting(context, SettingsWithoutKey.HIDDEN_FEATURES, R.string.hidden_features_title, R.string.hidden_features_summary) {
|
||||||
val ctx = LocalContext.current
|
val ctx = LocalContext.current
|
||||||
Preference(
|
Preference(
|
||||||
name = it.title,
|
name = it.title,
|
||||||
|
@ -123,7 +123,7 @@ fun createAboutPrefs(context: Context) = listOf(
|
||||||
icon = R.drawable.ic_settings_about_hidden_features_foreground
|
icon = R.drawable.ic_settings_about_hidden_features_foreground
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
PrefDef(context, NonSettingsPrefs.GITHUB, R.string.about_github_link) {
|
Setting(context, SettingsWithoutKey.GITHUB, R.string.about_github_link) {
|
||||||
val ctx = LocalContext.current
|
val ctx = LocalContext.current
|
||||||
Preference(
|
Preference(
|
||||||
name = it.title,
|
name = it.title,
|
||||||
|
@ -137,7 +137,7 @@ fun createAboutPrefs(context: Context) = listOf(
|
||||||
icon = R.drawable.ic_settings_about_github_foreground
|
icon = R.drawable.ic_settings_about_github_foreground
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
PrefDef(context, NonSettingsPrefs.SAVE_LOG, R.string.save_log) { def ->
|
Setting(context, SettingsWithoutKey.SAVE_LOG, R.string.save_log) { setting ->
|
||||||
val ctx = LocalContext.current
|
val ctx = LocalContext.current
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
val launcher = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
val launcher = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||||
|
@ -150,8 +150,8 @@ fun createAboutPrefs(context: Context) = listOf(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Preference(
|
Preference(
|
||||||
name = def.title,
|
name = setting.title,
|
||||||
description = def.description,
|
description = setting.description,
|
||||||
onClick = {
|
onClick = {
|
||||||
val intent = Intent(Intent.ACTION_CREATE_DOCUMENT)
|
val intent = Intent(Intent.ACTION_CREATE_DOCUMENT)
|
||||||
.addCategory(Intent.CATEGORY_OPENABLE)
|
.addCategory(Intent.CATEGORY_OPENABLE)
|
||||||
|
@ -171,7 +171,7 @@ fun createAboutPrefs(context: Context) = listOf(
|
||||||
@Preview
|
@Preview
|
||||||
@Composable
|
@Composable
|
||||||
private fun Preview() {
|
private fun Preview() {
|
||||||
SettingsActivity2.allPrefs = AllPrefs(LocalContext.current)
|
SettingsActivity.settingsContainer = SettingsContainer(LocalContext.current)
|
||||||
Theme(true) {
|
Theme(true) {
|
||||||
Surface {
|
Surface {
|
||||||
AboutScreen { }
|
AboutScreen { }
|
||||||
|
|
|
@ -33,13 +33,13 @@ import helium314.keyboard.latin.utils.CUSTOM_FUNCTIONAL_LAYOUT_SYMBOLS_SHIFTED
|
||||||
import helium314.keyboard.latin.utils.CUSTOM_LAYOUT_PREFIX
|
import helium314.keyboard.latin.utils.CUSTOM_LAYOUT_PREFIX
|
||||||
import helium314.keyboard.latin.utils.getStringResourceOrName
|
import helium314.keyboard.latin.utils.getStringResourceOrName
|
||||||
import helium314.keyboard.latin.utils.prefs
|
import helium314.keyboard.latin.utils.prefs
|
||||||
import helium314.keyboard.settings.AllPrefs
|
import helium314.keyboard.settings.SettingsContainer
|
||||||
import helium314.keyboard.settings.preferences.ListPreference
|
import helium314.keyboard.settings.preferences.ListPreference
|
||||||
import helium314.keyboard.settings.NonSettingsPrefs
|
import helium314.keyboard.settings.SettingsWithoutKey
|
||||||
import helium314.keyboard.settings.PrefDef
|
import helium314.keyboard.settings.Setting
|
||||||
import helium314.keyboard.settings.preferences.Preference
|
import helium314.keyboard.settings.preferences.Preference
|
||||||
import helium314.keyboard.settings.SearchPrefScreen
|
import helium314.keyboard.settings.SearchPrefScreen
|
||||||
import helium314.keyboard.settings.SettingsActivity2
|
import helium314.keyboard.settings.SettingsActivity
|
||||||
import helium314.keyboard.settings.SettingsDestination
|
import helium314.keyboard.settings.SettingsDestination
|
||||||
import helium314.keyboard.settings.preferences.SliderPreference
|
import helium314.keyboard.settings.preferences.SliderPreference
|
||||||
import helium314.keyboard.settings.preferences.SwitchPreference
|
import helium314.keyboard.settings.preferences.SwitchPreference
|
||||||
|
@ -73,14 +73,14 @@ fun AdvancedSettingsScreen(
|
||||||
Settings.PREF_ABC_AFTER_CLIP,
|
Settings.PREF_ABC_AFTER_CLIP,
|
||||||
Settings.PREF_CUSTOM_CURRENCY_KEY,
|
Settings.PREF_CUSTOM_CURRENCY_KEY,
|
||||||
Settings.PREF_MORE_POPUP_KEYS,
|
Settings.PREF_MORE_POPUP_KEYS,
|
||||||
NonSettingsPrefs.CUSTOM_SYMBOLS_NUMBER_LAYOUTS,
|
SettingsWithoutKey.CUSTOM_SYMBOLS_NUMBER_LAYOUTS,
|
||||||
NonSettingsPrefs.CUSTOM_FUNCTIONAL_LAYOUTS,
|
SettingsWithoutKey.CUSTOM_FUNCTIONAL_LAYOUTS,
|
||||||
NonSettingsPrefs.BACKUP_RESTORE,
|
SettingsWithoutKey.BACKUP_RESTORE,
|
||||||
if (BuildConfig.DEBUG || prefs.getBoolean(DebugSettings.PREF_SHOW_DEBUG_SETTINGS, false)) NonSettingsPrefs.DEBUG_SETTINGS else null,
|
if (BuildConfig.DEBUG || prefs.getBoolean(DebugSettings.PREF_SHOW_DEBUG_SETTINGS, false)) SettingsWithoutKey.DEBUG_SETTINGS else null,
|
||||||
R.string.settings_category_experimental,
|
R.string.settings_category_experimental,
|
||||||
Settings.PREF_EMOJI_MAX_SDK,
|
Settings.PREF_EMOJI_MAX_SDK,
|
||||||
Settings.PREF_URL_DETECTION,
|
Settings.PREF_URL_DETECTION,
|
||||||
if (BuildConfig.BUILD_TYPE != "nouserlib") NonSettingsPrefs.LOAD_GESTURE_LIB else null
|
if (BuildConfig.BUILD_TYPE != "nouserlib") SettingsWithoutKey.LOAD_GESTURE_LIB else null
|
||||||
)
|
)
|
||||||
SearchPrefScreen(
|
SearchPrefScreen(
|
||||||
onClickBack = onClickBack,
|
onClickBack = onClickBack,
|
||||||
|
@ -90,84 +90,84 @@ fun AdvancedSettingsScreen(
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("ApplySharedPref")
|
@SuppressLint("ApplySharedPref")
|
||||||
fun createAdvancedPrefs(context: Context) = listOf(
|
fun createAdvancedSettings(context: Context) = listOf(
|
||||||
PrefDef(context, Settings.PREF_ALWAYS_INCOGNITO_MODE,
|
Setting(context, Settings.PREF_ALWAYS_INCOGNITO_MODE,
|
||||||
R.string.incognito, R.string.prefs_force_incognito_mode_summary)
|
R.string.incognito, R.string.prefs_force_incognito_mode_summary)
|
||||||
{
|
{
|
||||||
SwitchPreference(it, false)
|
SwitchPreference(it, false)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_KEY_LONGPRESS_TIMEOUT, R.string.prefs_key_longpress_timeout_settings) { def ->
|
Setting(context, Settings.PREF_KEY_LONGPRESS_TIMEOUT, R.string.prefs_key_longpress_timeout_settings) { setting ->
|
||||||
SliderPreference(
|
SliderPreference(
|
||||||
name = def.title,
|
name = setting.title,
|
||||||
pref = def.key,
|
key = setting.key,
|
||||||
default = 300,
|
default = 300,
|
||||||
range = 100f..700f,
|
range = 100f..700f,
|
||||||
description = { stringResource(R.string.abbreviation_unit_milliseconds, it.toString()) }
|
description = { stringResource(R.string.abbreviation_unit_milliseconds, it.toString()) }
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_SPACE_HORIZONTAL_SWIPE, R.string.show_horizontal_space_swipe) { def ->
|
Setting(context, Settings.PREF_SPACE_HORIZONTAL_SWIPE, R.string.show_horizontal_space_swipe) {
|
||||||
val items = listOf(
|
val items = listOf(
|
||||||
stringResource(R.string.space_swipe_move_cursor_entry) to "move_cursor",
|
stringResource(R.string.space_swipe_move_cursor_entry) to "move_cursor",
|
||||||
stringResource(R.string.switch_language) to "switch_language",
|
stringResource(R.string.switch_language) to "switch_language",
|
||||||
stringResource(R.string.space_swipe_toggle_numpad_entry) to "toggle_numpad",
|
stringResource(R.string.space_swipe_toggle_numpad_entry) to "toggle_numpad",
|
||||||
stringResource(R.string.action_none) to "none",
|
stringResource(R.string.action_none) to "none",
|
||||||
)
|
)
|
||||||
ListPreference(def, items, "move_cursor")
|
ListPreference(it, items, "move_cursor")
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_SPACE_VERTICAL_SWIPE, R.string.show_vertical_space_swipe) { def ->
|
Setting(context, Settings.PREF_SPACE_VERTICAL_SWIPE, R.string.show_vertical_space_swipe) {
|
||||||
val items = listOf(
|
val items = listOf(
|
||||||
stringResource(R.string.space_swipe_move_cursor_entry) to "move_cursor",
|
stringResource(R.string.space_swipe_move_cursor_entry) to "move_cursor",
|
||||||
stringResource(R.string.switch_language) to "switch_language",
|
stringResource(R.string.switch_language) to "switch_language",
|
||||||
stringResource(R.string.space_swipe_toggle_numpad_entry) to "toggle_numpad",
|
stringResource(R.string.space_swipe_toggle_numpad_entry) to "toggle_numpad",
|
||||||
stringResource(R.string.action_none) to "none",
|
stringResource(R.string.action_none) to "none",
|
||||||
)
|
)
|
||||||
ListPreference(def, items, "none")
|
ListPreference(it, items, "none")
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_LANGUAGE_SWIPE_DISTANCE, R.string.prefs_language_swipe_distance) { def ->
|
Setting(context, Settings.PREF_LANGUAGE_SWIPE_DISTANCE, R.string.prefs_language_swipe_distance) { setting ->
|
||||||
SliderPreference(
|
SliderPreference(
|
||||||
name = def.title,
|
name = setting.title,
|
||||||
pref = def.key,
|
key = setting.key,
|
||||||
default = 5,
|
default = 5,
|
||||||
range = 2f..18f,
|
range = 2f..18f,
|
||||||
description = { it.toString() }
|
description = { it.toString() }
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_DELETE_SWIPE, R.string.delete_swipe, R.string.delete_swipe_summary) {
|
Setting(context, Settings.PREF_DELETE_SWIPE, R.string.delete_swipe, R.string.delete_swipe_summary) {
|
||||||
SwitchPreference(it, true)
|
SwitchPreference(it, true)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_SPACE_TO_CHANGE_LANG,
|
Setting(context, Settings.PREF_SPACE_TO_CHANGE_LANG,
|
||||||
R.string.prefs_long_press_keyboard_to_change_lang,
|
R.string.prefs_long_press_keyboard_to_change_lang,
|
||||||
R.string.prefs_long_press_keyboard_to_change_lang_summary)
|
R.string.prefs_long_press_keyboard_to_change_lang_summary)
|
||||||
{
|
{
|
||||||
SwitchPreference(it, true)
|
SwitchPreference(it, true)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREFS_LONG_PRESS_SYMBOLS_FOR_NUMPAD, R.string.prefs_long_press_symbol_for_numpad) {
|
Setting(context, Settings.PREFS_LONG_PRESS_SYMBOLS_FOR_NUMPAD, R.string.prefs_long_press_symbol_for_numpad) {
|
||||||
SwitchPreference(it, false)
|
SwitchPreference(it, false)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_ENABLE_EMOJI_ALT_PHYSICAL_KEY, R.string.prefs_enable_emoji_alt_physical_key,
|
Setting(context, Settings.PREF_ENABLE_EMOJI_ALT_PHYSICAL_KEY, R.string.prefs_enable_emoji_alt_physical_key,
|
||||||
R.string.prefs_enable_emoji_alt_physical_key_summary)
|
R.string.prefs_enable_emoji_alt_physical_key_summary)
|
||||||
{
|
{
|
||||||
SwitchPreference(it, true)
|
SwitchPreference(it, true)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_SHOW_SETUP_WIZARD_ICON, R.string.prefs_enable_emoji_alt_physical_key_summary) {
|
Setting(context, Settings.PREF_SHOW_SETUP_WIZARD_ICON, R.string.prefs_enable_emoji_alt_physical_key_summary) {
|
||||||
val ctx = LocalContext.current
|
val ctx = LocalContext.current
|
||||||
SwitchPreference(it, true) { SystemBroadcastReceiver.toggleAppIcon(ctx) }
|
SwitchPreference(it, true) { SystemBroadcastReceiver.toggleAppIcon(ctx) }
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_ABC_AFTER_SYMBOL_SPACE,
|
Setting(context, Settings.PREF_ABC_AFTER_SYMBOL_SPACE,
|
||||||
R.string.switch_keyboard_after, R.string.after_symbol_and_space)
|
R.string.switch_keyboard_after, R.string.after_symbol_and_space)
|
||||||
{
|
{
|
||||||
SwitchPreference(it, true)
|
SwitchPreference(it, true)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_ABC_AFTER_EMOJI, R.string.switch_keyboard_after, R.string.after_emoji) {
|
Setting(context, Settings.PREF_ABC_AFTER_EMOJI, R.string.switch_keyboard_after, R.string.after_emoji) {
|
||||||
SwitchPreference(it, false)
|
SwitchPreference(it, false)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_ABC_AFTER_CLIP, R.string.switch_keyboard_after, R.string.after_clip) {
|
Setting(context, Settings.PREF_ABC_AFTER_CLIP, R.string.switch_keyboard_after, R.string.after_clip) {
|
||||||
SwitchPreference(it, false)
|
SwitchPreference(it, false)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_CUSTOM_CURRENCY_KEY, R.string.customize_currencies) { def ->
|
Setting(context, Settings.PREF_CUSTOM_CURRENCY_KEY, R.string.customize_currencies) { setting ->
|
||||||
var showDialog by remember { mutableStateOf(false) }
|
var showDialog by remember { mutableStateOf(false) }
|
||||||
Preference(
|
Preference(
|
||||||
name = def.title,
|
name = setting.title,
|
||||||
onClick = { showDialog = true }
|
onClick = { showDialog = true }
|
||||||
)
|
)
|
||||||
if (showDialog) {
|
if (showDialog) {
|
||||||
|
@ -175,45 +175,45 @@ fun createAdvancedPrefs(context: Context) = listOf(
|
||||||
TextInputDialog(
|
TextInputDialog(
|
||||||
onDismissRequest = { showDialog = false },
|
onDismissRequest = { showDialog = false },
|
||||||
textInputLabel = { Text(stringResource(R.string.customize_currencies_detail)) },
|
textInputLabel = { Text(stringResource(R.string.customize_currencies_detail)) },
|
||||||
initialText = prefs.getString(def.key, "")!!,
|
initialText = prefs.getString(setting.key, "")!!,
|
||||||
onConfirmed = { prefs.edit().putString(def.key, it).apply(); KeyboardLayoutSet.onSystemLocaleChanged() },
|
onConfirmed = { prefs.edit().putString(setting.key, it).apply(); KeyboardLayoutSet.onSystemLocaleChanged() },
|
||||||
title = { Text(stringResource(R.string.customize_currencies)) },
|
title = { Text(stringResource(R.string.customize_currencies)) },
|
||||||
neutralButtonText = if (prefs.contains(def.key)) stringResource(R.string.button_default) else null,
|
neutralButtonText = if (prefs.contains(setting.key)) stringResource(R.string.button_default) else null,
|
||||||
onNeutral = { prefs.edit().remove(def.key).apply(); KeyboardLayoutSet.onSystemLocaleChanged() },
|
onNeutral = { prefs.edit().remove(setting.key).apply(); KeyboardLayoutSet.onSystemLocaleChanged() },
|
||||||
checkTextValid = { text -> text.splitOnWhitespace().none { it.length > 8 } }
|
checkTextValid = { text -> text.splitOnWhitespace().none { it.length > 8 } }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_MORE_POPUP_KEYS, R.string.show_popup_keys_title) { def ->
|
Setting(context, Settings.PREF_MORE_POPUP_KEYS, R.string.show_popup_keys_title) {
|
||||||
val items = listOf(
|
val items = listOf(
|
||||||
stringResource(R.string.show_popup_keys_normal) to "normal",
|
stringResource(R.string.show_popup_keys_normal) to "normal",
|
||||||
stringResource(R.string.show_popup_keys_main) to "main",
|
stringResource(R.string.show_popup_keys_main) to "main",
|
||||||
stringResource(R.string.show_popup_keys_more) to "more",
|
stringResource(R.string.show_popup_keys_more) to "more",
|
||||||
stringResource(R.string.show_popup_keys_all) to "all",
|
stringResource(R.string.show_popup_keys_all) to "all",
|
||||||
)
|
)
|
||||||
ListPreference(def, items, "main") { KeyboardLayoutSet.onSystemLocaleChanged() }
|
ListPreference(it, items, "main") { KeyboardLayoutSet.onSystemLocaleChanged() }
|
||||||
},
|
},
|
||||||
PrefDef(context, NonSettingsPrefs.CUSTOM_SYMBOLS_NUMBER_LAYOUTS, R.string.customize_symbols_number_layouts) { def ->
|
Setting(context, SettingsWithoutKey.CUSTOM_SYMBOLS_NUMBER_LAYOUTS, R.string.customize_symbols_number_layouts) { setting ->
|
||||||
LayoutEditPreference(
|
LayoutEditPreference(
|
||||||
def = def,
|
setting = setting,
|
||||||
items = RawKeyboardParser.symbolAndNumberLayouts,
|
items = RawKeyboardParser.symbolAndNumberLayouts,
|
||||||
getItemName = { it.getStringResourceOrName("layout_", LocalContext.current) },
|
getItemName = { it.getStringResourceOrName("layout_", LocalContext.current) },
|
||||||
getDefaultLayout = { LocalContext.current.assets.list("layouts")?.firstOrNull { it.startsWith("$it.") } }
|
getDefaultLayout = { LocalContext.current.assets.list("layouts")?.firstOrNull { it.startsWith("$it.") } }
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
PrefDef(context, NonSettingsPrefs.CUSTOM_FUNCTIONAL_LAYOUTS, R.string.customize_functional_key_layouts) { def ->
|
Setting(context, SettingsWithoutKey.CUSTOM_FUNCTIONAL_LAYOUTS, R.string.customize_functional_key_layouts) { setting ->
|
||||||
LayoutEditPreference(
|
LayoutEditPreference(
|
||||||
def = def,
|
setting = setting,
|
||||||
items = listOf(CUSTOM_FUNCTIONAL_LAYOUT_NORMAL, CUSTOM_FUNCTIONAL_LAYOUT_SYMBOLS, CUSTOM_FUNCTIONAL_LAYOUT_SYMBOLS_SHIFTED)
|
items = listOf(CUSTOM_FUNCTIONAL_LAYOUT_NORMAL, CUSTOM_FUNCTIONAL_LAYOUT_SYMBOLS, CUSTOM_FUNCTIONAL_LAYOUT_SYMBOLS_SHIFTED)
|
||||||
.map { it.substringBeforeLast(".") },
|
.map { it.substringBeforeLast(".") },
|
||||||
getItemName = { it.substringAfter(CUSTOM_LAYOUT_PREFIX).getStringResourceOrName("layout_", LocalContext.current) },
|
getItemName = { it.substringAfter(CUSTOM_LAYOUT_PREFIX).getStringResourceOrName("layout_", LocalContext.current) },
|
||||||
getDefaultLayout = { if (Settings.getInstance().isTablet) "functional_keys_tablet.json" else "functional_keys.json" }
|
getDefaultLayout = { if (Settings.getInstance().isTablet) "functional_keys_tablet.json" else "functional_keys.json" }
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
PrefDef(context, NonSettingsPrefs.BACKUP_RESTORE, R.string.backup_restore_title) {
|
Setting(context, SettingsWithoutKey.BACKUP_RESTORE, R.string.backup_restore_title) {
|
||||||
BackupRestorePreference(it)
|
BackupRestorePreference(it)
|
||||||
},
|
},
|
||||||
PrefDef(context, NonSettingsPrefs.DEBUG_SETTINGS, R.string.debug_settings_title) {
|
Setting(context, SettingsWithoutKey.DEBUG_SETTINGS, R.string.debug_settings_title) {
|
||||||
Preference(
|
Preference(
|
||||||
name = it.title,
|
name = it.title,
|
||||||
onClick = { SettingsDestination.navigateTo(SettingsDestination.Debug) }
|
onClick = { SettingsDestination.navigateTo(SettingsDestination.Debug) }
|
||||||
|
@ -225,10 +225,10 @@ fun createAdvancedPrefs(context: Context) = listOf(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_EMOJI_MAX_SDK, R.string.prefs_key_emoji_max_sdk) { def ->
|
Setting(context, Settings.PREF_EMOJI_MAX_SDK, R.string.prefs_key_emoji_max_sdk) { setting ->
|
||||||
SliderPreference(
|
SliderPreference(
|
||||||
name = def.title,
|
name = setting.title,
|
||||||
pref = def.key,
|
key = setting.key,
|
||||||
default = Build.VERSION.SDK_INT,
|
default = Build.VERSION.SDK_INT,
|
||||||
range = 21f..35f,
|
range = 21f..35f,
|
||||||
description = {
|
description = {
|
||||||
|
@ -254,10 +254,10 @@ fun createAdvancedPrefs(context: Context) = listOf(
|
||||||
onValueChanged = { keyboardNeedsReload = true }
|
onValueChanged = { keyboardNeedsReload = true }
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_URL_DETECTION, R.string.url_detection_title, R.string.url_detection_summary) {
|
Setting(context, Settings.PREF_URL_DETECTION, R.string.url_detection_title, R.string.url_detection_summary) {
|
||||||
SwitchPreference(it, false)
|
SwitchPreference(it, false)
|
||||||
},
|
},
|
||||||
PrefDef(context, NonSettingsPrefs.LOAD_GESTURE_LIB, R.string.load_gesture_library, R.string.load_gesture_library_summary) {
|
Setting(context, SettingsWithoutKey.LOAD_GESTURE_LIB, R.string.load_gesture_library, R.string.load_gesture_library_summary) {
|
||||||
LoadGestureLibPreference(it)
|
LoadGestureLibPreference(it)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -265,7 +265,7 @@ fun createAdvancedPrefs(context: Context) = listOf(
|
||||||
@Preview
|
@Preview
|
||||||
@Composable
|
@Composable
|
||||||
private fun Preview() {
|
private fun Preview() {
|
||||||
SettingsActivity2.allPrefs = AllPrefs(LocalContext.current)
|
SettingsActivity.settingsContainer = SettingsContainer(LocalContext.current)
|
||||||
Theme(true) {
|
Theme(true) {
|
||||||
Surface {
|
Surface {
|
||||||
AdvancedSettingsScreen { }
|
AdvancedSettingsScreen { }
|
||||||
|
|
|
@ -26,13 +26,13 @@ import helium314.keyboard.latin.utils.getActivity
|
||||||
import helium314.keyboard.latin.utils.getStringResourceOrName
|
import helium314.keyboard.latin.utils.getStringResourceOrName
|
||||||
import helium314.keyboard.latin.utils.prefs
|
import helium314.keyboard.latin.utils.prefs
|
||||||
import helium314.keyboard.latin.utils.switchTo
|
import helium314.keyboard.latin.utils.switchTo
|
||||||
import helium314.keyboard.settings.AllPrefs
|
import helium314.keyboard.settings.SettingsContainer
|
||||||
import helium314.keyboard.settings.preferences.ListPreference
|
import helium314.keyboard.settings.preferences.ListPreference
|
||||||
import helium314.keyboard.settings.NonSettingsPrefs
|
import helium314.keyboard.settings.SettingsWithoutKey
|
||||||
import helium314.keyboard.settings.PrefDef
|
import helium314.keyboard.settings.Setting
|
||||||
import helium314.keyboard.settings.preferences.Preference
|
import helium314.keyboard.settings.preferences.Preference
|
||||||
import helium314.keyboard.settings.SearchPrefScreen
|
import helium314.keyboard.settings.SearchPrefScreen
|
||||||
import helium314.keyboard.settings.SettingsActivity2
|
import helium314.keyboard.settings.SettingsActivity
|
||||||
import helium314.keyboard.settings.preferences.SliderPreference
|
import helium314.keyboard.settings.preferences.SliderPreference
|
||||||
import helium314.keyboard.settings.preferences.SwitchPreference
|
import helium314.keyboard.settings.preferences.SwitchPreference
|
||||||
import helium314.keyboard.settings.Theme
|
import helium314.keyboard.settings.Theme
|
||||||
|
@ -48,7 +48,7 @@ fun AppearanceScreen(
|
||||||
) {
|
) {
|
||||||
val ctx = LocalContext.current
|
val ctx = LocalContext.current
|
||||||
val prefs = ctx.prefs()
|
val prefs = ctx.prefs()
|
||||||
val b = (LocalContext.current.getActivity() as? SettingsActivity2)?.prefChanged?.collectAsState()
|
val b = (LocalContext.current.getActivity() as? SettingsActivity)?.prefChanged?.collectAsState()
|
||||||
if ((b?.value ?: 0) < 0)
|
if ((b?.value ?: 0) < 0)
|
||||||
Log.v("irrelevant", "stupid way to trigger recomposition on preference change")
|
Log.v("irrelevant", "stupid way to trigger recomposition on preference change")
|
||||||
val dayNightMode = Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && Settings.readDayNightPref(prefs, ctx.resources)
|
val dayNightMode = Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && Settings.readDayNightPref(prefs, ctx.resources)
|
||||||
|
@ -59,16 +59,16 @@ fun AppearanceScreen(
|
||||||
Settings.PREF_CUSTOM_ICON_NAMES,
|
Settings.PREF_CUSTOM_ICON_NAMES,
|
||||||
Settings.PREF_THEME_COLORS,
|
Settings.PREF_THEME_COLORS,
|
||||||
if (prefs.getString(Settings.PREF_THEME_COLORS, KeyboardTheme.THEME_LIGHT) == KeyboardTheme.THEME_USER)
|
if (prefs.getString(Settings.PREF_THEME_COLORS, KeyboardTheme.THEME_LIGHT) == KeyboardTheme.THEME_USER)
|
||||||
NonSettingsPrefs.ADJUST_COLORS else null,
|
SettingsWithoutKey.ADJUST_COLORS else null,
|
||||||
Settings.PREF_THEME_KEY_BORDERS,
|
Settings.PREF_THEME_KEY_BORDERS,
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
|
||||||
Settings.PREF_THEME_DAY_NIGHT else null,
|
Settings.PREF_THEME_DAY_NIGHT else null,
|
||||||
if (dayNightMode) Settings.PREF_THEME_COLORS_NIGHT else null,
|
if (dayNightMode) Settings.PREF_THEME_COLORS_NIGHT else null,
|
||||||
if (dayNightMode && prefs.getString(Settings.PREF_THEME_COLORS_NIGHT, KeyboardTheme.THEME_DARK) == KeyboardTheme.THEME_USER_NIGHT)
|
if (dayNightMode && prefs.getString(Settings.PREF_THEME_COLORS_NIGHT, KeyboardTheme.THEME_DARK) == KeyboardTheme.THEME_USER_NIGHT)
|
||||||
NonSettingsPrefs.ADJUST_COLORS_NIGHT else null,
|
SettingsWithoutKey.ADJUST_COLORS_NIGHT else null,
|
||||||
Settings.PREF_NAVBAR_COLOR,
|
Settings.PREF_NAVBAR_COLOR,
|
||||||
NonSettingsPrefs.BACKGROUND_IMAGE,
|
SettingsWithoutKey.BACKGROUND_IMAGE,
|
||||||
NonSettingsPrefs.BACKGROUND_IMAGE_LANDSCAPE,
|
SettingsWithoutKey.BACKGROUND_IMAGE_LANDSCAPE,
|
||||||
R.string.settings_category_miscellaneous,
|
R.string.settings_category_miscellaneous,
|
||||||
Settings.PREF_ENABLE_SPLIT_KEYBOARD,
|
Settings.PREF_ENABLE_SPLIT_KEYBOARD,
|
||||||
Settings.PREF_SPLIT_SPACER_SCALE,
|
Settings.PREF_SPLIT_SPACER_SCALE,
|
||||||
|
@ -79,7 +79,7 @@ fun AppearanceScreen(
|
||||||
Settings.PREF_SIDE_PADDING_SCALE,
|
Settings.PREF_SIDE_PADDING_SCALE,
|
||||||
Settings.PREF_SIDE_PADDING_SCALE_LANDSCAPE,
|
Settings.PREF_SIDE_PADDING_SCALE_LANDSCAPE,
|
||||||
Settings.PREF_SPACE_BAR_TEXT,
|
Settings.PREF_SPACE_BAR_TEXT,
|
||||||
NonSettingsPrefs.CUSTOM_FONT,
|
SettingsWithoutKey.CUSTOM_FONT,
|
||||||
Settings.PREF_FONT_SCALE,
|
Settings.PREF_FONT_SCALE,
|
||||||
Settings.PREF_EMOJI_FONT_SCALE,
|
Settings.PREF_EMOJI_FONT_SCALE,
|
||||||
)
|
)
|
||||||
|
@ -90,15 +90,15 @@ fun AppearanceScreen(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createAppearancePrefs(context: Context) = listOf(
|
fun createAppearanceSettings(context: Context) = listOf(
|
||||||
PrefDef(context, Settings.PREF_THEME_STYLE, R.string.theme_style) { def ->
|
Setting(context, Settings.PREF_THEME_STYLE, R.string.theme_style) { setting ->
|
||||||
val ctx = LocalContext.current
|
val ctx = LocalContext.current
|
||||||
val prefs = ctx.prefs()
|
val prefs = ctx.prefs()
|
||||||
val items = KeyboardTheme.STYLES.map {
|
val items = KeyboardTheme.STYLES.map {
|
||||||
it.getStringResourceOrName("style_name_", ctx) to it
|
it.getStringResourceOrName("style_name_", ctx) to it
|
||||||
}
|
}
|
||||||
ListPreference(
|
ListPreference(
|
||||||
def,
|
setting,
|
||||||
items,
|
items,
|
||||||
KeyboardTheme.STYLE_MATERIAL
|
KeyboardTheme.STYLE_MATERIAL
|
||||||
) {
|
) {
|
||||||
|
@ -111,19 +111,19 @@ fun createAppearancePrefs(context: Context) = listOf(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_ICON_STYLE, R.string.icon_style) { def ->
|
Setting(context, Settings.PREF_ICON_STYLE, R.string.icon_style) { setting ->
|
||||||
val ctx = LocalContext.current
|
val ctx = LocalContext.current
|
||||||
val items = KeyboardTheme.STYLES.map { it.getStringResourceOrName("style_name_", ctx) to it }
|
val items = KeyboardTheme.STYLES.map { it.getStringResourceOrName("style_name_", ctx) to it }
|
||||||
ListPreference(
|
ListPreference(
|
||||||
def,
|
setting,
|
||||||
items,
|
items,
|
||||||
KeyboardTheme.STYLE_MATERIAL
|
KeyboardTheme.STYLE_MATERIAL
|
||||||
) { keyboardNeedsReload = true }
|
) { keyboardNeedsReload = true }
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_CUSTOM_ICON_NAMES, R.string.customize_icons) { def ->
|
Setting(context, Settings.PREF_CUSTOM_ICON_NAMES, R.string.customize_icons) { setting ->
|
||||||
var showDialog by remember { mutableStateOf(false) }
|
var showDialog by remember { mutableStateOf(false) }
|
||||||
Preference(
|
Preference(
|
||||||
name = def.title,
|
name = setting.title,
|
||||||
onClick = { showDialog = true }
|
onClick = { showDialog = true }
|
||||||
)
|
)
|
||||||
if (showDialog) {
|
if (showDialog) {
|
||||||
|
@ -131,12 +131,12 @@ fun createAppearancePrefs(context: Context) = listOf(
|
||||||
KeyboardSwitcher.getInstance().forceUpdateKeyboardTheme(LocalContext.current)
|
KeyboardSwitcher.getInstance().forceUpdateKeyboardTheme(LocalContext.current)
|
||||||
keyboardNeedsReload = false
|
keyboardNeedsReload = false
|
||||||
}
|
}
|
||||||
CustomizeIconsDialog(def.key) { showDialog = false }
|
CustomizeIconsDialog(setting.key) { showDialog = false }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_THEME_COLORS, R.string.theme_colors) { def ->
|
Setting(context, Settings.PREF_THEME_COLORS, R.string.theme_colors) { setting ->
|
||||||
val ctx = LocalContext.current
|
val ctx = LocalContext.current
|
||||||
val b = (ctx.getActivity() as? SettingsActivity2)?.prefChanged?.collectAsState()
|
val b = (ctx.getActivity() as? SettingsActivity)?.prefChanged?.collectAsState()
|
||||||
if ((b?.value ?: 0) < 0)
|
if ((b?.value ?: 0) < 0)
|
||||||
Log.v("irrelevant", "stupid way to trigger recomposition on preference change")
|
Log.v("irrelevant", "stupid way to trigger recomposition on preference change")
|
||||||
val currentStyle = ctx.prefs().getString(Settings.PREF_THEME_STYLE, KeyboardTheme.STYLE_MATERIAL)
|
val currentStyle = ctx.prefs().getString(Settings.PREF_THEME_STYLE, KeyboardTheme.STYLE_MATERIAL)
|
||||||
|
@ -146,14 +146,14 @@ fun createAppearancePrefs(context: Context) = listOf(
|
||||||
it.getStringResourceOrName("theme_name_", ctx) to it
|
it.getStringResourceOrName("theme_name_", ctx) to it
|
||||||
}
|
}
|
||||||
ListPreference(
|
ListPreference(
|
||||||
def,
|
setting,
|
||||||
items,
|
items,
|
||||||
KeyboardTheme.THEME_LIGHT
|
KeyboardTheme.THEME_LIGHT
|
||||||
) { keyboardNeedsReload = true }
|
) { keyboardNeedsReload = true }
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_THEME_COLORS_NIGHT, R.string.theme_colors_night) { def ->
|
Setting(context, Settings.PREF_THEME_COLORS_NIGHT, R.string.theme_colors_night) { setting ->
|
||||||
val ctx = LocalContext.current
|
val ctx = LocalContext.current
|
||||||
val b = (ctx.getActivity() as? SettingsActivity2)?.prefChanged?.collectAsState()
|
val b = (ctx.getActivity() as? SettingsActivity)?.prefChanged?.collectAsState()
|
||||||
if ((b?.value ?: 0) < 0)
|
if ((b?.value ?: 0) < 0)
|
||||||
Log.v("irrelevant", "stupid way to trigger recomposition on preference change")
|
Log.v("irrelevant", "stupid way to trigger recomposition on preference change")
|
||||||
val currentStyle = ctx.prefs().getString(Settings.PREF_THEME_STYLE, KeyboardTheme.STYLE_MATERIAL)
|
val currentStyle = ctx.prefs().getString(Settings.PREF_THEME_STYLE, KeyboardTheme.STYLE_MATERIAL)
|
||||||
|
@ -163,147 +163,147 @@ fun createAppearancePrefs(context: Context) = listOf(
|
||||||
it.getStringResourceOrName("theme_name_", ctx) to it
|
it.getStringResourceOrName("theme_name_", ctx) to it
|
||||||
}
|
}
|
||||||
ListPreference(
|
ListPreference(
|
||||||
def,
|
setting,
|
||||||
items,
|
items,
|
||||||
KeyboardTheme.THEME_DARK
|
KeyboardTheme.THEME_DARK
|
||||||
) { keyboardNeedsReload = true }
|
) { keyboardNeedsReload = true }
|
||||||
},
|
},
|
||||||
PrefDef(context, NonSettingsPrefs.ADJUST_COLORS, R.string.select_user_colors, R.string.select_user_colors_summary) { def ->
|
Setting(context, SettingsWithoutKey.ADJUST_COLORS, R.string.select_user_colors, R.string.select_user_colors_summary) {
|
||||||
val ctx = LocalContext.current
|
val ctx = LocalContext.current
|
||||||
Preference(
|
Preference(
|
||||||
name = def.title,
|
name = it.title,
|
||||||
description = def.description,
|
description = it.description,
|
||||||
onClick = {
|
onClick = {
|
||||||
ctx.getActivity()?.switchTo(ColorsSettingsFragment())
|
ctx.getActivity()?.switchTo(ColorsSettingsFragment())
|
||||||
//SettingsDestination.navigateTo(SettingsDestination.Colors) todo: later
|
//SettingsDestination.navigateTo(SettingsDestination.Colors) todo: later
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
PrefDef(context, NonSettingsPrefs.ADJUST_COLORS_NIGHT, R.string.select_user_colors_night, R.string.select_user_colors_summary) { def ->
|
Setting(context, SettingsWithoutKey.ADJUST_COLORS_NIGHT, R.string.select_user_colors_night, R.string.select_user_colors_summary) {
|
||||||
val ctx = LocalContext.current
|
val ctx = LocalContext.current
|
||||||
Preference(
|
Preference(
|
||||||
name = def.title,
|
name = it.title,
|
||||||
description = def.description,
|
description = it.description,
|
||||||
onClick = {
|
onClick = {
|
||||||
ctx.getActivity()?.switchTo(ColorsNightSettingsFragment())
|
ctx.getActivity()?.switchTo(ColorsNightSettingsFragment())
|
||||||
//SettingsDestination.navigateTo(SettingsDestination.ColorsNight) todo: later
|
//SettingsDestination.navigateTo(SettingsDestination.ColorsNight) todo: later
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_THEME_KEY_BORDERS, R.string.key_borders) {
|
Setting(context, Settings.PREF_THEME_KEY_BORDERS, R.string.key_borders) {
|
||||||
SwitchPreference(it, false)
|
SwitchPreference(it, false)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_THEME_DAY_NIGHT, R.string.day_night_mode, R.string.day_night_mode_summary) {
|
Setting(context, Settings.PREF_THEME_DAY_NIGHT, R.string.day_night_mode, R.string.day_night_mode_summary) {
|
||||||
SwitchPreference(it, Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { keyboardNeedsReload = true }
|
SwitchPreference(it, Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { keyboardNeedsReload = true }
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_NAVBAR_COLOR, R.string.theme_navbar, R.string.day_night_mode_summary) {
|
Setting(context, Settings.PREF_NAVBAR_COLOR, R.string.theme_navbar, R.string.day_night_mode_summary) {
|
||||||
SwitchPreference(it, Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
|
SwitchPreference(it, Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
|
||||||
},
|
},
|
||||||
PrefDef(context, NonSettingsPrefs.BACKGROUND_IMAGE, R.string.customize_background_image) {
|
Setting(context, SettingsWithoutKey.BACKGROUND_IMAGE, R.string.customize_background_image) {
|
||||||
BackgroundImagePref(it, false)
|
BackgroundImagePref(it, false)
|
||||||
},
|
},
|
||||||
PrefDef(context, NonSettingsPrefs.BACKGROUND_IMAGE_LANDSCAPE,
|
Setting(context, SettingsWithoutKey.BACKGROUND_IMAGE_LANDSCAPE,
|
||||||
R.string.customize_background_image_landscape, R.string.summary_customize_background_image_landscape)
|
R.string.customize_background_image_landscape, R.string.summary_customize_background_image_landscape)
|
||||||
{
|
{
|
||||||
BackgroundImagePref(it, true)
|
BackgroundImagePref(it, true)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_ENABLE_SPLIT_KEYBOARD, R.string.enable_split_keyboard) {
|
Setting(context, Settings.PREF_ENABLE_SPLIT_KEYBOARD, R.string.enable_split_keyboard) {
|
||||||
SwitchPreference(it, false)
|
SwitchPreference(it, false)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_SPLIT_SPACER_SCALE, R.string.split_spacer_scale) { def ->
|
Setting(context, Settings.PREF_SPLIT_SPACER_SCALE, R.string.split_spacer_scale) { setting ->
|
||||||
SliderPreference(
|
SliderPreference(
|
||||||
name = def.title,
|
name = setting.title,
|
||||||
pref = def.key,
|
key = setting.key,
|
||||||
default = SettingsValues.DEFAULT_SIZE_SCALE,
|
default = SettingsValues.DEFAULT_SIZE_SCALE,
|
||||||
range = 0.5f..2f,
|
range = 0.5f..2f,
|
||||||
description = { "${(100 * it).toInt()}%" }
|
description = { "${(100 * it).toInt()}%" }
|
||||||
) { keyboardNeedsReload = true }
|
) { keyboardNeedsReload = true }
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_NARROW_KEY_GAPS, R.string.prefs_narrow_key_gaps) {
|
Setting(context, Settings.PREF_NARROW_KEY_GAPS, R.string.prefs_narrow_key_gaps) {
|
||||||
SwitchPreference(it, false) { keyboardNeedsReload = true }
|
SwitchPreference(it, false) { keyboardNeedsReload = true }
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_KEYBOARD_HEIGHT_SCALE, R.string.prefs_keyboard_height_scale) { def ->
|
Setting(context, Settings.PREF_KEYBOARD_HEIGHT_SCALE, R.string.prefs_keyboard_height_scale) { setting ->
|
||||||
SliderPreference(
|
SliderPreference(
|
||||||
name = def.title,
|
name = setting.title,
|
||||||
pref = def.key,
|
key = setting.key,
|
||||||
default = SettingsValues.DEFAULT_SIZE_SCALE,
|
default = SettingsValues.DEFAULT_SIZE_SCALE,
|
||||||
range = 0.5f..1.5f,
|
range = 0.5f..1.5f,
|
||||||
description = { "${(100 * it).toInt()}%" }
|
description = { "${(100 * it).toInt()}%" }
|
||||||
) { keyboardNeedsReload = true }
|
) { keyboardNeedsReload = true }
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_BOTTOM_PADDING_SCALE, R.string.prefs_bottom_padding_scale) { def ->
|
Setting(context, Settings.PREF_BOTTOM_PADDING_SCALE, R.string.prefs_bottom_padding_scale) { setting ->
|
||||||
SliderPreference(
|
SliderPreference(
|
||||||
name = def.title,
|
name = setting.title,
|
||||||
pref = def.key,
|
key = setting.key,
|
||||||
default = SettingsValues.DEFAULT_SIZE_SCALE,
|
default = SettingsValues.DEFAULT_SIZE_SCALE,
|
||||||
range = 0f..5f,
|
range = 0f..5f,
|
||||||
description = { "${(100 * it).toInt()}%" }
|
description = { "${(100 * it).toInt()}%" }
|
||||||
) { keyboardNeedsReload = true }
|
) { keyboardNeedsReload = true }
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_BOTTOM_PADDING_SCALE_LANDSCAPE, R.string.prefs_bottom_padding_scale_landscape) { def ->
|
Setting(context, Settings.PREF_BOTTOM_PADDING_SCALE_LANDSCAPE, R.string.prefs_bottom_padding_scale_landscape) { setting ->
|
||||||
SliderPreference(
|
SliderPreference(
|
||||||
name = def.title,
|
name = setting.title,
|
||||||
pref = def.key,
|
key = setting.key,
|
||||||
default = 0f,
|
default = 0f,
|
||||||
range = 0f..5f,
|
range = 0f..5f,
|
||||||
description = { "${(100 * it).toInt()}%" }
|
description = { "${(100 * it).toInt()}%" }
|
||||||
) { keyboardNeedsReload = true }
|
) { keyboardNeedsReload = true }
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_SIDE_PADDING_SCALE, R.string.prefs_side_padding_scale) { def ->
|
Setting(context, Settings.PREF_SIDE_PADDING_SCALE, R.string.prefs_side_padding_scale) { setting ->
|
||||||
SliderPreference(
|
SliderPreference(
|
||||||
name = def.title,
|
name = setting.title,
|
||||||
pref = def.key,
|
key = setting.key,
|
||||||
default = 0f,
|
default = 0f,
|
||||||
range = 0f..3f,
|
range = 0f..3f,
|
||||||
description = { "${(100 * it).toInt()}%" }
|
description = { "${(100 * it).toInt()}%" }
|
||||||
) { keyboardNeedsReload = true }
|
) { keyboardNeedsReload = true }
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_SIDE_PADDING_SCALE_LANDSCAPE, R.string.prefs_side_padding_scale_landscape) { def ->
|
Setting(context, Settings.PREF_SIDE_PADDING_SCALE_LANDSCAPE, R.string.prefs_side_padding_scale_landscape) { setting ->
|
||||||
SliderPreference(
|
SliderPreference(
|
||||||
name = def.title,
|
name = setting.title,
|
||||||
pref = def.key,
|
key = setting.key,
|
||||||
default = 0f,
|
default = 0f,
|
||||||
range = 0f..3f,
|
range = 0f..3f,
|
||||||
description = { "${(100 * it).toInt()}%" }
|
description = { "${(100 * it).toInt()}%" }
|
||||||
) { keyboardNeedsReload = true }
|
) { keyboardNeedsReload = true }
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_SPACE_BAR_TEXT, R.string.prefs_space_bar_text) { def ->
|
Setting(context, Settings.PREF_SPACE_BAR_TEXT, R.string.prefs_space_bar_text) { setting ->
|
||||||
var showDialog by remember { mutableStateOf(false) }
|
var showDialog by remember { mutableStateOf(false) }
|
||||||
val prefs = LocalContext.current.prefs()
|
val prefs = LocalContext.current.prefs()
|
||||||
Preference(
|
Preference(
|
||||||
name = def.title,
|
name = setting.title,
|
||||||
onClick = { showDialog = true },
|
onClick = { showDialog = true },
|
||||||
description = prefs.getString(def.key, "")
|
description = prefs.getString(setting.key, "")
|
||||||
)
|
)
|
||||||
if (showDialog) {
|
if (showDialog) {
|
||||||
TextInputDialog(
|
TextInputDialog(
|
||||||
onDismissRequest = { showDialog = false },
|
onDismissRequest = { showDialog = false },
|
||||||
onConfirmed = {
|
onConfirmed = {
|
||||||
prefs.edit().putString(def.key, it).apply()
|
prefs.edit().putString(setting.key, it).apply()
|
||||||
keyboardNeedsReload = true
|
keyboardNeedsReload = true
|
||||||
},
|
},
|
||||||
initialText = prefs.getString(def.key, "") ?: "",
|
initialText = prefs.getString(setting.key, "") ?: "",
|
||||||
title = { Text(def.title) },
|
title = { Text(setting.title) },
|
||||||
checkTextValid = { true }
|
checkTextValid = { true }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
PrefDef(context, NonSettingsPrefs.CUSTOM_FONT, R.string.custom_font) {
|
Setting(context, SettingsWithoutKey.CUSTOM_FONT, R.string.custom_font) {
|
||||||
CustomFontPreference(it)
|
CustomFontPreference(it)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_FONT_SCALE, R.string.prefs_font_scale) { def ->
|
Setting(context, Settings.PREF_FONT_SCALE, R.string.prefs_font_scale) { def ->
|
||||||
SliderPreference(
|
SliderPreference(
|
||||||
name = def.title,
|
name = def.title,
|
||||||
pref = def.key,
|
key = def.key,
|
||||||
default = 1f,
|
default = 1f,
|
||||||
range = 0.5f..1.5f,
|
range = 0.5f..1.5f,
|
||||||
description = { "${(100 * it).toInt()}%" }
|
description = { "${(100 * it).toInt()}%" }
|
||||||
) { keyboardNeedsReload = true }
|
) { keyboardNeedsReload = true }
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_EMOJI_FONT_SCALE, R.string.prefs_emoji_font_scale) { def ->
|
Setting(context, Settings.PREF_EMOJI_FONT_SCALE, R.string.prefs_emoji_font_scale) { setting ->
|
||||||
SliderPreference(
|
SliderPreference(
|
||||||
name = def.title,
|
name = setting.title,
|
||||||
pref = def.key,
|
key = setting.key,
|
||||||
default = 1f,
|
default = 1f,
|
||||||
range = 0.5f..1.5f,
|
range = 0.5f..1.5f,
|
||||||
description = { "${(100 * it).toInt()}%" }
|
description = { "${(100 * it).toInt()}%" }
|
||||||
|
@ -314,7 +314,7 @@ fun createAppearancePrefs(context: Context) = listOf(
|
||||||
@Preview
|
@Preview
|
||||||
@Composable
|
@Composable
|
||||||
private fun Preview() {
|
private fun Preview() {
|
||||||
SettingsActivity2.allPrefs = AllPrefs(LocalContext.current)
|
SettingsActivity.settingsContainer = SettingsContainer(LocalContext.current)
|
||||||
Theme(true) {
|
Theme(true) {
|
||||||
Surface {
|
Surface {
|
||||||
AppearanceScreen { }
|
AppearanceScreen { }
|
||||||
|
|
|
@ -27,7 +27,7 @@ fun ColorsScreen(
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ColorSetting(
|
private class ColorSetting(
|
||||||
val pref: String, // old, this should go away
|
val key: String, // old, this should go away
|
||||||
val displayName: String,
|
val displayName: String,
|
||||||
var auto: Boolean, // not for all
|
var auto: Boolean, // not for all
|
||||||
var color: Int
|
var color: Int
|
||||||
|
|
|
@ -20,11 +20,11 @@ import helium314.keyboard.latin.R
|
||||||
import helium314.keyboard.latin.settings.DebugSettings
|
import helium314.keyboard.latin.settings.DebugSettings
|
||||||
import helium314.keyboard.latin.settings.DebugSettingsFragment
|
import helium314.keyboard.latin.settings.DebugSettingsFragment
|
||||||
import helium314.keyboard.latin.utils.prefs
|
import helium314.keyboard.latin.utils.prefs
|
||||||
import helium314.keyboard.settings.AllPrefs
|
import helium314.keyboard.settings.SettingsContainer
|
||||||
import helium314.keyboard.settings.PrefDef
|
import helium314.keyboard.settings.Setting
|
||||||
import helium314.keyboard.settings.preferences.Preference
|
import helium314.keyboard.settings.preferences.Preference
|
||||||
import helium314.keyboard.settings.SearchPrefScreen
|
import helium314.keyboard.settings.SearchPrefScreen
|
||||||
import helium314.keyboard.settings.SettingsActivity2
|
import helium314.keyboard.settings.SettingsActivity
|
||||||
import helium314.keyboard.settings.preferences.SwitchPreference
|
import helium314.keyboard.settings.preferences.SwitchPreference
|
||||||
import helium314.keyboard.settings.Theme
|
import helium314.keyboard.settings.Theme
|
||||||
import helium314.keyboard.settings.dialogs.ConfirmationDialog
|
import helium314.keyboard.settings.dialogs.ConfirmationDialog
|
||||||
|
@ -49,21 +49,18 @@ fun DebugScreen(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createDebugPrefs(context: Context) = listOf(
|
fun createDebugSettings(context: Context) = listOf(
|
||||||
PrefDef(context, DebugSettings.PREF_SHOW_DEBUG_SETTINGS, R.string.prefs_show_debug_settings) { def ->
|
Setting(context, DebugSettings.PREF_SHOW_DEBUG_SETTINGS, R.string.prefs_show_debug_settings) { setting ->
|
||||||
val prefs = LocalContext.current.prefs()
|
val prefs = LocalContext.current.prefs()
|
||||||
SwitchPreference(
|
SwitchPreference(setting, false)
|
||||||
name = def.title,
|
{ if (!it) prefs.edit().putBoolean(DebugSettings.PREF_DEBUG_MODE, false).apply() }
|
||||||
pref = def.key,
|
|
||||||
default = false,
|
|
||||||
) { if (!it) prefs.edit().putBoolean(DebugSettings.PREF_DEBUG_MODE, false).apply() }
|
|
||||||
},
|
},
|
||||||
PrefDef(context, DebugSettings.PREF_DEBUG_MODE, R.string.prefs_debug_mode) { def ->
|
Setting(context, DebugSettings.PREF_DEBUG_MODE, R.string.prefs_debug_mode) { setting ->
|
||||||
val prefs = LocalContext.current.prefs()
|
val prefs = LocalContext.current.prefs()
|
||||||
var showConfirmDialog by remember { mutableStateOf(false) }
|
var showConfirmDialog by remember { mutableStateOf(false) }
|
||||||
SwitchPreference(
|
SwitchPreference(
|
||||||
name = def.title,
|
name = setting.title,
|
||||||
pref = def.key,
|
key = setting.key,
|
||||||
description = stringResource(R.string.version_text, BuildConfig.VERSION_NAME),
|
description = stringResource(R.string.version_text, BuildConfig.VERSION_NAME),
|
||||||
default = false,
|
default = false,
|
||||||
) {
|
) {
|
||||||
|
@ -78,12 +75,12 @@ fun createDebugPrefs(context: Context) = listOf(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
PrefDef(context, DebugSettings.PREF_SHOW_SUGGESTION_INFOS, R.string.prefs_show_suggestion_infos) { def ->
|
Setting(context, DebugSettings.PREF_SHOW_SUGGESTION_INFOS, R.string.prefs_show_suggestion_infos) {
|
||||||
SwitchPreference(def, false) { keyboardNeedsReload = true }
|
SwitchPreference(it, false) { keyboardNeedsReload = true }
|
||||||
},
|
},
|
||||||
PrefDef(context, DebugSettings.PREF_FORCE_NON_DISTINCT_MULTITOUCH, R.string.prefs_force_non_distinct_multitouch) { def ->
|
Setting(context, DebugSettings.PREF_FORCE_NON_DISTINCT_MULTITOUCH, R.string.prefs_force_non_distinct_multitouch) {
|
||||||
var showConfirmDialog by remember { mutableStateOf(false) }
|
var showConfirmDialog by remember { mutableStateOf(false) }
|
||||||
SwitchPreference(def, false) { showConfirmDialog = true }
|
SwitchPreference(it, false) { showConfirmDialog = true }
|
||||||
if (showConfirmDialog) {
|
if (showConfirmDialog) {
|
||||||
ConfirmationDialog(
|
ConfirmationDialog(
|
||||||
onDismissRequest = { showConfirmDialog = false },
|
onDismissRequest = { showConfirmDialog = false },
|
||||||
|
@ -92,17 +89,17 @@ fun createDebugPrefs(context: Context) = listOf(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
PrefDef(context, DebugSettings.PREF_SLIDING_KEY_INPUT_PREVIEW, R.string.sliding_key_input_preview, R.string.sliding_key_input_preview_summary) { def ->
|
Setting(context, DebugSettings.PREF_SLIDING_KEY_INPUT_PREVIEW, R.string.sliding_key_input_preview, R.string.sliding_key_input_preview_summary) { def ->
|
||||||
SwitchPreference(def, false)
|
SwitchPreference(def, false)
|
||||||
},
|
},
|
||||||
) + DictionaryFacilitator.DYNAMIC_DICTIONARY_TYPES.map {
|
) + DictionaryFacilitator.DYNAMIC_DICTIONARY_TYPES.map { type ->
|
||||||
PrefDef(context, DebugSettingsFragment.PREF_KEY_DUMP_DICT_PREFIX + it, R.string.button_default) { def ->
|
Setting(context, DebugSettingsFragment.PREF_KEY_DUMP_DICT_PREFIX + type, R.string.button_default) {
|
||||||
val ctx = LocalContext.current
|
val ctx = LocalContext.current
|
||||||
Preference(
|
Preference(
|
||||||
name = "Dump $it dictionary",
|
name = "Dump $type dictionary",
|
||||||
onClick = {
|
onClick = {
|
||||||
val intent = Intent(DictionaryDumpBroadcastReceiver.DICTIONARY_DUMP_INTENT_ACTION)
|
val intent = Intent(DictionaryDumpBroadcastReceiver.DICTIONARY_DUMP_INTENT_ACTION)
|
||||||
intent.putExtra(DictionaryDumpBroadcastReceiver.DICTIONARY_NAME_KEY, it)
|
intent.putExtra(DictionaryDumpBroadcastReceiver.DICTIONARY_NAME_KEY, type)
|
||||||
ctx.sendBroadcast(intent)
|
ctx.sendBroadcast(intent)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -112,7 +109,7 @@ fun createDebugPrefs(context: Context) = listOf(
|
||||||
@Preview
|
@Preview
|
||||||
@Composable
|
@Composable
|
||||||
private fun Preview() {
|
private fun Preview() {
|
||||||
SettingsActivity2.allPrefs = AllPrefs(LocalContext.current)
|
SettingsActivity.settingsContainer = SettingsContainer(LocalContext.current)
|
||||||
Theme(true) {
|
Theme(true) {
|
||||||
Surface {
|
Surface {
|
||||||
DebugScreen { }
|
DebugScreen { }
|
||||||
|
|
|
@ -13,10 +13,10 @@ import helium314.keyboard.latin.settings.Settings
|
||||||
import helium314.keyboard.latin.utils.Log
|
import helium314.keyboard.latin.utils.Log
|
||||||
import helium314.keyboard.latin.utils.getActivity
|
import helium314.keyboard.latin.utils.getActivity
|
||||||
import helium314.keyboard.latin.utils.prefs
|
import helium314.keyboard.latin.utils.prefs
|
||||||
import helium314.keyboard.settings.AllPrefs
|
import helium314.keyboard.settings.SettingsContainer
|
||||||
import helium314.keyboard.settings.PrefDef
|
import helium314.keyboard.settings.Setting
|
||||||
import helium314.keyboard.settings.SearchPrefScreen
|
import helium314.keyboard.settings.SearchPrefScreen
|
||||||
import helium314.keyboard.settings.SettingsActivity2
|
import helium314.keyboard.settings.SettingsActivity
|
||||||
import helium314.keyboard.settings.preferences.SliderPreference
|
import helium314.keyboard.settings.preferences.SliderPreference
|
||||||
import helium314.keyboard.settings.preferences.SwitchPreference
|
import helium314.keyboard.settings.preferences.SwitchPreference
|
||||||
import helium314.keyboard.settings.Theme
|
import helium314.keyboard.settings.Theme
|
||||||
|
@ -27,7 +27,7 @@ fun GestureTypingScreen(
|
||||||
onClickBack: () -> Unit,
|
onClickBack: () -> Unit,
|
||||||
) {
|
) {
|
||||||
val prefs = LocalContext.current.prefs()
|
val prefs = LocalContext.current.prefs()
|
||||||
val b = (LocalContext.current.getActivity() as? SettingsActivity2)?.prefChanged?.collectAsState()
|
val b = (LocalContext.current.getActivity() as? SettingsActivity)?.prefChanged?.collectAsState()
|
||||||
if ((b?.value ?: 0) < 0)
|
if ((b?.value ?: 0) < 0)
|
||||||
Log.v("irrelevant", "stupid way to trigger recomposition on preference change")
|
Log.v("irrelevant", "stupid way to trigger recomposition on preference change")
|
||||||
val gestureFloatingPreviewEnabled = prefs.getBoolean(Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT, true)
|
val gestureFloatingPreviewEnabled = prefs.getBoolean(Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT, true)
|
||||||
|
@ -51,19 +51,19 @@ fun GestureTypingScreen(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createGestureTypingPrefs(context: Context) = listOf(
|
fun createGestureTypingSettings(context: Context) = listOf(
|
||||||
PrefDef(context, Settings.PREF_GESTURE_INPUT, R.string.gesture_input, R.string.gesture_input_summary) {
|
Setting(context, Settings.PREF_GESTURE_INPUT, R.string.gesture_input, R.string.gesture_input_summary) {
|
||||||
SwitchPreference(it, true)
|
SwitchPreference(it, true)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_GESTURE_PREVIEW_TRAIL, R.string.gesture_preview_trail) {
|
Setting(context, Settings.PREF_GESTURE_PREVIEW_TRAIL, R.string.gesture_preview_trail) {
|
||||||
SwitchPreference(it, true)
|
SwitchPreference(it, true)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT,
|
Setting(context, Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT,
|
||||||
R.string.gesture_floating_preview_static, R.string.gesture_floating_preview_static_summary)
|
R.string.gesture_floating_preview_static, R.string.gesture_floating_preview_static_summary)
|
||||||
{
|
{
|
||||||
SwitchPreference(it, true)
|
SwitchPreference(it, true)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_GESTURE_FLOATING_PREVIEW_DYNAMIC,
|
Setting(context, Settings.PREF_GESTURE_FLOATING_PREVIEW_DYNAMIC,
|
||||||
R.string.gesture_floating_preview_text, R.string.gesture_floating_preview_dynamic_summary)
|
R.string.gesture_floating_preview_text, R.string.gesture_floating_preview_dynamic_summary)
|
||||||
{ def ->
|
{ def ->
|
||||||
val ctx = LocalContext.current
|
val ctx = LocalContext.current
|
||||||
|
@ -77,13 +77,13 @@ fun createGestureTypingPrefs(context: Context) = listOf(
|
||||||
keyboardNeedsReload = true
|
keyboardNeedsReload = true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_GESTURE_SPACE_AWARE, R.string.gesture_space_aware, R.string.gesture_space_aware_summary) {
|
Setting(context, Settings.PREF_GESTURE_SPACE_AWARE, R.string.gesture_space_aware, R.string.gesture_space_aware_summary) {
|
||||||
SwitchPreference(it, false)
|
SwitchPreference(it, false)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_GESTURE_FAST_TYPING_COOLDOWN, R.string.gesture_fast_typing_cooldown) { def ->
|
Setting(context, Settings.PREF_GESTURE_FAST_TYPING_COOLDOWN, R.string.gesture_fast_typing_cooldown) { def ->
|
||||||
SliderPreference(
|
SliderPreference(
|
||||||
name = def.title,
|
name = def.title,
|
||||||
pref = def.key,
|
key = def.key,
|
||||||
default = 500,
|
default = 500,
|
||||||
range = 0f..500f,
|
range = 0f..500f,
|
||||||
description = {
|
description = {
|
||||||
|
@ -92,10 +92,10 @@ fun createGestureTypingPrefs(context: Context) = listOf(
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_GESTURE_TRAIL_FADEOUT_DURATION, R.string.gesture_trail_fadeout_duration) { def ->
|
Setting(context, Settings.PREF_GESTURE_TRAIL_FADEOUT_DURATION, R.string.gesture_trail_fadeout_duration) { def ->
|
||||||
SliderPreference(
|
SliderPreference(
|
||||||
name = def.title,
|
name = def.title,
|
||||||
pref = def.key,
|
key = def.key,
|
||||||
default = 800,
|
default = 800,
|
||||||
range = 100f..1900f,
|
range = 100f..1900f,
|
||||||
description = { stringResource(R.string.abbreviation_unit_milliseconds, (it + 100).toString()) },
|
description = { stringResource(R.string.abbreviation_unit_milliseconds, (it + 100).toString()) },
|
||||||
|
@ -107,7 +107,7 @@ fun createGestureTypingPrefs(context: Context) = listOf(
|
||||||
@Preview
|
@Preview
|
||||||
@Composable
|
@Composable
|
||||||
private fun Preview() {
|
private fun Preview() {
|
||||||
SettingsActivity2.allPrefs = AllPrefs(LocalContext.current)
|
SettingsActivity.settingsContainer = SettingsContainer(LocalContext.current)
|
||||||
Theme(true) {
|
Theme(true) {
|
||||||
Surface {
|
Surface {
|
||||||
GestureTypingScreen { }
|
GestureTypingScreen { }
|
||||||
|
|
|
@ -22,12 +22,12 @@ import helium314.keyboard.latin.utils.getActivity
|
||||||
import helium314.keyboard.latin.utils.getEnabledSubtypes
|
import helium314.keyboard.latin.utils.getEnabledSubtypes
|
||||||
import helium314.keyboard.latin.utils.locale
|
import helium314.keyboard.latin.utils.locale
|
||||||
import helium314.keyboard.latin.utils.prefs
|
import helium314.keyboard.latin.utils.prefs
|
||||||
import helium314.keyboard.settings.AllPrefs
|
import helium314.keyboard.settings.SettingsContainer
|
||||||
import helium314.keyboard.settings.preferences.ListPreference
|
import helium314.keyboard.settings.preferences.ListPreference
|
||||||
import helium314.keyboard.settings.PrefDef
|
import helium314.keyboard.settings.Setting
|
||||||
import helium314.keyboard.settings.preferences.ReorderSwitchPreference
|
import helium314.keyboard.settings.preferences.ReorderSwitchPreference
|
||||||
import helium314.keyboard.settings.SearchPrefScreen
|
import helium314.keyboard.settings.SearchPrefScreen
|
||||||
import helium314.keyboard.settings.SettingsActivity2
|
import helium314.keyboard.settings.SettingsActivity
|
||||||
import helium314.keyboard.settings.preferences.SliderPreference
|
import helium314.keyboard.settings.preferences.SliderPreference
|
||||||
import helium314.keyboard.settings.preferences.SwitchPreference
|
import helium314.keyboard.settings.preferences.SwitchPreference
|
||||||
import helium314.keyboard.settings.Theme
|
import helium314.keyboard.settings.Theme
|
||||||
|
@ -38,7 +38,7 @@ fun PreferencesScreen(
|
||||||
onClickBack: () -> Unit,
|
onClickBack: () -> Unit,
|
||||||
) {
|
) {
|
||||||
val prefs = LocalContext.current.prefs()
|
val prefs = LocalContext.current.prefs()
|
||||||
val b = (LocalContext.current.getActivity() as? SettingsActivity2)?.prefChanged?.collectAsState()
|
val b = (LocalContext.current.getActivity() as? SettingsActivity)?.prefChanged?.collectAsState()
|
||||||
if ((b?.value ?: 0) < 0)
|
if ((b?.value ?: 0) < 0)
|
||||||
Log.v("irrelevant", "stupid way to trigger recomposition on preference change")
|
Log.v("irrelevant", "stupid way to trigger recomposition on preference change")
|
||||||
val items = listOfNotNull(
|
val items = listOfNotNull(
|
||||||
|
@ -79,51 +79,51 @@ fun PreferencesScreen(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createPreferencesPrefs(context: Context) = listOf(
|
fun createPreferencesSettings(context: Context) = listOf(
|
||||||
PrefDef(context, Settings.PREF_SHOW_HINTS, R.string.show_hints, R.string.show_hints_summary) {
|
Setting(context, Settings.PREF_SHOW_HINTS, R.string.show_hints, R.string.show_hints_summary) {
|
||||||
SwitchPreference(it, true)
|
SwitchPreference(it, true)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_POPUP_KEYS_LABELS_ORDER, R.string.hint_source) {
|
Setting(context, Settings.PREF_POPUP_KEYS_LABELS_ORDER, R.string.hint_source) {
|
||||||
ReorderSwitchPreference(it, POPUP_KEYS_LABEL_DEFAULT)
|
ReorderSwitchPreference(it, POPUP_KEYS_LABEL_DEFAULT)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_POPUP_KEYS_ORDER, R.string.popup_order) {
|
Setting(context, Settings.PREF_POPUP_KEYS_ORDER, R.string.popup_order) {
|
||||||
ReorderSwitchPreference(it, POPUP_KEYS_ORDER_DEFAULT)
|
ReorderSwitchPreference(it, POPUP_KEYS_ORDER_DEFAULT)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_SHOW_POPUP_HINTS, R.string.show_popup_hints, R.string.show_popup_hints_summary) {
|
Setting(context, Settings.PREF_SHOW_POPUP_HINTS, R.string.show_popup_hints, R.string.show_popup_hints_summary) {
|
||||||
SwitchPreference(it, false) { keyboardNeedsReload = true }
|
SwitchPreference(it, false) { keyboardNeedsReload = true }
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_POPUP_ON, R.string.popup_on_keypress) {
|
Setting(context, Settings.PREF_POPUP_ON, R.string.popup_on_keypress) {
|
||||||
val dm = LocalContext.current.resources.displayMetrics
|
val dm = LocalContext.current.resources.displayMetrics
|
||||||
val px600 = with(LocalDensity.current) { 600.dp.toPx() }
|
val px600 = with(LocalDensity.current) { 600.dp.toPx() }
|
||||||
SwitchPreference(it, dm.widthPixels >= px600 || dm.heightPixels >= px600)
|
SwitchPreference(it, dm.widthPixels >= px600 || dm.heightPixels >= px600)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_VIBRATE_ON, R.string.vibrate_on_keypress) {
|
Setting(context, Settings.PREF_VIBRATE_ON, R.string.vibrate_on_keypress) {
|
||||||
SwitchPreference(it, false)
|
SwitchPreference(it, false)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_VIBRATE_IN_DND_MODE, R.string.vibrate_in_dnd_mode) {
|
Setting(context, Settings.PREF_VIBRATE_IN_DND_MODE, R.string.vibrate_in_dnd_mode) {
|
||||||
SwitchPreference(it, false)
|
SwitchPreference(it, false)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_SOUND_ON, R.string.sound_on_keypress) {
|
Setting(context, Settings.PREF_SOUND_ON, R.string.sound_on_keypress) {
|
||||||
SwitchPreference(it, false)
|
SwitchPreference(it, false)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_ENABLE_CLIPBOARD_HISTORY,
|
Setting(context, Settings.PREF_ENABLE_CLIPBOARD_HISTORY,
|
||||||
R.string.enable_clipboard_history, R.string.enable_clipboard_history_summary)
|
R.string.enable_clipboard_history, R.string.enable_clipboard_history_summary)
|
||||||
{
|
{
|
||||||
SwitchPreference(it, true)
|
SwitchPreference(it, true)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_SHOW_NUMBER_ROW, R.string.number_row, R.string.number_row_summary) {
|
Setting(context, Settings.PREF_SHOW_NUMBER_ROW, R.string.number_row, R.string.number_row_summary) {
|
||||||
SwitchPreference(it, false) { keyboardNeedsReload = true }
|
SwitchPreference(it, false) { keyboardNeedsReload = true }
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_LOCALIZED_NUMBER_ROW, R.string.localized_number_row, R.string.localized_number_row_summary) {
|
Setting(context, Settings.PREF_LOCALIZED_NUMBER_ROW, R.string.localized_number_row, R.string.localized_number_row_summary) {
|
||||||
SwitchPreference(it, true) { KeyboardLayoutSet.onSystemLocaleChanged() }
|
SwitchPreference(it, true) { KeyboardLayoutSet.onSystemLocaleChanged() }
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_SHOW_NUMBER_ROW_HINTS, R.string.number_row_hints) {
|
Setting(context, Settings.PREF_SHOW_NUMBER_ROW_HINTS, R.string.number_row_hints) {
|
||||||
SwitchPreference(it, false) { keyboardNeedsReload = true }
|
SwitchPreference(it, false) { keyboardNeedsReload = true }
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_SHOW_LANGUAGE_SWITCH_KEY, R.string.show_language_switch_key) {
|
Setting(context, Settings.PREF_SHOW_LANGUAGE_SWITCH_KEY, R.string.show_language_switch_key) {
|
||||||
SwitchPreference(it, false) { keyboardNeedsReload = true }
|
SwitchPreference(it, false) { keyboardNeedsReload = true }
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_LANGUAGE_SWITCH_KEY, R.string.language_switch_key_behavior) {
|
Setting(context, Settings.PREF_LANGUAGE_SWITCH_KEY, R.string.language_switch_key_behavior) {
|
||||||
ListPreference(
|
ListPreference(
|
||||||
it,
|
it,
|
||||||
listOf(
|
listOf(
|
||||||
|
@ -134,18 +134,18 @@ fun createPreferencesPrefs(context: Context) = listOf(
|
||||||
"internal"
|
"internal"
|
||||||
) { keyboardNeedsReload = true }
|
) { keyboardNeedsReload = true }
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_SHOW_EMOJI_KEY, R.string.show_emoji_key) {
|
Setting(context, Settings.PREF_SHOW_EMOJI_KEY, R.string.show_emoji_key) {
|
||||||
SwitchPreference(it, false)
|
SwitchPreference(it, false)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_REMOVE_REDUNDANT_POPUPS,
|
Setting(context, Settings.PREF_REMOVE_REDUNDANT_POPUPS,
|
||||||
R.string.remove_redundant_popups, R.string.remove_redundant_popups_summary)
|
R.string.remove_redundant_popups, R.string.remove_redundant_popups_summary)
|
||||||
{
|
{
|
||||||
SwitchPreference(it, false) { keyboardNeedsReload = true }
|
SwitchPreference(it, false) { keyboardNeedsReload = true }
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_CLIPBOARD_HISTORY_RETENTION_TIME, R.string.clipboard_history_retention_time) { def ->
|
Setting(context, Settings.PREF_CLIPBOARD_HISTORY_RETENTION_TIME, R.string.clipboard_history_retention_time) { setting ->
|
||||||
SliderPreference(
|
SliderPreference(
|
||||||
name = def.title,
|
name = setting.title,
|
||||||
pref = def.key,
|
key = setting.key,
|
||||||
default = 10,
|
default = 10,
|
||||||
description = {
|
description = {
|
||||||
if (it < 0) stringResource(R.string.settings_no_limit)
|
if (it < 0) stringResource(R.string.settings_no_limit)
|
||||||
|
@ -154,10 +154,10 @@ fun createPreferencesPrefs(context: Context) = listOf(
|
||||||
range = -1f..120f,
|
range = -1f..120f,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_VIBRATION_DURATION_SETTINGS, R.string.prefs_keypress_vibration_duration_settings) { def ->
|
Setting(context, Settings.PREF_VIBRATION_DURATION_SETTINGS, R.string.prefs_keypress_vibration_duration_settings) { setting ->
|
||||||
SliderPreference(
|
SliderPreference(
|
||||||
name = def.title,
|
name = setting.title,
|
||||||
pref = def.key,
|
key = setting.key,
|
||||||
default = -1,
|
default = -1,
|
||||||
description = {
|
description = {
|
||||||
if (it < 0) stringResource(R.string.settings_system_default)
|
if (it < 0) stringResource(R.string.settings_system_default)
|
||||||
|
@ -167,11 +167,11 @@ fun createPreferencesPrefs(context: Context) = listOf(
|
||||||
onValueChanged = { AudioAndHapticFeedbackManager.getInstance().vibrate(it.toLong()) }
|
onValueChanged = { AudioAndHapticFeedbackManager.getInstance().vibrate(it.toLong()) }
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_KEYPRESS_SOUND_VOLUME, R.string.prefs_keypress_sound_volume_settings) { def ->
|
Setting(context, Settings.PREF_KEYPRESS_SOUND_VOLUME, R.string.prefs_keypress_sound_volume_settings) { setting ->
|
||||||
val audioManager = LocalContext.current.getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
val audioManager = LocalContext.current.getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
||||||
SliderPreference(
|
SliderPreference(
|
||||||
name = def.title,
|
name = setting.title,
|
||||||
pref = def.key,
|
key = setting.key,
|
||||||
default = -0.01f,
|
default = -0.01f,
|
||||||
description = {
|
description = {
|
||||||
if (it < 0) stringResource(R.string.settings_system_default)
|
if (it < 0) stringResource(R.string.settings_system_default)
|
||||||
|
@ -189,7 +189,7 @@ private val localesWithLocalizedNumberRow = listOf("ar", "bn", "fa", "gu", "hi",
|
||||||
@Preview
|
@Preview
|
||||||
@Composable
|
@Composable
|
||||||
private fun Preview() {
|
private fun Preview() {
|
||||||
SettingsActivity2.allPrefs = AllPrefs(LocalContext.current)
|
SettingsActivity.settingsContainer = SettingsContainer(LocalContext.current)
|
||||||
Theme(true) {
|
Theme(true) {
|
||||||
Surface {
|
Surface {
|
||||||
PreferencesScreen { }
|
PreferencesScreen { }
|
||||||
|
|
|
@ -28,13 +28,13 @@ import helium314.keyboard.latin.utils.Log
|
||||||
import helium314.keyboard.latin.utils.getActivity
|
import helium314.keyboard.latin.utils.getActivity
|
||||||
import helium314.keyboard.latin.utils.prefs
|
import helium314.keyboard.latin.utils.prefs
|
||||||
import helium314.keyboard.latin.utils.switchTo
|
import helium314.keyboard.latin.utils.switchTo
|
||||||
import helium314.keyboard.settings.AllPrefs
|
import helium314.keyboard.settings.SettingsContainer
|
||||||
import helium314.keyboard.settings.preferences.ListPreference
|
import helium314.keyboard.settings.preferences.ListPreference
|
||||||
import helium314.keyboard.settings.NonSettingsPrefs
|
import helium314.keyboard.settings.SettingsWithoutKey
|
||||||
import helium314.keyboard.settings.PrefDef
|
import helium314.keyboard.settings.Setting
|
||||||
import helium314.keyboard.settings.preferences.Preference
|
import helium314.keyboard.settings.preferences.Preference
|
||||||
import helium314.keyboard.settings.SearchPrefScreen
|
import helium314.keyboard.settings.SearchPrefScreen
|
||||||
import helium314.keyboard.settings.SettingsActivity2
|
import helium314.keyboard.settings.SettingsActivity
|
||||||
import helium314.keyboard.settings.preferences.SwitchPreference
|
import helium314.keyboard.settings.preferences.SwitchPreference
|
||||||
import helium314.keyboard.settings.Theme
|
import helium314.keyboard.settings.Theme
|
||||||
import helium314.keyboard.settings.dialogs.ConfirmationDialog
|
import helium314.keyboard.settings.dialogs.ConfirmationDialog
|
||||||
|
@ -45,13 +45,13 @@ fun TextCorrectionScreen(
|
||||||
onClickBack: () -> Unit,
|
onClickBack: () -> Unit,
|
||||||
) {
|
) {
|
||||||
val prefs = LocalContext.current.prefs()
|
val prefs = LocalContext.current.prefs()
|
||||||
val b = (LocalContext.current.getActivity() as? SettingsActivity2)?.prefChanged?.collectAsState()
|
val b = (LocalContext.current.getActivity() as? SettingsActivity)?.prefChanged?.collectAsState()
|
||||||
if ((b?.value ?: 0) < 0)
|
if ((b?.value ?: 0) < 0)
|
||||||
Log.v("irrelevant", "stupid way to trigger recomposition on preference change")
|
Log.v("irrelevant", "stupid way to trigger recomposition on preference change")
|
||||||
val autocorrectEnabled = prefs.getBoolean(Settings.PREF_AUTO_CORRECTION, true)
|
val autocorrectEnabled = prefs.getBoolean(Settings.PREF_AUTO_CORRECTION, true)
|
||||||
val suggestionsEnabled = prefs.getBoolean(Settings.PREF_SHOW_SUGGESTIONS, true)
|
val suggestionsEnabled = prefs.getBoolean(Settings.PREF_SHOW_SUGGESTIONS, true)
|
||||||
val items = listOfNotNull(
|
val items = listOfNotNull(
|
||||||
NonSettingsPrefs.EDIT_PERSONAL_DICTIONARY,
|
SettingsWithoutKey.EDIT_PERSONAL_DICTIONARY,
|
||||||
R.string.settings_category_correction,
|
R.string.settings_category_correction,
|
||||||
Settings.PREF_BLOCK_POTENTIALLY_OFFENSIVE,
|
Settings.PREF_BLOCK_POTENTIALLY_OFFENSIVE,
|
||||||
Settings.PREF_AUTO_CORRECTION,
|
Settings.PREF_AUTO_CORRECTION,
|
||||||
|
@ -79,8 +79,8 @@ fun TextCorrectionScreen(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createCorrectionPrefs(context: Context) = listOf(
|
fun createCorrectionSettings(context: Context) = listOf(
|
||||||
PrefDef(context, NonSettingsPrefs.EDIT_PERSONAL_DICTIONARY, R.string.edit_personal_dictionary) {
|
Setting(context, SettingsWithoutKey.EDIT_PERSONAL_DICTIONARY, R.string.edit_personal_dictionary) {
|
||||||
val ctx = LocalContext.current
|
val ctx = LocalContext.current
|
||||||
Preference(
|
Preference(
|
||||||
name = stringResource(R.string.edit_personal_dictionary),
|
name = stringResource(R.string.edit_personal_dictionary),
|
||||||
|
@ -93,27 +93,27 @@ fun createCorrectionPrefs(context: Context) = listOf(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_BLOCK_POTENTIALLY_OFFENSIVE,
|
Setting(context, Settings.PREF_BLOCK_POTENTIALLY_OFFENSIVE,
|
||||||
R.string.prefs_block_potentially_offensive_title, R.string.prefs_block_potentially_offensive_summary
|
R.string.prefs_block_potentially_offensive_title, R.string.prefs_block_potentially_offensive_summary
|
||||||
) {
|
) {
|
||||||
SwitchPreference(it, true)
|
SwitchPreference(it, true)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_AUTO_CORRECTION,
|
Setting(context, Settings.PREF_AUTO_CORRECTION,
|
||||||
R.string.autocorrect, R.string.auto_correction_summary
|
R.string.autocorrect, R.string.auto_correction_summary
|
||||||
) {
|
) {
|
||||||
SwitchPreference(it, true)
|
SwitchPreference(it, true)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_MORE_AUTO_CORRECTION,
|
Setting(context, Settings.PREF_MORE_AUTO_CORRECTION,
|
||||||
R.string.more_autocorrect, R.string.more_autocorrect_summary
|
R.string.more_autocorrect, R.string.more_autocorrect_summary
|
||||||
) {
|
) {
|
||||||
SwitchPreference(it, true) // todo (later): shouldn't it better be false?
|
SwitchPreference(it, true) // todo (later): shouldn't it better be false?
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_AUTOCORRECT_SHORTCUTS,
|
Setting(context, Settings.PREF_AUTOCORRECT_SHORTCUTS,
|
||||||
R.string.auto_correct_shortcuts, R.string.auto_correct_shortcuts_summary
|
R.string.auto_correct_shortcuts, R.string.auto_correct_shortcuts_summary
|
||||||
) {
|
) {
|
||||||
SwitchPreference(it, true)
|
SwitchPreference(it, true)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_AUTO_CORRECTION_CONFIDENCE, R.string.auto_correction_confidence) {
|
Setting(context, Settings.PREF_AUTO_CORRECTION_CONFIDENCE, R.string.auto_correction_confidence) {
|
||||||
val items = listOf(
|
val items = listOf(
|
||||||
stringResource(R.string.auto_correction_threshold_mode_modest) to "0",
|
stringResource(R.string.auto_correction_threshold_mode_modest) to "0",
|
||||||
stringResource(R.string.auto_correction_threshold_mode_aggressive) to "1",
|
stringResource(R.string.auto_correction_threshold_mode_aggressive) to "1",
|
||||||
|
@ -121,38 +121,36 @@ fun createCorrectionPrefs(context: Context) = listOf(
|
||||||
)
|
)
|
||||||
ListPreference(it, items, "0")
|
ListPreference(it, items, "0")
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_AUTO_CAP,
|
Setting(context, Settings.PREF_AUTO_CAP,
|
||||||
R.string.auto_cap, R.string.auto_cap_summary
|
R.string.auto_cap, R.string.auto_cap_summary
|
||||||
) {
|
) {
|
||||||
SwitchPreference(it, true)
|
SwitchPreference(it, true)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD,
|
Setting(context, Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD,
|
||||||
R.string.use_double_space_period, R.string.use_double_space_period_summary
|
R.string.use_double_space_period, R.string.use_double_space_period_summary
|
||||||
) {
|
) {
|
||||||
SwitchPreference(it, true)
|
SwitchPreference(it, true)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_AUTOSPACE_AFTER_PUNCTUATION,
|
Setting(context, Settings.PREF_AUTOSPACE_AFTER_PUNCTUATION,
|
||||||
R.string.autospace_after_punctuation, R.string.autospace_after_punctuation_summary
|
R.string.autospace_after_punctuation, R.string.autospace_after_punctuation_summary
|
||||||
) {
|
) {
|
||||||
SwitchPreference(it, false)
|
SwitchPreference(it, false)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_SHOW_SUGGESTIONS,
|
Setting(context, Settings.PREF_SHOW_SUGGESTIONS,
|
||||||
R.string.prefs_show_suggestions, R.string.prefs_show_suggestions_summary
|
R.string.prefs_show_suggestions, R.string.prefs_show_suggestions_summary
|
||||||
) {
|
) {
|
||||||
SwitchPreference(it, true)
|
SwitchPreference(it, true)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_ALWAYS_SHOW_SUGGESTIONS,
|
Setting(context, Settings.PREF_ALWAYS_SHOW_SUGGESTIONS,
|
||||||
R.string.prefs_always_show_suggestions, R.string.prefs_always_show_suggestions_summary
|
R.string.prefs_always_show_suggestions, R.string.prefs_always_show_suggestions_summary
|
||||||
) {
|
) {
|
||||||
SwitchPreference(it, false)
|
SwitchPreference(it, false)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_KEY_USE_PERSONALIZED_DICTS,
|
Setting(context, Settings.PREF_KEY_USE_PERSONALIZED_DICTS,
|
||||||
R.string.use_personalized_dicts, R.string.use_personalized_dicts_summary
|
R.string.use_personalized_dicts, R.string.use_personalized_dicts_summary
|
||||||
) { prefDef ->
|
) { setting ->
|
||||||
var showConfirmDialog by remember { mutableStateOf(false) }
|
var showConfirmDialog by remember { mutableStateOf(false) }
|
||||||
SwitchPreference(
|
SwitchPreference(setting, true,
|
||||||
prefDef,
|
|
||||||
true,
|
|
||||||
allowCheckedChange = {
|
allowCheckedChange = {
|
||||||
showConfirmDialog = !it
|
showConfirmDialog = !it
|
||||||
it
|
it
|
||||||
|
@ -163,41 +161,39 @@ fun createCorrectionPrefs(context: Context) = listOf(
|
||||||
ConfirmationDialog(
|
ConfirmationDialog(
|
||||||
onDismissRequest = { showConfirmDialog = false },
|
onDismissRequest = { showConfirmDialog = false },
|
||||||
onConfirmed = {
|
onConfirmed = {
|
||||||
prefs.edit().putBoolean(prefDef.key, false).apply()
|
prefs.edit().putBoolean(setting.key, false).apply()
|
||||||
},
|
},
|
||||||
text = { Text(stringResource(R.string.disable_personalized_dicts_message)) }
|
text = { Text(stringResource(R.string.disable_personalized_dicts_message)) }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_BIGRAM_PREDICTIONS,
|
Setting(context, Settings.PREF_BIGRAM_PREDICTIONS,
|
||||||
R.string.bigram_prediction, R.string.bigram_prediction_summary
|
R.string.bigram_prediction, R.string.bigram_prediction_summary
|
||||||
) {
|
) {
|
||||||
SwitchPreference(it, true) { keyboardNeedsReload = true }
|
SwitchPreference(it, true) { keyboardNeedsReload = true }
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_CENTER_SUGGESTION_TEXT_TO_ENTER,
|
Setting(context, Settings.PREF_CENTER_SUGGESTION_TEXT_TO_ENTER,
|
||||||
R.string.center_suggestion_text_to_enter, R.string.center_suggestion_text_to_enter_summary
|
R.string.center_suggestion_text_to_enter, R.string.center_suggestion_text_to_enter_summary
|
||||||
) {
|
) {
|
||||||
SwitchPreference(it, false)
|
SwitchPreference(it, false)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_SUGGEST_CLIPBOARD_CONTENT,
|
Setting(context, Settings.PREF_SUGGEST_CLIPBOARD_CONTENT,
|
||||||
R.string.suggest_clipboard_content, R.string.suggest_clipboard_content_summary
|
R.string.suggest_clipboard_content, R.string.suggest_clipboard_content_summary
|
||||||
) {
|
) {
|
||||||
SwitchPreference(it, true)
|
SwitchPreference(it, true)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_USE_CONTACTS,
|
Setting(context, Settings.PREF_USE_CONTACTS,
|
||||||
R.string.use_contacts_dict, R.string.use_contacts_dict_summary
|
R.string.use_contacts_dict, R.string.use_contacts_dict_summary
|
||||||
) { def ->
|
) { setting ->
|
||||||
val activity = LocalContext.current.getActivity() ?: return@PrefDef
|
val activity = LocalContext.current.getActivity() ?: return@Setting
|
||||||
var granted by remember { mutableStateOf(PermissionsUtil.checkAllPermissionsGranted(activity, Manifest.permission.READ_CONTACTS)) }
|
var granted by remember { mutableStateOf(PermissionsUtil.checkAllPermissionsGranted(activity, Manifest.permission.READ_CONTACTS)) }
|
||||||
val launcher = rememberLauncherForActivityResult(ActivityResultContracts.RequestPermission()) {
|
val launcher = rememberLauncherForActivityResult(ActivityResultContracts.RequestPermission()) {
|
||||||
granted = it
|
granted = it
|
||||||
if (granted)
|
if (granted)
|
||||||
activity.prefs().edit().putBoolean(def.key, true).apply()
|
activity.prefs().edit().putBoolean(setting.key, true).apply()
|
||||||
}
|
}
|
||||||
SwitchPreference(
|
SwitchPreference(setting, false,
|
||||||
def,
|
|
||||||
false,
|
|
||||||
allowCheckedChange = {
|
allowCheckedChange = {
|
||||||
if (it && !granted) {
|
if (it && !granted) {
|
||||||
launcher.launch(Manifest.permission.READ_CONTACTS)
|
launcher.launch(Manifest.permission.READ_CONTACTS)
|
||||||
|
@ -206,7 +202,7 @@ fun createCorrectionPrefs(context: Context) = listOf(
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_ADD_TO_PERSONAL_DICTIONARY,
|
Setting(context, Settings.PREF_ADD_TO_PERSONAL_DICTIONARY,
|
||||||
R.string.add_to_personal_dictionary, R.string.add_to_personal_dictionary_summary
|
R.string.add_to_personal_dictionary, R.string.add_to_personal_dictionary_summary
|
||||||
) {
|
) {
|
||||||
SwitchPreference(it, false)
|
SwitchPreference(it, false)
|
||||||
|
@ -216,7 +212,7 @@ fun createCorrectionPrefs(context: Context) = listOf(
|
||||||
@Preview
|
@Preview
|
||||||
@Composable
|
@Composable
|
||||||
private fun PreferencePreview() {
|
private fun PreferencePreview() {
|
||||||
SettingsActivity2.allPrefs = AllPrefs(LocalContext.current)
|
SettingsActivity.settingsContainer = SettingsContainer(LocalContext.current)
|
||||||
Theme(true) {
|
Theme(true) {
|
||||||
Surface {
|
Surface {
|
||||||
TextCorrectionScreen { }
|
TextCorrectionScreen { }
|
||||||
|
|
|
@ -29,13 +29,13 @@ import helium314.keyboard.latin.settings.Settings
|
||||||
import helium314.keyboard.latin.utils.defaultClipboardToolbarPref
|
import helium314.keyboard.latin.utils.defaultClipboardToolbarPref
|
||||||
import helium314.keyboard.latin.utils.defaultPinnedToolbarPref
|
import helium314.keyboard.latin.utils.defaultPinnedToolbarPref
|
||||||
import helium314.keyboard.latin.utils.defaultToolbarPref
|
import helium314.keyboard.latin.utils.defaultToolbarPref
|
||||||
import helium314.keyboard.settings.AllPrefs
|
import helium314.keyboard.settings.SettingsContainer
|
||||||
import helium314.keyboard.settings.NonSettingsPrefs
|
import helium314.keyboard.settings.SettingsWithoutKey
|
||||||
import helium314.keyboard.settings.PrefDef
|
import helium314.keyboard.settings.Setting
|
||||||
import helium314.keyboard.settings.preferences.Preference
|
import helium314.keyboard.settings.preferences.Preference
|
||||||
import helium314.keyboard.settings.preferences.ReorderSwitchPreference
|
import helium314.keyboard.settings.preferences.ReorderSwitchPreference
|
||||||
import helium314.keyboard.settings.SearchPrefScreen
|
import helium314.keyboard.settings.SearchPrefScreen
|
||||||
import helium314.keyboard.settings.SettingsActivity2
|
import helium314.keyboard.settings.SettingsActivity
|
||||||
import helium314.keyboard.settings.preferences.SwitchPreference
|
import helium314.keyboard.settings.preferences.SwitchPreference
|
||||||
import helium314.keyboard.settings.Theme
|
import helium314.keyboard.settings.Theme
|
||||||
import helium314.keyboard.settings.dialogs.ToolbarKeysCustomizer
|
import helium314.keyboard.settings.dialogs.ToolbarKeysCustomizer
|
||||||
|
@ -49,7 +49,7 @@ fun ToolbarScreen(
|
||||||
Settings.PREF_TOOLBAR_KEYS,
|
Settings.PREF_TOOLBAR_KEYS,
|
||||||
Settings.PREF_PINNED_TOOLBAR_KEYS,
|
Settings.PREF_PINNED_TOOLBAR_KEYS,
|
||||||
Settings.PREF_CLIPBOARD_TOOLBAR_KEYS,
|
Settings.PREF_CLIPBOARD_TOOLBAR_KEYS,
|
||||||
NonSettingsPrefs.CUSTOM_KEY_CODES,
|
SettingsWithoutKey.CUSTOM_KEY_CODES,
|
||||||
Settings.PREF_QUICK_PIN_TOOLBAR_KEYS,
|
Settings.PREF_QUICK_PIN_TOOLBAR_KEYS,
|
||||||
Settings.PREF_AUTO_SHOW_TOOLBAR,
|
Settings.PREF_AUTO_SHOW_TOOLBAR,
|
||||||
Settings.PREF_AUTO_HIDE_TOOLBAR,
|
Settings.PREF_AUTO_HIDE_TOOLBAR,
|
||||||
|
@ -62,17 +62,17 @@ fun ToolbarScreen(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createToolbarPrefs(context: Context) = listOf(
|
fun createToolbarSettingss(context: Context) = listOf(
|
||||||
PrefDef(context, Settings.PREF_TOOLBAR_KEYS, R.string.toolbar_keys) {
|
Setting(context, Settings.PREF_TOOLBAR_KEYS, R.string.toolbar_keys) {
|
||||||
ReorderSwitchPreference(it, defaultToolbarPref)
|
ReorderSwitchPreference(it, defaultToolbarPref)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_PINNED_TOOLBAR_KEYS, R.string.pinned_toolbar_keys) {
|
Setting(context, Settings.PREF_PINNED_TOOLBAR_KEYS, R.string.pinned_toolbar_keys) {
|
||||||
ReorderSwitchPreference(it, defaultPinnedToolbarPref)
|
ReorderSwitchPreference(it, defaultPinnedToolbarPref)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_CLIPBOARD_TOOLBAR_KEYS, R.string.clipboard_toolbar_keys) {
|
Setting(context, Settings.PREF_CLIPBOARD_TOOLBAR_KEYS, R.string.clipboard_toolbar_keys) {
|
||||||
ReorderSwitchPreference(it, defaultClipboardToolbarPref)
|
ReorderSwitchPreference(it, defaultClipboardToolbarPref)
|
||||||
},
|
},
|
||||||
PrefDef(context, NonSettingsPrefs.CUSTOM_KEY_CODES, R.string.customize_toolbar_key_codes) {
|
Setting(context, SettingsWithoutKey.CUSTOM_KEY_CODES, R.string.customize_toolbar_key_codes) {
|
||||||
var showDialog by remember { mutableStateOf(false) }
|
var showDialog by remember { mutableStateOf(false) }
|
||||||
Preference(
|
Preference(
|
||||||
name = it.title,
|
name = it.title,
|
||||||
|
@ -84,20 +84,20 @@ fun createToolbarPrefs(context: Context) = listOf(
|
||||||
onDismissRequest = { showDialog = false }
|
onDismissRequest = { showDialog = false }
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_QUICK_PIN_TOOLBAR_KEYS,
|
Setting(context, Settings.PREF_QUICK_PIN_TOOLBAR_KEYS,
|
||||||
R.string.quick_pin_toolbar_keys, R.string.quick_pin_toolbar_keys_summary)
|
R.string.quick_pin_toolbar_keys, R.string.quick_pin_toolbar_keys_summary)
|
||||||
{
|
{
|
||||||
SwitchPreference(it, false,) { keyboardNeedsReload = true }
|
SwitchPreference(it, false,) { keyboardNeedsReload = true }
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_AUTO_SHOW_TOOLBAR, R.string.auto_show_toolbar, R.string.auto_show_toolbar_summary)
|
Setting(context, Settings.PREF_AUTO_SHOW_TOOLBAR, R.string.auto_show_toolbar, R.string.auto_show_toolbar_summary)
|
||||||
{
|
{
|
||||||
SwitchPreference(it, false,)
|
SwitchPreference(it, false,)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_AUTO_HIDE_TOOLBAR, R.string.auto_hide_toolbar, R.string.auto_hide_toolbar_summary)
|
Setting(context, Settings.PREF_AUTO_HIDE_TOOLBAR, R.string.auto_hide_toolbar, R.string.auto_hide_toolbar_summary)
|
||||||
{
|
{
|
||||||
SwitchPreference(it, false,)
|
SwitchPreference(it, false,)
|
||||||
},
|
},
|
||||||
PrefDef(context, Settings.PREF_VARIABLE_TOOLBAR_DIRECTION,
|
Setting(context, Settings.PREF_VARIABLE_TOOLBAR_DIRECTION,
|
||||||
R.string.var_toolbar_direction, R.string.var_toolbar_direction_summary)
|
R.string.var_toolbar_direction, R.string.var_toolbar_direction_summary)
|
||||||
{
|
{
|
||||||
SwitchPreference(it, true,)
|
SwitchPreference(it, true,)
|
||||||
|
@ -107,7 +107,7 @@ fun createToolbarPrefs(context: Context) = listOf(
|
||||||
@Preview
|
@Preview
|
||||||
@Composable
|
@Composable
|
||||||
private fun Preview() {
|
private fun Preview() {
|
||||||
SettingsActivity2.allPrefs = AllPrefs(LocalContext.current)
|
SettingsActivity.settingsContainer = SettingsContainer(LocalContext.current)
|
||||||
KeyboardIconsSet.instance.loadIcons(LocalContext.current)
|
KeyboardIconsSet.instance.loadIcons(LocalContext.current)
|
||||||
Theme(true) {
|
Theme(true) {
|
||||||
Surface {
|
Surface {
|
||||||
|
|
Loading…
Add table
Reference in a new issue