send the targeted number at the Thread activity to be used

This commit is contained in:
tibbi 2020-04-04 15:25:21 +02:00
parent 2ed255ae5d
commit 2e078af782
6 changed files with 19 additions and 12 deletions

View File

@ -16,6 +16,7 @@ import com.simplemobiletools.smsmessenger.extensions.config
import com.simplemobiletools.smsmessenger.extensions.getMessages import com.simplemobiletools.smsmessenger.extensions.getMessages
import com.simplemobiletools.smsmessenger.helpers.THREAD_ID import com.simplemobiletools.smsmessenger.helpers.THREAD_ID
import com.simplemobiletools.smsmessenger.helpers.THREAD_NAME import com.simplemobiletools.smsmessenger.helpers.THREAD_NAME
import com.simplemobiletools.smsmessenger.helpers.THREAD_NUMBER
import com.simplemobiletools.smsmessenger.models.Message import com.simplemobiletools.smsmessenger.models.Message
import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.activity_main.*
@ -79,7 +80,8 @@ class MainActivity : SimpleActivity() {
MessagesAdapter(this, messages, messages_list, messages_fastscroller) { MessagesAdapter(this, messages, messages_list, messages_fastscroller) {
Intent(this, ThreadActivity::class.java).apply { Intent(this, ThreadActivity::class.java).apply {
putExtra(THREAD_ID, (it as Message).thread) putExtra(THREAD_ID, (it as Message).thread)
putExtra(THREAD_NAME, it.address) putExtra(THREAD_NAME, it.senderName)
putExtra(THREAD_NUMBER, it.senderNumber)
startActivity(this) startActivity(this)
} }
}.apply { }.apply {

View File

@ -2,12 +2,14 @@ package com.simplemobiletools.smsmessenger.activities
import android.os.Bundle import android.os.Bundle
import com.simplemobiletools.commons.extensions.applyColorFilter import com.simplemobiletools.commons.extensions.applyColorFilter
import com.simplemobiletools.commons.extensions.value
import com.simplemobiletools.smsmessenger.R import com.simplemobiletools.smsmessenger.R
import com.simplemobiletools.smsmessenger.adapters.ThreadAdapter import com.simplemobiletools.smsmessenger.adapters.ThreadAdapter
import com.simplemobiletools.smsmessenger.extensions.config import com.simplemobiletools.smsmessenger.extensions.config
import com.simplemobiletools.smsmessenger.extensions.getMessages import com.simplemobiletools.smsmessenger.extensions.getMessages
import com.simplemobiletools.smsmessenger.helpers.THREAD_ID import com.simplemobiletools.smsmessenger.helpers.THREAD_ID
import com.simplemobiletools.smsmessenger.helpers.THREAD_NAME import com.simplemobiletools.smsmessenger.helpers.THREAD_NAME
import com.simplemobiletools.smsmessenger.helpers.THREAD_NUMBER
import com.simplemobiletools.smsmessenger.models.ThreadDateTime import com.simplemobiletools.smsmessenger.models.ThreadDateTime
import com.simplemobiletools.smsmessenger.models.ThreadItem import com.simplemobiletools.smsmessenger.models.ThreadItem
import kotlinx.android.synthetic.main.activity_thread.* import kotlinx.android.synthetic.main.activity_thread.*
@ -21,6 +23,7 @@ class ThreadActivity : SimpleActivity() {
title = intent.getStringExtra(THREAD_NAME) ?: getString(R.string.app_launcher_name) title = intent.getStringExtra(THREAD_NAME) ?: getString(R.string.app_launcher_name)
val threadID = intent.getIntExtra(THREAD_ID, 0) val threadID = intent.getIntExtra(THREAD_ID, 0)
val targetNumber = intent.getStringExtra(THREAD_NUMBER)
val messages = getMessages(threadID) val messages = getMessages(threadID)
messages.sortBy { it.id } messages.sortBy { it.id }
@ -44,7 +47,7 @@ class ThreadActivity : SimpleActivity() {
thread_type_message.setColors(config.textColor, config.primaryColor, config.backgroundColor) thread_type_message.setColors(config.textColor, config.primaryColor, config.backgroundColor)
thread_send_message.applyColorFilter(config.textColor) thread_send_message.applyColorFilter(config.textColor)
thread_send_message.setOnClickListener { thread_send_message.setOnClickListener {
val msg = thread_type_message.value
} }
} }
} }

View File

@ -71,7 +71,7 @@ class MessagesAdapter(
view.apply { view.apply {
message_frame.isSelected = selectedKeys.contains(message.id) message_frame.isSelected = selectedKeys.contains(message.id)
message_address.text = message.address message_address.text = message.senderName
message_body_short.text = message.body message_body_short.text = message.body
message_date.text = message.date.formatDateOrTime(context, true) message_date.text = message.date.formatDateOrTime(context, true)

View File

@ -50,24 +50,25 @@ fun Context.getMessages(threadID: Int? = null): ArrayList<Message> {
val subject = cursor.getStringValue(Telephony.Sms.SUBJECT) ?: "" val subject = cursor.getStringValue(Telephony.Sms.SUBJECT) ?: ""
val body = cursor.getStringValue(Telephony.Sms.BODY) val body = cursor.getStringValue(Telephony.Sms.BODY)
val type = cursor.getIntValue(Telephony.Sms.TYPE) val type = cursor.getIntValue(Telephony.Sms.TYPE)
var address = cursor.getStringValue(Telephony.Sms.ADDRESS) var senderName = cursor.getStringValue(Telephony.Sms.ADDRESS)
val senderNumber = senderName
val date = (cursor.getLongValue(Telephony.Sms.DATE) / 1000).toInt() val date = (cursor.getLongValue(Telephony.Sms.DATE) / 1000).toInt()
val read = cursor.getIntValue(Telephony.Sms.READ) == 1 val read = cursor.getIntValue(Telephony.Sms.READ) == 1
val person = cursor.getIntValue(Telephony.Sms.PERSON) val person = cursor.getIntValue(Telephony.Sms.PERSON)
val thread = cursor.getIntValue(Telephony.Sms.THREAD_ID) val thread = cursor.getIntValue(Telephony.Sms.THREAD_ID)
if (hasContactsPermission) { if (hasContactsPermission) {
if (address != null && person != 0) { if (senderName != null && person != 0) {
address = getPersonsName(person) ?: address senderName = getPersonsName(person) ?: senderName
} else if (address.areDigitsOnly()) { } else if (senderName.areDigitsOnly()) {
val contactId = getNameFromPhoneNumber(address) val contactId = getNameFromPhoneNumber(senderName)
if (contactId != null) { if (contactId != null) {
address = getPersonsName(contactId) ?: address senderName = getPersonsName(contactId) ?: senderName
} }
} }
} }
val message = Message(id, subject, body, type, address, date, read, thread) val message = Message(id, subject, body, type, senderName, senderNumber, date, read, thread)
messages.add(message) messages.add(message)
} while (cursor.moveToNext()) } while (cursor.moveToNext())
} }

View File

@ -2,6 +2,7 @@ package com.simplemobiletools.smsmessenger.helpers
const val THREAD_ID = "thread_id" const val THREAD_ID = "thread_id"
const val THREAD_NAME = "thread_name" const val THREAD_NAME = "thread_name"
const val THREAD_NUMBER = "thread_number"
// view types for the thread list view // view types for the thread list view
const val THREAD_DATE_TIME = 1 const val THREAD_DATE_TIME = 1

View File

@ -3,8 +3,8 @@ package com.simplemobiletools.smsmessenger.models
import android.provider.Telephony import android.provider.Telephony
data class Message( data class Message(
val id: Int, val subject: String, val body: String, val type: Int, val address: String, val date: Int, val read: Boolean, val id: Int, val subject: String, val body: String, val type: Int, val senderName: String, val senderNumber: String, val date: Int,
val thread: Int val read: Boolean, val thread: Int
) : ThreadItem() { ) : ThreadItem() {
fun isReceivedMessage() = type == Telephony.Sms.MESSAGE_TYPE_INBOX fun isReceivedMessage() = type == Telephony.Sms.MESSAGE_TYPE_INBOX
} }