Added pinning conversations (#197)
This commit is contained in:
parent
b52cafef09
commit
c14e1f5b95
36 changed files with 166 additions and 7 deletions
|
|
@ -28,6 +28,7 @@ import org.greenrobot.eventbus.EventBus
|
|||
import org.greenrobot.eventbus.Subscribe
|
||||
import org.greenrobot.eventbus.ThreadMode
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
class MainActivity : SimpleActivity() {
|
||||
private val MAKE_DEFAULT_APP_REQUEST = 1
|
||||
|
|
@ -170,7 +171,7 @@ class MainActivity : SimpleActivity() {
|
|||
private fun getCachedConversations() {
|
||||
ensureBackgroundThread {
|
||||
val conversations = try {
|
||||
conversationsDB.getAll().sortedByDescending { it.date }.toMutableList() as ArrayList<Conversation>
|
||||
conversationsDB.getAll().toMutableList() as ArrayList<Conversation>
|
||||
} catch (e: Exception) {
|
||||
ArrayList()
|
||||
}
|
||||
|
|
@ -226,6 +227,10 @@ class MainActivity : SimpleActivity() {
|
|||
|
||||
private fun setupConversations(conversations: ArrayList<Conversation>) {
|
||||
val hasConversations = conversations.isNotEmpty()
|
||||
val sortedConversations = conversations.sortedWith(
|
||||
compareByDescending<Conversation>{ config.pinnedConversations.contains(it.threadId.toString()) }
|
||||
.thenByDescending{ it.date }
|
||||
).toMutableList() as ArrayList<Conversation>
|
||||
conversations_list.beVisibleIf(hasConversations)
|
||||
no_conversations_placeholder.beVisibleIf(!hasConversations)
|
||||
no_conversations_placeholder_2.beVisibleIf(!hasConversations)
|
||||
|
|
@ -237,7 +242,7 @@ class MainActivity : SimpleActivity() {
|
|||
|
||||
val currAdapter = conversations_list.adapter
|
||||
if (currAdapter == null) {
|
||||
ConversationsAdapter(this, conversations, conversations_list, conversations_fastscroller) {
|
||||
ConversationsAdapter(this, sortedConversations, conversations_list, conversations_fastscroller) {
|
||||
Intent(this, ThreadActivity::class.java).apply {
|
||||
putExtra(THREAD_ID, (it as Conversation).threadId)
|
||||
putExtra(THREAD_TITLE, it.title)
|
||||
|
|
@ -254,7 +259,7 @@ class MainActivity : SimpleActivity() {
|
|||
}
|
||||
} else {
|
||||
try {
|
||||
(currAdapter as ConversationsAdapter).updateConversations(conversations)
|
||||
(currAdapter as ConversationsAdapter).updateConversations(sortedConversations)
|
||||
} catch (ignored: Exception) {
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue