mirror of
https://github.com/SimpleMobileTools/Simple-SMS-Messenger.git
synced 2025-01-01 02:57:27 +01:00
just moving a function down
This commit is contained in:
parent
4bcab69a5f
commit
ad3812abb5
@ -106,62 +106,6 @@ class ThreadActivity : SimpleActivity() {
|
||||
isActivityVisible = false
|
||||
}
|
||||
|
||||
private fun setupThread() {
|
||||
val privateCursor = getMyContactsCursor()?.loadInBackground()
|
||||
ensureBackgroundThread {
|
||||
val cachedMessagesCode = messages.hashCode()
|
||||
messages = getMessages(threadId)
|
||||
if (messages.hashCode() == cachedMessagesCode && participants.isNotEmpty()) {
|
||||
return@ensureBackgroundThread
|
||||
}
|
||||
|
||||
setupParticipants()
|
||||
|
||||
// check if no participant came from a privately stored contact in Simple Contacts
|
||||
privateContacts = MyContactsContentProvider.getSimpleContacts(this, privateCursor)
|
||||
if (privateContacts.isNotEmpty()) {
|
||||
val senderNumbersToReplace = HashMap<String, String>()
|
||||
participants.filter { it.doesContainPhoneNumber(it.name) }.forEach { participant ->
|
||||
privateContacts.firstOrNull { it.doesContainPhoneNumber(participant.phoneNumbers.first()) }?.apply {
|
||||
senderNumbersToReplace[participant.phoneNumbers.first()] = name
|
||||
participant.name = name
|
||||
participant.photoUri = photoUri
|
||||
}
|
||||
}
|
||||
|
||||
messages.forEach { message ->
|
||||
if (senderNumbersToReplace.keys.contains(message.senderName)) {
|
||||
message.senderName = senderNumbersToReplace[message.senderName]!!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (participants.isEmpty()) {
|
||||
val name = intent.getStringExtra(THREAD_TITLE) ?: ""
|
||||
val number = intent.getStringExtra(THREAD_NUMBER)
|
||||
if (number == null) {
|
||||
toast(R.string.unknown_error_occurred)
|
||||
finish()
|
||||
return@ensureBackgroundThread
|
||||
}
|
||||
|
||||
val contact = SimpleContact(0, 0, name, "", arrayListOf(number), ArrayList(), ArrayList())
|
||||
participants.add(contact)
|
||||
}
|
||||
|
||||
messages.chunked(30).forEach { currentMessages ->
|
||||
messagesDB.insertMessages(*currentMessages.toTypedArray())
|
||||
}
|
||||
|
||||
setupAttachmentSizes()
|
||||
setupAdapter()
|
||||
runOnUiThread {
|
||||
setupThreadTitle()
|
||||
setupSIMSelector()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
bus?.unregister(this)
|
||||
@ -219,6 +163,62 @@ class ThreadActivity : SimpleActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupThread() {
|
||||
val privateCursor = getMyContactsCursor()?.loadInBackground()
|
||||
ensureBackgroundThread {
|
||||
val cachedMessagesCode = messages.hashCode()
|
||||
messages = getMessages(threadId)
|
||||
if (messages.hashCode() == cachedMessagesCode && participants.isNotEmpty()) {
|
||||
return@ensureBackgroundThread
|
||||
}
|
||||
|
||||
setupParticipants()
|
||||
|
||||
// check if no participant came from a privately stored contact in Simple Contacts
|
||||
privateContacts = MyContactsContentProvider.getSimpleContacts(this, privateCursor)
|
||||
if (privateContacts.isNotEmpty()) {
|
||||
val senderNumbersToReplace = HashMap<String, String>()
|
||||
participants.filter { it.doesContainPhoneNumber(it.name) }.forEach { participant ->
|
||||
privateContacts.firstOrNull { it.doesContainPhoneNumber(participant.phoneNumbers.first()) }?.apply {
|
||||
senderNumbersToReplace[participant.phoneNumbers.first()] = name
|
||||
participant.name = name
|
||||
participant.photoUri = photoUri
|
||||
}
|
||||
}
|
||||
|
||||
messages.forEach { message ->
|
||||
if (senderNumbersToReplace.keys.contains(message.senderName)) {
|
||||
message.senderName = senderNumbersToReplace[message.senderName]!!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (participants.isEmpty()) {
|
||||
val name = intent.getStringExtra(THREAD_TITLE) ?: ""
|
||||
val number = intent.getStringExtra(THREAD_NUMBER)
|
||||
if (number == null) {
|
||||
toast(R.string.unknown_error_occurred)
|
||||
finish()
|
||||
return@ensureBackgroundThread
|
||||
}
|
||||
|
||||
val contact = SimpleContact(0, 0, name, "", arrayListOf(number), ArrayList(), ArrayList())
|
||||
participants.add(contact)
|
||||
}
|
||||
|
||||
messages.chunked(30).forEach { currentMessages ->
|
||||
messagesDB.insertMessages(*currentMessages.toTypedArray())
|
||||
}
|
||||
|
||||
setupAttachmentSizes()
|
||||
setupAdapter()
|
||||
runOnUiThread {
|
||||
setupThreadTitle()
|
||||
setupSIMSelector()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupAdapter() {
|
||||
threadItems = getThreadItems()
|
||||
invalidateOptionsMenu()
|
||||
|
Loading…
Reference in New Issue
Block a user