mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 11:38:51 +01:00
Set correct padding between messages
This commit is contained in:
@@ -9,6 +9,8 @@ import com.moez.QKSMS.dagger.AppComponentManager
|
||||
import com.moez.QKSMS.data.model.Contact
|
||||
import com.moez.QKSMS.data.model.Message
|
||||
import com.moez.QKSMS.util.DateFormatter
|
||||
import com.moez.QKSMS.util.extensions.dpToPx
|
||||
import com.moez.QKSMS.util.extensions.setMargins
|
||||
import io.realm.OrderedRealmCollection
|
||||
import io.realm.RealmRecyclerViewAdapter
|
||||
import timber.log.Timber
|
||||
@@ -66,20 +68,24 @@ class MessageAdapter(data: OrderedRealmCollection<Message>?) : RealmRecyclerView
|
||||
|
||||
when {
|
||||
!canGroupWithPrevious && canGroupWithNext -> {
|
||||
viewHolder.message.setMargins(bottom = 2.dpToPx(context))
|
||||
viewHolder.body.setBackgroundResource(if (sent) R.drawable.message_out_first else R.drawable.message_in_first)
|
||||
viewHolder.avatar?.apply { visibility = View.INVISIBLE }
|
||||
viewHolder.avatar?.visibility = View.INVISIBLE
|
||||
}
|
||||
canGroupWithPrevious && canGroupWithNext -> {
|
||||
viewHolder.message.setMargins(bottom = 2.dpToPx(context))
|
||||
viewHolder.body.setBackgroundResource(if (sent) R.drawable.message_out_middle else R.drawable.message_in_middle)
|
||||
viewHolder.avatar?.apply { visibility = View.INVISIBLE }
|
||||
viewHolder.avatar?.visibility = View.INVISIBLE
|
||||
}
|
||||
canGroupWithPrevious && !canGroupWithNext -> {
|
||||
viewHolder.message.setMargins(bottom = 16.dpToPx(context))
|
||||
viewHolder.body.setBackgroundResource(if (sent) R.drawable.message_out_last else R.drawable.message_in_last)
|
||||
viewHolder.avatar?.apply { visibility = View.VISIBLE }
|
||||
viewHolder.avatar?.visibility = View.VISIBLE
|
||||
}
|
||||
else -> {
|
||||
viewHolder.message.setMargins(bottom = 16.dpToPx(context))
|
||||
viewHolder.body.setBackgroundResource(R.drawable.message_only)
|
||||
viewHolder.avatar?.apply { visibility = View.VISIBLE }
|
||||
viewHolder.avatar?.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,9 @@ import com.moez.QKSMS.ui.view.AvatarView
|
||||
|
||||
class MessageViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||
|
||||
val timestamp: TextView = view.findViewById(R.id.timestamp)
|
||||
val message: View = view.findViewById(R.id.message)
|
||||
val avatar: AvatarView? = view.findViewById(R.id.avatar)
|
||||
val body: TextView = view.findViewById(R.id.body)
|
||||
val timestamp: TextView = view.findViewById(R.id.timestamp)
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.moez.QKSMS.util.extensions
|
||||
|
||||
import android.content.Context
|
||||
import android.util.TypedValue
|
||||
|
||||
fun Int.dpToPx(context: Context): Int {
|
||||
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, this.toFloat(), context.resources.displayMetrics).toInt()
|
||||
}
|
||||
@@ -1,8 +1,22 @@
|
||||
package com.moez.QKSMS.util.extensions
|
||||
|
||||
import android.content.res.ColorStateList
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
|
||||
fun ImageView.setTint(color: Int) {
|
||||
imageTintList = ColorStateList.valueOf(color)
|
||||
}
|
||||
|
||||
fun View.setMargins(left: Int? = null, top: Int? = null, right: Int? = null, bottom: Int? = null) {
|
||||
val lp = layoutParams as? ViewGroup.MarginLayoutParams ?: return
|
||||
|
||||
lp.setMargins(
|
||||
left ?: lp.leftMargin,
|
||||
top ?: lp.topMargin,
|
||||
right ?: lp.rightMargin,
|
||||
bottom ?: lp.rightMargin)
|
||||
|
||||
layoutParams = lp
|
||||
}
|
||||
Reference in New Issue
Block a user