mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-04-24 08:36:26 +00:00
allow customizing currency keys, fixes #353
This commit is contained in:
parent
d7cb655c21
commit
f7d82b9589
5 changed files with 49 additions and 0 deletions
|
@ -274,6 +274,11 @@ private const val READER_MODE_NUMBER_ROW = 4
|
|||
|
||||
// probably could be improved and extended, currently this is what's done in key_styles_currency.xml
|
||||
private fun getCurrencyKey(locale: Locale): Pair<String, List<String>> {
|
||||
Settings.getInstance().readCustomCurrencyKey().takeIf { it.isNotBlank() }?.let {
|
||||
val split = it.trim().splitOnWhitespace()
|
||||
if (split.isNotEmpty())
|
||||
return split[0] to (split.toSet() + genericCurrencyPopupKeys).filterNot { it == split[0] }
|
||||
}
|
||||
if (locale.country.matches(euroCountries))
|
||||
return euro
|
||||
if (locale.toString().matches(euroLocales))
|
||||
|
|
|
@ -12,9 +12,13 @@ import android.content.SharedPreferences
|
|||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.widget.EditText
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import helium314.keyboard.latin.utils.Log
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.content.edit
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceManager
|
||||
import kotlinx.serialization.encodeToString
|
||||
|
@ -48,6 +52,7 @@ import helium314.keyboard.latin.utils.CUSTOM_LAYOUT_PREFIX
|
|||
import helium314.keyboard.latin.utils.DeviceProtectedUtils
|
||||
import helium314.keyboard.latin.utils.ExecutorUtils
|
||||
import helium314.keyboard.latin.utils.JniUtils
|
||||
import helium314.keyboard.latin.utils.ResourceUtils
|
||||
import helium314.keyboard.latin.utils.editCustomLayout
|
||||
import helium314.keyboard.latin.utils.getCustomLayoutFiles
|
||||
import helium314.keyboard.latin.utils.getStringResourceOrName
|
||||
|
@ -137,6 +142,11 @@ class AdvancedSettingsFragment : SubScreenFragment() {
|
|||
showCustomizeFunctionalKeyLayoutsDialog()
|
||||
true
|
||||
}
|
||||
|
||||
findPreference<Preference>(Settings.PREF_CUSTOM_CURRENCY_KEY)?.setOnPreferenceClickListener {
|
||||
customCurrencyDialog()
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
|
@ -451,6 +461,26 @@ class AdvancedSettingsFragment : SubScreenFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun customCurrencyDialog() {
|
||||
val layout = LinearLayout(requireContext())
|
||||
layout.orientation = LinearLayout.VERTICAL
|
||||
layout.addView(TextView(requireContext()).apply { setText(R.string.customize_currencies_detail) })
|
||||
val et = EditText(requireContext()).apply { setText(sharedPreferences.getString(Settings.PREF_CUSTOM_CURRENCY_KEY, "")) }
|
||||
layout.addView(et)
|
||||
val padding = ResourceUtils.toPx(8, resources)
|
||||
layout.setPadding(3 * padding, padding, padding, padding)
|
||||
AlertDialog.Builder(requireContext())
|
||||
.setTitle(R.string.customize_currencies)
|
||||
.setView(layout)
|
||||
.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||
sharedPreferences.edit { putString(Settings.PREF_CUSTOM_CURRENCY_KEY, et.text.toString()) }
|
||||
KeyboardLayoutSet.onSystemLocaleChanged()
|
||||
}
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setNeutralButton(R.string.button_default) { _, _ -> sharedPreferences.edit { putString(Settings.PREF_CUSTOM_CURRENCY_KEY, "") } }
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun setupKeyLongpressTimeoutSettings() {
|
||||
val prefs = sharedPreferences
|
||||
findPreference<SeekBarDialogPreference>(Settings.PREF_KEY_LONGPRESS_TIMEOUT)?.setInterface(object : ValueProxy {
|
||||
|
|
|
@ -127,6 +127,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
|
|||
|
||||
public static final String PREF_SHOW_NUMBER_ROW = "show_number_row";
|
||||
public static final String PREF_LOCALIZED_NUMBER_ROW = "localized_number_row";
|
||||
public static final String PREF_CUSTOM_CURRENCY_KEY = "custom_currency_key";
|
||||
|
||||
public static final String PREF_SHOW_HINTS = "show_hints";
|
||||
public static final String PREF_POPUP_KEYS_ORDER = "popup_keys_order";
|
||||
|
@ -661,4 +662,8 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
|
|||
public String getInLocale(@StringRes final int resId, final Locale locale) {
|
||||
return RunInLocaleKt.runInLocale(mContext, locale, (ctx) -> ctx.getString(resId));
|
||||
}
|
||||
|
||||
public String readCustomCurrencyKey() {
|
||||
return mPrefs.getString(PREF_CUSTOM_CURRENCY_KEY, "");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -501,6 +501,10 @@ disposition rather than other common dispositions for Latin languages. [CHAR LIM
|
|||
<string name="layout_numpad_landscape" tools:keep="@string/layout_numpad_landscape">Numpad (landscape)</string>
|
||||
<!-- Title for customizing background image -->
|
||||
<string name="customize_background_image">Set background image</string>
|
||||
<!-- Title for customizing currencies -->
|
||||
<string name="customize_currencies">Customize currencies</string>
|
||||
<!-- Info for customizing currencies -->
|
||||
<string name="customize_currencies_detail">Set main and secondary currency symbols, separated with space</string>
|
||||
<!-- Message for selecting day or night background image -->
|
||||
<string name="day_or_night_image">Set image for day or night mode?</string>
|
||||
<!-- Button for selecting day -->
|
||||
|
|
|
@ -76,6 +76,11 @@
|
|||
android:defaultValue="true"
|
||||
android:persistent="true" />
|
||||
|
||||
<Preference
|
||||
android:key="custom_currency_key"
|
||||
android:title="@string/customize_currencies"
|
||||
android:persistent="true" />
|
||||
|
||||
<ListPreference
|
||||
android:key="more_popup_keys"
|
||||
android:title="@string/show_popup_keys_title"
|
||||
|
|
Loading…
Add table
Reference in a new issue