forked from upstream-mirrors/quik
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.Contact
|
||||||
import com.moez.QKSMS.data.model.Message
|
import com.moez.QKSMS.data.model.Message
|
||||||
import com.moez.QKSMS.util.DateFormatter
|
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.OrderedRealmCollection
|
||||||
import io.realm.RealmRecyclerViewAdapter
|
import io.realm.RealmRecyclerViewAdapter
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
@@ -66,20 +68,24 @@ class MessageAdapter(data: OrderedRealmCollection<Message>?) : RealmRecyclerView
|
|||||||
|
|
||||||
when {
|
when {
|
||||||
!canGroupWithPrevious && canGroupWithNext -> {
|
!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.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 -> {
|
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.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 -> {
|
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.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 -> {
|
else -> {
|
||||||
|
viewHolder.message.setMargins(bottom = 16.dpToPx(context))
|
||||||
viewHolder.body.setBackgroundResource(R.drawable.message_only)
|
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) {
|
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 avatar: AvatarView? = view.findViewById(R.id.avatar)
|
||||||
val body: TextView = view.findViewById(R.id.body)
|
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
|
package com.moez.QKSMS.util.extensions
|
||||||
|
|
||||||
import android.content.res.ColorStateList
|
import android.content.res.ColorStateList
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
|
|
||||||
fun ImageView.setTint(color: Int) {
|
fun ImageView.setTint(color: Int) {
|
||||||
imageTintList = ColorStateList.valueOf(color)
|
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
|
||||||
|
}
|
||||||
@@ -12,11 +12,12 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="8dp"
|
android:layout_marginBottom="8dp"
|
||||||
android:layout_marginTop="24dp"
|
android:layout_marginTop="8dp"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
tools:text="Tue at 11:39pm" />
|
tools:text="Tue at 11:39pm" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
android:id="@+id/message"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="2dp"
|
android:layout_marginBottom="2dp"
|
||||||
|
|||||||
@@ -12,11 +12,12 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="8dp"
|
android:layout_marginBottom="8dp"
|
||||||
android:layout_marginTop="24dp"
|
android:layout_marginTop="8dp"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
tools:text="Tue at 11:39pm" />
|
tools:text="Tue at 11:39pm" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
android:id="@+id/message"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="2dp"
|
android:layout_marginBottom="2dp"
|
||||||
|
|||||||
Reference in New Issue
Block a user