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:
gavine99
2025-03-26 17:28:34 +11:00
parent 669932ef0e
commit 8356008b88
18 changed files with 707 additions and 340 deletions
@@ -0,0 +1,7 @@
package dev.octoshrimpy.quik.extensions
import java.util.concurrent.TimeUnit
fun Long.millisecondsToMinutes(): Long {
return TimeUnit.MILLISECONDS.toMinutes(this)
}
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package dev.octoshrimpy.quik.extensions
import java.text.Normalizer
/**
* Strip the accents from a string
*/
fun CharSequence.removeAccents(): String = Normalizer.normalize(this, Normalizer.Form.NFKD).replace(Regex("\\p{M}"), "")
fun String.joinTo(rhs:String, separator: String) =
when {
this.isEmpty() -> rhs
rhs.isEmpty() -> this
else -> "$this$separator$rhs"
}
fun String.truncateWithEllipses(maxLengthIncEllipses: Int) =
when (this.length) {
in 0..maxLengthIncEllipses -> this
else -> this.take(maxLengthIncEllipses - 1) + "…"
}
@@ -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()