fix: Add date breaks on control messages

This commit is contained in:
ceokot 2021-12-03 07:51:21 +02:00
parent 0ba9e4938d
commit bfe91427ab
3 changed files with 31 additions and 14 deletions

View File

@ -64,15 +64,16 @@ class ConversationAdapter(context: Context, cursor: Cursor, private val onItemPr
override fun onBindItemViewHolder(viewHolder: ViewHolder, cursor: Cursor) { override fun onBindItemViewHolder(viewHolder: ViewHolder, cursor: Cursor) {
val message = getMessage(cursor)!! val message = getMessage(cursor)!!
val position = viewHolder.adapterPosition
val messageBefore = getMessageBefore(position, cursor)
when (viewHolder) { when (viewHolder) {
is VisibleMessageViewHolder -> { is VisibleMessageViewHolder -> {
val view = viewHolder.view val view = viewHolder.view
val isSelected = selectedItems.contains(message) val isSelected = selectedItems.contains(message)
view.snIsSelected = isSelected view.snIsSelected = isSelected
view.messageTimestampTextView.isVisible = isSelected view.messageTimestampTextView.isVisible = isSelected
val position = viewHolder.adapterPosition
view.indexInAdapter = position view.indexInAdapter = position
view.bind(message, getMessageBefore(position, cursor), getMessageAfter(position, cursor), glide, searchQuery) view.bind(message, messageBefore, getMessageAfter(position, cursor), glide, searchQuery)
if (!message.isDeleted) { if (!message.isDeleted) {
view.onPress = { event -> onItemPress(message, viewHolder.adapterPosition, view, event) } view.onPress = { event -> onItemPress(message, viewHolder.adapterPosition, view, event) }
view.onSwipeToReply = { onItemSwipeToReply(message, viewHolder.adapterPosition) } view.onSwipeToReply = { onItemSwipeToReply(message, viewHolder.adapterPosition) }
@ -80,7 +81,7 @@ class ConversationAdapter(context: Context, cursor: Cursor, private val onItemPr
} }
view.contentViewDelegate = visibleMessageContentViewDelegate view.contentViewDelegate = visibleMessageContentViewDelegate
} }
is ControlMessageViewHolder -> viewHolder.view.bind(message) is ControlMessageViewHolder -> viewHolder.view.bind(message, messageBefore)
} }
} }

View File

@ -1,17 +1,18 @@
package org.thoughtcrime.securesms.conversation.v2.messages package org.thoughtcrime.securesms.conversation.v2.messages
import android.content.Context import android.content.Context
import android.content.res.Resources
import android.util.AttributeSet import android.util.AttributeSet
import android.view.Gravity
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.widget.LinearLayout import android.widget.LinearLayout
import androidx.core.content.res.ResourcesCompat import androidx.core.content.res.ResourcesCompat
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.view_control_message.view.* import kotlinx.android.synthetic.main.view_control_message.view.*
import network.loki.messenger.R import network.loki.messenger.R
import org.thoughtcrime.securesms.database.model.MessageRecord import org.thoughtcrime.securesms.database.model.MessageRecord
import org.thoughtcrime.securesms.util.DateUtils
import java.util.Locale
class ControlMessageView : LinearLayout { class ControlMessageView : LinearLayout {
@ -27,7 +28,10 @@ class ControlMessageView : LinearLayout {
// endregion // endregion
// region Updating // region Updating
fun bind(message: MessageRecord) { fun bind(message: MessageRecord, previous: MessageRecord?) {
val showDateBreak = (previous == null || message.timestamp - previous.timestamp > VisibleMessageView.maxTimeBetweenBreaks)
dateBreakTextView.isVisible = showDateBreak
dateBreakTextView.text = if (showDateBreak) DateUtils.getDisplayFormattedTimeSpanString(context, Locale.getDefault(), message.timestamp) else ""
iconImageView.visibility = View.GONE iconImageView.visibility = View.GONE
if (message.isExpirationTimerUpdate) { if (message.isExpirationTimerUpdate) {
iconImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ic_timer, context.theme)) iconImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ic_timer, context.theme))

View File

@ -1,28 +1,40 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto" android:gravity="center"
android:orientation="vertical" android:orientation="vertical"
android:paddingVertical="@dimen/medium_spacing"
android:paddingHorizontal="@dimen/massive_spacing" android:paddingHorizontal="@dimen/massive_spacing"
android:gravity="center"> android:paddingVertical="@dimen/medium_spacing">
<TextView
android:id="@+id/dateBreakTextView"
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="center"
android:textColor="@color/text"
android:textSize="@dimen/very_small_font_size"
android:textStyle="bold"
tools:text="@tools:sample/date/hhmm" />
<ImageView <ImageView
android:id="@+id/iconImageView" android:id="@+id/iconImageView"
android:layout_width="12dp" android:layout_width="12dp"
android:layout_height="12dp" android:layout_height="12dp"
android:layout_marginBottom="@dimen/small_spacing" android:layout_marginBottom="@dimen/small_spacing"
app:tint="@color/text" /> app:tint="@color/text"
tools:src="@drawable/ic_timer" />
<TextView <TextView
android:id="@+id/textView" android:id="@+id/textView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textSize="@dimen/very_small_font_size" android:gravity="center"
android:textColor="@color/text" android:textColor="@color/text"
android:textSize="@dimen/very_small_font_size"
android:textStyle="bold" android:textStyle="bold"
android:gravity="center" /> tools:text="@string/MessageRecord_you_disabled_disappearing_messages" />
</LinearLayout> </LinearLayout>