@@ -11,6 +11,7 @@ import android.net.Uri
1111import android.os.Bundle
1212import android.text.Editable
1313import android.text.TextWatcher
14+ import android.view.KeyEvent
1415import android.view.View
1516import android.widget.AdapterView
1617import android.widget.EditText
@@ -332,11 +333,20 @@ class SettingsFragment : PreferenceFragmentCompat() {
332333
333334 val dialog = Dialog (requireActivity())
334335 dialog.setContentView(R .layout.dialog_select_language)
335- dialog.setCancelable(false )
336+ dialog.setCancelable(true ) // Allow dialog to close with the back button
336337 dialog.window?.setLayout(
337338 (resources.displayMetrics.widthPixels * 0.90 ).toInt(),
338339 (resources.displayMetrics.heightPixels * 0.90 ).toInt()
339340 )
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+ }
340350 dialog.show()
341351
342352 val editText: EditText = dialog.findViewById(R .id.search_language)
@@ -378,10 +388,12 @@ class SettingsFragment : PreferenceFragmentCompat() {
378388 if (keyListPreference == " appUiDefaultLanguagePref" ) {
379389 appUiLanguageListPreference?.summary = defLocale.getDisplayLanguage(defLocale)
380390 setLocale(requireActivity(), lCode)
381- requireActivity().recreate()
382391 val intent = Intent (requireActivity(), MainActivity ::class .java)
392+ intent.flags = Intent .FLAG_ACTIVITY_CLEAR_TOP or Intent .FLAG_ACTIVITY_SINGLE_TOP
393+ requireActivity().finish()
383394 startActivity(intent)
384- } else {
395+ }
396+ else {
385397 descriptionLanguageListPreference?.summary = defLocale.getDisplayLanguage(defLocale)
386398 }
387399 dialog.dismiss()
0 commit comments