mirror of
https://github.com/SimpleMobileTools/Simple-SMS-Messenger.git
synced 2025-02-13 18:20:39 +01:00
get proper image resolutions at loading a thread
This commit is contained in:
parent
b6c628e38b
commit
5880fa3c85
@ -246,7 +246,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
|
|
||||||
if (config.appRunCount == 1) {
|
if (config.appRunCount == 1) {
|
||||||
conversations.map { it.threadId }.forEach { threadId ->
|
conversations.map { it.threadId }.forEach { threadId ->
|
||||||
val messages = getMessages(threadId)
|
val messages = getMessages(threadId, false)
|
||||||
messages.chunked(30).forEach { currentMessages ->
|
messages.chunked(30).forEach { currentMessages ->
|
||||||
messagesDB.insertMessages(*currentMessages.toTypedArray())
|
messagesDB.insertMessages(*currentMessages.toTypedArray())
|
||||||
}
|
}
|
||||||
|
@ -237,7 +237,7 @@ class ThreadActivity : SimpleActivity() {
|
|||||||
privateContacts = MyContactsContentProvider.getSimpleContacts(this, privateCursor)
|
privateContacts = MyContactsContentProvider.getSimpleContacts(this, privateCursor)
|
||||||
|
|
||||||
val cachedMessagesCode = messages.clone().hashCode()
|
val cachedMessagesCode = messages.clone().hashCode()
|
||||||
messages = getMessages(threadId)
|
messages = getMessages(threadId, true)
|
||||||
|
|
||||||
val hasParticipantWithoutName = participants.any {
|
val hasParticipantWithoutName = participants.any {
|
||||||
it.phoneNumbers.map { it.normalizedNumber }.contains(it.name)
|
it.phoneNumbers.map { it.normalizedNumber }.contains(it.name)
|
||||||
@ -959,7 +959,7 @@ class ThreadActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val lastMaxId = messages.maxByOrNull { it.id }?.id ?: 0L
|
val lastMaxId = messages.maxByOrNull { it.id }?.id ?: 0L
|
||||||
messages = getMessages(threadId)
|
messages = getMessages(threadId, true)
|
||||||
|
|
||||||
messages.filter { !it.isReceivedMessage() && it.id > lastMaxId }.forEach { latestMessage ->
|
messages.filter { !it.isReceivedMessage() && it.id > lastMaxId }.forEach { latestMessage ->
|
||||||
// subscriptionIds seem to be not filled out at sending with multiple SIM cards, so fill it manually
|
// subscriptionIds seem to be not filled out at sending with multiple SIM cards, so fill it manually
|
||||||
|
@ -8,6 +8,7 @@ import android.app.PendingIntent
|
|||||||
import android.content.*
|
import android.content.*
|
||||||
import android.database.Cursor
|
import android.database.Cursor
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
|
import android.graphics.BitmapFactory
|
||||||
import android.media.AudioAttributes
|
import android.media.AudioAttributes
|
||||||
import android.media.AudioManager
|
import android.media.AudioManager
|
||||||
import android.media.RingtoneManager
|
import android.media.RingtoneManager
|
||||||
@ -53,7 +54,7 @@ val Context.messageAttachmentsDB: MessageAttachmentsDao get() = getMessagessDB()
|
|||||||
|
|
||||||
val Context.messagesDB: MessagesDao get() = getMessagessDB().MessagesDao()
|
val Context.messagesDB: MessagesDao get() = getMessagessDB().MessagesDao()
|
||||||
|
|
||||||
fun Context.getMessages(threadId: Long): ArrayList<Message> {
|
fun Context.getMessages(threadId: Long, getImageResolutions: Boolean): ArrayList<Message> {
|
||||||
val uri = Sms.CONTENT_URI
|
val uri = Sms.CONTENT_URI
|
||||||
val projection = arrayOf(
|
val projection = arrayOf(
|
||||||
Sms._ID,
|
Sms._ID,
|
||||||
@ -107,7 +108,7 @@ fun Context.getMessages(threadId: Long): ArrayList<Message> {
|
|||||||
messages.add(message)
|
messages.add(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
messages.addAll(getMMS(threadId, sortOrder))
|
messages.addAll(getMMS(threadId, getImageResolutions, sortOrder))
|
||||||
messages = messages.filter { it.participants.isNotEmpty() }
|
messages = messages.filter { it.participants.isNotEmpty() }
|
||||||
.sortedWith(compareBy<Message> { it.date }.thenBy { it.id }).toMutableList() as ArrayList<Message>
|
.sortedWith(compareBy<Message> { it.date }.thenBy { it.id }).toMutableList() as ArrayList<Message>
|
||||||
|
|
||||||
@ -115,7 +116,7 @@ fun Context.getMessages(threadId: Long): ArrayList<Message> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// as soon as a message contains multiple recipients it counts as an MMS instead of SMS
|
// as soon as a message contains multiple recipients it counts as an MMS instead of SMS
|
||||||
fun Context.getMMS(threadId: Long? = null, sortOrder: String? = null): ArrayList<Message> {
|
fun Context.getMMS(threadId: Long? = null, getImageResolutions: Boolean = false, sortOrder: String? = null): ArrayList<Message> {
|
||||||
val uri = Mms.CONTENT_URI
|
val uri = Mms.CONTENT_URI
|
||||||
val projection = arrayOf(
|
val projection = arrayOf(
|
||||||
Mms._ID,
|
Mms._ID,
|
||||||
@ -159,7 +160,7 @@ fun Context.getMMS(threadId: Long? = null, sortOrder: String? = null): ArrayList
|
|||||||
}
|
}
|
||||||
|
|
||||||
val isMMS = true
|
val isMMS = true
|
||||||
val attachment = getMmsAttachment(mmsId)
|
val attachment = getMmsAttachment(mmsId, getImageResolutions)
|
||||||
val body = attachment.text
|
val body = attachment.text
|
||||||
var senderName = ""
|
var senderName = ""
|
||||||
var senderPhotoUri = ""
|
var senderPhotoUri = ""
|
||||||
@ -270,7 +271,7 @@ fun Context.getConversationIds(): List<Long> {
|
|||||||
|
|
||||||
// based on https://stackoverflow.com/a/6446831/1967672
|
// based on https://stackoverflow.com/a/6446831/1967672
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
fun Context.getMmsAttachment(id: Long): MessageAttachment {
|
fun Context.getMmsAttachment(id: Long, getImageResolutions: Boolean): MessageAttachment {
|
||||||
val uri = if (isQPlus()) {
|
val uri = if (isQPlus()) {
|
||||||
Mms.Part.CONTENT_URI
|
Mms.Part.CONTENT_URI
|
||||||
} else {
|
} else {
|
||||||
@ -293,7 +294,22 @@ fun Context.getMmsAttachment(id: Long): MessageAttachment {
|
|||||||
if (mimetype == "text/plain") {
|
if (mimetype == "text/plain") {
|
||||||
messageAttachment.text = cursor.getStringValue(Mms.Part.TEXT) ?: ""
|
messageAttachment.text = cursor.getStringValue(Mms.Part.TEXT) ?: ""
|
||||||
} else if (mimetype.startsWith("image/") || mimetype.startsWith("video/")) {
|
} else if (mimetype.startsWith("image/") || mimetype.startsWith("video/")) {
|
||||||
val attachment = Attachment(partId, id, Uri.withAppendedPath(uri, partId.toString()).toString(), mimetype, 0, 0, "")
|
val fileUri = Uri.withAppendedPath(uri, partId.toString())
|
||||||
|
var width = 0
|
||||||
|
var height = 0
|
||||||
|
|
||||||
|
if (getImageResolutions) {
|
||||||
|
try {
|
||||||
|
val options = BitmapFactory.Options()
|
||||||
|
options.inJustDecodeBounds = true
|
||||||
|
BitmapFactory.decodeStream(contentResolver.openInputStream(fileUri), null, options)
|
||||||
|
width = options.outWidth
|
||||||
|
height = options.outHeight
|
||||||
|
} catch (e: Exception) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val attachment = Attachment(partId, id, fileUri.toString(), mimetype, width, height, "")
|
||||||
messageAttachment.attachments.add(attachment)
|
messageAttachment.attachments.add(attachment)
|
||||||
} else if (mimetype != "application/smil") {
|
} else if (mimetype != "application/smil") {
|
||||||
val attachment = Attachment(partId, id, Uri.withAppendedPath(uri, partId.toString()).toString(), mimetype, 0, 0, attachmentName)
|
val attachment = Attachment(partId, id, Uri.withAppendedPath(uri, partId.toString()).toString(), mimetype, 0, 0, attachmentName)
|
||||||
@ -317,7 +333,7 @@ fun Context.getLatestMMS(): Message? {
|
|||||||
|
|
||||||
fun Context.getThreadSnippet(threadId: Long): String {
|
fun Context.getThreadSnippet(threadId: Long): String {
|
||||||
val sortOrder = "${Mms.DATE} DESC LIMIT 1"
|
val sortOrder = "${Mms.DATE} DESC LIMIT 1"
|
||||||
val latestMms = getMMS(threadId, sortOrder).firstOrNull()
|
val latestMms = getMMS(threadId, false, sortOrder).firstOrNull()
|
||||||
var snippet = latestMms?.body ?: ""
|
var snippet = latestMms?.body ?: ""
|
||||||
|
|
||||||
val uri = Sms.CONTENT_URI
|
val uri = Sms.CONTENT_URI
|
||||||
|
Loading…
x
Reference in New Issue
Block a user