lets pass more info at the ThreadActivity again, as backup

This commit is contained in:
tibbi 2020-04-06 20:24:30 +02:00
parent 8736473b35
commit 705f015a96
3 changed files with 41 additions and 10 deletions

View File

@ -19,6 +19,9 @@ import com.simplemobiletools.smsmessenger.adapters.MessagesAdapter
import com.simplemobiletools.smsmessenger.extensions.config
import com.simplemobiletools.smsmessenger.extensions.getMessages
import com.simplemobiletools.smsmessenger.extensions.launchThreadActivity
import com.simplemobiletools.smsmessenger.helpers.THREAD_ID
import com.simplemobiletools.smsmessenger.helpers.THREAD_NAME
import com.simplemobiletools.smsmessenger.helpers.THREAD_NUMBER
import com.simplemobiletools.smsmessenger.models.Events
import com.simplemobiletools.smsmessenger.models.Message
import kotlinx.android.synthetic.main.activity_main.*
@ -136,7 +139,12 @@ class MainActivity : SimpleActivity() {
val messages = getMessages()
runOnUiThread {
MessagesAdapter(this, messages, messages_list, messages_fastscroller) {
launchThreadActivity((it as Message).thread)
Intent(this, ThreadActivity::class.java).apply {
putExtra(THREAD_ID, (it as Message).thread)
putExtra(THREAD_NAME, it.senderName)
putExtra(THREAD_NUMBER, it.senderNumber)
startActivity(this)
}
}.apply {
messages_list.adapter = this
}

View File

@ -1,5 +1,6 @@
package com.simplemobiletools.smsmessenger.activities
import android.content.Intent
import android.database.Cursor
import android.os.Bundle
import android.provider.ContactsContract
@ -17,7 +18,11 @@ import com.simplemobiletools.smsmessenger.R
import com.simplemobiletools.smsmessenger.adapters.ContactsAdapter
import com.simplemobiletools.smsmessenger.extensions.getThreadId
import com.simplemobiletools.smsmessenger.extensions.launchThreadActivity
import com.simplemobiletools.smsmessenger.helpers.THREAD_ID
import com.simplemobiletools.smsmessenger.helpers.THREAD_NAME
import com.simplemobiletools.smsmessenger.helpers.THREAD_NUMBER
import com.simplemobiletools.smsmessenger.models.Contact
import com.simplemobiletools.smsmessenger.models.Message
import kotlinx.android.synthetic.main.activity_new_message.*
import kotlinx.android.synthetic.main.item_selected_contact.view.*
@ -68,7 +73,12 @@ class NewMessageActivity : SimpleActivity() {
ContactsAdapter(this, contacts, suggestions_list, null) {
hideKeyboard()
launchThreadActivity(getThreadId((it as Contact).phoneNumber).toInt())
Intent(this, ThreadActivity::class.java).apply {
putExtra(THREAD_ID, getThreadId((it as Contact).phoneNumber).toInt())
putExtra(THREAD_NAME, it.name)
putExtra(THREAD_NUMBER, it.phoneNumber)
startActivity(this)
}
}.apply {
suggestions_list.adapter = this
}

View File

@ -15,12 +15,12 @@ import com.simplemobiletools.commons.extensions.value
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.smsmessenger.R
import com.simplemobiletools.smsmessenger.adapters.ThreadAdapter
import com.simplemobiletools.smsmessenger.extensions.*
import com.simplemobiletools.smsmessenger.extensions.config
import com.simplemobiletools.smsmessenger.extensions.getMessages
import com.simplemobiletools.smsmessenger.extensions.getThreadInfo
import com.simplemobiletools.smsmessenger.extensions.markSMSRead
import com.simplemobiletools.smsmessenger.helpers.*
import com.simplemobiletools.smsmessenger.models.Events
import com.simplemobiletools.smsmessenger.models.ThreadDateTime
import com.simplemobiletools.smsmessenger.models.ThreadError
import com.simplemobiletools.smsmessenger.models.ThreadItem
import com.simplemobiletools.smsmessenger.models.*
import com.simplemobiletools.smsmessenger.receivers.SmsSentReceiver
import kotlinx.android.synthetic.main.activity_thread.*
import org.greenrobot.eventbus.EventBus
@ -38,14 +38,27 @@ class ThreadActivity : SimpleActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_thread)
threadId = intent.getIntExtra(THREAD_ID, 0)
val thread = getThreadInfo(threadId)
if (thread == null) {
val extras = intent.extras
if (extras == null) {
toast(R.string.unknown_error_occurred)
finish()
return
}
threadId = intent.getIntExtra(THREAD_ID, 0)
var thread = getThreadInfo(threadId)
if (thread == null) {
if (extras.containsKey(THREAD_NUMBER)) {
val threadTitle = extras.getString(THREAD_NAME) ?: getString(R.string.app_launcher_name)
targetNumber = extras.getString(THREAD_NUMBER)!!
thread = MessagingThread(threadId, threadTitle, targetNumber)
} else {
toast(R.string.unknown_error_occurred)
finish()
return
}
}
title = thread.title
targetNumber = thread.address
bus = EventBus.getDefault()