Fix parsing and display for text based MMS parts

This commit is contained in:
Moez Bhatti
2018-01-08 19:31:19 -05:00
parent 5c13f9b86e
commit 33b817ead8
3 changed files with 29 additions and 23 deletions
+21 -22
View File
@@ -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)
}