Add support for language switching (#1108)

* Add support for language switching

* Clean and improve code based on feedback

* Remove useless logging
This commit is contained in:
Mélanie Chauvel (ariasuni) 2019-03-08 20:33:42 +01:00 committed by Konrad Pozniak
commit bac131c6d5
8 changed files with 171 additions and 22 deletions

View file

@ -62,6 +62,8 @@ class PreferencesFragment : PreferenceFragmentCompat() {
true
}
val languagePreference: Preference = findPreference("language")
languagePreference.icon = IconicsDrawable(languagePreference.context, GoogleMaterial.Icon.gmd_translate).sizePx(iconSize).color(ThemeUtils.getColor(languagePreference.context, R.attr.toolbar_icon_tint))
}
override fun onResume() {
@ -75,22 +77,22 @@ class PreferencesFragment : PreferenceFragmentCompat() {
val sharedPreferences = preferenceManager.sharedPreferences
val httpProxyEnabled = sharedPreferences.getBoolean("httpProxyEnabled", false)
val httpProxyEnabled = sharedPreferences.getBoolean("httpProxyEnabled", false)
val httpServer = sharedPreferences.getNonNullString("httpProxyServer", "")
val httpServer = sharedPreferences.getNonNullString("httpProxyServer", "")
try {
val httpPort = sharedPreferences.getNonNullString("httpProxyPort", "-1").toInt()
try {
val httpPort = sharedPreferences.getNonNullString("httpProxyPort", "-1").toInt()
if (httpProxyEnabled && httpServer.isNotBlank() && httpPort > 0 && httpPort < 65535) {
httpProxyPref.summary = "$httpServer:$httpPort"
return
}
} catch (e: NumberFormatException) {
// user has entered wrong port, fall back to empty summary
if (httpProxyEnabled && httpServer.isNotBlank() && httpPort > 0 && httpPort < 65535) {
httpProxyPref.summary = "$httpServer:$httpPort"
return
}
} catch (e: NumberFormatException) {
// user has entered wrong port, fall back to empty summary
}
httpProxyPref.summary = ""
httpProxyPref.summary = ""
}