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
@@ -24,21 +24,22 @@ import android.content.Context
import android.widget.Toast
import dev.octoshrimpy.quik.R
object ClipboardUtils {
fun copy(context: Context, string: String) {
try {
(context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager)
.setPrimaryClip(ClipData.newPlainText("SMS", string))
} catch (e: Exception) {
Toast.makeText(
context,
if ((e is RuntimeException) &&
e.message?.startsWith("android.os.TransactionTooLargeException") == true
) R.string.clipboard_too_large_to_copy
else R.string.clipboard_unable_to_copy_to,
Toast.LENGTH_LONG
).show()
class ClipboardUtils {
companion object {
fun copy(context: Context, string: String) {
try {
(context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager)
.setPrimaryClip(ClipData.newPlainText("SMS", string))
} catch (e: Exception) {
Toast.makeText(
context,
if ((e is RuntimeException) &&
e.message?.startsWith("android.os.TransactionTooLargeException") == true
) R.string.clipboard_too_large_to_copy
else R.string.clipboard_unable_to_copy_to,
Toast.LENGTH_LONG
).show()
}
}
}
@@ -20,16 +20,11 @@ package dev.octoshrimpy.quik.common.util
import android.content.Context
import android.net.Uri
import android.os.Build
import android.os.Environment
import android.provider.MediaStore
import android.util.Log
import androidx.core.content.contentValuesOf
import dev.octoshrimpy.quik.util.Preferences
import dev.octoshrimpy.quik.util.tryOrNull
import dev.octoshrimpy.quik.util.FileUtils
import io.reactivex.schedulers.Schedulers
import timber.log.Timber
import java.io.File
import java.io.FileNotFoundException
import java.text.SimpleDateFormat
import java.util.*
@@ -78,48 +73,33 @@ class FileLoggingTree @Inject constructor(
Log.getStackTraceString(t)
}\n"
try {
// if uri of log file not yet determined, get one now
if (logFileUri == null) {
val filename = "Quik-log-${
SimpleDateFormat(
"yyyy-MM-dd",
Locale.getDefault()
).format(System.currentTimeMillis())
}.log"
// if uri of log file not yet determined, get one now
if (logFileUri == null) {
val filename = "Quik-log-${
SimpleDateFormat(
"yyyy-MM-dd",
Locale.getDefault()
).format(System.currentTimeMillis())
}.log"
logFileUri =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
// use media store
context.contentResolver.insert(
MediaStore.Downloads.EXTERNAL_CONTENT_URI,
contentValuesOf(
MediaStore.MediaColumns.MIME_TYPE to "text/plain",
MediaStore.MediaColumns.RELATIVE_PATH to
Environment.DIRECTORY_DOWNLOADS,
MediaStore.MediaColumns.DISPLAY_NAME to filename,
)
)
else
// use direct access to 'external' dir
File(Environment.getExternalStorageDirectory(), filename).let {
tryOrNull { it.createNewFile() }
Uri.fromFile(it)
}
}
val (uri, e) = FileUtils.create(
FileUtils.Companion.Location.Downloads,
context,
filename,
"text/plain"
)
if (e is Exception)
Log.e(TAG, "Error opening log file", e)
else
logFileUri = uri
}
logFileUri?.let {
context.contentResolver.openOutputStream(it, "wa")?.use {
// write the log entry
it.write(logItem.toByteArray())
}
}
} catch (e: FileNotFoundException) {
Log.e(TAG, "Log file went away. Lost log file item: $logItem")
// log file seems to have gone away. start a new file next time through
logFileUri = null
} catch (e: Exception) {
Log.e(TAG, "Error while logging into file", e)
logFileUri?.let {
val e = FileUtils.append(context, it, logItem.toByteArray())
if (e is FileNotFoundException)
Log.e(TAG, "Log file went away. Lost log file item: $logItem", e)
else if (e is Exception)
Log.e(TAG, "Error while logging into file", e)
}
}
}