|
1 | 1 | package org.fossify.phone.dialogs |
2 | 2 |
|
3 | 3 | import android.graphics.Color |
4 | | -import android.view.KeyEvent |
5 | 4 | import android.view.inputmethod.EditorInfo |
6 | 5 | import android.widget.ImageView |
| 6 | +import androidx.activity.addCallback |
7 | 7 | import androidx.appcompat.app.AlertDialog |
8 | 8 | import org.fossify.commons.extensions.* |
9 | 9 | import org.fossify.commons.models.contacts.Contact |
@@ -37,15 +37,17 @@ class SelectContactDialog(val activity: SimpleActivity, val contacts: List<Conta |
37 | 37 |
|
38 | 38 | activity.getAlertDialogBuilder() |
39 | 39 | .setNegativeButton(R.string.cancel, null) |
40 | | - .setOnKeyListener { _, i, keyEvent -> |
41 | | - if (keyEvent.action == KeyEvent.ACTION_UP && i == KeyEvent.KEYCODE_BACK) { |
42 | | - backPressed() |
43 | | - } |
44 | | - true |
45 | | - } |
46 | 40 | .apply { |
47 | 41 | activity.setupDialogStuff(binding.root, this, R.string.choose_contact) { alertDialog -> |
48 | 42 | dialog = alertDialog |
| 43 | + alertDialog.onBackPressedDispatcher.addCallback(alertDialog) { |
| 44 | + if (binding.contactSearchView.isSearchOpen) { |
| 45 | + binding.contactSearchView.closeSearch() |
| 46 | + } else { |
| 47 | + isEnabled = false |
| 48 | + alertDialog.onBackPressedDispatcher.onBackPressed() |
| 49 | + } |
| 50 | + } |
49 | 51 | } |
50 | 52 | } |
51 | 53 | } |
@@ -122,12 +124,4 @@ class SelectContactDialog(val activity: SimpleActivity, val contacts: List<Conta |
122 | 124 | letterFastscroller.beVisibleIf(contactsEmptyPlaceholder.isGone()) |
123 | 125 | letterFastscrollerThumb.beVisibleIf(contactsEmptyPlaceholder.isGone()) |
124 | 126 | } |
125 | | - |
126 | | - private fun backPressed() { |
127 | | - if (binding.contactSearchView.isSearchOpen) { |
128 | | - binding.contactSearchView.closeSearch() |
129 | | - } else { |
130 | | - dialog?.dismiss() |
131 | | - } |
132 | | - } |
133 | 127 | } |
0 commit comments