forked from upstream-mirrors/quik
#1028 - Fix backspace not working when searching for contacts
This commit is contained in:
@@ -20,14 +20,11 @@ package feature.compose
|
||||
|
||||
import android.content.Context
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.KeyEvent
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.EditText
|
||||
import android.widget.RelativeLayout
|
||||
import com.google.android.flexbox.FlexboxLayoutManager
|
||||
import com.jakewharton.rxbinding2.view.keys
|
||||
import com.jakewharton.rxbinding2.widget.editorActions
|
||||
import com.jakewharton.rxbinding2.widget.textChanges
|
||||
import com.moez.QKSMS.R
|
||||
@@ -37,7 +34,7 @@ import common.util.Colors
|
||||
import common.util.extensions.dpToPx
|
||||
import common.util.extensions.setBackgroundTint
|
||||
import common.util.extensions.showKeyboard
|
||||
import io.reactivex.functions.Predicate
|
||||
import common.widget.QkEditText
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import kotlinx.android.synthetic.main.contact_chip.view.*
|
||||
import model.Contact
|
||||
@@ -51,21 +48,13 @@ class ChipsAdapter @Inject constructor(private val context: Context, private val
|
||||
}
|
||||
|
||||
private val hint: String = context.getString(R.string.title_compose)
|
||||
private val editText = View.inflate(context, R.layout.chip_input_list_item, null) as EditText
|
||||
private val editText = View.inflate(context, R.layout.chip_input_list_item, null) as QkEditText
|
||||
|
||||
var view: RecyclerView? = null
|
||||
val chipDeleted: PublishSubject<Contact> = PublishSubject.create<Contact>()
|
||||
val textChanges = editText.textChanges()
|
||||
val actions = editText.editorActions()
|
||||
|
||||
/**
|
||||
* On certain devices, not returning false in this predicate for number entry will result in
|
||||
* the user not being able to enter numbers into the text field. As a result, we have to only
|
||||
* pass the events that we're looking for
|
||||
*/
|
||||
val keyEvents = editText.keys(Predicate { event ->
|
||||
event.keyCode == KeyEvent.KEYCODE_BACK || event.keyCode == KeyEvent.KEYCODE_DEL
|
||||
})
|
||||
val backspaces = editText.backspaces
|
||||
|
||||
init {
|
||||
val wrap = ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
|
||||
@@ -23,7 +23,6 @@ import android.graphics.PorterDuff
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.support.v7.widget.LinearLayoutManager
|
||||
import android.view.KeyEvent
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import com.google.android.flexbox.FlexboxLayoutManager
|
||||
@@ -54,7 +53,7 @@ class ComposeActivity : QkThemedActivity<ComposeViewModel>(), ComposeView {
|
||||
override val viewModelClass = ComposeViewModel::class
|
||||
override val activityVisibleIntent: Subject<Boolean> = PublishSubject.create()
|
||||
override val queryChangedIntent: Observable<CharSequence> by lazy { chipsAdapter.textChanges }
|
||||
override val queryKeyEventIntent: Observable<KeyEvent> by lazy { chipsAdapter.keyEvents }
|
||||
override val queryBackspaceIntent: Observable<*> by lazy { chipsAdapter.backspaces }
|
||||
override val queryEditorActionIntent: Observable<Int> by lazy { chipsAdapter.actions }
|
||||
override val chipSelectedIntent: Subject<Contact> by lazy { contactsAdapter.contactSelected }
|
||||
override val chipDeletedIntent: Subject<Contact> by lazy { chipsAdapter.chipDeleted }
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
package feature.compose
|
||||
|
||||
import android.net.Uri
|
||||
import android.view.KeyEvent
|
||||
import common.MenuItem
|
||||
import common.base.QkView
|
||||
import io.reactivex.Observable
|
||||
@@ -31,7 +30,7 @@ interface ComposeView : QkView<ComposeState> {
|
||||
|
||||
val activityVisibleIntent: Observable<Boolean>
|
||||
val queryChangedIntent: Observable<CharSequence>
|
||||
val queryKeyEventIntent: Observable<KeyEvent>
|
||||
val queryBackspaceIntent: Observable<*>
|
||||
val queryEditorActionIntent: Observable<Int>
|
||||
val chipSelectedIntent: Subject<Contact>
|
||||
val chipDeletedIntent: Subject<Contact>
|
||||
|
||||
@@ -23,7 +23,6 @@ import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.telephony.PhoneNumberUtils
|
||||
import android.telephony.SmsMessage
|
||||
import android.view.KeyEvent
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import com.mlsdev.rximagepicker.RxImagePicker
|
||||
import com.mlsdev.rximagepicker.Sources
|
||||
@@ -241,21 +240,11 @@ class ComposeViewModel(intent: Intent) : QkViewModel<ComposeView, ComposeState>(
|
||||
|
||||
// Backspaces should delete the most recent contact if there's no text input
|
||||
// Close the activity if user presses back
|
||||
view.queryKeyEventIntent
|
||||
.filter { event -> event.action == KeyEvent.ACTION_DOWN }
|
||||
view.queryBackspaceIntent
|
||||
.withLatestFrom(selectedContacts, view.queryChangedIntent, { event, contacts, query ->
|
||||
when (event.keyCode) {
|
||||
KeyEvent.KEYCODE_DEL -> {
|
||||
if (contacts.isNotEmpty() && query.isEmpty()) {
|
||||
contactsReducer.onNext { it.dropLast(1) }
|
||||
}
|
||||
}
|
||||
|
||||
KeyEvent.KEYCODE_BACK -> {
|
||||
newState { it.copy(hasError = true) }
|
||||
}
|
||||
if (contacts.isNotEmpty() && query.isEmpty()) {
|
||||
contactsReducer.onNext { it.dropLast(1) }
|
||||
}
|
||||
|
||||
})
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
Reference in New Issue
Block a user