mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-29 22:03:55 +01:00
add cancel button (#6078)
Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>
This commit is contained in:
parent
dec56a3342
commit
a6444968fa
16 changed files with 67 additions and 24 deletions
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue