Skip to content

Commit

Permalink
fix(sample): refresh message inbox view on tag deletion
Browse files Browse the repository at this point in the history
SUITEDEV-23715

Co-authored-by: davidSchuppa <[email protected]>
Co-authored-by: megamegax <[email protected]>
  • Loading branch information
3 people committed Aug 31, 2020
1 parent b4f62a0 commit 535d970
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.emarsys.sample.adapters

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand All @@ -10,23 +11,26 @@ import com.emarsys.mobileengage.api.inbox.Message
import com.emarsys.sample.R
import com.emarsys.sample.TagChangeListener
import kotlinx.android.synthetic.main.notification_view_with_labels.view.*

class MessageInboxAdapter(private val tagChangeListener: TagChangeListener) : RecyclerView.Adapter<MessageInboxAdapter.NotificationViewHolder>() {
private var notifications = mutableListOf<Message>()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NotificationViewHolder {
return NotificationViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.notification_view_with_labels, parent, false))
}

override fun getItemCount(): Int {
return notifications.size
}

override fun onBindViewHolder(holder: NotificationViewHolder, position: Int) {
holder.title.text = notifications[position].title
holder.body.text = notifications[position].body
val tags = notifications[position].tags
if (!tags.isNullOrEmpty()){
holder.messageLabels.text = tags.toString()
}

holder.messageLabels.text = if (tags.isNullOrEmpty()) "" else tags.toString()

val imageUrl = notifications[position].imageUrl
holder.image.load(imageUrl){
holder.image.load(imageUrl) {
placeholder(R.drawable.placeholder)
crossfade(true)
}
Expand All @@ -37,10 +41,12 @@ class MessageInboxAdapter(private val tagChangeListener: TagChangeListener) : Re
tagChangeListener.removeTagClicked(notifications[position].id)
}
}

fun addItems(notifications: List<Message>) {
this.notifications = notifications as MutableList<Message>
notifyDataSetChanged()
}

class NotificationViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val title: TextView = view.notification_title
val body: TextView = view.notification_body
Expand Down

0 comments on commit 535d970

Please sign in to comment.