Fix up adapter & coloring of the X button

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2020-01-24 10:00:27 +01:00
parent 00abcd9c48
commit e88b49b506
No known key found for this signature in database
GPG Key ID: CDE0BBD2738C4CC0
4 changed files with 46 additions and 4 deletions

View File

@ -91,7 +91,7 @@ open class ContactPresenter<T : Any>(context: Context, onElementClick: ((Page, H
holder.itemView.participantNameTextView.text = context.getString(R.string.nc_guest)
}
holder.itemView.clearImageView?.load(Images().getImageWithBackground(context, R.drawable.ic_baseline_clear_24, R.color.white))
holder.itemView.clearImageView?.load(Images().getImageWithBackground(context, R.drawable.ic_baseline_clear_24, R.color.bg_selected_participant_clear_icon, R.color.white))
when (participant?.source) {
"users" -> {

View File

@ -96,6 +96,38 @@ class ContactsView<T : Any>(private val bundle: Bundle? = null) : BaseView() {
selectedParticipantsRecyclerView.initRecyclerView(LinearLayoutManager(activity, RecyclerView.HORIZONTAL, false), selectedParticipantsAdapter, true)
}
selectedParticipantsAdapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
override fun onChanged() {
super.onChanged()
toggleSelectedParticipantsViewVisibility()
}
override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) {
super.onItemRangeRemoved(positionStart, itemCount)
toggleSelectedParticipantsViewVisibility()
}
override fun onItemRangeMoved(fromPosition: Int, toPosition: Int, itemCount: Int) {
super.onItemRangeMoved(fromPosition, toPosition, itemCount)
toggleSelectedParticipantsViewVisibility()
}
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
super.onItemRangeInserted(positionStart, itemCount)
toggleSelectedParticipantsViewVisibility()
}
override fun onItemRangeChanged(positionStart: Int, itemCount: Int) {
super.onItemRangeChanged(positionStart, itemCount)
toggleSelectedParticipantsViewVisibility()
}
override fun onItemRangeChanged(positionStart: Int, itemCount: Int, payload: Any?) {
super.onItemRangeChanged(positionStart, itemCount, payload)
toggleSelectedParticipantsViewVisibility()
}
})
viewModel.apply {
selectedParticipantsLiveData.observe(this@ContactsView) { participants ->
view.selectedParticipantsRecyclerView.isVisible = participants.isNotEmpty()
@ -110,6 +142,11 @@ class ContactsView<T : Any>(private val bundle: Bundle? = null) : BaseView() {
return view
}
private fun toggleSelectedParticipantsViewVisibility() {
view?.selectedParticipantsRecyclerView?.isVisible = selectedParticipantsAdapter.itemCount > 0
view?.divider?.isVisible = selectedParticipantsAdapter.itemCount > 0
}
private fun onElementClick(page: Page, holder: Presenter.Holder, element: Element<T>) {
if (element.data is Participant?) {
val participant = element.data as Participant?
@ -121,7 +158,11 @@ class ContactsView<T : Any>(private val bundle: Bundle? = null) : BaseView() {
viewModel.selectParticipant(it)
}
it.selected = !isElementSelected
participantsAdapter.notifyItemChanged(holder.adapterPosition, ElementPayload.SELECTION_TOGGLE)
if (element.type == ParticipantElementType.PARTICIPANT_SELECTED.ordinal) {
participantsAdapter.notifyItemRangeChanged(0, participantsAdapter.itemCount, ElementPayload.SELECTION_TOGGLE)
} else {
participantsAdapter.notifyItemChanged(holder.adapterPosition, ElementPayload.SELECTION_TOGGLE)
}
}
}

View File

@ -70,9 +70,9 @@ class Images {
}
}
fun getImageWithBackground(context: Context, drawableId: Int, foregroundColorTint: Int? = null): Bitmap {
fun getImageWithBackground(context: Context, drawableId: Int, backgroundDrawableId: Int = R.color.bg_message_list_incoming_bubble, foregroundColorTint: Int? = null): Bitmap {
val layers = arrayOfNulls<Drawable>(2)
layers[0] = context.getDrawable(R.color.bg_message_list_incoming_bubble)
layers[0] = context.getDrawable(backgroundDrawableId)
var scale = 0.25f
if (drawableId == R.drawable.ic_baseline_email_24 || drawableId == R.drawable.ic_link_white_24px) {
scale = 0.5f

View File

@ -64,6 +64,7 @@
<color name="bg_dark_mention_chips">#333333</color>
<color name="bg_selected_participant_clear_icon">#484848</color>
<color name="bg_message_list_incoming_bubble">#EFEFEF</color>
<color name="bg_message_list_outcoming_bubble">@color/colorPrimary</color>