mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-23 18:15:22 +00:00
Add message date break extension function to reduce duplication
This commit is contained in:
parent
a966623db2
commit
ba51102b6d
@ -1,5 +0,0 @@
|
|||||||
package org.thoughtcrime.securesms.conversation.v2
|
|
||||||
|
|
||||||
object ConversationConstants {
|
|
||||||
const val MAX_TIME_BETWEEN_BREAKS = 5 * 60 * 1000L // 5 minutes
|
|
||||||
}
|
|
@ -6,14 +6,10 @@ 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.conversation.v2.ConversationConstants.MAX_TIME_BETWEEN_BREAKS
|
|
||||||
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 {
|
||||||
|
|
||||||
@ -30,9 +26,7 @@ class ControlMessageView : LinearLayout {
|
|||||||
|
|
||||||
// region Updating
|
// region Updating
|
||||||
fun bind(message: MessageRecord, previous: MessageRecord?) {
|
fun bind(message: MessageRecord, previous: MessageRecord?) {
|
||||||
val showDateBreak = (previous == null || message.timestamp - previous.timestamp > MAX_TIME_BETWEEN_BREAKS)
|
dateBreakTextView.showDateBreak(message, previous)
|
||||||
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))
|
||||||
|
@ -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 ""
|
||||||
|
}
|
@ -25,7 +25,6 @@ import org.session.libsession.messaging.open_groups.OpenGroupAPIV2
|
|||||||
import org.session.libsession.utilities.ViewUtil
|
import org.session.libsession.utilities.ViewUtil
|
||||||
import org.session.libsignal.utilities.ThreadUtils
|
import org.session.libsignal.utilities.ThreadUtils
|
||||||
import org.thoughtcrime.securesms.ApplicationContext
|
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.*
|
||||||
import org.thoughtcrime.securesms.database.model.MessageRecord
|
import org.thoughtcrime.securesms.database.model.MessageRecord
|
||||||
import org.thoughtcrime.securesms.home.UserDetailsBottomSheet
|
import org.thoughtcrime.securesms.home.UserDetailsBottomSheet
|
||||||
@ -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 > MAX_TIME_BETWEEN_BREAKS)
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user