mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 01:07:47 +00:00
Merge pull request #804 from ceokot/fix_control_message_date_breaks
fix: Add date breaks on control messages
This commit is contained in:
commit
6a11c0d375
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
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
|
||||||
@ -27,7 +25,8 @@ class ControlMessageView : LinearLayout {
|
|||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
// region Updating
|
// region Updating
|
||||||
fun bind(message: MessageRecord) {
|
fun bind(message: MessageRecord, previous: MessageRecord?) {
|
||||||
|
dateBreakTextView.showDateBreak(message, previous)
|
||||||
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))
|
||||||
|
@ -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 ""
|
||||||
|
}
|
@ -69,7 +69,6 @@ class VisibleMessageView : LinearLayout {
|
|||||||
const val longPressMovementTreshold = 10.0f // dp
|
const val longPressMovementTreshold = 10.0f // dp
|
||||||
const val longPressDurationThreshold = 250L // ms
|
const val longPressDurationThreshold = 250L // ms
|
||||||
const val maxDoubleTapInterval = 200L
|
const val maxDoubleTapInterval = 200L
|
||||||
const val maxTimeBetweenBreaks = 5 * 60 * 1000L // 5 minutes
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// region Lifecycle
|
// region Lifecycle
|
||||||
@ -120,9 +119,7 @@ class VisibleMessageView : LinearLayout {
|
|||||||
senderNameTextView.visibility = View.GONE
|
senderNameTextView.visibility = View.GONE
|
||||||
}
|
}
|
||||||
// Date break
|
// Date break
|
||||||
val showDateBreak = (previous == null || message.timestamp - previous.timestamp > maxTimeBetweenBreaks)
|
dateBreakTextView.showDateBreak(message, previous)
|
||||||
dateBreakTextView.isVisible = showDateBreak
|
|
||||||
dateBreakTextView.text = if (showDateBreak) DateUtils.getDisplayFormattedTimeSpanString(context, Locale.getDefault(), message.timestamp) else ""
|
|
||||||
// Timestamp
|
// Timestamp
|
||||||
messageTimestampTextView.text = DateUtils.getDisplayFormattedTimeSpanString(context, Locale.getDefault(), message.timestamp)
|
messageTimestampTextView.text = DateUtils.getDisplayFormattedTimeSpanString(context, Locale.getDefault(), message.timestamp)
|
||||||
// Margins
|
// Margins
|
||||||
|
@ -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>
|
Loading…
x
Reference in New Issue
Block a user