mirror of
https://github.com/SimpleMobileTools/Simple-SMS-Messenger.git
synced 2025-02-20 21:50:54 +01:00
fix #8, load some cached messages instantly
This commit is contained in:
parent
a013c110ec
commit
2b3df2719b
@ -19,6 +19,7 @@ import com.simplemobiletools.smsmessenger.BuildConfig
|
||||
import com.simplemobiletools.smsmessenger.R
|
||||
import com.simplemobiletools.smsmessenger.adapters.ConversationsAdapter
|
||||
import com.simplemobiletools.smsmessenger.extensions.config
|
||||
import com.simplemobiletools.smsmessenger.extensions.conversationsDB
|
||||
import com.simplemobiletools.smsmessenger.extensions.getConversations
|
||||
import com.simplemobiletools.smsmessenger.helpers.THREAD_ID
|
||||
import com.simplemobiletools.smsmessenger.helpers.THREAD_TITLE
|
||||
@ -144,8 +145,29 @@ class MainActivity : SimpleActivity() {
|
||||
|
||||
private fun initMessenger() {
|
||||
storeStateVariables()
|
||||
val privateCursor = getMyContactsContentProviderCursorLoader().loadInBackground()
|
||||
getCachedConversations()
|
||||
|
||||
no_conversations_placeholder_2.setOnClickListener {
|
||||
launchNewConversation()
|
||||
}
|
||||
|
||||
conversations_fab.setOnClickListener {
|
||||
launchNewConversation()
|
||||
}
|
||||
}
|
||||
|
||||
private fun getCachedConversations() {
|
||||
ensureBackgroundThread {
|
||||
val conversations = conversationsDB.getAll().toMutableList() as ArrayList<Conversation>
|
||||
runOnUiThread {
|
||||
setupConversations(conversations)
|
||||
getNewConversations()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getNewConversations() {
|
||||
val privateCursor = getMyContactsContentProviderCursorLoader().loadInBackground()
|
||||
ensureBackgroundThread {
|
||||
val conversations = getConversations()
|
||||
|
||||
@ -161,24 +183,19 @@ class MainActivity : SimpleActivity() {
|
||||
}
|
||||
|
||||
runOnUiThread {
|
||||
val hasConversations = conversations.isNotEmpty()
|
||||
conversations_list.beVisibleIf(hasConversations)
|
||||
no_conversations_placeholder.beVisibleIf(!hasConversations)
|
||||
no_conversations_placeholder_2.beVisibleIf(!hasConversations)
|
||||
updateConversations(conversations)
|
||||
setupConversations(conversations)
|
||||
}
|
||||
}
|
||||
|
||||
no_conversations_placeholder_2.setOnClickListener {
|
||||
launchNewConversation()
|
||||
}
|
||||
|
||||
conversations_fab.setOnClickListener {
|
||||
launchNewConversation()
|
||||
conversationsDB.insertAll(conversations)
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateConversations(conversations: ArrayList<Conversation>) {
|
||||
private fun setupConversations(conversations: ArrayList<Conversation>) {
|
||||
val hasConversations = conversations.isNotEmpty()
|
||||
conversations_list.beVisibleIf(hasConversations)
|
||||
no_conversations_placeholder.beVisibleIf(!hasConversations)
|
||||
no_conversations_placeholder_2.beVisibleIf(!hasConversations)
|
||||
|
||||
val currAdapter = conversations_list.adapter
|
||||
if (currAdapter == null) {
|
||||
ConversationsAdapter(this, conversations, conversations_list, conversations_fastscroller) {
|
||||
|
@ -2,5 +2,8 @@ package com.simplemobiletools.smsmessenger.extensions
|
||||
|
||||
import android.text.TextUtils
|
||||
import com.simplemobiletools.commons.models.SimpleContact
|
||||
import com.simplemobiletools.smsmessenger.models.Conversation
|
||||
|
||||
fun ArrayList<SimpleContact>.getThreadTitle() = TextUtils.join(", ", map { it.name }.toTypedArray())
|
||||
|
||||
fun ArrayList<Conversation>.getHashToCompare() = map { it.getStringToCompare() }.hashCode()
|
||||
|
@ -227,7 +227,6 @@ fun Context.getConversations(): ArrayList<Conversation> {
|
||||
}
|
||||
|
||||
conversations.sortByDescending { it.date }
|
||||
conversationsDB.insertAll(conversations)
|
||||
return conversations
|
||||
}
|
||||
|
||||
|
@ -16,4 +16,8 @@ data class Conversation(
|
||||
@ColumnInfo(name = "photo_uri") var photoUri: String,
|
||||
@ColumnInfo(name = "is_group_conversation") var isGroupConversation: Boolean,
|
||||
@ColumnInfo(name = "phone_number") var phoneNumber: String
|
||||
)
|
||||
) {
|
||||
fun getStringToCompare(): String {
|
||||
return copy(id = 0).toString()
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user