Skip to content

Fix: Allow back button functionality to dismiss language selection dialog #6066 #6067

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 23, 2024
Merged
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
18 changes: 15 additions & 3 deletions app/src/main/java/fr/free/nrw/commons/settings/SettingsFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import android.net.Uri
import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.view.KeyEvent
import android.view.View
import android.widget.AdapterView
import android.widget.EditText
Expand Down Expand Up @@ -332,11 +333,20 @@ class SettingsFragment : PreferenceFragmentCompat() {

val dialog = Dialog(requireActivity())
dialog.setContentView(R.layout.dialog_select_language)
dialog.setCancelable(false)
dialog.setCancelable(true)// Allow dialog to close with the back button
dialog.window?.setLayout(
(resources.displayMetrics.widthPixels * 0.90).toInt(),
(resources.displayMetrics.heightPixels * 0.90).toInt()
)
// Handle back button explicitly to dismiss the dialog
dialog.setOnKeyListener { _, keyCode, event ->
if (keyCode == KeyEvent.KEYCODE_BACK && event.action == KeyEvent.ACTION_UP) {
dialog.dismiss() // Close the dialog when the back button is pressed
true
} else {
false
}
}
dialog.show()

val editText: EditText = dialog.findViewById(R.id.search_language)
Expand Down Expand Up @@ -378,10 +388,12 @@ class SettingsFragment : PreferenceFragmentCompat() {
if (keyListPreference == "appUiDefaultLanguagePref") {
appUiLanguageListPreference?.summary = defLocale.getDisplayLanguage(defLocale)
setLocale(requireActivity(), lCode)
requireActivity().recreate()
val intent = Intent(requireActivity(), MainActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP
requireActivity().finish()
startActivity(intent)
} else {
}
else {
descriptionLanguageListPreference?.summary = defLocale.getDisplayLanguage(defLocale)
}
dialog.dismiss()
Expand Down
Loading