add cancel button (#6078)

Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>
This commit is contained in:
Parneet Singh 2024-12-29 04:50:32 +05:30 committed by GitHub
parent dec56a3342
commit a6444968fa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 67 additions and 24 deletions

View file

@ -14,6 +14,7 @@ import android.text.TextWatcher
import android.view.KeyEvent
import android.view.View
import android.widget.AdapterView
import android.widget.Button
import android.widget.EditText
import android.widget.ListView
import android.widget.TextView
@ -333,24 +334,16 @@ class SettingsFragment : PreferenceFragmentCompat() {
val dialog = Dialog(requireActivity())
dialog.setContentView(R.layout.dialog_select_language)
dialog.setCancelable(true)// Allow dialog to close with the back button
dialog.setCancelable(false)
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)
val listView: ListView = dialog.findViewById(R.id.language_list)
val cancelButton = dialog.findViewById<Button>(R.id.cancel_button)
languageHistoryListView = dialog.findViewById(R.id.language_history_list)
recentLanguagesTextView = dialog.findViewById(R.id.recent_searches)
separator = dialog.findViewById(R.id.separator)
@ -359,6 +352,8 @@ class SettingsFragment : PreferenceFragmentCompat() {
listView.adapter = languagesAdapter
cancelButton.setOnClickListener { dialog.dismiss() }
editText.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(charSequence: CharSequence, start: Int, count: Int, after: Int) {
hideRecentLanguagesSection()