Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
package io.github.vvb2060.keyattestation.app

import android.content.Context
import android.content.res.Configuration
import android.content.res.Resources
import android.graphics.Color
import android.os.Build
import androidx.appcompat.app.AppCompatDelegate
import rikka.core.res.resolveColor
import rikka.material.app.MaterialActivity

open class AppActivity : MaterialActivity() {

override fun attachBaseContext(newBase: Context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
val locales = AppCompatDelegate.getApplicationLocales()
if (locales.size() > 0) {
val locale = locales[0]!!
val config = Configuration(newBase.resources.configuration)
config.setLocale(locale)
super.attachBaseContext(newBase.createConfigurationContext(config))
} else {
super.attachBaseContext(newBase)
}
} else {
super.attachBaseContext(newBase)
}
}

override fun shouldApplyTranslucentSystemBars(): Boolean {
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ package io.github.vvb2060.keyattestation.util

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.res.Resources
import android.os.Build
import android.os.Handler
import android.os.Looper
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.os.LocaleListCompat
Expand All @@ -15,6 +19,7 @@ object LocaleManager {
Locale("en"),
Locale("el"),
Locale("it"),
Locale("iw"),
Locale("pt", "BR"),
Locale("uk", "UA"),
Locale("zh", "CN"),
Expand All @@ -34,7 +39,7 @@ object LocaleManager {

fun updateLocale(context: Context, code: String): String {
context.getSharedPreferences("locale_prefs", Context.MODE_PRIVATE)
.edit().putString("app_locale", code).apply()
.edit().putString("app_locale", code).commit()
AppCompatDelegate.setApplicationLocales(
if (code.isEmpty()) LocaleListCompat.getEmptyLocaleList()
else LocaleListCompat.create(Locale.forLanguageTag(code))
Expand All @@ -58,7 +63,18 @@ object LocaleManager {
.setSingleChoiceItems(languages.toTypedArray(), currentIndex) { dialog, which ->
updateLocale(context, languageCodes[which])
dialog.dismiss()
if (context is Activity) context.recreate()

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
Handler(Looper.getMainLooper()).post {
val pm = context.packageManager
val intent = pm.getLaunchIntentForPackage(context.packageName)
intent?.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(intent)
Runtime.getRuntime().exit(0)
}
} else {
if (context is Activity) context.recreate()
}
}
.show()
}
Expand Down
Loading