mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 19:38:52 +01:00
Fix parsing and display for text based MMS parts
This commit is contained in:
@@ -24,30 +24,29 @@ class CursorToPart @Inject constructor(private val context: Context) : Mapper<Cu
|
||||
data = from.getString(from.getColumnIndexOrThrow(Telephony.Mms.Part._DATA))
|
||||
|
||||
when {
|
||||
isImage() -> image = getMmsImage(id)
|
||||
isText() -> text = getMmsText(id)
|
||||
isImage() -> image = ContentUris.withAppendedId(CONTENT_URI, id).toString()
|
||||
|
||||
isText() -> {
|
||||
text = if (data == null) {
|
||||
from.getString(from.getColumnIndexOrThrow("text"))
|
||||
} else {
|
||||
val uri = ContentUris.withAppendedId(CONTENT_URI, id)
|
||||
val sb = StringBuilder()
|
||||
context.contentResolver.openInputStream(uri)?.use { inputStream ->
|
||||
val isr = InputStreamReader(inputStream, "UTF-8")
|
||||
val reader = BufferedReader(isr)
|
||||
var temp = reader.readLine()
|
||||
while (temp != null) {
|
||||
sb.append(temp)
|
||||
temp = reader.readLine()
|
||||
}
|
||||
}
|
||||
sb.toString()
|
||||
}
|
||||
}
|
||||
|
||||
else -> Timber.v("Unhandled type: $type")
|
||||
}
|
||||
}
|
||||
|
||||
private fun getMmsText(id: Long): String {
|
||||
val uri = ContentUris.withAppendedId(CONTENT_URI, id)
|
||||
val sb = StringBuilder()
|
||||
context.contentResolver.openInputStream(uri)?.use { inputStream ->
|
||||
val isr = InputStreamReader(inputStream, "UTF-8")
|
||||
val reader = BufferedReader(isr)
|
||||
var temp = reader.readLine()
|
||||
while (temp != null) {
|
||||
sb.append(temp)
|
||||
temp = reader.readLine()
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString()
|
||||
}
|
||||
|
||||
private fun getMmsImage(id: Long): String? {
|
||||
return ContentUris.withAppendedId(CONTENT_URI, id).toString()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -101,6 +101,13 @@ open class Message : RealmObject() {
|
||||
return isOutgoingMms || isOutgoingSms
|
||||
}
|
||||
|
||||
fun getText() : String {
|
||||
return when {
|
||||
isSms() -> body
|
||||
else -> parts.filter { it.isText() }.joinToString("") { it.text ?: "" }
|
||||
}
|
||||
}
|
||||
|
||||
fun isSending(): Boolean {
|
||||
return !isFailedMessage() && isOutgoingMessage()
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ class MessagesAdapter @Inject constructor(
|
||||
}
|
||||
view.status?.setVisible(!view.status?.text.isNullOrBlank())
|
||||
|
||||
view.body.text = message.body
|
||||
view.body.text = message.getText()
|
||||
view.timestamp.text = dateFormatter.getMessageTimestamp(message.date)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user