forked from upstream-mirrors/quik
Sort drafts first, save drafts for new conversations, show drafts in widget
Closes #1296
This commit is contained in:
@@ -58,11 +58,18 @@ class ConversationRepositoryImpl @Inject constructor(
|
|||||||
return Realm.getDefaultInstance()
|
return Realm.getDefaultInstance()
|
||||||
.where(Conversation::class.java)
|
.where(Conversation::class.java)
|
||||||
.notEqualTo("id", 0L)
|
.notEqualTo("id", 0L)
|
||||||
.isNotNull("lastMessage")
|
|
||||||
.equalTo("archived", archived)
|
.equalTo("archived", archived)
|
||||||
.equalTo("blocked", false)
|
.equalTo("blocked", false)
|
||||||
.isNotEmpty("recipients")
|
.isNotEmpty("recipients")
|
||||||
.sort("pinned", Sort.DESCENDING, "lastMessage.date", Sort.DESCENDING)
|
.beginGroup()
|
||||||
|
.isNotNull("lastMessage")
|
||||||
|
.or()
|
||||||
|
.isNotEmpty("draft")
|
||||||
|
.endGroup()
|
||||||
|
.sort(
|
||||||
|
arrayOf("pinned", "draft", "lastMessage.date"),
|
||||||
|
arrayOf(Sort.DESCENDING, Sort.DESCENDING, Sort.DESCENDING)
|
||||||
|
)
|
||||||
.findAllAsync()
|
.findAllAsync()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,11 +78,18 @@ class ConversationRepositoryImpl @Inject constructor(
|
|||||||
realm.refresh()
|
realm.refresh()
|
||||||
realm.copyFromRealm(realm.where(Conversation::class.java)
|
realm.copyFromRealm(realm.where(Conversation::class.java)
|
||||||
.notEqualTo("id", 0L)
|
.notEqualTo("id", 0L)
|
||||||
.isNotNull("lastMessage")
|
|
||||||
.equalTo("archived", false)
|
.equalTo("archived", false)
|
||||||
.equalTo("blocked", false)
|
.equalTo("blocked", false)
|
||||||
.isNotEmpty("recipients")
|
.isNotEmpty("recipients")
|
||||||
.sort("pinned", Sort.DESCENDING, "lastMessage.date", Sort.DESCENDING)
|
.beginGroup()
|
||||||
|
.isNotNull("lastMessage")
|
||||||
|
.or()
|
||||||
|
.isNotEmpty("draft")
|
||||||
|
.endGroup()
|
||||||
|
.sort(
|
||||||
|
arrayOf("pinned", "draft", "lastMessage.date"),
|
||||||
|
arrayOf(Sort.DESCENDING, Sort.DESCENDING, Sort.DESCENDING)
|
||||||
|
)
|
||||||
.findAll())
|
.findAll())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -86,7 +86,6 @@ class ConversationsAdapter @Inject constructor(
|
|||||||
|
|
||||||
override fun onBindViewHolder(viewHolder: QkViewHolder, position: Int) {
|
override fun onBindViewHolder(viewHolder: QkViewHolder, position: Int) {
|
||||||
val conversation = getItem(position) ?: return
|
val conversation = getItem(position) ?: return
|
||||||
val lastMessage = conversation.lastMessage ?: return
|
|
||||||
val view = viewHolder.containerView
|
val view = viewHolder.containerView
|
||||||
|
|
||||||
view.isActivated = isSelected(conversation.id)
|
view.isActivated = isSelected(conversation.id)
|
||||||
@@ -94,7 +93,7 @@ class ConversationsAdapter @Inject constructor(
|
|||||||
view.avatars.recipients = conversation.recipients
|
view.avatars.recipients = conversation.recipients
|
||||||
view.title.collapseEnabled = conversation.recipients.size > 1
|
view.title.collapseEnabled = conversation.recipients.size > 1
|
||||||
view.title.text = conversation.getTitle()
|
view.title.text = conversation.getTitle()
|
||||||
view.date.text = dateFormatter.getConversationTimestamp(conversation.date)
|
view.date.text = conversation.date.takeIf { it > 0 }?.let(dateFormatter::getConversationTimestamp)
|
||||||
view.snippet.text = when {
|
view.snippet.text = when {
|
||||||
conversation.draft.isNotEmpty() -> context.getString(R.string.main_draft, conversation.draft)
|
conversation.draft.isNotEmpty() -> context.getString(R.string.main_draft, conversation.draft)
|
||||||
conversation.me -> context.getString(R.string.main_sender_you, conversation.snippet)
|
conversation.me -> context.getString(R.string.main_sender_you, conversation.snippet)
|
||||||
@@ -103,8 +102,9 @@ class ConversationsAdapter @Inject constructor(
|
|||||||
view.pinned.isVisible = conversation.pinned
|
view.pinned.isVisible = conversation.pinned
|
||||||
|
|
||||||
// If the last message wasn't incoming, then the colour doesn't really matter anyway
|
// If the last message wasn't incoming, then the colour doesn't really matter anyway
|
||||||
val recipient = when (conversation.recipients.size) {
|
val lastMessage = conversation.lastMessage
|
||||||
1 -> conversation.recipients.firstOrNull()
|
val recipient = when {
|
||||||
|
conversation.recipients.size == 1 || lastMessage == null -> conversation.recipients.firstOrNull()
|
||||||
else -> conversation.recipients.find { recipient ->
|
else -> conversation.recipients.find { recipient ->
|
||||||
phoneNumberUtils.compare(recipient.address, lastMessage.address)
|
phoneNumberUtils.compare(recipient.address, lastMessage.address)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,13 +142,18 @@ class WidgetAdapter(intent: Intent) : RemoteViewsService.RemoteViewsFactory {
|
|||||||
remoteViews.setTextViewText(R.id.name, boldText(conversation.getTitle(), conversation.unread))
|
remoteViews.setTextViewText(R.id.name, boldText(conversation.getTitle(), conversation.unread))
|
||||||
|
|
||||||
// Date
|
// Date
|
||||||
val timestamp = dateFormatter.getConversationTimestamp(conversation.date)
|
val timestamp = conversation.date.takeIf { it > 0 }?.let(dateFormatter::getConversationTimestamp)
|
||||||
remoteViews.setTextColor(R.id.date, if (conversation.unread) textPrimary else textTertiary)
|
remoteViews.setTextColor(R.id.date, if (conversation.unread) textPrimary else textTertiary)
|
||||||
remoteViews.setTextViewText(R.id.date, boldText(timestamp, conversation.unread))
|
remoteViews.setTextViewText(R.id.date, boldText(timestamp, conversation.unread))
|
||||||
|
|
||||||
// Snippet
|
// Snippet
|
||||||
|
val snippet = when {
|
||||||
|
conversation.draft.isNotEmpty() -> context.getString(R.string.main_draft, conversation.draft)
|
||||||
|
conversation.me -> context.getString(R.string.main_sender_you, conversation.snippet)
|
||||||
|
else -> conversation.snippet
|
||||||
|
}
|
||||||
remoteViews.setTextColor(R.id.snippet, if (conversation.unread) textPrimary else textTertiary)
|
remoteViews.setTextColor(R.id.snippet, if (conversation.unread) textPrimary else textTertiary)
|
||||||
remoteViews.setTextViewText(R.id.snippet, boldText(conversation.snippet, conversation.unread))
|
remoteViews.setTextViewText(R.id.snippet, boldText(snippet, conversation.unread))
|
||||||
|
|
||||||
// Launch conversation on click
|
// Launch conversation on click
|
||||||
val clickIntent = Intent().putExtra("threadId", conversation.id)
|
val clickIntent = Intent().putExtra("threadId", conversation.id)
|
||||||
|
|||||||
Reference in New Issue
Block a user