From bfe91427abe63cc3cde69e5f47f60deb48e268b9 Mon Sep 17 00:00:00 2001 From: ceokot Date: Fri, 3 Dec 2021 07:51:21 +0200 Subject: [PATCH 1/3] fix: Add date breaks on control messages --- .../conversation/v2/ConversationAdapter.kt | 7 +++-- .../v2/messages/ControlMessageView.kt | 10 +++++-- .../main/res/layout/view_control_message.xml | 28 +++++++++++++------ 3 files changed, 31 insertions(+), 14 deletions(-) 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..75f5af85f6 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,17 +1,18 @@ 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 import androidx.core.content.res.ResourcesCompat +import androidx.core.view.isVisible import androidx.recyclerview.widget.RecyclerView import kotlinx.android.synthetic.main.view_control_message.view.* import network.loki.messenger.R import org.thoughtcrime.securesms.database.model.MessageRecord +import org.thoughtcrime.securesms.util.DateUtils +import java.util.Locale class ControlMessageView : LinearLayout { @@ -27,7 +28,10 @@ class ControlMessageView : LinearLayout { // endregion // 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 if (message.isExpirationTimerUpdate) { iconImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ic_timer, context.theme)) 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 From a966623db2db1febd35819ac327296fbac8d3fe5 Mon Sep 17 00:00:00 2001 From: ceokot Date: Mon, 6 Dec 2021 06:07:46 +0200 Subject: [PATCH 2/3] Add conversation constants file --- .../securesms/conversation/v2/ConversationConstants.kt | 5 +++++ .../securesms/conversation/v2/messages/ControlMessageView.kt | 3 ++- .../securesms/conversation/v2/messages/VisibleMessageView.kt | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationConstants.kt diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationConstants.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationConstants.kt new file mode 100644 index 0000000000..9e893ef89f --- /dev/null +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationConstants.kt @@ -0,0 +1,5 @@ +package org.thoughtcrime.securesms.conversation.v2 + +object ConversationConstants { + const val MAX_TIME_BETWEEN_BREAKS = 5 * 60 * 1000L // 5 minutes +} \ No newline at end of file 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 75f5af85f6..76215040d2 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 @@ -10,6 +10,7 @@ import androidx.core.view.isVisible import androidx.recyclerview.widget.RecyclerView import kotlinx.android.synthetic.main.view_control_message.view.* import network.loki.messenger.R +import org.thoughtcrime.securesms.conversation.v2.ConversationConstants.MAX_TIME_BETWEEN_BREAKS import org.thoughtcrime.securesms.database.model.MessageRecord import org.thoughtcrime.securesms.util.DateUtils import java.util.Locale @@ -29,7 +30,7 @@ class ControlMessageView : LinearLayout { // region Updating fun bind(message: MessageRecord, previous: MessageRecord?) { - val showDateBreak = (previous == null || message.timestamp - previous.timestamp > VisibleMessageView.maxTimeBetweenBreaks) + val showDateBreak = (previous == null || message.timestamp - previous.timestamp > MAX_TIME_BETWEEN_BREAKS) dateBreakTextView.isVisible = showDateBreak dateBreakTextView.text = if (showDateBreak) DateUtils.getDisplayFormattedTimeSpanString(context, Locale.getDefault(), message.timestamp) else "" iconImageView.visibility = View.GONE 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..64db47c5f5 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 @@ -25,6 +25,7 @@ import org.session.libsession.messaging.open_groups.OpenGroupAPIV2 import org.session.libsession.utilities.ViewUtil import org.session.libsignal.utilities.ThreadUtils import org.thoughtcrime.securesms.ApplicationContext +import org.thoughtcrime.securesms.conversation.v2.ConversationConstants.MAX_TIME_BETWEEN_BREAKS import org.thoughtcrime.securesms.database.* import org.thoughtcrime.securesms.database.model.MessageRecord import org.thoughtcrime.securesms.home.UserDetailsBottomSheet @@ -69,7 +70,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,7 +120,7 @@ class VisibleMessageView : LinearLayout { senderNameTextView.visibility = View.GONE } // Date break - val showDateBreak = (previous == null || message.timestamp - previous.timestamp > maxTimeBetweenBreaks) + val showDateBreak = (previous == null || message.timestamp - previous.timestamp > MAX_TIME_BETWEEN_BREAKS) dateBreakTextView.isVisible = showDateBreak dateBreakTextView.text = if (showDateBreak) DateUtils.getDisplayFormattedTimeSpanString(context, Locale.getDefault(), message.timestamp) else "" // Timestamp From ba51102b6d8cf8b4494ef4105a77a17700ab6052 Mon Sep 17 00:00:00 2001 From: ceokot Date: Mon, 6 Dec 2021 06:34:32 +0200 Subject: [PATCH 3/3] Add message date break extension function to reduce duplication --- .../conversation/v2/ConversationConstants.kt | 5 ----- .../v2/messages/ControlMessageView.kt | 8 +------- .../conversation/v2/messages/MessageUtilities.kt | 15 +++++++++++++++ .../v2/messages/VisibleMessageView.kt | 5 +---- 4 files changed, 17 insertions(+), 16 deletions(-) delete mode 100644 app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationConstants.kt create mode 100644 app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/MessageUtilities.kt diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationConstants.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationConstants.kt deleted file mode 100644 index 9e893ef89f..0000000000 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationConstants.kt +++ /dev/null @@ -1,5 +0,0 @@ -package org.thoughtcrime.securesms.conversation.v2 - -object ConversationConstants { - const val MAX_TIME_BETWEEN_BREAKS = 5 * 60 * 1000L // 5 minutes -} \ No newline at end of file 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 76215040d2..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 @@ -6,14 +6,10 @@ import android.view.LayoutInflater import android.view.View import android.widget.LinearLayout import androidx.core.content.res.ResourcesCompat -import androidx.core.view.isVisible import androidx.recyclerview.widget.RecyclerView import kotlinx.android.synthetic.main.view_control_message.view.* import network.loki.messenger.R -import org.thoughtcrime.securesms.conversation.v2.ConversationConstants.MAX_TIME_BETWEEN_BREAKS import org.thoughtcrime.securesms.database.model.MessageRecord -import org.thoughtcrime.securesms.util.DateUtils -import java.util.Locale class ControlMessageView : LinearLayout { @@ -30,9 +26,7 @@ class ControlMessageView : LinearLayout { // region Updating fun bind(message: MessageRecord, previous: MessageRecord?) { - val showDateBreak = (previous == null || message.timestamp - previous.timestamp > MAX_TIME_BETWEEN_BREAKS) - dateBreakTextView.isVisible = showDateBreak - dateBreakTextView.text = if (showDateBreak) DateUtils.getDisplayFormattedTimeSpanString(context, Locale.getDefault(), message.timestamp) else "" + 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 64db47c5f5..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 @@ -25,7 +25,6 @@ import org.session.libsession.messaging.open_groups.OpenGroupAPIV2 import org.session.libsession.utilities.ViewUtil import org.session.libsignal.utilities.ThreadUtils import org.thoughtcrime.securesms.ApplicationContext -import org.thoughtcrime.securesms.conversation.v2.ConversationConstants.MAX_TIME_BETWEEN_BREAKS import org.thoughtcrime.securesms.database.* import org.thoughtcrime.securesms.database.model.MessageRecord import org.thoughtcrime.securesms.home.UserDetailsBottomSheet @@ -120,9 +119,7 @@ class VisibleMessageView : LinearLayout { senderNameTextView.visibility = View.GONE } // Date break - val showDateBreak = (previous == null || message.timestamp - previous.timestamp > MAX_TIME_BETWEEN_BREAKS) - 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