Remove ability to set in-app language differently from system's

This commit is contained in:
arkon
2021-08-06 16:45:40 -04:00
parent 664e5cfb59
commit 03980b2f27
8 changed files with 18 additions and 167 deletions

View File

@@ -1,15 +1,9 @@
package eu.kanade.tachiyomi.util.system
import android.content.Context
import android.content.ContextWrapper
import android.content.res.Configuration
import android.os.Build
import android.os.LocaleList
import androidx.core.os.LocaleListCompat
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.ui.browse.source.SourcePresenter
import uy.kohesive.injekt.injectLazy
import java.util.Locale
/**
@@ -17,8 +11,6 @@ import java.util.Locale
*/
object LocaleHelper {
private val preferences: PreferencesHelper by injectLazy()
/**
* Returns Display name of a string language code
*/
@@ -50,21 +42,6 @@ object LocaleHelper {
return locale.getDisplayName(locale).replaceFirstChar { it.uppercase(locale) }
}
/**
* Creates a ContextWrapper using selected Locale
*/
fun createLocaleWrapper(context: Context): ContextWrapper {
val appLocale = getLocaleFromString(preferences.lang().get())
val newConfiguration = Configuration(context.resources.configuration)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
val localeList = LocaleList(appLocale)
newConfiguration.setLocales(localeList)
} else {
newConfiguration.setLocale(appLocale)
}
return ContextWrapper(context.createConfigurationContext(newConfiguration))
}
/**
* Return Locale from string language code
*/
@@ -76,16 +53,4 @@ object LocaleHelper {
else -> Locale(lang)
}
}
/**
* Returns the locale for the value stored in preferences, defaults to main system language.
*
* @param pref the string value stored in preferences.
*/
private fun getLocaleFromString(pref: String?): Locale {
if (pref.isNullOrEmpty()) {
return LocaleListCompat.getDefault()[0]
}
return getLocale(pref)
}
}