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