@@ -14,6 +14,7 @@ import android.text.TextWatcher
14
14
import android.view.KeyEvent
15
15
import android.view.View
16
16
import android.widget.AdapterView
17
+ import android.widget.Button
17
18
import android.widget.EditText
18
19
import android.widget.ListView
19
20
import android.widget.TextView
@@ -333,24 +334,16 @@ class SettingsFragment : PreferenceFragmentCompat() {
333
334
334
335
val dialog = Dialog (requireActivity())
335
336
dialog.setContentView(R .layout.dialog_select_language)
336
- dialog.setCancelable(true ) // Allow dialog to close with the back button
337
+ dialog.setCancelable(false )
337
338
dialog.window?.setLayout(
338
339
(resources.displayMetrics.widthPixels * 0.90 ).toInt(),
339
340
(resources.displayMetrics.heightPixels * 0.90 ).toInt()
340
341
)
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
- }
350
342
dialog.show()
351
343
352
344
val editText: EditText = dialog.findViewById(R .id.search_language)
353
345
val listView: ListView = dialog.findViewById(R .id.language_list)
346
+ val cancelButton = dialog.findViewById<Button >(R .id.cancel_button)
354
347
languageHistoryListView = dialog.findViewById(R .id.language_history_list)
355
348
recentLanguagesTextView = dialog.findViewById(R .id.recent_searches)
356
349
separator = dialog.findViewById(R .id.separator)
@@ -359,6 +352,8 @@ class SettingsFragment : PreferenceFragmentCompat() {
359
352
360
353
listView.adapter = languagesAdapter
361
354
355
+ cancelButton.setOnClickListener { dialog.dismiss() }
356
+
362
357
editText.addTextChangedListener(object : TextWatcher {
363
358
override fun beforeTextChanged (charSequence : CharSequence , start : Int , count : Int , after : Int ) {
364
359
hideRecentLanguagesSection()
0 commit comments