LocaleHelper dependency remove

This commit is contained in:
Milos Kozak 2020-03-30 00:57:33 +02:00
parent d1ee12fafc
commit ddd9110912
3 changed files with 11 additions and 9 deletions

View file

@ -92,7 +92,6 @@ public class MainActivity extends NoSplashAppCompatActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
AndroidInjection.inject(this);
super.onCreate(savedInstanceState);
Iconify.with(new FontAwesomeModule());

View file

@ -10,8 +10,8 @@ import info.nightscout.androidaps.utils.LocaleHelper
open class NoSplashAppCompatActivity : DaggerAppCompatActivity() {
public override fun onCreate(savedInstanceState: Bundle?) {
setTheme(R.style.AppTheme_NoActionBar)
super.onCreate(savedInstanceState)
setTheme(R.style.AppTheme_NoActionBar)
}
public override fun attachBaseContext(newBase: Context) {

View file

@ -4,16 +4,19 @@ import android.content.Context
import android.content.ContextWrapper
import android.os.Build
import android.os.LocaleList
import androidx.preference.PreferenceManager
import info.nightscout.androidaps.R
import java.util.*
object LocaleHelper {
fun currentLanguage(): String =
SP.getString(R.string.key_language, Locale.getDefault().language)
private fun currentLanguage(context: Context): String =
PreferenceManager.getDefaultSharedPreferences(context).getString(context.getString(R.string.key_language), "en")
?: "en"
// injection not possible because of use in attachBaseContext
//SP.getString(R.string.key_language, Locale.getDefault().language)
private fun currentLocale(): Locale {
val language = currentLanguage()
private fun currentLocale(context: Context): Locale {
val language = currentLanguage(context)
var locale = Locale(language)
if (language.contains("_")) {
// language with country like pt_BR defined in arrays.xml
@ -26,7 +29,7 @@ object LocaleHelper {
@Suppress("DEPRECATION")
fun update(context: Context) {
val locale = currentLocale()
val locale = currentLocale(context)
Locale.setDefault(locale)
val resources = context.resources
val configuration = resources.configuration
@ -39,7 +42,7 @@ object LocaleHelper {
fun wrap(ctx: Context): ContextWrapper {
val res = ctx.resources
val configuration = res.configuration
val newLocale = currentLocale()
val newLocale = currentLocale(ctx)
val context = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
configuration.setLocale(newLocale)
val localeList = LocaleList(newLocale)