mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2025-01-31 21:02:45 +01:00
Show information when the recipient has read the message (#1430)
This commit is contained in:
parent
aba2068a84
commit
2979d8b62a
@ -20,14 +20,12 @@ import io.github.wulkanowy.data.pojos.MessageDraftJsonAdapter
|
|||||||
import io.github.wulkanowy.sdk.Sdk
|
import io.github.wulkanowy.sdk.Sdk
|
||||||
import io.github.wulkanowy.sdk.pojo.Folder
|
import io.github.wulkanowy.sdk.pojo.Folder
|
||||||
import io.github.wulkanowy.sdk.pojo.SentMessage
|
import io.github.wulkanowy.sdk.pojo.SentMessage
|
||||||
import io.github.wulkanowy.ui.modules.message.send.RecipientChipItem
|
|
||||||
import io.github.wulkanowy.utils.AutoRefreshHelper
|
import io.github.wulkanowy.utils.AutoRefreshHelper
|
||||||
import io.github.wulkanowy.utils.getRefreshKey
|
import io.github.wulkanowy.utils.getRefreshKey
|
||||||
import io.github.wulkanowy.utils.init
|
import io.github.wulkanowy.utils.init
|
||||||
import io.github.wulkanowy.utils.networkBoundResource
|
import io.github.wulkanowy.utils.networkBoundResource
|
||||||
import io.github.wulkanowy.utils.uniqueSubtract
|
import io.github.wulkanowy.utils.uniqueSubtract
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.map
|
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.time.LocalDateTime.now
|
import java.time.LocalDateTime.now
|
||||||
@ -79,8 +77,9 @@ class MessageRepository @Inject constructor(
|
|||||||
},
|
},
|
||||||
saveFetchResult = { old, (downloadedMessage, attachments) ->
|
saveFetchResult = { old, (downloadedMessage, attachments) ->
|
||||||
checkNotNull(old, { "Fetched message no longer exist!" })
|
checkNotNull(old, { "Fetched message no longer exist!" })
|
||||||
messagesDb.updateAll(listOf(old.message.copy(unread = !markAsRead).apply {
|
messagesDb.updateAll(listOf(old.message.apply {
|
||||||
id = old.message.id
|
id = old.message.id
|
||||||
|
unread = !markAsRead
|
||||||
content = content.ifBlank { downloadedMessage }
|
content = content.ifBlank { downloadedMessage }
|
||||||
}))
|
}))
|
||||||
messageAttachmentDao.insertAttachments(attachments)
|
messageAttachmentDao.insertAttachments(attachments)
|
||||||
|
@ -33,7 +33,8 @@ class MessagePreviewAdapter @Inject constructor() :
|
|||||||
|
|
||||||
private var attachments: List<MessageAttachment> = emptyList()
|
private var attachments: List<MessageAttachment> = emptyList()
|
||||||
|
|
||||||
override fun getItemCount() = if (messageWithAttachment == null) 0 else attachments.size + 1 + if (attachments.isNotEmpty()) 1 else 0
|
override fun getItemCount() =
|
||||||
|
if (messageWithAttachment == null) 0 else attachments.size + 1 + if (attachments.isNotEmpty()) 1 else 0
|
||||||
|
|
||||||
override fun getItemViewType(position: Int) = when (position) {
|
override fun getItemViewType(position: Int) = when (position) {
|
||||||
0 -> ViewType.MESSAGE.id
|
0 -> ViewType.MESSAGE.id
|
||||||
@ -45,25 +46,60 @@ class MessagePreviewAdapter @Inject constructor() :
|
|||||||
val inflater = LayoutInflater.from(parent.context)
|
val inflater = LayoutInflater.from(parent.context)
|
||||||
|
|
||||||
return when (viewType) {
|
return when (viewType) {
|
||||||
ViewType.MESSAGE.id -> MessageViewHolder(ItemMessagePreviewBinding.inflate(inflater, parent, false))
|
ViewType.MESSAGE.id -> MessageViewHolder(
|
||||||
ViewType.DIVIDER.id -> DividerViewHolder(ItemMessageDividerBinding.inflate(inflater, parent, false))
|
ItemMessagePreviewBinding.inflate(inflater, parent, false)
|
||||||
ViewType.ATTACHMENT.id -> AttachmentViewHolder(ItemMessageAttachmentBinding.inflate(inflater, parent, false))
|
)
|
||||||
|
ViewType.DIVIDER.id -> DividerViewHolder(
|
||||||
|
ItemMessageDividerBinding.inflate(inflater, parent, false)
|
||||||
|
)
|
||||||
|
ViewType.ATTACHMENT.id -> AttachmentViewHolder(
|
||||||
|
ItemMessageAttachmentBinding.inflate(inflater, parent, false)
|
||||||
|
)
|
||||||
else -> throw IllegalStateException()
|
else -> throw IllegalStateException()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
||||||
when (holder) {
|
when (holder) {
|
||||||
is MessageViewHolder -> bindMessage(holder, requireNotNull(messageWithAttachment).message)
|
is MessageViewHolder -> bindMessage(
|
||||||
is AttachmentViewHolder -> bindAttachment(holder, requireNotNull(messageWithAttachment).attachments[position - 2])
|
holder,
|
||||||
|
requireNotNull(messageWithAttachment).message
|
||||||
|
)
|
||||||
|
is AttachmentViewHolder -> bindAttachment(
|
||||||
|
holder,
|
||||||
|
requireNotNull(messageWithAttachment).attachments[position - 2]
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("SetTextI18n")
|
@SuppressLint("SetTextI18n")
|
||||||
private fun bindMessage(holder: MessageViewHolder, message: Message) {
|
private fun bindMessage(holder: MessageViewHolder, message: Message) {
|
||||||
|
val context = holder.binding.root.context
|
||||||
|
val recipientCount = message.unreadBy + message.readBy
|
||||||
|
|
||||||
|
val readText = when {
|
||||||
|
recipientCount > 1 -> {
|
||||||
|
context.resources.getQuantityString(
|
||||||
|
R.plurals.message_read_by,
|
||||||
|
message.readBy,
|
||||||
|
message.readBy,
|
||||||
|
recipientCount
|
||||||
|
)
|
||||||
|
}
|
||||||
|
message.readBy == 1 -> {
|
||||||
|
context.getString(R.string.message_read, context.getString(R.string.all_yes))
|
||||||
|
}
|
||||||
|
else -> context.getString(R.string.message_read, context.getString(R.string.all_no))
|
||||||
|
}
|
||||||
|
|
||||||
with(holder.binding) {
|
with(holder.binding) {
|
||||||
messagePreviewSubject.text = message.subject.ifBlank { root.context.getString(R.string.message_no_subject) }
|
messagePreviewSubject.text =
|
||||||
messagePreviewDate.text = root.context.getString(R.string.message_date, message.date.toFormattedString("yyyy-MM-dd HH:mm:ss"))
|
message.subject.ifBlank { root.context.getString(R.string.message_no_subject) }
|
||||||
|
messagePreviewDate.text = root.context.getString(
|
||||||
|
R.string.message_date,
|
||||||
|
message.date.toFormattedString("yyyy-MM-dd HH:mm:ss")
|
||||||
|
)
|
||||||
|
messagePreviewRead.text = readText
|
||||||
messagePreviewContent.text = message.content
|
messagePreviewContent.text = message.content
|
||||||
messagePreviewFromSender.text = message.sender
|
messagePreviewFromSender.text = message.sender
|
||||||
messagePreviewToRecipient.text = message.recipient
|
messagePreviewToRecipient.text = message.recipient
|
||||||
|
@ -78,6 +78,17 @@
|
|||||||
app:layout_constraintTop_toBottomOf="@id/messagePreviewToLabel"
|
app:layout_constraintTop_toBottomOf="@id/messagePreviewToLabel"
|
||||||
tools:text="@tools:sample/date/ddmmyy" />
|
tools:text="@tools:sample/date/ddmmyy" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/messagePreviewRead"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="4dp"
|
||||||
|
android:textColor="?android:textColorSecondary"
|
||||||
|
android:textSize="15sp"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/messagePreviewDate"
|
||||||
|
tools:text="Read: Yes" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/messagePreviewContent"
|
android:id="@+id/messagePreviewContent"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
@ -88,6 +99,6 @@
|
|||||||
android:textIsSelectable="true"
|
android:textIsSelectable="true"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/messagePreviewDate"
|
app:layout_constraintTop_toBottomOf="@+id/messagePreviewRead"
|
||||||
tools:text="@tools:sample/lorem/random" />
|
tools:text="@tools:sample/lorem/random" />
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
@ -101,7 +101,7 @@
|
|||||||
<string name="grade_summary_predicted_grade">Predicted grade</string>
|
<string name="grade_summary_predicted_grade">Predicted grade</string>
|
||||||
<string name="grade_summary_calculated_average">Calculated average</string>
|
<string name="grade_summary_calculated_average">Calculated average</string>
|
||||||
<string name="grade_summary_final_average">Final average</string>
|
<string name="grade_summary_final_average">Final average</string>
|
||||||
<string name="grade_summary_from_subjects">From %d of %d subjects</string>
|
<string name="grade_summary_from_subjects">From %1$d of %2$d subjects</string>
|
||||||
<string name="grade_menu_summary">Summary</string>
|
<string name="grade_menu_summary">Summary</string>
|
||||||
<string name="grade_menu_statistics">Class</string>
|
<string name="grade_menu_statistics">Class</string>
|
||||||
<string name="grade_menu_read">Mark as read</string>
|
<string name="grade_menu_read">Mark as read</string>
|
||||||
@ -237,6 +237,11 @@
|
|||||||
<string name="message_content_min_length">The message content must be at least 3 characters</string>
|
<string name="message_content_min_length">The message content must be at least 3 characters</string>
|
||||||
<string name="message_chip_only_unread">Only unread</string>
|
<string name="message_chip_only_unread">Only unread</string>
|
||||||
<string name="message_chip_only_with_attachments">Only with attachments</string>
|
<string name="message_chip_only_with_attachments">Only with attachments</string>
|
||||||
|
<string name="message_read">Read: %s</string>
|
||||||
|
<plurals name="message_read_by">
|
||||||
|
<item quantity="one">Read by: %1$d of %2$d people</item>
|
||||||
|
<item quantity="other">Read by: %1$d of %2$d people</item>
|
||||||
|
</plurals>
|
||||||
<plurals name="message_number_item">
|
<plurals name="message_number_item">
|
||||||
<item quantity="one">%d message</item>
|
<item quantity="one">%d message</item>
|
||||||
<item quantity="other">%d messages</item>
|
<item quantity="other">%d messages</item>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user