cleanup code
This commit is contained in:
parent
bac131c6d5
commit
028db440ee
5 changed files with 4 additions and 14 deletions
|
@ -18,28 +18,24 @@ package com.keylesspalace.tusky.util
|
|||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.content.res.Configuration
|
||||
import android.content.res.Resources
|
||||
import android.preference.PreferenceManager
|
||||
|
||||
import java.util.Locale
|
||||
|
||||
import com.keylesspalace.tusky.util.getNonNullString
|
||||
|
||||
|
||||
class LocaleManager(context: Context) {
|
||||
|
||||
private var prefs: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
|
||||
fun setLocale(context: Context): Context {
|
||||
val language = prefs.getNonNullString("language", "default")
|
||||
if (language.equals("default")) {
|
||||
return context;
|
||||
if (language == "default") {
|
||||
return context
|
||||
}
|
||||
val locale = Locale.forLanguageTag(language)
|
||||
Locale.setDefault(locale)
|
||||
|
||||
val res = context.getResources()
|
||||
val config = Configuration(res.getConfiguration());
|
||||
val res = context.resources
|
||||
val config = Configuration(res.configuration)
|
||||
config.setLocale(locale)
|
||||
return context.createConfigurationContext(config)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue