forked from upstream-mirrors/quik
Fix keyboard focus during contact entry
This commit is contained in:
@@ -1,10 +1,19 @@
|
||||
package com.moez.QKSMS.common.util.extensions
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.EditText
|
||||
import android.widget.ImageView
|
||||
|
||||
fun EditText.showKeyboard() {
|
||||
requestFocus()
|
||||
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
imm.showSoftInput(this, 0)
|
||||
}
|
||||
|
||||
fun ImageView.setTint(color: Int) {
|
||||
imageTintList = ColorStateList.valueOf(color)
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ abstract class QkAdapter<T, VH : RecyclerView.ViewHolder> : RecyclerView.Adapter
|
||||
val diff = DiffUtil.calculateDiff(provideDiffUtilCallback(field, value))
|
||||
field = value
|
||||
diff.dispatchUpdatesTo(this)
|
||||
onDatasetChanged()
|
||||
}
|
||||
|
||||
fun getItem(position: Int): T {
|
||||
@@ -25,6 +26,10 @@ abstract class QkAdapter<T, VH : RecyclerView.ViewHolder> : RecyclerView.Adapter
|
||||
return data.size
|
||||
}
|
||||
|
||||
open fun onDatasetChanged() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows the adapter implementation to provide a custom DiffUtil.Callback
|
||||
* If not, then the abstract implementation will be used
|
||||
|
||||
@@ -16,6 +16,7 @@ import com.jakewharton.rxbinding2.view.keys
|
||||
import com.jakewharton.rxbinding2.widget.textChanges
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.util.extensions.dpToPx
|
||||
import com.moez.QKSMS.common.util.extensions.showKeyboard
|
||||
import com.moez.QKSMS.data.model.Contact
|
||||
import com.moez.QKSMS.presentation.base.QkAdapter
|
||||
import com.moez.QKSMS.presentation.base.QkViewHolder
|
||||
@@ -64,6 +65,15 @@ class ChipsAdapter(
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDatasetChanged() {
|
||||
editText.text = null
|
||||
editText.hint = if (itemCount == 1) hint else null
|
||||
|
||||
if (itemCount != 2) {
|
||||
editText.showKeyboard()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = when (viewType) {
|
||||
TYPE_EDIT_TEXT -> QkViewHolder(editText)
|
||||
else -> QkViewHolder(LayoutInflater.from(context).inflate(R.layout.contact_chip, parent, false))
|
||||
@@ -71,18 +81,7 @@ class ChipsAdapter(
|
||||
|
||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||
when (getItemViewType(position)) {
|
||||
TYPE_EDIT_TEXT -> {
|
||||
if (itemCount == 1) {
|
||||
editText.hint = hint
|
||||
} else {
|
||||
editText.hint = null
|
||||
editText.text = null
|
||||
}
|
||||
|
||||
editText.requestFocus()
|
||||
}
|
||||
|
||||
else -> {
|
||||
TYPE_ITEM -> {
|
||||
val contact = getItem(position)
|
||||
val view = holder.itemView
|
||||
|
||||
@@ -119,5 +118,4 @@ class ChipsAdapter(
|
||||
detailedChipView.hide()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.moez.QKSMS.common.di.AppComponentManager
|
||||
import com.moez.QKSMS.common.util.ThemeManager
|
||||
import com.moez.QKSMS.common.util.extensions.setTint
|
||||
import com.moez.QKSMS.common.util.extensions.setVisible
|
||||
import com.moez.QKSMS.common.util.extensions.showKeyboard
|
||||
import com.moez.QKSMS.data.model.Contact
|
||||
import com.moez.QKSMS.data.model.Message
|
||||
import com.moez.QKSMS.presentation.base.QkActivity
|
||||
@@ -51,6 +52,7 @@ class ComposeActivity : QkActivity<ComposeViewModel>(), ComposeView {
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
viewModel.bindView(this)
|
||||
|
||||
chips.itemAnimator = null
|
||||
chips.layoutManager = FlexboxLayoutManager(this)
|
||||
chips.adapter = chipsAdapter
|
||||
|
||||
@@ -73,6 +75,10 @@ class ComposeActivity : QkActivity<ComposeViewModel>(), ComposeView {
|
||||
contacts.setVisible(state.contactsVisible)
|
||||
composeBar.setVisible(!state.contactsVisible)
|
||||
|
||||
if (chipsAdapter.data.isEmpty() && state.selectedContacts.isNotEmpty()) {
|
||||
message.showKeyboard()
|
||||
}
|
||||
|
||||
if (chipsAdapter.data !== state.selectedContacts) {
|
||||
chipsAdapter.data = state.selectedContacts
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user