forked from upstream-mirrors/quik
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))
|
data = from.getString(from.getColumnIndexOrThrow(Telephony.Mms.Part._DATA))
|
||||||
|
|
||||||
when {
|
when {
|
||||||
isImage() -> image = getMmsImage(id)
|
isImage() -> image = ContentUris.withAppendedId(CONTENT_URI, id).toString()
|
||||||
isText() -> text = getMmsText(id)
|
|
||||||
|
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")
|
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
|
return isOutgoingMms || isOutgoingSms
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getText() : String {
|
||||||
|
return when {
|
||||||
|
isSms() -> body
|
||||||
|
else -> parts.filter { it.isText() }.joinToString("") { it.text ?: "" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun isSending(): Boolean {
|
fun isSending(): Boolean {
|
||||||
return !isFailedMessage() && isOutgoingMessage()
|
return !isFailedMessage() && isOutgoingMessage()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ class MessagesAdapter @Inject constructor(
|
|||||||
}
|
}
|
||||||
view.status?.setVisible(!view.status?.text.isNullOrBlank())
|
view.status?.setVisible(!view.status?.text.isNullOrBlank())
|
||||||
|
|
||||||
view.body.text = message.body
|
view.body.text = message.getText()
|
||||||
view.timestamp.text = dateFormatter.getMessageTimestamp(message.date)
|
view.timestamp.text = dateFormatter.getMessageTimestamp(message.date)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user