mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-19 04:18:53 +01:00
limit bubble display of text to 5000 chars.
add instruction status message when bubble char limit exceeded. add share text feature. make copy and share text menu options only available when there is text in selected messages. new FileProvider to share messages text files out of app's cache dir. add message subject to copy messages text feature. a lot of refactoring of MessagesAdapter class. add new FileUtils class. convert file logging to use new FileUtils class. change MediaRecorder to use new FileUtils class. housekeeping worker now cleans messages text cache files. housekeeping worker now checks cache files older than 2 hours before deleting.
This commit is contained in:
@@ -21,6 +21,7 @@ package dev.octoshrimpy.quik.model
|
||||
import android.content.ContentUris
|
||||
import android.net.Uri
|
||||
import android.provider.Telephony.*
|
||||
import dev.octoshrimpy.quik.extensions.joinTo
|
||||
import io.realm.RealmList
|
||||
import io.realm.RealmObject
|
||||
import io.realm.annotations.Index
|
||||
@@ -100,14 +101,30 @@ open class Message : RealmObject() {
|
||||
/**
|
||||
* Returns the text that should be copied to the clipboard
|
||||
*/
|
||||
fun getText(): String {
|
||||
return when {
|
||||
fun getText(withSubject: Boolean = true): String {
|
||||
val messageText = when {
|
||||
isSms() -> body
|
||||
|
||||
else -> parts
|
||||
.filter { it.type == "text/plain" }
|
||||
.mapNotNull { it.text }
|
||||
.joinToString("\n") { text -> text }
|
||||
.filter { it.type.lowercase() == "text/plain" }
|
||||
.mapNotNull { it.text }
|
||||
.filter { it.isNotBlank() }
|
||||
.joinToString("\n") { text -> text }
|
||||
}
|
||||
|
||||
if (!withSubject)
|
||||
return messageText
|
||||
|
||||
return getCleansedSubject().joinTo(messageText, "\n")
|
||||
}
|
||||
|
||||
// returns a boolean indicating if message has any text parts that are not whitespace only
|
||||
fun hasNonWhitespaceText(): Boolean {
|
||||
return when {
|
||||
isSms() -> body.isNotBlank()
|
||||
else -> parts
|
||||
.filter { it.type.lowercase() == "text/plain" }
|
||||
.mapNotNull { it.text }
|
||||
.any { it.isNotBlank() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,4 +178,19 @@ open class Message : RealmObject() {
|
||||
!isMe() && !other.isMe() -> subId == other.subId && address == other.address
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// extension function to get all text from a list of messages
|
||||
fun List<Message>.getText(withSubject: Boolean = true): String =
|
||||
foldIndexed(StringBuilder()) { index, acc, message ->
|
||||
when {
|
||||
index == 0 ->
|
||||
acc.append(message.getText(withSubject))
|
||||
|
||||
this[index - 1].compareSender(message) ->
|
||||
acc.appendLine().append(message.getText(withSubject))
|
||||
|
||||
else ->
|
||||
acc.appendLine().appendLine().append(message.getText(withSubject))
|
||||
}
|
||||
}.toString()
|
||||
|
||||
Reference in New Issue
Block a user