Implemented closing Autocomplete popup on back button press

This commit is contained in:
dankito 2020-05-14 00:02:51 +02:00
parent a56240a300
commit fc94b47fca
3 changed files with 32 additions and 0 deletions

View File

@ -20,6 +20,7 @@ import kotlinx.android.synthetic.main.dialog_add_account.view.*
import net.dankito.banking.fints4java.android.R
import net.dankito.banking.fints4java.android.di.BankingComponent
import net.dankito.banking.fints4java.android.ui.adapter.presenter.BankInfoPresenter
import net.dankito.banking.fints4java.android.ui.extensions.closePopupOnBackButtonPress
import net.dankito.banking.fints4java.android.util.StandardAutocompleteCallback
import net.dankito.banking.ui.model.responses.AddAccountResponse
import net.dankito.banking.ui.presenter.BankingPresenter
@ -87,6 +88,7 @@ open class AddAccountDialog : DialogFragment() {
.with(autocompleteCallback)
.with(BankInfoPresenter(presenter, rootView.context))
.build()
.closePopupOnBackButtonPress(dialog)
}
protected open fun addAccount() {

View File

@ -20,6 +20,7 @@ import net.dankito.banking.fints4java.android.di.BankingComponent
import net.dankito.banking.fints4java.android.ui.adapter.BankAccountsAdapter
import net.dankito.banking.fints4java.android.ui.adapter.presenter.RemitteePresenter
import net.dankito.banking.fints4java.android.ui.extensions.addEnterPressedListener
import net.dankito.banking.fints4java.android.ui.extensions.closePopupOnBackButtonPress
import net.dankito.banking.fints4java.android.ui.listener.ListItemSelectedListener
import net.dankito.banking.fints4java.android.util.StandardAutocompleteCallback
import net.dankito.banking.fints4java.android.util.StandardTextWatcher
@ -182,6 +183,7 @@ open class TransferMoneyDialog : DialogFragment() {
.with(autocompleteCallback)
.with(RemitteePresenter(remitteeSearcher, edtxtRemitteeName.context))
.build()
.closePopupOnBackButtonPress(dialog)
}

View File

@ -0,0 +1,28 @@
package net.dankito.banking.fints4java.android.ui.extensions
import android.app.Dialog
import android.view.KeyEvent
import com.otaliastudios.autocomplete.Autocomplete
/**
* This will not work if Dialog is null!
*
* Making the Dialog parameter nullable is just for convienience to be able to call
* Autocomplete
* .on<>(view)
* .build()
* .closePopupOnBackButtonPress(dialog)
*/
fun Autocomplete<*>.closePopupOnBackButtonPress(dialog: Dialog?) {
dialog?.setOnKeyListener { _, keyCode, _ ->
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (this.isPopupShowing) { // close autocomplete popup on back button press
this.dismissPopup()
return@setOnKeyListener true
}
}
false
}
}