forked from upstream-mirrors/quik
Autoformat
This commit is contained in:
@@ -66,12 +66,12 @@ import java.util.concurrent.TimeUnit
|
|||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class MessagesAdapter @Inject constructor(
|
class MessagesAdapter @Inject constructor(
|
||||||
|
subscriptionManager: SubscriptionManagerCompat,
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
private val colors: Colors,
|
private val colors: Colors,
|
||||||
private val dateFormatter: DateFormatter,
|
private val dateFormatter: DateFormatter,
|
||||||
private val navigator: Navigator,
|
private val navigator: Navigator,
|
||||||
private val prefs: Preferences,
|
private val prefs: Preferences
|
||||||
private val subscriptionManager: SubscriptionManagerCompat
|
|
||||||
) : QkRealmAdapter<Message>() {
|
) : QkRealmAdapter<Message>() {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@@ -79,8 +79,8 @@ class MessagesAdapter @Inject constructor(
|
|||||||
private const val VIEW_TYPE_MESSAGE_OUT = 1
|
private const val VIEW_TYPE_MESSAGE_OUT = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
val clicks: Subject<Message> = PublishSubject.create<Message>()
|
val clicks: Subject<Message> = PublishSubject.create()
|
||||||
val cancelSending: Subject<Message> = PublishSubject.create<Message>()
|
val cancelSending: Subject<Message> = PublishSubject.create()
|
||||||
|
|
||||||
var data: Pair<Conversation, RealmResults<Message>>? = null
|
var data: Pair<Conversation, RealmResults<Message>>? = null
|
||||||
set(value) {
|
set(value) {
|
||||||
@@ -176,11 +176,9 @@ class MessagesAdapter @Inject constructor(
|
|||||||
val next = if (position == itemCount - 1) null else getItem(position + 1)
|
val next = if (position == itemCount - 1) null else getItem(position + 1)
|
||||||
val view = viewHolder.containerView
|
val view = viewHolder.containerView
|
||||||
|
|
||||||
|
|
||||||
// Update the selected state
|
// Update the selected state
|
||||||
view.isActivated = isSelected(message.id) || highlight == message.id
|
view.isActivated = isSelected(message.id) || highlight == message.id
|
||||||
|
|
||||||
|
|
||||||
// Bind the cancel view
|
// Bind the cancel view
|
||||||
view.findViewById<ProgressBar>(R.id.cancel)?.let { cancel ->
|
view.findViewById<ProgressBar>(R.id.cancel)?.let { cancel ->
|
||||||
val isCancellable = message.isSending() && message.date > System.currentTimeMillis()
|
val isCancellable = message.isSending() && message.date > System.currentTimeMillis()
|
||||||
@@ -203,11 +201,9 @@ class MessagesAdapter @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Bind the message status
|
// Bind the message status
|
||||||
bindStatus(viewHolder, message, next)
|
bindStatus(viewHolder, message, next)
|
||||||
|
|
||||||
|
|
||||||
// Bind the timestamp
|
// Bind the timestamp
|
||||||
val timeSincePrevious = TimeUnit.MILLISECONDS.toMinutes(message.date - (previous?.date ?: 0))
|
val timeSincePrevious = TimeUnit.MILLISECONDS.toMinutes(message.date - (previous?.date ?: 0))
|
||||||
val simIndex = subs.takeIf { it.size > 1 }?.indexOfFirst { it.subscriptionId == message.subId } ?: -1
|
val simIndex = subs.takeIf { it.size > 1 }?.indexOfFirst { it.subscriptionId == message.subId } ?: -1
|
||||||
@@ -215,16 +211,15 @@ class MessagesAdapter @Inject constructor(
|
|||||||
view.timestamp.text = dateFormatter.getMessageTimestamp(message.date)
|
view.timestamp.text = dateFormatter.getMessageTimestamp(message.date)
|
||||||
view.simIndex.text = "${simIndex + 1}"
|
view.simIndex.text = "${simIndex + 1}"
|
||||||
|
|
||||||
view.timestamp.setVisible(timeSincePrevious >= BubbleUtils.TIMESTAMP_THRESHOLD || message.subId != previous?.subId && simIndex != -1)
|
view.timestamp.setVisible(timeSincePrevious >= BubbleUtils.TIMESTAMP_THRESHOLD
|
||||||
|
|| message.subId != previous?.subId && simIndex != -1)
|
||||||
view.sim.setVisible(message.subId != previous?.subId && simIndex != -1)
|
view.sim.setVisible(message.subId != previous?.subId && simIndex != -1)
|
||||||
view.simIndex.setVisible(message.subId != previous?.subId && simIndex != -1)
|
view.simIndex.setVisible(message.subId != previous?.subId && simIndex != -1)
|
||||||
|
|
||||||
|
|
||||||
// Bind the grouping
|
// Bind the grouping
|
||||||
val media = message.parts.filter { it.isImage() || it.isVideo() || it.isVCard() }
|
val media = message.parts.filter { it.isImage() || it.isVideo() || it.isVCard() }
|
||||||
view.setPadding(bottom = if (canGroup(message, next)) 0 else 16.dpToPx(context))
|
view.setPadding(bottom = if (canGroup(message, next)) 0 else 16.dpToPx(context))
|
||||||
|
|
||||||
|
|
||||||
// Bind the avatar
|
// Bind the avatar
|
||||||
if (!message.isMe()) {
|
if (!message.isMe()) {
|
||||||
view.avatar.threadId = conversation?.id ?: 0
|
view.avatar.threadId = conversation?.id ?: 0
|
||||||
@@ -232,7 +227,6 @@ class MessagesAdapter @Inject constructor(
|
|||||||
view.avatar.setVisible(!canGroup(message, next), View.INVISIBLE)
|
view.avatar.setVisible(!canGroup(message, next), View.INVISIBLE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Bind the body text
|
// Bind the body text
|
||||||
view.body.text = when (message.isSms()) {
|
view.body.text = when (message.isSms()) {
|
||||||
true -> message.body
|
true -> message.body
|
||||||
@@ -247,7 +241,8 @@ class MessagesAdapter @Inject constructor(
|
|||||||
when {
|
when {
|
||||||
subject.isNotBlank() -> {
|
subject.isNotBlank() -> {
|
||||||
val spannable = SpannableString(if (body.isNotBlank()) "$subject\n$body" else subject)
|
val spannable = SpannableString(if (body.isNotBlank()) "$subject\n$body" else subject)
|
||||||
spannable.setSpan(StyleSpan(Typeface.BOLD), 0, subject.length, Spannable.SPAN_INCLUSIVE_EXCLUSIVE)
|
spannable.setSpan(StyleSpan(Typeface.BOLD), 0, subject.length,
|
||||||
|
Spannable.SPAN_INCLUSIVE_EXCLUSIVE)
|
||||||
spannable
|
spannable
|
||||||
}
|
}
|
||||||
else -> body
|
else -> body
|
||||||
@@ -260,7 +255,6 @@ class MessagesAdapter @Inject constructor(
|
|||||||
canGroupWithNext = canGroup(message, next),
|
canGroupWithNext = canGroup(message, next),
|
||||||
isMe = message.isMe()))
|
isMe = message.isMe()))
|
||||||
|
|
||||||
|
|
||||||
// Bind the attachments
|
// Bind the attachments
|
||||||
val partsAdapter = view.attachments.adapter as PartsAdapter
|
val partsAdapter = view.attachments.adapter as PartsAdapter
|
||||||
partsAdapter.setData(message, previous, next, view)
|
partsAdapter.setData(message, previous, next, view)
|
||||||
@@ -273,7 +267,8 @@ class MessagesAdapter @Inject constructor(
|
|||||||
|
|
||||||
view.status.text = when {
|
view.status.text = when {
|
||||||
message.isSending() -> context.getString(R.string.message_status_sending)
|
message.isSending() -> context.getString(R.string.message_status_sending)
|
||||||
message.isDelivered() -> context.getString(R.string.message_status_delivered, dateFormatter.getTimestamp(message.dateSent))
|
message.isDelivered() -> context.getString(R.string.message_status_delivered,
|
||||||
|
dateFormatter.getTimestamp(message.dateSent))
|
||||||
message.isFailedMessage() -> context.getString(R.string.message_status_failed)
|
message.isFailedMessage() -> context.getString(R.string.message_status_failed)
|
||||||
|
|
||||||
// Incoming group message
|
// Incoming group message
|
||||||
|
|||||||
Reference in New Issue
Block a user