mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 11:38:51 +01:00
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()
|
||||
.where(Conversation::class.java)
|
||||
.notEqualTo("id", 0L)
|
||||
.isNotNull("lastMessage")
|
||||
.equalTo("archived", archived)
|
||||
.equalTo("blocked", false)
|
||||
.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()
|
||||
}
|
||||
|
||||
@@ -71,11 +78,18 @@ class ConversationRepositoryImpl @Inject constructor(
|
||||
realm.refresh()
|
||||
realm.copyFromRealm(realm.where(Conversation::class.java)
|
||||
.notEqualTo("id", 0L)
|
||||
.isNotNull("lastMessage")
|
||||
.equalTo("archived", false)
|
||||
.equalTo("blocked", false)
|
||||
.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())
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -86,7 +86,6 @@ class ConversationsAdapter @Inject constructor(
|
||||
|
||||
override fun onBindViewHolder(viewHolder: QkViewHolder, position: Int) {
|
||||
val conversation = getItem(position) ?: return
|
||||
val lastMessage = conversation.lastMessage ?: return
|
||||
val view = viewHolder.containerView
|
||||
|
||||
view.isActivated = isSelected(conversation.id)
|
||||
@@ -94,7 +93,7 @@ class ConversationsAdapter @Inject constructor(
|
||||
view.avatars.recipients = conversation.recipients
|
||||
view.title.collapseEnabled = conversation.recipients.size > 1
|
||||
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 {
|
||||
conversation.draft.isNotEmpty() -> context.getString(R.string.main_draft, conversation.draft)
|
||||
conversation.me -> context.getString(R.string.main_sender_you, conversation.snippet)
|
||||
@@ -103,8 +102,9 @@ class ConversationsAdapter @Inject constructor(
|
||||
view.pinned.isVisible = conversation.pinned
|
||||
|
||||
// If the last message wasn't incoming, then the colour doesn't really matter anyway
|
||||
val recipient = when (conversation.recipients.size) {
|
||||
1 -> conversation.recipients.firstOrNull()
|
||||
val lastMessage = conversation.lastMessage
|
||||
val recipient = when {
|
||||
conversation.recipients.size == 1 || lastMessage == null -> conversation.recipients.firstOrNull()
|
||||
else -> conversation.recipients.find { recipient ->
|
||||
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))
|
||||
|
||||
// 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.setTextViewText(R.id.date, boldText(timestamp, conversation.unread))
|
||||
|
||||
// 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.setTextViewText(R.id.snippet, boldText(conversation.snippet, conversation.unread))
|
||||
remoteViews.setTextViewText(R.id.snippet, boldText(snippet, conversation.unread))
|
||||
|
||||
// Launch conversation on click
|
||||
val clickIntent = Intent().putExtra("threadId", conversation.id)
|
||||
|
||||
Reference in New Issue
Block a user