Fix unread status in sent messages (#2048)

This commit is contained in:
Mikołaj Pich 2022-11-16 12:54:55 +01:00 committed by GitHub
parent 4d49e956b8
commit db4f172fb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 2451 additions and 10 deletions

View File

@ -186,7 +186,7 @@ ext {
} }
dependencies { dependencies {
implementation "io.github.wulkanowy:sdk:2840d9d6d0" implementation "io.github.wulkanowy:sdk:701016eda2"
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.8' coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.8'

File diff suppressed because it is too large Load Diff

View File

@ -47,6 +47,7 @@ import javax.inject.Singleton
AutoMigration(from = 44, to = 45), AutoMigration(from = 44, to = 45),
AutoMigration(from = 46, to = 47), AutoMigration(from = 46, to = 47),
AutoMigration(from = 47, to = 48), AutoMigration(from = 47, to = 48),
AutoMigration(from = 51, to = 52),
], ],
version = AppDatabase.VERSION_SCHEMA, version = AppDatabase.VERSION_SCHEMA,
exportSchema = true exportSchema = true
@ -55,7 +56,7 @@ import javax.inject.Singleton
abstract class AppDatabase : RoomDatabase() { abstract class AppDatabase : RoomDatabase() {
companion object { companion object {
const val VERSION_SCHEMA = 51 const val VERSION_SCHEMA = 52
fun getMigrations(sharedPrefProvider: SharedPrefProvider, appInfo: AppInfo) = arrayOf( fun getMigrations(sharedPrefProvider: SharedPrefProvider, appInfo: AppInfo) = arrayOf(
Migration2(), Migration2(),

View File

@ -29,6 +29,12 @@ data class Message(
var unread: Boolean, var unread: Boolean,
@ColumnInfo(name = "read_by")
val readBy: Int?,
@ColumnInfo(name = "unread_by")
val unreadBy: Int?,
@ColumnInfo(name = "has_attachments") @ColumnInfo(name = "has_attachments")
val hasAttachments: Boolean val hasAttachments: Boolean
) : Serializable { ) : Serializable {

View File

@ -16,7 +16,9 @@ fun List<SdkMessage>.mapToEntities(mailbox: Mailbox) = map {
date = it.dateZoned.toInstant(), date = it.dateZoned.toInstant(),
folderId = it.folderId, folderId = it.folderId,
unread = it.unread, unread = it.unread,
hasAttachments = it.hasAttachments unreadBy = it.unreadBy,
readBy = it.readBy,
hasAttachments = it.hasAttachments,
).apply { ).apply {
content = it.content.orEmpty() content = it.content.orEmpty()
} }

View File

@ -22,6 +22,8 @@ private fun generateMessage(sender: String, subject: String) = Message(
date = Instant.now(), date = Instant.now(),
folderId = 0, folderId = 0,
unread = true, unread = true,
readBy = 2,
unreadBy = 2,
hasAttachments = false, hasAttachments = false,
messageGlobalKey = "", messageGlobalKey = "",
correspondents = sender, correspondents = sender,

View File

@ -1,6 +1,5 @@
package io.github.wulkanowy.ui.modules.message.preview package io.github.wulkanowy.ui.modules.message.preview
import android.annotation.SuppressLint
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
@ -74,15 +73,20 @@ class MessagePreviewAdapter @Inject constructor() :
} }
} }
@SuppressLint("SetTextI18n")
private fun bindMessage(holder: MessageViewHolder, message: Message) { private fun bindMessage(holder: MessageViewHolder, message: Message) {
val context = holder.binding.root.context val context = holder.binding.root.context
val recipientCount = (message.unreadBy ?: 0) + (message.readBy ?: 0)
val isReceived = message.unreadBy == null
val readTextValue = when { val readText = when {
!message.unread -> R.string.all_yes recipientCount > 1 -> {
else -> R.string.all_no context.getString(R.string.message_read_by, message.readBy, recipientCount)
}
message.readBy == 1 || (isReceived && !message.unread) -> {
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))
} }
val readText = context.getString(R.string.message_read, context.getString(readTextValue))
with(holder.binding) { with(holder.binding) {
messagePreviewSubject.text = message.subject.ifBlank { messagePreviewSubject.text = message.subject.ifBlank {

View File

@ -304,6 +304,7 @@
<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> <string name="message_read">Read: %s</string>
<string name="message_read_by">Read by: %1$d of %2$d people</string>
<plurals name="message_number_item"> <plurals name="message_number_item">
<item quantity="one">%1$d message</item> <item quantity="one">%1$d message</item>
<item quantity="other">%1$d messages</item> <item quantity="other">%1$d messages</item>

View File

@ -193,7 +193,9 @@ class MessageRepositoryTest {
date = Instant.EPOCH, date = Instant.EPOCH,
folderId = 1, folderId = 1,
unread = unread, unread = unread,
hasAttachments = false readBy = 1,
unreadBy = 1,
hasAttachments = false,
).apply { ).apply {
this.content = content this.content = content
} }
@ -209,6 +211,8 @@ class MessageRepositoryTest {
dateZoned = Instant.EPOCH.atZone(ZoneOffset.UTC), dateZoned = Instant.EPOCH.atZone(ZoneOffset.UTC),
folderId = 1, folderId = 1,
unread = true, unread = true,
readBy = 1,
unreadBy = 1,
hasAttachments = false, hasAttachments = false,
) )
} }