Skip to content

Commit

Permalink
Code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
ndegwamartin committed Nov 16, 2021
1 parent 67178c4 commit 809b722
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

package com.google.android.fhir.datacapture.gallery

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.content.res.Configuration
import android.os.Bundle
Expand Down Expand Up @@ -49,11 +47,11 @@ class MainActivity : AppCompatActivity() {
return true
}

private fun refreshToSelectedLanguage(language: LocaleUtils.Language, context: Activity) {
private fun refreshToSelectedLanguage(language: LocaleUtils.Language) {

LocaleUtils.saveSelectedLanguage(language, sharedPreferences)

this reload context
this.recreate()
}

override fun attachBaseContext(baseContext: Context) {
Expand All @@ -78,16 +76,11 @@ class MainActivity : AppCompatActivity() {
return when (item.itemId) {
R.id.action_language -> {
LocaleUtils.renderSelectLanguageDialog(this, languageList) { _, i ->
refreshToSelectedLanguage(languageList[i], this)
refreshToSelectedLanguage(languageList[i])
}
true
}
else -> super.onOptionsItemSelected(item)
}
}

private infix fun Activity.reload(activity: Activity) {
val intent = Intent(activity, activity.javaClass)
activity.startActivity(intent)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,9 @@ object LocaleUtils {
@RequiresApi(Build.VERSION_CODES.N)
private fun updateResourcesLocaleConfiguration(context: Context, locale: Locale) {
context.resources.configuration.also {
it.setLocale(locale)

val localeList = LocaleList(locale)
LocaleList.setDefault(localeList)
it.setLocales(localeList)
LocaleList.setDefault(it.locales)

context.createConfigurationContext(it)
}
Expand Down

0 comments on commit 809b722

Please sign in to comment.