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

View File

@ -2,12 +2,14 @@ package com.simplemobiletools.smsmessenger.activities
import android.os.Bundle
import com.simplemobiletools.commons.extensions.applyColorFilter
import com.simplemobiletools.commons.extensions.value
import com.simplemobiletools.smsmessenger.R
import com.simplemobiletools.smsmessenger.adapters.ThreadAdapter
import com.simplemobiletools.smsmessenger.extensions.config
import com.simplemobiletools.smsmessenger.extensions.getMessages
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.ThreadDateTime
import com.simplemobiletools.smsmessenger.models.ThreadItem
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)
val threadID = intent.getIntExtra(THREAD_ID, 0)
val targetNumber = intent.getStringExtra(THREAD_NUMBER)
val messages = getMessages(threadID)
messages.sortBy { it.id }
@ -44,7 +47,7 @@ class ThreadActivity : SimpleActivity() {
thread_type_message.setColors(config.textColor, config.primaryColor, config.backgroundColor)
thread_send_message.applyColorFilter(config.textColor)
thread_send_message.setOnClickListener {
val msg = thread_type_message.value
}
}
}

View File

@ -71,7 +71,7 @@ class MessagesAdapter(
view.apply {
message_frame.isSelected = selectedKeys.contains(message.id)
message_address.text = message.address
message_address.text = message.senderName
message_body_short.text = message.body
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 body = cursor.getStringValue(Telephony.Sms.BODY)
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 read = cursor.getIntValue(Telephony.Sms.READ) == 1
val person = cursor.getIntValue(Telephony.Sms.PERSON)
val thread = cursor.getIntValue(Telephony.Sms.THREAD_ID)
if (hasContactsPermission) {
if (address != null && person != 0) {
address = getPersonsName(person) ?: address
} else if (address.areDigitsOnly()) {
val contactId = getNameFromPhoneNumber(address)
if (senderName != null && person != 0) {
senderName = getPersonsName(person) ?: senderName
} else if (senderName.areDigitsOnly()) {
val contactId = getNameFromPhoneNumber(senderName)
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)
} while (cursor.moveToNext())
}

View File

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

View File

@ -3,8 +3,8 @@ package com.simplemobiletools.smsmessenger.models
import android.provider.Telephony
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 thread: Int
val id: Int, val subject: String, val body: String, val type: Int, val senderName: String, val senderNumber: String, val date: Int,
val read: Boolean, val thread: Int
) : ThreadItem() {
fun isReceivedMessage() = type == Telephony.Sms.MESSAGE_TYPE_INBOX
}