diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationAdapter.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationAdapter.kt index 29f06e51ea..c033009ad1 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationAdapter.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationAdapter.kt @@ -64,15 +64,16 @@ class ConversationAdapter(context: Context, cursor: Cursor, private val onItemPr override fun onBindItemViewHolder(viewHolder: ViewHolder, cursor: Cursor) { val message = getMessage(cursor)!! + val position = viewHolder.adapterPosition + val messageBefore = getMessageBefore(position, cursor) when (viewHolder) { is VisibleMessageViewHolder -> { val view = viewHolder.view val isSelected = selectedItems.contains(message) view.snIsSelected = isSelected view.messageTimestampTextView.isVisible = isSelected - val position = viewHolder.adapterPosition 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) { view.onPress = { event -> onItemPress(message, viewHolder.adapterPosition, view, event) } view.onSwipeToReply = { onItemSwipeToReply(message, viewHolder.adapterPosition) } @@ -80,7 +81,7 @@ class ConversationAdapter(context: Context, cursor: Cursor, private val onItemPr } view.contentViewDelegate = visibleMessageContentViewDelegate } - is ControlMessageViewHolder -> viewHolder.view.bind(message) + is ControlMessageViewHolder -> viewHolder.view.bind(message, messageBefore) } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/ControlMessageView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/ControlMessageView.kt index 78e926d041..2b3a545b03 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/ControlMessageView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/ControlMessageView.kt @@ -1,9 +1,7 @@ package org.thoughtcrime.securesms.conversation.v2.messages import android.content.Context -import android.content.res.Resources import android.util.AttributeSet -import android.view.Gravity import android.view.LayoutInflater import android.view.View import android.widget.LinearLayout @@ -27,7 +25,8 @@ class ControlMessageView : LinearLayout { // endregion // region Updating - fun bind(message: MessageRecord) { + fun bind(message: MessageRecord, previous: MessageRecord?) { + dateBreakTextView.showDateBreak(message, previous) iconImageView.visibility = View.GONE if (message.isExpirationTimerUpdate) { iconImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ic_timer, context.theme)) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/MessageUtilities.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/MessageUtilities.kt new file mode 100644 index 0000000000..2eed1ee614 --- /dev/null +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/MessageUtilities.kt @@ -0,0 +1,15 @@ +package org.thoughtcrime.securesms.conversation.v2.messages + +import android.widget.TextView +import androidx.core.view.isVisible +import org.thoughtcrime.securesms.database.model.MessageRecord +import org.thoughtcrime.securesms.util.DateUtils +import java.util.Locale + +private const val maxTimeBetweenBreaks = 5 * 60 * 1000L // 5 minutes + +fun TextView.showDateBreak(message: MessageRecord, previous: MessageRecord?) { + val showDateBreak = (previous == null || message.timestamp - previous.timestamp > maxTimeBetweenBreaks) + isVisible = showDateBreak + text = if (showDateBreak) DateUtils.getDisplayFormattedTimeSpanString(context, Locale.getDefault(), message.timestamp) else "" +} diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt index 521a249e06..d9cd334bc8 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt @@ -69,7 +69,6 @@ class VisibleMessageView : LinearLayout { const val longPressMovementTreshold = 10.0f // dp const val longPressDurationThreshold = 250L // ms const val maxDoubleTapInterval = 200L - const val maxTimeBetweenBreaks = 5 * 60 * 1000L // 5 minutes } // region Lifecycle @@ -120,9 +119,7 @@ class VisibleMessageView : LinearLayout { senderNameTextView.visibility = View.GONE } // Date break - val showDateBreak = (previous == null || message.timestamp - previous.timestamp > maxTimeBetweenBreaks) - dateBreakTextView.isVisible = showDateBreak - dateBreakTextView.text = if (showDateBreak) DateUtils.getDisplayFormattedTimeSpanString(context, Locale.getDefault(), message.timestamp) else "" + dateBreakTextView.showDateBreak(message, previous) // Timestamp messageTimestampTextView.text = DateUtils.getDisplayFormattedTimeSpanString(context, Locale.getDefault(), message.timestamp) // Margins diff --git a/app/src/main/res/layout/view_control_message.xml b/app/src/main/res/layout/view_control_message.xml index cedf0dbca4..909bb83322 100644 --- a/app/src/main/res/layout/view_control_message.xml +++ b/app/src/main/res/layout/view_control_message.xml @@ -1,28 +1,40 @@ - + android:paddingVertical="@dimen/medium_spacing"> + + + app:tint="@color/text" + tools:src="@drawable/ic_timer" /> + tools:text="@string/MessageRecord_you_disabled_disappearing_messages" /> \ No newline at end of file