mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-14 14:02:44 +00:00
reduce number of deprecation warnings for the same issue
This commit is contained in:
parent
3a14893e9e
commit
fb81b8c722
4 changed files with 24 additions and 22 deletions
|
@ -88,13 +88,13 @@ class LanguageFakeSettingsFragment : Fragment(R.layout.language_fake_settings) {
|
||||||
// this could be rather slow with looping multiple times over all ~100 subtypes,
|
// this could be rather slow with looping multiple times over all ~100 subtypes,
|
||||||
// but usually there aren't many locales to be checked, and usually the first loop already finds a match
|
// but usually there aren't many locales to be checked, and usually the first loop already finds a match
|
||||||
val localeString = locale.toString()
|
val localeString = locale.toString()
|
||||||
val iter = allSubtypes.iterator()
|
val iterator = allSubtypes.iterator()
|
||||||
var added = false
|
var added = false
|
||||||
while (iter.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
val subtype = iter.next()
|
val subtype = iterator.next()
|
||||||
if (subtype.locale == localeString) {
|
if (subtype.locale() == localeString) {
|
||||||
subtypesToAdd.add(subtype.toSubtypeInfo(locale))
|
subtypesToAdd.add(subtype.toSubtypeInfo(locale))
|
||||||
iter.remove()
|
iterator.remove()
|
||||||
added = true
|
added = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ class LanguageFakeSettingsFragment : Fragment(R.layout.language_fake_settings) {
|
||||||
val iter = allSubtypes.iterator()
|
val iter = allSubtypes.iterator()
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
val subtype = iter.next()
|
val subtype = iter.next()
|
||||||
if (subtype.locale == languageString) {
|
if (subtype.locale() == languageString) {
|
||||||
subtypesToAdd.add(subtype.toSubtypeInfo(LocaleUtils.constructLocaleFromString(languageString)))
|
subtypesToAdd.add(subtype.toSubtypeInfo(LocaleUtils.constructLocaleFromString(languageString)))
|
||||||
iter.remove()
|
iter.remove()
|
||||||
added = true
|
added = true
|
||||||
|
@ -119,8 +119,8 @@ class LanguageFakeSettingsFragment : Fragment(R.layout.language_fake_settings) {
|
||||||
val iter = allSubtypes.iterator()
|
val iter = allSubtypes.iterator()
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
val subtype = iter.next()
|
val subtype = iter.next()
|
||||||
if (subtype.locale.substringBefore("_") == languageString) {
|
if (subtype.locale().substringBefore("_") == languageString) {
|
||||||
subtypesToAdd.add(subtype.toSubtypeInfo(LocaleUtils.constructLocaleFromString(subtype.locale)))
|
subtypesToAdd.add(subtype.toSubtypeInfo(LocaleUtils.constructLocaleFromString(subtype.locale())))
|
||||||
iter.remove()
|
iter.remove()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,7 @@ class LanguageFakeSettingsFragment : Fragment(R.layout.language_fake_settings) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// add enabled subtypes
|
// add enabled subtypes
|
||||||
enabledSubtypes.map { it.toSubtypeInfo(LocaleUtils.constructLocaleFromString(it.locale), true) }
|
enabledSubtypes.map { it.toSubtypeInfo(LocaleUtils.constructLocaleFromString(it.locale()), true) }
|
||||||
.sortedBy { it.displayName }.addToSortedSubtypes()
|
.sortedBy { it.displayName }.addToSortedSubtypes()
|
||||||
allSubtypes.removeAll(enabledSubtypes)
|
allSubtypes.removeAll(enabledSubtypes)
|
||||||
|
|
||||||
|
@ -153,8 +153,8 @@ class LanguageFakeSettingsFragment : Fragment(R.layout.language_fake_settings) {
|
||||||
systemLocales.sortedAddToSubtypesAndRemoveFromAllSubtypes()
|
systemLocales.sortedAddToSubtypesAndRemoveFromAllSubtypes()
|
||||||
|
|
||||||
// add the remaining ones
|
// add the remaining ones
|
||||||
allSubtypes.map { it.toSubtypeInfo(LocaleUtils.constructLocaleFromString(it.locale)) }
|
allSubtypes.map { it.toSubtypeInfo(LocaleUtils.constructLocaleFromString(it.locale())) }
|
||||||
.sortedBy { if (it.subtype.locale.equals("zz", true))
|
.sortedBy { if (it.subtype.locale().equals("zz", true))
|
||||||
"zz" // "No language (Alphabet)" should be last
|
"zz" // "No language (Alphabet)" should be last
|
||||||
else it.displayName
|
else it.displayName
|
||||||
}.addToSortedSubtypes()
|
}.addToSortedSubtypes()
|
||||||
|
|
|
@ -91,11 +91,11 @@ class LanguageAdapter(list: List<MutableList<SubtypeInfo>> = listOf(), context:
|
||||||
sb.append(string)
|
sb.append(string)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val secondaryLocales = Settings.getSecondaryLocales(prefs, infos.first().subtype.locale)
|
val secondaryLocales = Settings.getSecondaryLocales(prefs, infos.first().subtype.locale())
|
||||||
if (secondaryLocales.isNotEmpty()) {
|
if (secondaryLocales.isNotEmpty()) {
|
||||||
if (sb.isNotEmpty())
|
if (sb.isNotEmpty())
|
||||||
sb.append("\n")
|
sb.append("\n")
|
||||||
sb.append(Settings.getSecondaryLocales(prefs, infos.first().subtype.locale)
|
sb.append(Settings.getSecondaryLocales(prefs, infos.first().subtype.locale())
|
||||||
.joinToString(", ") {
|
.joinToString(", ") {
|
||||||
LocaleUtils.getLocaleDisplayNameInSystemLocale(it, context)
|
LocaleUtils.getLocaleDisplayNameInSystemLocale(it, context)
|
||||||
})
|
})
|
||||||
|
@ -116,7 +116,7 @@ class LanguageAdapter(list: List<MutableList<SubtypeInfo>> = listOf(), context:
|
||||||
if (b) {
|
if (b) {
|
||||||
if (infos.size == 1) {
|
if (infos.size == 1) {
|
||||||
if (!infos.first().hasDictionary)
|
if (!infos.first().hasDictionary)
|
||||||
showMissingDictionaryDialog(context, infos.first().subtype.locale.toLocale())
|
showMissingDictionaryDialog(context, infos.first().subtype.locale().toLocale())
|
||||||
addEnabledSubtype(prefs, infos.first().subtype)
|
addEnabledSubtype(prefs, infos.first().subtype)
|
||||||
infos.single().isEnabled = true
|
infos.single().isEnabled = true
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -29,7 +29,7 @@ class LanguageSettingsDialog(
|
||||||
) : AlertDialog(context), LanguageFakeSettingsFragment.Listener {
|
) : AlertDialog(context), LanguageFakeSettingsFragment.Listener {
|
||||||
private val prefs = DeviceProtectedUtils.getSharedPreferences(context)!!
|
private val prefs = DeviceProtectedUtils.getSharedPreferences(context)!!
|
||||||
private val view = LayoutInflater.from(context).inflate(R.layout.locale_settings_dialog, null)
|
private val view = LayoutInflater.from(context).inflate(R.layout.locale_settings_dialog, null)
|
||||||
private val mainLocaleString = infos.first().subtype.locale
|
private val mainLocaleString = infos.first().subtype.locale()
|
||||||
private val mainLocale = mainLocaleString.toLocale()
|
private val mainLocale = mainLocaleString.toLocale()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
|
|
@ -44,7 +44,7 @@ fun addEnabledSubtype(prefs: SharedPreferences, subtype: InputMethodSubtype) {
|
||||||
|
|
||||||
if (subtype !in enabledSubtypes) {
|
if (subtype !in enabledSubtypes) {
|
||||||
enabledSubtypes.add(subtype)
|
enabledSubtypes.add(subtype)
|
||||||
enabledSubtypes.sortBy { it.locale } // for consistent order
|
enabledSubtypes.sortBy { it.locale() } // for consistent order
|
||||||
RichInputMethodManager.getInstance().refreshSubtypeCaches()
|
RichInputMethodManager.getInstance().refreshSubtypeCaches()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,12 +90,12 @@ fun getSelectedSubtype(prefs: SharedPreferences): InputMethodSubtype {
|
||||||
val subtypeString = prefs.getString(Settings.PREF_SELECTED_INPUT_STYLE, "")!!.split(LOCALE_LAYOUT_SEPARATOR)
|
val subtypeString = prefs.getString(Settings.PREF_SELECTED_INPUT_STYLE, "")!!.split(LOCALE_LAYOUT_SEPARATOR)
|
||||||
val subtypes = if (prefs.getBoolean(Settings.PREF_USE_SYSTEM_LOCALES, true)) getDefaultEnabledSubtypes()
|
val subtypes = if (prefs.getBoolean(Settings.PREF_USE_SYSTEM_LOCALES, true)) getDefaultEnabledSubtypes()
|
||||||
else enabledSubtypes
|
else enabledSubtypes
|
||||||
val subtype = subtypes.firstOrNull { subtypeString.first() == it.locale && subtypeString.last() == SubtypeLocaleUtils.getKeyboardLayoutSetName(it) }
|
val subtype = subtypes.firstOrNull { subtypeString.first() == it.locale() && subtypeString.last() == SubtypeLocaleUtils.getKeyboardLayoutSetName(it) }
|
||||||
?: subtypes.firstOrNull()
|
?: subtypes.firstOrNull()
|
||||||
if (subtype == null) {
|
if (subtype == null) {
|
||||||
val defaultSubtypes = getDefaultEnabledSubtypes()
|
val defaultSubtypes = getDefaultEnabledSubtypes()
|
||||||
return defaultSubtypes.firstOrNull { subtypeString.first() == it.locale && subtypeString.last() == SubtypeLocaleUtils.getKeyboardLayoutSetName(it) }
|
return defaultSubtypes.firstOrNull { subtypeString.first() == it.locale() && subtypeString.last() == SubtypeLocaleUtils.getKeyboardLayoutSetName(it) }
|
||||||
?: defaultSubtypes.firstOrNull { subtypeString.first().substringBefore("_") == it.locale.substringBefore("_") && subtypeString.last() == SubtypeLocaleUtils.getKeyboardLayoutSetName(it) }
|
?: defaultSubtypes.firstOrNull { subtypeString.first().substringBefore("_") == it.locale().substringBefore("_") && subtypeString.last() == SubtypeLocaleUtils.getKeyboardLayoutSetName(it) }
|
||||||
?: defaultSubtypes.first()
|
?: defaultSubtypes.first()
|
||||||
}
|
}
|
||||||
return subtype
|
return subtype
|
||||||
|
@ -103,7 +103,7 @@ fun getSelectedSubtype(prefs: SharedPreferences): InputMethodSubtype {
|
||||||
|
|
||||||
fun setSelectedSubtype(prefs: SharedPreferences, subtype: InputMethodSubtype) {
|
fun setSelectedSubtype(prefs: SharedPreferences, subtype: InputMethodSubtype) {
|
||||||
val subtypeString = subtype.prefString()
|
val subtypeString = subtype.prefString()
|
||||||
if (subtype.locale.isEmpty() || prefs.getString(Settings.PREF_SELECTED_INPUT_STYLE, "") == subtypeString)
|
if (subtype.locale().isEmpty() || prefs.getString(Settings.PREF_SELECTED_INPUT_STYLE, "") == subtypeString)
|
||||||
return
|
return
|
||||||
prefs.edit { putString(Settings.PREF_SELECTED_INPUT_STYLE, subtypeString) }
|
prefs.edit { putString(Settings.PREF_SELECTED_INPUT_STYLE, subtypeString) }
|
||||||
}
|
}
|
||||||
|
@ -182,7 +182,7 @@ private fun getDefaultEnabledSubtypes(): List<InputMethodSubtype> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun InputMethodSubtype.prefString() =
|
private fun InputMethodSubtype.prefString() =
|
||||||
locale + LOCALE_LAYOUT_SEPARATOR + SubtypeLocaleUtils.getKeyboardLayoutSetName(this)
|
locale() + LOCALE_LAYOUT_SEPARATOR + SubtypeLocaleUtils.getKeyboardLayoutSetName(this)
|
||||||
|
|
||||||
private fun loadResourceSubtypes(resources: Resources) {
|
private fun loadResourceSubtypes(resources: Resources) {
|
||||||
val xml = resources.getXml(R.xml.method)
|
val xml = resources.getXml(R.xml.method)
|
||||||
|
@ -238,7 +238,7 @@ private fun loadEnabledSubtypes(context: Context) {
|
||||||
continue
|
continue
|
||||||
|
|
||||||
val subtype = subtypesForLocale.firstOrNull { SubtypeLocaleUtils.getKeyboardLayoutSetName(it) == localeAndLayout.last() }
|
val subtype = subtypesForLocale.firstOrNull { SubtypeLocaleUtils.getKeyboardLayoutSetName(it) == localeAndLayout.last() }
|
||||||
?: additionalSubtypes.firstOrNull { it.locale == localeAndLayout.first() && SubtypeLocaleUtils.getKeyboardLayoutSetName(it) == localeAndLayout.last() }
|
?: additionalSubtypes.firstOrNull { it.locale() == localeAndLayout.first() && SubtypeLocaleUtils.getKeyboardLayoutSetName(it) == localeAndLayout.last() }
|
||||||
if (BuildConfig.DEBUG) // should not happen, but should not crash for normal user
|
if (BuildConfig.DEBUG) // should not happen, but should not crash for normal user
|
||||||
require(subtype != null)
|
require(subtype != null)
|
||||||
else if (subtype == null)
|
else if (subtype == null)
|
||||||
|
@ -258,3 +258,5 @@ private val systemSubtypes = mutableListOf<InputMethodSubtype>()
|
||||||
|
|
||||||
private const val SUBTYPE_SEPARATOR = ";"
|
private const val SUBTYPE_SEPARATOR = ";"
|
||||||
private const val LOCALE_LAYOUT_SEPARATOR = ":"
|
private const val LOCALE_LAYOUT_SEPARATOR = ":"
|
||||||
|
|
||||||
|
fun InputMethodSubtype.locale() = locale
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue