From 705f015a9614b7aa05e463d191342d9c33f0994e Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 6 Apr 2020 20:24:30 +0200 Subject: [PATCH] lets pass more info at the ThreadActivity again, as backup --- .../smsmessenger/activities/MainActivity.kt | 10 ++++++- .../activities/NewMessageActivity.kt | 12 +++++++- .../smsmessenger/activities/ThreadActivity.kt | 29 ++++++++++++++----- 3 files changed, 41 insertions(+), 10 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/MainActivity.kt index 6fc1b17a..2cbd0ac3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/MainActivity.kt @@ -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 } diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/NewMessageActivity.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/NewMessageActivity.kt index 38f54638..05e6300e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/NewMessageActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/NewMessageActivity.kt @@ -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 } diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt index 88089b70..f35694ae 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt @@ -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()