forked from upstream-mirrors/quik
Provide more detailed message summary
This commit is contained in:
@@ -20,6 +20,7 @@ package com.moez.QKSMS.repository
|
|||||||
|
|
||||||
import android.content.ContentResolver
|
import android.content.ContentResolver
|
||||||
import android.content.ContentUris
|
import android.content.ContentUris
|
||||||
|
import android.content.Context
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.provider.Telephony
|
import android.provider.Telephony
|
||||||
import android.telephony.PhoneNumberUtils
|
import android.telephony.PhoneNumberUtils
|
||||||
@@ -47,6 +48,7 @@ import javax.inject.Singleton
|
|||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class SyncRepositoryImpl @Inject constructor(
|
class SyncRepositoryImpl @Inject constructor(
|
||||||
|
private val context: Context,
|
||||||
private val contentResolver: ContentResolver,
|
private val contentResolver: ContentResolver,
|
||||||
private val conversationRepo: ConversationRepository,
|
private val conversationRepo: ConversationRepository,
|
||||||
private val cursorToConversation: CursorToConversation,
|
private val cursorToConversation: CursorToConversation,
|
||||||
|
|||||||
@@ -113,19 +113,20 @@ open class Message : RealmObject() {
|
|||||||
/**
|
/**
|
||||||
* Returns the text that should be displayed when a preview of the message
|
* Returns the text that should be displayed when a preview of the message
|
||||||
* needs to be displayed, such as in the conversation view or in a notification
|
* needs to be displayed, such as in the conversation view or in a notification
|
||||||
*
|
|
||||||
* TODO: Don't return a hardcoded string
|
|
||||||
*/
|
*/
|
||||||
fun getSummary(): String {
|
fun getSummary(): String = when {
|
||||||
return when {
|
isSms() -> body
|
||||||
isSms() -> body
|
|
||||||
|
|
||||||
else -> parts
|
else -> {
|
||||||
.mapNotNull { it.text }
|
val sb = StringBuilder()
|
||||||
.joinToString("\n") { text -> text }
|
|
||||||
.takeIf { it.isNotEmpty() }
|
// Add subject
|
||||||
?: getCleansedSubject().takeIf { it.isNotEmpty() }
|
getCleansedSubject().takeIf { it.isNotEmpty() }?.run(sb::appendln)
|
||||||
?: "An MMS message"
|
|
||||||
|
// Add parts
|
||||||
|
parts.mapNotNull { it.getSummary() }.forEach { summary -> sb.appendln(summary) }
|
||||||
|
|
||||||
|
sb.toString().trim()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,4 +35,12 @@ open class MmsPart : RealmObject() {
|
|||||||
|
|
||||||
fun getUri() = "content://mms/part/$id".toUri()
|
fun getUri() = "content://mms/part/$id".toUri()
|
||||||
|
|
||||||
|
fun getSummary(): String? = when {
|
||||||
|
type == "text/plain" -> text
|
||||||
|
type == "text/x-vCard" -> "Contact card"
|
||||||
|
type.startsWith("image") -> "Photo"
|
||||||
|
type.startsWith("video") -> "Video"
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user