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,
|
||||
// but usually there aren't many locales to be checked, and usually the first loop already finds a match
|
||||
val localeString = locale.toString()
|
||||
val iter = allSubtypes.iterator()
|
||||
val iterator = allSubtypes.iterator()
|
||||
var added = false
|
||||
while (iter.hasNext()) {
|
||||
val subtype = iter.next()
|
||||
if (subtype.locale == localeString) {
|
||||
while (iterator.hasNext()) {
|
||||
val subtype = iterator.next()
|
||||
if (subtype.locale() == localeString) {
|
||||
subtypesToAdd.add(subtype.toSubtypeInfo(locale))
|
||||
iter.remove()
|
||||
iterator.remove()
|
||||
added = true
|
||||
}
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ class LanguageFakeSettingsFragment : Fragment(R.layout.language_fake_settings) {
|
|||
val iter = allSubtypes.iterator()
|
||||
while (iter.hasNext()) {
|
||||
val subtype = iter.next()
|
||||
if (subtype.locale == languageString) {
|
||||
if (subtype.locale() == languageString) {
|
||||
subtypesToAdd.add(subtype.toSubtypeInfo(LocaleUtils.constructLocaleFromString(languageString)))
|
||||
iter.remove()
|
||||
added = true
|
||||
|
@ -119,8 +119,8 @@ class LanguageFakeSettingsFragment : Fragment(R.layout.language_fake_settings) {
|
|||
val iter = allSubtypes.iterator()
|
||||
while (iter.hasNext()) {
|
||||
val subtype = iter.next()
|
||||
if (subtype.locale.substringBefore("_") == languageString) {
|
||||
subtypesToAdd.add(subtype.toSubtypeInfo(LocaleUtils.constructLocaleFromString(subtype.locale)))
|
||||
if (subtype.locale().substringBefore("_") == languageString) {
|
||||
subtypesToAdd.add(subtype.toSubtypeInfo(LocaleUtils.constructLocaleFromString(subtype.locale())))
|
||||
iter.remove()
|
||||
}
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ class LanguageFakeSettingsFragment : Fragment(R.layout.language_fake_settings) {
|
|||
}
|
||||
|
||||
// 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()
|
||||
allSubtypes.removeAll(enabledSubtypes)
|
||||
|
||||
|
@ -153,8 +153,8 @@ class LanguageFakeSettingsFragment : Fragment(R.layout.language_fake_settings) {
|
|||
systemLocales.sortedAddToSubtypesAndRemoveFromAllSubtypes()
|
||||
|
||||
// add the remaining ones
|
||||
allSubtypes.map { it.toSubtypeInfo(LocaleUtils.constructLocaleFromString(it.locale)) }
|
||||
.sortedBy { if (it.subtype.locale.equals("zz", true))
|
||||
allSubtypes.map { it.toSubtypeInfo(LocaleUtils.constructLocaleFromString(it.locale())) }
|
||||
.sortedBy { if (it.subtype.locale().equals("zz", true))
|
||||
"zz" // "No language (Alphabet)" should be last
|
||||
else it.displayName
|
||||
}.addToSortedSubtypes()
|
||||
|
|
|
@ -91,11 +91,11 @@ class LanguageAdapter(list: List<MutableList<SubtypeInfo>> = listOf(), context:
|
|||
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 (sb.isNotEmpty())
|
||||
sb.append("\n")
|
||||
sb.append(Settings.getSecondaryLocales(prefs, infos.first().subtype.locale)
|
||||
sb.append(Settings.getSecondaryLocales(prefs, infos.first().subtype.locale())
|
||||
.joinToString(", ") {
|
||||
LocaleUtils.getLocaleDisplayNameInSystemLocale(it, context)
|
||||
})
|
||||
|
@ -116,7 +116,7 @@ class LanguageAdapter(list: List<MutableList<SubtypeInfo>> = listOf(), context:
|
|||
if (b) {
|
||||
if (infos.size == 1) {
|
||||
if (!infos.first().hasDictionary)
|
||||
showMissingDictionaryDialog(context, infos.first().subtype.locale.toLocale())
|
||||
showMissingDictionaryDialog(context, infos.first().subtype.locale().toLocale())
|
||||
addEnabledSubtype(prefs, infos.first().subtype)
|
||||
infos.single().isEnabled = true
|
||||
} else {
|
||||
|
|
|
@ -29,7 +29,7 @@ class LanguageSettingsDialog(
|
|||
) : AlertDialog(context), LanguageFakeSettingsFragment.Listener {
|
||||
private val prefs = DeviceProtectedUtils.getSharedPreferences(context)!!
|
||||
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()
|
||||
|
||||
init {
|
||||
|
|
|
@ -44,7 +44,7 @@ fun addEnabledSubtype(prefs: SharedPreferences, subtype: InputMethodSubtype) {
|
|||
|
||||
if (subtype !in enabledSubtypes) {
|
||||
enabledSubtypes.add(subtype)
|
||||
enabledSubtypes.sortBy { it.locale } // for consistent order
|
||||
enabledSubtypes.sortBy { it.locale() } // for consistent order
|
||||
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 subtypes = if (prefs.getBoolean(Settings.PREF_USE_SYSTEM_LOCALES, true)) getDefaultEnabledSubtypes()
|
||||
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()
|
||||
if (subtype == null) {
|
||||
val defaultSubtypes = getDefaultEnabledSubtypes()
|
||||
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) }
|
||||
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.first()
|
||||
}
|
||||
return subtype
|
||||
|
@ -103,7 +103,7 @@ fun getSelectedSubtype(prefs: SharedPreferences): InputMethodSubtype {
|
|||
|
||||
fun setSelectedSubtype(prefs: SharedPreferences, subtype: InputMethodSubtype) {
|
||||
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
|
||||
prefs.edit { putString(Settings.PREF_SELECTED_INPUT_STYLE, subtypeString) }
|
||||
}
|
||||
|
@ -182,7 +182,7 @@ private fun getDefaultEnabledSubtypes(): List<InputMethodSubtype> {
|
|||
}
|
||||
|
||||
private fun InputMethodSubtype.prefString() =
|
||||
locale + LOCALE_LAYOUT_SEPARATOR + SubtypeLocaleUtils.getKeyboardLayoutSetName(this)
|
||||
locale() + LOCALE_LAYOUT_SEPARATOR + SubtypeLocaleUtils.getKeyboardLayoutSetName(this)
|
||||
|
||||
private fun loadResourceSubtypes(resources: Resources) {
|
||||
val xml = resources.getXml(R.xml.method)
|
||||
|
@ -238,7 +238,7 @@ private fun loadEnabledSubtypes(context: Context) {
|
|||
continue
|
||||
|
||||
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
|
||||
require(subtype != null)
|
||||
else if (subtype == null)
|
||||
|
@ -258,3 +258,5 @@ private val systemSubtypes = mutableListOf<InputMethodSubtype>()
|
|||
|
||||
private const val SUBTYPE_SEPARATOR = ";"
|
||||
private const val LOCALE_LAYOUT_SEPARATOR = ":"
|
||||
|
||||
fun InputMethodSubtype.locale() = locale
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue