@@ -11,6 +11,7 @@ import android.net.Uri
11
11
import android.os.Bundle
12
12
import android.text.Editable
13
13
import android.text.TextWatcher
14
+ import android.view.KeyEvent
14
15
import android.view.View
15
16
import android.widget.AdapterView
16
17
import android.widget.EditText
@@ -332,11 +333,20 @@ class SettingsFragment : PreferenceFragmentCompat() {
332
333
333
334
val dialog = Dialog (requireActivity())
334
335
dialog.setContentView(R .layout.dialog_select_language)
335
- dialog.setCancelable(false )
336
+ dialog.setCancelable(true ) // Allow dialog to close with the back button
336
337
dialog.window?.setLayout(
337
338
(resources.displayMetrics.widthPixels * 0.90 ).toInt(),
338
339
(resources.displayMetrics.heightPixels * 0.90 ).toInt()
339
340
)
341
+ // Handle back button explicitly to dismiss the dialog
342
+ dialog.setOnKeyListener { _, keyCode, event ->
343
+ if (keyCode == KeyEvent .KEYCODE_BACK && event.action == KeyEvent .ACTION_UP ) {
344
+ dialog.dismiss() // Close the dialog when the back button is pressed
345
+ true
346
+ } else {
347
+ false
348
+ }
349
+ }
340
350
dialog.show()
341
351
342
352
val editText: EditText = dialog.findViewById(R .id.search_language)
@@ -378,10 +388,12 @@ class SettingsFragment : PreferenceFragmentCompat() {
378
388
if (keyListPreference == " appUiDefaultLanguagePref" ) {
379
389
appUiLanguageListPreference?.summary = defLocale.getDisplayLanguage(defLocale)
380
390
setLocale(requireActivity(), lCode)
381
- requireActivity().recreate()
382
391
val intent = Intent (requireActivity(), MainActivity ::class .java)
392
+ intent.flags = Intent .FLAG_ACTIVITY_CLEAR_TOP or Intent .FLAG_ACTIVITY_SINGLE_TOP
393
+ requireActivity().finish()
383
394
startActivity(intent)
384
- } else {
395
+ }
396
+ else {
385
397
descriptionLanguageListPreference?.summary = defLocale.getDisplayLanguage(defLocale)
386
398
}
387
399
dialog.dismiss()
0 commit comments