Commit 550090c1 authored by wanglei's avatar wanglei

...

parent ff9b4366
......@@ -20,9 +20,7 @@
android:theme="@style/Theme.PDFViewerScannerWhite"
android:usesCleartextTraffic="true"
tools:targetApi="34">
<activity
android:name=".ui.set.SetLanguageActivity"
android:exported="false" />
<meta-data
android:name="com.google.android.gms.version"
......@@ -51,6 +49,12 @@
android:launchMode="singleTask"
android:screenOrientation="portrait"
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<activity
android:name=".ui.set.SetLanguageActivity"
android:exported="false"
android:launchMode="standard"
android:screenOrientation="portrait"
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<activity
android:name=".ui.set.FeedbackActivity"
android:exported="false"
......
......@@ -14,6 +14,10 @@ import com.base.pdfviewerscannerwhite.ui.main.MainActivity
import com.base.pdfviewerscannerwhite.utils.ActivityLauncher
import com.base.pdfviewerscannerwhite.utils.ActivityManagerUtils
import com.base.pdfviewerscannerwhite.utils.LogEx
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import java.util.Locale
abstract class BaseActivity<T : ViewBinding> : AppCompatActivity() {
......@@ -74,20 +78,22 @@ abstract class BaseActivity<T : ViewBinding> : AppCompatActivity() {
"changeLanguageSp=$changeLanguageSp " +
"activityLanguage=$activityLanguage"
)
if (appLanguageSp != changeLanguageSp || appLanguageSp != activityLanguage) {
if (appLanguageSp != changeLanguageSp || activityLanguage != appLanguageSp) {
val config = resources.configuration
val locale = Locale(changeLanguageSp)
config.setLocale(locale)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
createConfigurationContext(config)
} else {
resources.updateConfiguration(config, resources.displayMetrics)
}
//Android 7.0以上的方法
config.setLocale(locale);
config.setLocales(LocaleList(locale));
createConfigurationContext(config);
resources.updateConfiguration(config, resources.displayMetrics)
// Restart the app
appLanguageSp = changeLanguageSp
callback?.invoke(changeLanguageSp)
this.recreate()
LogEx.logDebug(TAG, "activityTag=$activityTag recreate")
this@BaseActivity.recreate()
}
}
......
......@@ -3,19 +3,28 @@ package com.base.pdfviewerscannerwhite.ui.set
import android.content.Intent
import android.net.Uri
import androidx.activity.addCallback
import com.base.pdfviewerscannerwhite.R
import com.base.pdfviewerscannerwhite.databinding.ActivitySetBinding
import com.base.pdfviewerscannerwhite.helper.BaseActivity
import com.base.pdfviewerscannerwhite.helper.ConfigHelper
import com.base.pdfviewerscannerwhite.helper.MyApplication
import com.base.pdfviewerscannerwhite.ui.view.RateDialog.showRateDialog
import com.base.pdfviewerscannerwhite.utils.LogEx
class SetActivity : BaseActivity<ActivitySetBinding>() {
private val TAG = "SetActivity"
override val binding: ActivitySetBinding by lazy {
LogEx.logDebug(TAG, "binding")
ActivitySetBinding.inflate(layoutInflater)
}
override fun initView() {
val ss = getString(R.string.language)
LogEx.logDebug(TAG, "ss=$ss")
binding.tvLanguage.text = ss
}
override fun initListener() {
......@@ -54,4 +63,11 @@ class SetActivity : BaseActivity<ActivitySetBinding>() {
}
}
override fun onResume() {
super.onResume()
updateAppLanguage(MyApplication.setLanguage, TAG) {
MyApplication.setLanguage = it
}
}
}
\ No newline at end of file
......@@ -42,9 +42,6 @@ class SetLanguageActivity : BaseActivity<ActivitySetLanguageBinding>() {
val selectLanguage = adapter.items.find { it.isSelect }?.language ?: Locale.ENGLISH.language
if (changeLanguageSp != selectLanguage) {
changeLanguageSp = selectLanguage
updateAppLanguage(MyApplication.setLanguage, "Set") { language ->
MyApplication.setLanguage = language
}
}
onBackPressedDispatcher.onBackPressed()
}
......
......@@ -57,6 +57,7 @@
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/tv_language"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment