forked from upstream-mirrors/quik
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:
@@ -23,8 +23,8 @@ import android.media.AudioDeviceInfo
|
|||||||
import android.media.MediaRecorder
|
import android.media.MediaRecorder
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toFile
|
||||||
import java.io.File
|
import dev.octoshrimpy.quik.util.FileUtils
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|
||||||
object MediaRecorderManager : MediaRecorder() {
|
object MediaRecorderManager : MediaRecorder() {
|
||||||
@@ -63,10 +63,16 @@ object MediaRecorderManager : MediaRecorder() {
|
|||||||
|
|
||||||
fun startRecording(context: Context, preferredAudioDevice: AudioDeviceInfo? = null): Uri {
|
fun startRecording(context: Context, preferredAudioDevice: AudioDeviceInfo? = null): Uri {
|
||||||
return try {
|
return try {
|
||||||
val file = File(
|
val (newUri, e) = FileUtils.create(
|
||||||
context.cacheDir,
|
FileUtils.Companion.Location.Cache,
|
||||||
AUDIO_FILE_PREFIX + UUID.randomUUID() + AUDIO_FILE_SUFFIX
|
context,
|
||||||
|
"$AUDIO_FILE_PREFIX${UUID.randomUUID()}$AUDIO_FILE_SUFFIX",
|
||||||
|
""
|
||||||
)
|
)
|
||||||
|
if (e is Exception)
|
||||||
|
throw e
|
||||||
|
|
||||||
|
uri = newUri
|
||||||
|
|
||||||
// ensure stopped before using again
|
// ensure stopped before using again
|
||||||
stopRecording()
|
stopRecording()
|
||||||
@@ -76,13 +82,12 @@ object MediaRecorderManager : MediaRecorder() {
|
|||||||
setOutputFormat(OutputFormat.THREE_GPP)
|
setOutputFormat(OutputFormat.THREE_GPP)
|
||||||
setAudioEncoder(AudioEncoder.AMR_WB)
|
setAudioEncoder(AudioEncoder.AMR_WB)
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
|
||||||
preferredDevice = preferredAudioDevice
|
preferredDevice = preferredAudioDevice
|
||||||
}
|
|
||||||
|
|
||||||
recordingState = RecordingState.DataSourceConfigured
|
recordingState = RecordingState.DataSourceConfigured
|
||||||
|
|
||||||
setOutputFile(file.path)
|
setOutputFile(uri.toFile().path)
|
||||||
|
|
||||||
prepare()
|
prepare()
|
||||||
recordingState = RecordingState.Prepared
|
recordingState = RecordingState.Prepared
|
||||||
@@ -90,8 +95,6 @@ object MediaRecorderManager : MediaRecorder() {
|
|||||||
start()
|
start()
|
||||||
recordingState = RecordingState.Recording
|
recordingState = RecordingState.Recording
|
||||||
|
|
||||||
uri = file.toUri()
|
|
||||||
|
|
||||||
uri
|
uri
|
||||||
}
|
}
|
||||||
catch (e: Exception) {
|
catch (e: Exception) {
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.moez.QKSMS.util
|
||||||
|
|
||||||
|
class Constants {
|
||||||
|
companion object {
|
||||||
|
const val SAVED_MESSAGE_TEXT_FILE_PREFIX = "QuikSmsText-"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,149 @@
|
|||||||
|
package dev.octoshrimpy.quik.util
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.net.Uri
|
||||||
|
import android.os.Build
|
||||||
|
import android.os.Environment
|
||||||
|
import android.provider.MediaStore
|
||||||
|
import androidx.core.content.contentValuesOf
|
||||||
|
import androidx.core.net.toFile
|
||||||
|
import dev.octoshrimpy.quik.extensions.isEmpty
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
class FileUtils {
|
||||||
|
companion object {
|
||||||
|
enum class Location {
|
||||||
|
Downloads,
|
||||||
|
ExternalCache,
|
||||||
|
Cache,
|
||||||
|
Files,
|
||||||
|
Obb,
|
||||||
|
CodeCache,
|
||||||
|
NoBackup,
|
||||||
|
}
|
||||||
|
|
||||||
|
fun create(
|
||||||
|
location: Location,
|
||||||
|
context: Context,
|
||||||
|
filename: String,
|
||||||
|
mimeType: String
|
||||||
|
) =
|
||||||
|
if (location == Location.Downloads) createDownloadsFile(context, filename, mimeType)
|
||||||
|
else createLocation(location, context, filename)
|
||||||
|
|
||||||
|
private fun createDownloadsFile(
|
||||||
|
context: Context,
|
||||||
|
filename: String,
|
||||||
|
mimeType: String
|
||||||
|
): Pair<Uri, Exception?> =
|
||||||
|
try {
|
||||||
|
val uri = 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 mimeType,
|
||||||
|
MediaStore.MediaColumns.RELATIVE_PATH to
|
||||||
|
Environment.DIRECTORY_DOWNLOADS,
|
||||||
|
MediaStore.MediaColumns.DISPLAY_NAME to filename,
|
||||||
|
)
|
||||||
|
) ?: Uri.EMPTY
|
||||||
|
} else { // use direct access to 'external' dir
|
||||||
|
File(Environment.getExternalStorageDirectory(), filename).let {
|
||||||
|
if (tryOrNull { it.createNewFile() } == true) Uri.fromFile(it)
|
||||||
|
else Uri.EMPTY
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (uri.isEmpty())
|
||||||
|
throw Exception("Opening file returned an empty uri")
|
||||||
|
|
||||||
|
Pair(uri, null)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Pair(Uri.EMPTY, e)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createLocation(
|
||||||
|
location: Location,
|
||||||
|
context: Context,
|
||||||
|
filename: String
|
||||||
|
): Pair<Uri, Exception?> =
|
||||||
|
try {
|
||||||
|
val uri = File(
|
||||||
|
when (location) {
|
||||||
|
Location.ExternalCache -> context.externalCacheDir
|
||||||
|
Location.Files -> context.filesDir
|
||||||
|
Location.Obb -> context.obbDir
|
||||||
|
Location.CodeCache -> context.codeCacheDir
|
||||||
|
Location.NoBackup -> context.noBackupFilesDir
|
||||||
|
else -> context.cacheDir
|
||||||
|
},
|
||||||
|
filename
|
||||||
|
).let {
|
||||||
|
if (tryOrNull { it.createNewFile() } == true) Uri.fromFile(it)
|
||||||
|
else Uri.EMPTY
|
||||||
|
}
|
||||||
|
|
||||||
|
if (uri.isEmpty())
|
||||||
|
throw Exception("Opening file returned an empty uri")
|
||||||
|
|
||||||
|
Pair(uri, null)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Pair(Uri.EMPTY, e)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun writeBytes(
|
||||||
|
context: Context,
|
||||||
|
uri: Uri,
|
||||||
|
bytes: ByteArray,
|
||||||
|
mode: String
|
||||||
|
): Exception? =
|
||||||
|
try {
|
||||||
|
context.contentResolver.openOutputStream(uri, mode)?.use { it.write(bytes) }
|
||||||
|
null
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e
|
||||||
|
}
|
||||||
|
|
||||||
|
fun append(context: Context, uri: Uri, bytes: ByteArray): Exception? =
|
||||||
|
writeBytes(context, uri, bytes, "wa")
|
||||||
|
|
||||||
|
fun write(context: Context, uri: Uri, bytes: ByteArray): Exception? =
|
||||||
|
writeBytes(context, uri, bytes, "w")
|
||||||
|
|
||||||
|
fun truncateAndWrite(context: Context, uri: Uri, bytes: ByteArray): Exception? =
|
||||||
|
writeBytes(context, uri, bytes, "wt")
|
||||||
|
|
||||||
|
fun createAndWrite(
|
||||||
|
context: Context,
|
||||||
|
location: Location,
|
||||||
|
filename: String,
|
||||||
|
mimeType: String,
|
||||||
|
bytes: ByteArray
|
||||||
|
): Pair<Uri, Exception?> =
|
||||||
|
create(location, context, filename, mimeType).let { (uri, e) ->
|
||||||
|
if (e is Exception) Pair(Uri.EMPTY, e)
|
||||||
|
else {
|
||||||
|
val we = writeBytes(context, uri, bytes, "w")
|
||||||
|
if (we is Exception) {
|
||||||
|
deleteFile(uri)
|
||||||
|
Pair(Uri.EMPTY, we)
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Pair(uri, null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun deleteFile(uri: Uri): Boolean {
|
||||||
|
return try {
|
||||||
|
if (uri == Uri.EMPTY) false
|
||||||
|
else uri.toFile().delete()
|
||||||
|
}
|
||||||
|
catch (e: Exception) { false }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun renameTo(fromUri: Uri, toUri: Uri) {
|
||||||
|
fromUri.toFile().renameTo(toUri.toFile())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -27,6 +27,7 @@ import androidx.work.PeriodicWorkRequest
|
|||||||
import androidx.work.WorkManager
|
import androidx.work.WorkManager
|
||||||
import androidx.work.Worker
|
import androidx.work.Worker
|
||||||
import androidx.work.WorkerParameters
|
import androidx.work.WorkerParameters
|
||||||
|
import com.moez.QKSMS.util.Constants
|
||||||
import androidx.work.workDataOf
|
import androidx.work.workDataOf
|
||||||
import com.moez.QKSMS.manager.MediaRecorderManager
|
import com.moez.QKSMS.manager.MediaRecorderManager
|
||||||
import com.moez.QKSMS.manager.MediaRecorderManager.AUDIO_FILE_PREFIX
|
import com.moez.QKSMS.manager.MediaRecorderManager.AUDIO_FILE_PREFIX
|
||||||
@@ -42,6 +43,8 @@ class HousekeepingWorker(appContext: Context, workerParams: WorkerParameters)
|
|||||||
companion object {
|
companion object {
|
||||||
private val WORKER_TAG: String = HousekeepingWorker::class.java.simpleName
|
private val WORKER_TAG: String = HousekeepingWorker::class.java.simpleName
|
||||||
|
|
||||||
|
private val someHoursAgo = (System.currentTimeMillis() - (2 * 60 * 60 * 1000))
|
||||||
|
|
||||||
fun register(context: Context) {
|
fun register(context: Context) {
|
||||||
// don't check return value because, well, we can't do much about a failure
|
// don't check return value because, well, we can't do much about a failure
|
||||||
WorkManager.getInstance(context).enqueueUniquePeriodicWork(
|
WorkManager.getInstance(context).enqueueUniquePeriodicWork(
|
||||||
@@ -49,12 +52,12 @@ class HousekeepingWorker(appContext: Context, workerParams: WorkerParameters)
|
|||||||
ExistingPeriodicWorkPolicy.UPDATE,
|
ExistingPeriodicWorkPolicy.UPDATE,
|
||||||
PeriodicWorkRequest.Builder(
|
PeriodicWorkRequest.Builder(
|
||||||
HousekeepingWorker::class.java,
|
HousekeepingWorker::class.java,
|
||||||
24,
|
1,
|
||||||
TimeUnit.HOURS
|
TimeUnit.DAYS
|
||||||
)
|
)
|
||||||
.setConstraints(
|
.setConstraints(
|
||||||
Constraints.Builder()
|
Constraints.Builder()
|
||||||
// idle device constraint kinda guarantees quik won't be in use
|
// idle device constraint helps guarantees quik won't be in use
|
||||||
// as files are deleted (primarily for deleting audio recordings)
|
// as files are deleted (primarily for deleting audio recordings)
|
||||||
.setRequiresDeviceIdle(true)
|
.setRequiresDeviceIdle(true)
|
||||||
// good citizens don't use up low batteries
|
// good citizens don't use up low batteries
|
||||||
@@ -76,7 +79,9 @@ class HousekeepingWorker(appContext: Context, workerParams: WorkerParameters)
|
|||||||
override fun doWork(): Result {
|
override fun doWork(): Result {
|
||||||
removeOrphanedScheduledMessageAttachmentFiles()
|
removeOrphanedScheduledMessageAttachmentFiles()
|
||||||
|
|
||||||
removeOrphanedComposeAudioRecording()
|
removeOrphanedComposeAudioRecordings()
|
||||||
|
|
||||||
|
removeSavedMessagesTexts()
|
||||||
|
|
||||||
return Result.success()
|
return Result.success()
|
||||||
}
|
}
|
||||||
@@ -97,15 +102,21 @@ class HousekeepingWorker(appContext: Context, workerParams: WorkerParameters)
|
|||||||
?.forEach { it.deleteRecursively() }
|
?.forEach { it.deleteRecursively() }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun removeOrphanedComposeAudioRecording() {
|
private fun removeOrphanedComposeAudioRecordings() =
|
||||||
// find recording files in cache dir
|
// find recording files in cache dir
|
||||||
applicationContext.cacheDir.listFiles { entry ->
|
applicationContext.cacheDir.listFiles { entry ->
|
||||||
entry.isFile &&
|
entry.isFile &&
|
||||||
entry.name.startsWith(AUDIO_FILE_PREFIX) &&
|
entry.name.startsWith(MediaRecorderManager.AUDIO_FILE_PREFIX) &&
|
||||||
entry.name.endsWith(MediaRecorderManager.AUDIO_FILE_SUFFIX)
|
entry.name.endsWith(MediaRecorderManager.AUDIO_FILE_SUFFIX) &&
|
||||||
}
|
(entry.lastModified() < someHoursAgo)
|
||||||
// delete recording file
|
}?.forEach { it.delete() } // delete recording file
|
||||||
?.forEach { it.delete() }
|
|
||||||
}
|
private fun removeSavedMessagesTexts() =
|
||||||
|
// find saved message text files in cache dir
|
||||||
|
applicationContext.cacheDir.listFiles { entry ->
|
||||||
|
entry.isFile &&
|
||||||
|
entry.name.startsWith(Constants.SAVED_MESSAGE_TEXT_FILE_PREFIX) &&
|
||||||
|
(entry.lastModified() < someHoursAgo)
|
||||||
|
}?.forEach { it.delete() } // delete message text file
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -25,6 +25,17 @@
|
|||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:grantUriPermissions="true">
|
android:grantUriPermissions="true">
|
||||||
</provider>
|
</provider>
|
||||||
|
|
||||||
|
<provider
|
||||||
|
android:name="androidx.core.content.FileProvider"
|
||||||
|
android:authorities="dev.octoshrimpy.quik.messagesText"
|
||||||
|
android:enabled="true"
|
||||||
|
android:exported="false"
|
||||||
|
android:grantUriPermissions="true">
|
||||||
|
<meta-data
|
||||||
|
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||||
|
android:resource="@xml/messages_text_file_provider_paths" />
|
||||||
|
</provider>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
<queries>
|
<queries>
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package dev.octoshrimpy.quik.extensions
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
fun Long.millisecondsToMinutes(): Long {
|
||||||
|
return TimeUnit.MILLISECONDS.toMinutes(this)
|
||||||
|
}
|
||||||
+13
@@ -24,3 +24,16 @@ import java.text.Normalizer
|
|||||||
* Strip the accents from a string
|
* Strip the accents from a string
|
||||||
*/
|
*/
|
||||||
fun CharSequence.removeAccents(): String = Normalizer.normalize(this, Normalizer.Form.NFKD).replace(Regex("\\p{M}"), "")
|
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.content.ContentUris
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.provider.Telephony.*
|
import android.provider.Telephony.*
|
||||||
|
import dev.octoshrimpy.quik.extensions.joinTo
|
||||||
import io.realm.RealmList
|
import io.realm.RealmList
|
||||||
import io.realm.RealmObject
|
import io.realm.RealmObject
|
||||||
import io.realm.annotations.Index
|
import io.realm.annotations.Index
|
||||||
@@ -100,14 +101,30 @@ open class Message : RealmObject() {
|
|||||||
/**
|
/**
|
||||||
* Returns the text that should be copied to the clipboard
|
* Returns the text that should be copied to the clipboard
|
||||||
*/
|
*/
|
||||||
fun getText(): String {
|
fun getText(withSubject: Boolean = true): String {
|
||||||
return when {
|
val messageText = when {
|
||||||
isSms() -> body
|
isSms() -> body
|
||||||
|
|
||||||
else -> parts
|
else -> parts
|
||||||
.filter { it.type == "text/plain" }
|
.filter { it.type.lowercase() == "text/plain" }
|
||||||
.mapNotNull { it.text }
|
.mapNotNull { it.text }
|
||||||
.joinToString("\n") { text -> 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
|
!isMe() && !other.isMe() -> subId == other.subId && address == other.address
|
||||||
else -> false
|
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()
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<paths xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<cache-path name="messages_text" path="." />
|
||||||
|
</paths>
|
||||||
@@ -24,21 +24,22 @@ import android.content.Context
|
|||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import dev.octoshrimpy.quik.R
|
import dev.octoshrimpy.quik.R
|
||||||
|
|
||||||
object ClipboardUtils {
|
class ClipboardUtils {
|
||||||
|
companion object {
|
||||||
fun copy(context: Context, string: String) {
|
fun copy(context: Context, string: String) {
|
||||||
try {
|
try {
|
||||||
(context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager)
|
(context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager)
|
||||||
.setPrimaryClip(ClipData.newPlainText("SMS", string))
|
.setPrimaryClip(ClipData.newPlainText("SMS", string))
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
context,
|
context,
|
||||||
if ((e is RuntimeException) &&
|
if ((e is RuntimeException) &&
|
||||||
e.message?.startsWith("android.os.TransactionTooLargeException") == true
|
e.message?.startsWith("android.os.TransactionTooLargeException") == true
|
||||||
) R.string.clipboard_too_large_to_copy
|
) R.string.clipboard_too_large_to_copy
|
||||||
else R.string.clipboard_unable_to_copy_to,
|
else R.string.clipboard_unable_to_copy_to,
|
||||||
Toast.LENGTH_LONG
|
Toast.LENGTH_LONG
|
||||||
).show()
|
).show()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,16 +20,11 @@ package dev.octoshrimpy.quik.common.util
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
|
||||||
import android.os.Environment
|
|
||||||
import android.provider.MediaStore
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.core.content.contentValuesOf
|
|
||||||
import dev.octoshrimpy.quik.util.Preferences
|
import dev.octoshrimpy.quik.util.Preferences
|
||||||
import dev.octoshrimpy.quik.util.tryOrNull
|
import dev.octoshrimpy.quik.util.FileUtils
|
||||||
import io.reactivex.schedulers.Schedulers
|
import io.reactivex.schedulers.Schedulers
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.io.File
|
|
||||||
import java.io.FileNotFoundException
|
import java.io.FileNotFoundException
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@@ -78,48 +73,33 @@ class FileLoggingTree @Inject constructor(
|
|||||||
Log.getStackTraceString(t)
|
Log.getStackTraceString(t)
|
||||||
}\n"
|
}\n"
|
||||||
|
|
||||||
try {
|
// if uri of log file not yet determined, get one now
|
||||||
// if uri of log file not yet determined, get one now
|
if (logFileUri == null) {
|
||||||
if (logFileUri == null) {
|
val filename = "Quik-log-${
|
||||||
val filename = "Quik-log-${
|
SimpleDateFormat(
|
||||||
SimpleDateFormat(
|
"yyyy-MM-dd",
|
||||||
"yyyy-MM-dd",
|
Locale.getDefault()
|
||||||
Locale.getDefault()
|
).format(System.currentTimeMillis())
|
||||||
).format(System.currentTimeMillis())
|
}.log"
|
||||||
}.log"
|
|
||||||
|
|
||||||
logFileUri =
|
val (uri, e) = FileUtils.create(
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
|
FileUtils.Companion.Location.Downloads,
|
||||||
// use media store
|
context,
|
||||||
context.contentResolver.insert(
|
filename,
|
||||||
MediaStore.Downloads.EXTERNAL_CONTENT_URI,
|
"text/plain"
|
||||||
contentValuesOf(
|
)
|
||||||
MediaStore.MediaColumns.MIME_TYPE to "text/plain",
|
if (e is Exception)
|
||||||
MediaStore.MediaColumns.RELATIVE_PATH to
|
Log.e(TAG, "Error opening log file", e)
|
||||||
Environment.DIRECTORY_DOWNLOADS,
|
else
|
||||||
MediaStore.MediaColumns.DISPLAY_NAME to filename,
|
logFileUri = uri
|
||||||
)
|
}
|
||||||
)
|
|
||||||
else
|
|
||||||
// use direct access to 'external' dir
|
|
||||||
File(Environment.getExternalStorageDirectory(), filename).let {
|
|
||||||
tryOrNull { it.createNewFile() }
|
|
||||||
Uri.fromFile(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
logFileUri?.let {
|
logFileUri?.let {
|
||||||
context.contentResolver.openOutputStream(it, "wa")?.use {
|
val e = FileUtils.append(context, it, logItem.toByteArray())
|
||||||
// write the log entry
|
if (e is FileNotFoundException)
|
||||||
it.write(logItem.toByteArray())
|
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)
|
||||||
} 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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ import dev.octoshrimpy.quik.common.util.extensions.setVisible
|
|||||||
import dev.octoshrimpy.quik.common.util.extensions.showKeyboard
|
import dev.octoshrimpy.quik.common.util.extensions.showKeyboard
|
||||||
import dev.octoshrimpy.quik.common.widget.MicInputCloudView
|
import dev.octoshrimpy.quik.common.widget.MicInputCloudView
|
||||||
import dev.octoshrimpy.quik.common.widget.QkEditText
|
import dev.octoshrimpy.quik.common.widget.QkEditText
|
||||||
|
import dev.octoshrimpy.quik.common.widget.TextInputDialog
|
||||||
import dev.octoshrimpy.quik.extensions.mapNotNull
|
import dev.octoshrimpy.quik.extensions.mapNotNull
|
||||||
import dev.octoshrimpy.quik.feature.compose.editing.ChipsAdapter
|
import dev.octoshrimpy.quik.feature.compose.editing.ChipsAdapter
|
||||||
import dev.octoshrimpy.quik.feature.contacts.ContactsActivity
|
import dev.octoshrimpy.quik.feature.contacts.ContactsActivity
|
||||||
@@ -206,6 +207,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
|||||||
override val recordAudioMsgRecordVisible: Subject<Boolean> = PublishSubject.create()
|
override val recordAudioMsgRecordVisible: Subject<Boolean> = PublishSubject.create()
|
||||||
override val recordAudioChronometer: Subject<Boolean> = PublishSubject.create()
|
override val recordAudioChronometer: Subject<Boolean> = PublishSubject.create()
|
||||||
override val recordAudioRecord: Subject<MicInputCloudView.ViewState> = PublishSubject.create()
|
override val recordAudioRecord: Subject<MicInputCloudView.ViewState> = PublishSubject.create()
|
||||||
|
// override val saveMessagesTextIntent: Subject<String> = PublishSubject.create()
|
||||||
|
|
||||||
private var seekBarUpdater: Disposable? = null
|
private var seekBarUpdater: Disposable? = null
|
||||||
|
|
||||||
@@ -224,25 +226,6 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
|||||||
return SpeechRecognizer.isRecognitionAvailable(this)
|
return SpeechRecognizer.isRecognitionAvailable(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val speechResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
|
||||||
if (result.resultCode != Activity.RESULT_OK)
|
|
||||||
return@registerForActivityResult
|
|
||||||
|
|
||||||
// check returned results are good
|
|
||||||
val match = result.data?.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS)
|
|
||||||
if ((match === null) || (match.size < 1) || (match[0].isNullOrEmpty()))
|
|
||||||
return@registerForActivityResult
|
|
||||||
|
|
||||||
// get the edit text view
|
|
||||||
val message = findViewById<QkEditText>(R.id.message)
|
|
||||||
if (message === null)
|
|
||||||
return@registerForActivityResult
|
|
||||||
|
|
||||||
// populate message box with data returned by STT, set cursor to end, and focus
|
|
||||||
message.append(match[0])
|
|
||||||
message.setSelection(message.text.length)
|
|
||||||
message.requestFocus()
|
|
||||||
}
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
AndroidInjection.inject(this)
|
AndroidInjection.inject(this)
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
@@ -495,7 +478,10 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
|||||||
&& state.query.isEmpty()
|
&& state.query.isEmpty()
|
||||||
toolbar.menu.findItem(R.id.info)?.isVisible = !state.editingMode && state.selectedMessages == 0
|
toolbar.menu.findItem(R.id.info)?.isVisible = !state.editingMode && state.selectedMessages == 0
|
||||||
&& state.query.isEmpty()
|
&& state.query.isEmpty()
|
||||||
toolbar.menu.findItem(R.id.copy)?.isVisible = !state.editingMode && state.selectedMessages > 0
|
toolbar.menu.findItem(R.id.copy)?.isVisible =
|
||||||
|
!state.editingMode && state.selectedMessages > 0 && state.selectedMessagesHaveText
|
||||||
|
toolbar.menu.findItem(R.id.share)?.isVisible =
|
||||||
|
!state.editingMode && state.selectedMessages > 0 && state.selectedMessagesHaveText
|
||||||
toolbar.menu.findItem(R.id.details)?.isVisible = !state.editingMode && state.selectedMessages == 1
|
toolbar.menu.findItem(R.id.details)?.isVisible = !state.editingMode && state.selectedMessages == 1
|
||||||
toolbar.menu.findItem(R.id.delete)?.isVisible = !state.editingMode && ((state.selectedMessages > 0) || state.canSend)
|
toolbar.menu.findItem(R.id.delete)?.isVisible = !state.editingMode && ((state.selectedMessages > 0) || state.canSend)
|
||||||
toolbar.menu.findItem(R.id.forward)?.isVisible = !state.editingMode && state.selectedMessages == 1
|
toolbar.menu.findItem(R.id.forward)?.isVisible = !state.editingMode && state.selectedMessages == 1
|
||||||
@@ -628,6 +614,14 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
|||||||
.setNegativeButton(R.string.messageLinkHandling_dialog_negative) { _, _ -> { } }
|
.setNegativeButton(R.string.messageLinkHandling_dialog_negative) { _, _ -> { } }
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
|
//
|
||||||
|
// override fun showSaveMessagesFilenameDialog(filename: String) {
|
||||||
|
// TextInputDialog(
|
||||||
|
// this,
|
||||||
|
// getString(R.string.messages_save_file_dialog_title),
|
||||||
|
// saveMessagesTextIntent::onNext
|
||||||
|
// ).setText(filename).show()
|
||||||
|
// }
|
||||||
|
|
||||||
override fun requestDefaultSms() {
|
override fun requestDefaultSms() {
|
||||||
navigator.showDefaultSmsDialog(this)
|
navigator.showDefaultSmsDialog(this)
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ data class ComposeState(
|
|||||||
val searchResults: Int = 0,
|
val searchResults: Int = 0,
|
||||||
val messages: Pair<Conversation, RealmResults<Message>>? = null,
|
val messages: Pair<Conversation, RealmResults<Message>>? = null,
|
||||||
val selectedMessages: Int = 0,
|
val selectedMessages: Int = 0,
|
||||||
|
val selectedMessagesHaveText: Boolean = false,
|
||||||
val scheduled: Long = 0,
|
val scheduled: Long = 0,
|
||||||
val attachments: List<Attachment> = listOf(),
|
val attachments: List<Attachment> = listOf(),
|
||||||
val attaching: Boolean = false,
|
val attaching: Boolean = false,
|
||||||
|
|||||||
@@ -89,12 +89,14 @@ interface ComposeView : QkView<ComposeState> {
|
|||||||
val recordAudioMsgRecordVisible: Subject<Boolean>
|
val recordAudioMsgRecordVisible: Subject<Boolean>
|
||||||
val recordAudioRecord: Subject<MicInputCloudView.ViewState>
|
val recordAudioRecord: Subject<MicInputCloudView.ViewState>
|
||||||
val recordAudioChronometer: Subject<Boolean>
|
val recordAudioChronometer: Subject<Boolean>
|
||||||
|
// val saveMessagesTextIntent: Subject<String>
|
||||||
|
|
||||||
fun clearSelection()
|
fun clearSelection()
|
||||||
fun toggleSelectAll()
|
fun toggleSelectAll()
|
||||||
fun expandMessages(messageIds: List<Long>, expand: Boolean)
|
fun expandMessages(messageIds: List<Long>, expand: Boolean)
|
||||||
fun showDetails(details: String)
|
fun showDetails(details: String)
|
||||||
fun showMessageLinkAskDialog(uri: Uri)
|
fun showMessageLinkAskDialog(uri: Uri)
|
||||||
|
// fun showSaveMessagesFilenameDialog(filename: String)
|
||||||
fun requestDefaultSms()
|
fun requestDefaultSms()
|
||||||
fun requestStoragePermission()
|
fun requestStoragePermission()
|
||||||
fun requestRecordAudioPermission()
|
fun requestRecordAudioPermission()
|
||||||
|
|||||||
@@ -25,23 +25,33 @@ import android.media.AudioDeviceInfo
|
|||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Vibrator
|
import android.os.Vibrator
|
||||||
import android.telephony.SmsMessage
|
import android.telephony.SmsMessage
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.core.content.getSystemService
|
import androidx.core.content.getSystemService
|
||||||
|
import androidx.core.content.FileProvider
|
||||||
import androidx.core.net.toFile
|
import androidx.core.net.toFile
|
||||||
import androidx.core.net.toUri
|
import com.google.android.exoplayer2.util.MimeTypes
|
||||||
import com.moez.QKSMS.common.QkMediaPlayer
|
import com.moez.QKSMS.common.QkMediaPlayer
|
||||||
import com.moez.QKSMS.contentproviders.MmsPartProvider
|
import com.moez.QKSMS.contentproviders.MmsPartProvider
|
||||||
import com.moez.QKSMS.manager.MediaRecorderManager
|
|
||||||
import com.moez.QKSMS.manager.BluetoothMicManager
|
import com.moez.QKSMS.manager.BluetoothMicManager
|
||||||
|
import com.moez.QKSMS.manager.MediaRecorderManager
|
||||||
|
import com.moez.QKSMS.manager.MediaRecorderManager.AUDIO_FILE_PREFIX
|
||||||
|
import com.moez.QKSMS.manager.MediaRecorderManager.AUDIO_FILE_SUFFIX
|
||||||
|
import com.moez.QKSMS.util.Constants.Companion.SAVED_MESSAGE_TEXT_FILE_PREFIX
|
||||||
|
import com.uber.autodispose.android.lifecycle.scope
|
||||||
|
import com.uber.autodispose.autoDisposable
|
||||||
import dev.octoshrimpy.quik.R
|
import dev.octoshrimpy.quik.R
|
||||||
import dev.octoshrimpy.quik.common.Navigator
|
import dev.octoshrimpy.quik.common.Navigator
|
||||||
import dev.octoshrimpy.quik.common.base.QkViewModel
|
import dev.octoshrimpy.quik.common.base.QkViewModel
|
||||||
import dev.octoshrimpy.quik.common.util.ClipboardUtils
|
import dev.octoshrimpy.quik.common.util.ClipboardUtils
|
||||||
import dev.octoshrimpy.quik.common.util.MessageDetailsFormatter
|
import dev.octoshrimpy.quik.common.util.MessageDetailsFormatter
|
||||||
import dev.octoshrimpy.quik.common.util.extensions.makeToast
|
import dev.octoshrimpy.quik.common.util.extensions.makeToast
|
||||||
|
import dev.octoshrimpy.quik.common.widget.MicInputCloudView
|
||||||
|
import dev.octoshrimpy.quik.common.widget.QkContextMenuRecyclerView
|
||||||
import dev.octoshrimpy.quik.compat.SubscriptionManagerCompat
|
import dev.octoshrimpy.quik.compat.SubscriptionManagerCompat
|
||||||
import dev.octoshrimpy.quik.compat.TelephonyCompat
|
import dev.octoshrimpy.quik.compat.TelephonyCompat
|
||||||
import dev.octoshrimpy.quik.extensions.asObservable
|
import dev.octoshrimpy.quik.extensions.asObservable
|
||||||
import dev.octoshrimpy.quik.extensions.isImage
|
import dev.octoshrimpy.quik.extensions.isImage
|
||||||
|
import dev.octoshrimpy.quik.extensions.isSmil
|
||||||
import dev.octoshrimpy.quik.extensions.isVideo
|
import dev.octoshrimpy.quik.extensions.isVideo
|
||||||
import dev.octoshrimpy.quik.extensions.mapNotNull
|
import dev.octoshrimpy.quik.extensions.mapNotNull
|
||||||
import dev.octoshrimpy.quik.interactor.AddScheduledMessage
|
import dev.octoshrimpy.quik.interactor.AddScheduledMessage
|
||||||
@@ -49,6 +59,7 @@ import dev.octoshrimpy.quik.interactor.CancelDelayedMessage
|
|||||||
import dev.octoshrimpy.quik.interactor.DeleteMessages
|
import dev.octoshrimpy.quik.interactor.DeleteMessages
|
||||||
import dev.octoshrimpy.quik.interactor.MarkRead
|
import dev.octoshrimpy.quik.interactor.MarkRead
|
||||||
import dev.octoshrimpy.quik.interactor.RetrySending
|
import dev.octoshrimpy.quik.interactor.RetrySending
|
||||||
|
import dev.octoshrimpy.quik.interactor.SaveImage
|
||||||
import dev.octoshrimpy.quik.interactor.SendMessage
|
import dev.octoshrimpy.quik.interactor.SendMessage
|
||||||
import dev.octoshrimpy.quik.manager.ActiveConversationManager
|
import dev.octoshrimpy.quik.manager.ActiveConversationManager
|
||||||
import dev.octoshrimpy.quik.manager.BillingManager
|
import dev.octoshrimpy.quik.manager.BillingManager
|
||||||
@@ -56,21 +67,17 @@ import dev.octoshrimpy.quik.manager.PermissionManager
|
|||||||
import dev.octoshrimpy.quik.model.Attachment
|
import dev.octoshrimpy.quik.model.Attachment
|
||||||
import dev.octoshrimpy.quik.model.Conversation
|
import dev.octoshrimpy.quik.model.Conversation
|
||||||
import dev.octoshrimpy.quik.model.Message
|
import dev.octoshrimpy.quik.model.Message
|
||||||
|
import dev.octoshrimpy.quik.model.MmsPart
|
||||||
import dev.octoshrimpy.quik.model.Recipient
|
import dev.octoshrimpy.quik.model.Recipient
|
||||||
|
import dev.octoshrimpy.quik.model.getText
|
||||||
import dev.octoshrimpy.quik.repository.ContactRepository
|
import dev.octoshrimpy.quik.repository.ContactRepository
|
||||||
import dev.octoshrimpy.quik.repository.ConversationRepository
|
import dev.octoshrimpy.quik.repository.ConversationRepository
|
||||||
import dev.octoshrimpy.quik.repository.MessageRepository
|
import dev.octoshrimpy.quik.repository.MessageRepository
|
||||||
import dev.octoshrimpy.quik.util.ActiveSubscriptionObservable
|
import dev.octoshrimpy.quik.util.ActiveSubscriptionObservable
|
||||||
import dev.octoshrimpy.quik.util.PhoneNumberUtils
|
import dev.octoshrimpy.quik.util.PhoneNumberUtils
|
||||||
import dev.octoshrimpy.quik.util.Preferences
|
import dev.octoshrimpy.quik.util.Preferences
|
||||||
|
import dev.octoshrimpy.quik.util.FileUtils
|
||||||
import dev.octoshrimpy.quik.util.tryOrNull
|
import dev.octoshrimpy.quik.util.tryOrNull
|
||||||
import com.uber.autodispose.android.lifecycle.scope
|
|
||||||
import com.uber.autodispose.autoDisposable
|
|
||||||
import dev.octoshrimpy.quik.common.widget.MicInputCloudView
|
|
||||||
import dev.octoshrimpy.quik.common.widget.QkContextMenuRecyclerView
|
|
||||||
import dev.octoshrimpy.quik.extensions.isSmil
|
|
||||||
import dev.octoshrimpy.quik.interactor.SaveImage
|
|
||||||
import dev.octoshrimpy.quik.model.MmsPart
|
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
import io.reactivex.rxkotlin.Observables
|
import io.reactivex.rxkotlin.Observables
|
||||||
@@ -81,7 +88,7 @@ import io.reactivex.subjects.BehaviorSubject
|
|||||||
import io.reactivex.subjects.PublishSubject
|
import io.reactivex.subjects.PublishSubject
|
||||||
import io.reactivex.subjects.Subject
|
import io.reactivex.subjects.Subject
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.io.File
|
import java.text.SimpleDateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Named
|
import javax.inject.Named
|
||||||
@@ -120,11 +127,6 @@ class ComposeViewModel @Inject constructor(
|
|||||||
threadId = threadId,
|
threadId = threadId,
|
||||||
query = query)
|
query = query)
|
||||||
) {
|
) {
|
||||||
|
|
||||||
companion object {
|
|
||||||
private const val AUDIO_FILE_PREFIX = "recorded-"
|
|
||||||
}
|
|
||||||
|
|
||||||
private val chipsReducer: Subject<(List<Recipient>) -> List<Recipient>> = PublishSubject.create()
|
private val chipsReducer: Subject<(List<Recipient>) -> List<Recipient>> = PublishSubject.create()
|
||||||
private val conversation: Subject<Conversation> = BehaviorSubject.create()
|
private val conversation: Subject<Conversation> = BehaviorSubject.create()
|
||||||
private val messages: Subject<List<Message>> = BehaviorSubject.create()
|
private val messages: Subject<List<Message>> = BehaviorSubject.create()
|
||||||
@@ -380,23 +382,76 @@ class ComposeViewModel @Inject constructor(
|
|||||||
view.optionsItemIntent
|
view.optionsItemIntent
|
||||||
.filter { it == R.id.copy }
|
.filter { it == R.id.copy }
|
||||||
.withLatestFrom(view.messagesSelectedIntent) { _, messageIds ->
|
.withLatestFrom(view.messagesSelectedIntent) { _, messageIds ->
|
||||||
val messages = messageIds.mapNotNull(messageRepo::getMessage).sortedBy { it.date }
|
|
||||||
ClipboardUtils.copy(
|
ClipboardUtils.copy(
|
||||||
context,
|
context,
|
||||||
messages.foldIndexed(StringBuilder()) { index, acc, message ->
|
messageIds
|
||||||
when {
|
.mapNotNull(messageRepo::getMessage)
|
||||||
index == 0 ->
|
.sortedBy { it.date }
|
||||||
acc.append(message.getText())
|
.getText()
|
||||||
messages[index - 1].compareSender(message) ->
|
)
|
||||||
acc.appendLine().append(message.getText())
|
|
||||||
else ->
|
|
||||||
acc.appendLine().appendLine().append(message.getText())
|
|
||||||
}
|
|
||||||
}.toString())
|
|
||||||
}
|
}
|
||||||
.autoDisposable(view.scope())
|
.autoDisposable(view.scope())
|
||||||
.subscribe { view.clearSelection() }
|
.subscribe { view.clearSelection() }
|
||||||
|
|
||||||
|
// share the message text contents
|
||||||
|
view.optionsItemIntent
|
||||||
|
.filter { it == R.id.share }
|
||||||
|
.observeOn(Schedulers.io())
|
||||||
|
.withLatestFrom(view.messagesSelectedIntent) { _, messageIds -> messageIds }
|
||||||
|
.mapNotNull { messageIds ->
|
||||||
|
val filename = "$SAVED_MESSAGE_TEXT_FILE_PREFIX${
|
||||||
|
SimpleDateFormat(
|
||||||
|
"yyyy-MM-dd-HH-mm-ss",
|
||||||
|
Locale.getDefault()
|
||||||
|
).format(System.currentTimeMillis())}.txt"
|
||||||
|
|
||||||
|
val mimeType = "${MimeTypes.BASE_TYPE_TEXT}/plain"
|
||||||
|
|
||||||
|
// save all messages text to a file in cache
|
||||||
|
val (uri, e) = FileUtils.createAndWrite(
|
||||||
|
context,
|
||||||
|
FileUtils.Companion.Location.Cache,
|
||||||
|
filename,
|
||||||
|
mimeType,
|
||||||
|
messageIds
|
||||||
|
.mapNotNull(messageRepo::getMessage)
|
||||||
|
.sortedBy { it.date }
|
||||||
|
.getText()
|
||||||
|
.toByteArray()
|
||||||
|
)
|
||||||
|
|
||||||
|
if (e is Exception)
|
||||||
|
Pair(filename, e)
|
||||||
|
else {
|
||||||
|
// share file from cache
|
||||||
|
navigator.viewFile(
|
||||||
|
FileProvider.getUriForFile(
|
||||||
|
context,
|
||||||
|
"dev.octoshrimpy.quik.messagesText",
|
||||||
|
uri.toFile()
|
||||||
|
),
|
||||||
|
mimeType
|
||||||
|
)
|
||||||
|
|
||||||
|
Pair(filename, null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.map { (filename, e) ->
|
||||||
|
if (e is Exception)
|
||||||
|
Toast.makeText(
|
||||||
|
context,
|
||||||
|
context.getString(R.string.messages_text_share_file_error),
|
||||||
|
Toast.LENGTH_LONG
|
||||||
|
).show().also {
|
||||||
|
Timber.e("Error writing to messages text cache file", e)
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Timber.d("Created and shared messages text file: $filename", e)
|
||||||
|
}
|
||||||
|
.autoDisposable(view.scope())
|
||||||
|
.subscribe { view.clearSelection() }
|
||||||
|
|
||||||
// Show the message details
|
// Show the message details
|
||||||
view.optionsItemIntent
|
view.optionsItemIntent
|
||||||
.filter { it == R.id.details }
|
.filter { it == R.id.details }
|
||||||
@@ -572,14 +627,27 @@ class ComposeViewModel @Inject constructor(
|
|||||||
|
|
||||||
// Update the State when the message selected count changes
|
// Update the State when the message selected count changes
|
||||||
view.messagesSelectedIntent
|
view.messagesSelectedIntent
|
||||||
.map { selection -> selection.size }
|
.map {
|
||||||
|
Pair(
|
||||||
|
it.size,
|
||||||
|
it.any { messageRepo.getMessage(it)?.hasNonWhitespaceText() ?: false }
|
||||||
|
)
|
||||||
|
}
|
||||||
.autoDisposable(view.scope())
|
.autoDisposable(view.scope())
|
||||||
.subscribe { messages -> newState { copy(selectedMessages = messages, editingMode = false) } }
|
.subscribe {
|
||||||
|
newState {
|
||||||
|
copy(
|
||||||
|
selectedMessages = it.first,
|
||||||
|
selectedMessagesHaveText = it.second,
|
||||||
|
editingMode = false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Cancel sending a message
|
// Cancel sending a message
|
||||||
view.cancelSendingIntent
|
view.cancelSendingIntent
|
||||||
.mapNotNull(messageRepo::getMessage)
|
.mapNotNull(messageRepo::getMessage)
|
||||||
.doOnNext { message -> view.setDraft(message.getText()) }
|
.doOnNext { message -> view.setDraft(message.getText(false)) }
|
||||||
.autoDisposable(view.scope())
|
.autoDisposable(view.scope())
|
||||||
.subscribe { message ->
|
.subscribe { message ->
|
||||||
cancelMessage.execute(CancelDelayedMessage.Params(message.id, message.threadId))
|
cancelMessage.execute(CancelDelayedMessage.Params(message.id, message.threadId))
|
||||||
@@ -646,7 +714,15 @@ class ComposeViewModel @Inject constructor(
|
|||||||
.observeOn(Schedulers.io())
|
.observeOn(Schedulers.io())
|
||||||
.withLatestFrom(view.textChangedIntent, state) { threadId, draftText, state ->
|
.withLatestFrom(view.textChangedIntent, state) { threadId, draftText, state ->
|
||||||
if (state.saveDraft)
|
if (state.saveDraft)
|
||||||
conversationRepo.saveDraft(threadId, draftText.toString())
|
conversationRepo.saveDraft(
|
||||||
|
threadId,
|
||||||
|
if (draftText.isNotBlank()) draftText.toString()
|
||||||
|
else ""
|
||||||
|
)
|
||||||
|
|
||||||
|
// remove attachments
|
||||||
|
state.attachments.forEach { it.removeCacheFile() }
|
||||||
|
|
||||||
newState { copy(saveDraft = true) }
|
newState { copy(saveDraft = true) }
|
||||||
}
|
}
|
||||||
.autoDisposable(view.scope())
|
.autoDisposable(view.scope())
|
||||||
@@ -846,7 +922,7 @@ class ComposeViewModel @Inject constructor(
|
|||||||
// if leaving audio recording mode
|
// if leaving audio recording mode
|
||||||
if (!it.audioMsgRecording) {
|
if (!it.audioMsgRecording) {
|
||||||
// ensure recording stopped and delete any recording file
|
// ensure recording stopped and delete any recording file
|
||||||
safeDeleteLocalFile(MediaRecorderManager.stopRecording())
|
FileUtils.deleteFile(MediaRecorderManager.stopRecording())
|
||||||
view.recordAudioStartStopRecording.onNext(false)
|
view.recordAudioStartStopRecording.onNext(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -925,7 +1001,7 @@ class ComposeViewModel @Inject constructor(
|
|||||||
view.recordAudioStartStopRecording.onNext(false) // stop recording
|
view.recordAudioStartStopRecording.onNext(false) // stop recording
|
||||||
view.recordAudioPlayerVisible.onNext(true) // show audio player
|
view.recordAudioPlayerVisible.onNext(true) // show audio player
|
||||||
} else { // state = start recording
|
} else { // state = start recording
|
||||||
safeDeleteLocalFile(MediaRecorderManager.uri) // delete old recording file
|
FileUtils.deleteFile(MediaRecorderManager.uri) // delete old recording file
|
||||||
view.recordAudioStartStopRecording.onNext(true) // start new recording
|
view.recordAudioStartStopRecording.onNext(true) // start new recording
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -937,21 +1013,25 @@ class ComposeViewModel @Inject constructor(
|
|||||||
MediaRecorderManager.stopRecording()
|
MediaRecorderManager.stopRecording()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// create new filename for recorded file (so cache clean doesn't accidentally
|
// create new filename for recorded file because leaving the recording ui
|
||||||
// delete the attachment file)
|
// will delete the original filename as a catch-all to not leave orphaned files
|
||||||
val newFile = File(
|
val (newUri, e) = FileUtils.create(
|
||||||
context.cacheDir,
|
FileUtils.Companion.Location.Cache,
|
||||||
"${AUDIO_FILE_PREFIX}${UUID.randomUUID()}${MediaRecorderManager.AUDIO_FILE_SUFFIX}"
|
context,
|
||||||
|
"$AUDIO_FILE_PREFIX-${UUID.randomUUID()}$AUDIO_FILE_SUFFIX",
|
||||||
|
""
|
||||||
)
|
)
|
||||||
|
if (e is Exception)
|
||||||
|
throw e
|
||||||
|
|
||||||
// rename recorded file to new name
|
// rename recorded file to new name
|
||||||
MediaRecorderManager.uri.toFile().renameTo(newFile)
|
FileUtils.renameTo(MediaRecorderManager.uri, newUri)
|
||||||
|
|
||||||
// attach newly named file to message
|
// attach newly named file to message
|
||||||
newState {
|
newState {
|
||||||
copy(
|
copy(
|
||||||
audioMsgRecording = false,
|
audioMsgRecording = false,
|
||||||
attachments = attachments + Attachment(context, newFile.toUri())
|
attachments = attachments + Attachment(context, newUri)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1133,6 +1213,11 @@ class ComposeViewModel @Inject constructor(
|
|||||||
// clear the current message schedule, text and attachments
|
// clear the current message schedule, text and attachments
|
||||||
view.clearCurrentMessageIntent
|
view.clearCurrentMessageIntent
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.withLatestFrom(state) { hasError, state ->
|
||||||
|
// remove attachments
|
||||||
|
state.attachments.forEach { it.removeCacheFile() }
|
||||||
|
hasError
|
||||||
|
}
|
||||||
.autoDisposable(view.scope())
|
.autoDisposable(view.scope())
|
||||||
.subscribe {
|
.subscribe {
|
||||||
view.setDraft("")
|
view.setDraft("")
|
||||||
@@ -1147,13 +1232,4 @@ class ComposeViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun safeDeleteLocalFile(uri: Uri): Boolean {
|
|
||||||
return try {
|
|
||||||
if (uri == Uri.EMPTY)
|
|
||||||
false
|
|
||||||
uri.toFile().delete()
|
|
||||||
}
|
|
||||||
catch (e: Exception) { false }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,9 +37,11 @@ import android.view.View
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.ProgressBar
|
import android.widget.ProgressBar
|
||||||
|
import androidx.core.net.toUri
|
||||||
import com.jakewharton.rxbinding2.view.clicks
|
import com.jakewharton.rxbinding2.view.clicks
|
||||||
import com.moez.QKSMS.common.QkMediaPlayer
|
import com.moez.QKSMS.common.QkMediaPlayer
|
||||||
import dev.octoshrimpy.quik.R
|
import dev.octoshrimpy.quik.R
|
||||||
|
import dev.octoshrimpy.quik.common.Navigator
|
||||||
import dev.octoshrimpy.quik.common.base.QkRealmAdapter
|
import dev.octoshrimpy.quik.common.base.QkRealmAdapter
|
||||||
import dev.octoshrimpy.quik.common.base.QkViewHolder
|
import dev.octoshrimpy.quik.common.base.QkViewHolder
|
||||||
import dev.octoshrimpy.quik.common.util.Colors
|
import dev.octoshrimpy.quik.common.util.Colors
|
||||||
@@ -54,6 +56,9 @@ import dev.octoshrimpy.quik.common.util.extensions.withAlpha
|
|||||||
import dev.octoshrimpy.quik.compat.SubscriptionManagerCompat
|
import dev.octoshrimpy.quik.compat.SubscriptionManagerCompat
|
||||||
import dev.octoshrimpy.quik.extensions.isSmil
|
import dev.octoshrimpy.quik.extensions.isSmil
|
||||||
import dev.octoshrimpy.quik.extensions.isText
|
import dev.octoshrimpy.quik.extensions.isText
|
||||||
|
import dev.octoshrimpy.quik.extensions.joinTo
|
||||||
|
import dev.octoshrimpy.quik.extensions.millisecondsToMinutes
|
||||||
|
import dev.octoshrimpy.quik.extensions.truncateWithEllipses
|
||||||
import dev.octoshrimpy.quik.feature.compose.BubbleUtils.canGroup
|
import dev.octoshrimpy.quik.feature.compose.BubbleUtils.canGroup
|
||||||
import dev.octoshrimpy.quik.feature.compose.BubbleUtils.getBubble
|
import dev.octoshrimpy.quik.feature.compose.BubbleUtils.getBubble
|
||||||
import dev.octoshrimpy.quik.feature.compose.part.PartsAdapter
|
import dev.octoshrimpy.quik.feature.compose.part.PartsAdapter
|
||||||
@@ -89,9 +94,9 @@ class MessagesAdapter @Inject constructor(
|
|||||||
private val partsAdapterProvider: Provider<PartsAdapter>,
|
private val partsAdapterProvider: Provider<PartsAdapter>,
|
||||||
private val phoneNumberUtils: PhoneNumberUtils,
|
private val phoneNumberUtils: PhoneNumberUtils,
|
||||||
private val prefs: Preferences,
|
private val prefs: Preferences,
|
||||||
private val textViewStyler: TextViewStyler
|
private val textViewStyler: TextViewStyler,
|
||||||
|
private val navigator: Navigator,
|
||||||
) : QkRealmAdapter<Message>() {
|
) : QkRealmAdapter<Message>() {
|
||||||
|
|
||||||
class AudioState(
|
class AudioState(
|
||||||
var partId: Long = -1,
|
var partId: Long = -1,
|
||||||
var state: QkMediaPlayer.PlayingState = QkMediaPlayer.PlayingState.Stopped,
|
var state: QkMediaPlayer.PlayingState = QkMediaPlayer.PlayingState.Stopped,
|
||||||
@@ -103,10 +108,30 @@ class MessagesAdapter @Inject constructor(
|
|||||||
private const val VIEW_TYPE_MESSAGE_IN = 0
|
private const val VIEW_TYPE_MESSAGE_IN = 0
|
||||||
private const val VIEW_TYPE_MESSAGE_OUT = 1
|
private const val VIEW_TYPE_MESSAGE_OUT = 1
|
||||||
|
|
||||||
|
private const val MAX_MESSAGE_DISPLAY_LENGTH = 5000
|
||||||
|
|
||||||
// Thanks to Cory Kilger for this regex
|
// Thanks to Cory Kilger for this regex
|
||||||
// https://gist.github.com/cmkilger/b8f7dba3e76244a84e7e
|
// https://gist.github.com/cmkilger/b8f7dba3e76244a84e7e
|
||||||
private val EMOJI_REGEX = Regex(
|
private val EMOJI_REGEX = Regex(
|
||||||
"^[\\s\n\r]*(?:(?:[\u00a9\u00ae\u203c\u2049\u2122\u2139\u2194-\u2199\u21a9-\u21aa\u231a-\u231b\u2328\u23cf\u23e9-\u23f3\u23f8-\u23fa\u24c2\u25aa-\u25ab\u25b6\u25c0\u25fb-\u25fe\u2600-\u2604\u260e\u2611\u2614-\u2615\u2618\u261d\u2620\u2622-\u2623\u2626\u262a\u262e-\u262f\u2638-\u263a\u2648-\u2653\u2660\u2663\u2665-\u2666\u2668\u267b\u267f\u2692-\u2694\u2696-\u2697\u2699\u269b-\u269c\u26a0-\u26a1\u26aa-\u26ab\u26b0-\u26b1\u26bd-\u26be\u26c4-\u26c5\u26c8\u26ce-\u26cf\u26d1\u26d3-\u26d4\u26e9-\u26ea\u26f0-\u26f5\u26f7-\u26fa\u26fd\u2702\u2705\u2708-\u270d\u270f\u2712\u2714\u2716\u271d\u2721\u2728\u2733-\u2734\u2744\u2747\u274c\u274e\u2753-\u2755\u2757\u2763-\u2764\u2795-\u2797\u27a1\u27b0\u27bf\u2934-\u2935\u2b05-\u2b07\u2b1b-\u2b1c\u2b50\u2b55\u3030\u303d\u3297\u3299\ud83c\udc04\ud83c\udccf\ud83c\udd70-\ud83c\udd71\ud83c\udd7e-\ud83c\udd7f\ud83c\udd8e\ud83c\udd91-\ud83c\udd9a\ud83c\ude01-\ud83c\ude02\ud83c\ude1a\ud83c\ude2f\ud83c\ude32-\ud83c\ude3a\ud83c\ude50-\ud83c\ude51\u200d\ud83c\udf00-\ud83d\uddff\ud83d\ude00-\ud83d\ude4f\ud83d\ude80-\ud83d\udeff\ud83e\udd00-\ud83e\uddff\udb40\udc20-\udb40\udc7f]|\u200d[\u2640\u2642]|[\ud83c\udde6-\ud83c\uddff]{2}|.[\u20e0\u20e3\ufe0f]+)+[\\s\n\r]*)+$")
|
"^[\\s\n\r]*(?:(?:[\u00a9\u00ae\u203c\u2049\u2122\u2139\u2194-\u2199" +
|
||||||
|
"\u21a9-\u21aa\u231a-\u231b\u2328\u23cf\u23e9-\u23f3\u23f8-\u23fa\u24c2" +
|
||||||
|
"\u25aa-\u25ab\u25b6\u25c0\u25fb-\u25fe\u2600-\u2604\u260e\u2611\u2614-" +
|
||||||
|
"\u2615\u2618\u261d\u2620\u2622-\u2623\u2626\u262a\u262e-\u262f\u2638-" +
|
||||||
|
"\u263a\u2648-\u2653\u2660\u2663\u2665-\u2666\u2668\u267b\u267f\u2692-" +
|
||||||
|
"\u2694\u2696-\u2697\u2699\u269b-\u269c\u26a0-\u26a1\u26aa-\u26ab\u26b0-" +
|
||||||
|
"\u26b1\u26bd-\u26be\u26c4-\u26c5\u26c8\u26ce-\u26cf\u26d1\u26d3-\u26d4" +
|
||||||
|
"\u26e9-\u26ea\u26f0-\u26f5\u26f7-\u26fa\u26fd\u2702\u2705\u2708-\u270d" +
|
||||||
|
"\u270f\u2712\u2714\u2716\u271d\u2721\u2728\u2733-\u2734\u2744\u2747\u274c" +
|
||||||
|
"\u274e\u2753-\u2755\u2757\u2763-\u2764\u2795-\u2797\u27a1\u27b0\u27bf" +
|
||||||
|
"\u2934-\u2935\u2b05-\u2b07\u2b1b-\u2b1c\u2b50\u2b55\u3030\u303d\u3297" +
|
||||||
|
"\u3299\ud83c\udc04\ud83c\udccf\ud83c\udd70-\ud83c\udd71\ud83c\udd7e-" +
|
||||||
|
"\ud83c\udd7f\ud83c\udd8e\ud83c\udd91-\ud83c\udd9a\ud83c\ude01-\ud83c" +
|
||||||
|
"\ude02\ud83c\ude1a\ud83c\ude2f\ud83c\ude32-\ud83c\ude3a\ud83c\ude50-" +
|
||||||
|
"\ud83c\ude51\u200d\ud83c\udf00-\ud83d\uddff\ud83d\ude00-\ud83d\ude4f" +
|
||||||
|
"\ud83d\ude80-\ud83d\udeff\ud83e\udd00-\ud83e\uddff\udb40\udc20-\udb40" +
|
||||||
|
"\udc7f]|\u200d[\u2640\u2642]|[\ud83c\udde6-\ud83c\uddff]" +
|
||||||
|
"{2}|.[\u20e0\u20e3\ufe0f]+)+[\\s\n\r]*)+$"
|
||||||
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,20 +168,18 @@ class MessagesAdapter @Inject constructor(
|
|||||||
private val audioState = AudioState()
|
private val audioState = AudioState()
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
||||||
|
|
||||||
// Use the parent's context to inflate the layout, otherwise link clicks will crash the app
|
// Use the parent's context to inflate the layout, otherwise link clicks will crash the app
|
||||||
val layoutInflater = LayoutInflater.from(parent.context)
|
val inflater = LayoutInflater.from(parent.context)
|
||||||
val view: View
|
|
||||||
|
|
||||||
if (viewType == VIEW_TYPE_MESSAGE_OUT) {
|
val view = if (viewType == VIEW_TYPE_MESSAGE_OUT) {
|
||||||
view = layoutInflater.inflate(R.layout.message_list_item_out, parent, false)
|
inflater.inflate(R.layout.message_list_item_out, parent,false).apply {
|
||||||
view.findViewById<ImageView>(R.id.cancelIcon).setTint(theme.theme)
|
findViewById<ImageView>(R.id.cancelIcon).setTint(theme.theme)
|
||||||
view.findViewById<ProgressBar>(R.id.cancel).setTint(theme.theme)
|
findViewById<ProgressBar>(R.id.cancel).setTint(theme.theme)
|
||||||
view.findViewById<ImageView>(R.id.sendNowIcon).setTint(theme.theme)
|
findViewById<ImageView>(R.id.sendNowIcon).setTint(theme.theme)
|
||||||
view.findViewById<ImageView>(R.id.resendIcon).setTint(theme.theme)
|
findViewById<ImageView>(R.id.resendIcon).setTint(theme.theme)
|
||||||
} else {
|
}
|
||||||
view = layoutInflater.inflate(R.layout.message_list_item_in, parent, false)
|
} else
|
||||||
}
|
inflater.inflate(R.layout.message_list_item_in, parent, false)
|
||||||
|
|
||||||
view.body.hyphenationFrequency = Layout.HYPHENATION_FREQUENCY_NONE
|
view.body.hyphenationFrequency = Layout.HYPHENATION_FREQUENCY_NONE
|
||||||
|
|
||||||
@@ -165,19 +188,21 @@ class MessagesAdapter @Inject constructor(
|
|||||||
|
|
||||||
return QkViewHolder(view).apply {
|
return QkViewHolder(view).apply {
|
||||||
view.setOnClickListener {
|
view.setOnClickListener {
|
||||||
val message = getItem(adapterPosition) ?: return@setOnClickListener
|
getItem(adapterPosition)?.let {
|
||||||
when (toggleSelection(message.id, false)) {
|
when (toggleSelection(it.id, false)) {
|
||||||
true -> view.isActivated = isSelected(message.id)
|
true -> view.isActivated = isSelected(it.id)
|
||||||
false -> {
|
false -> {
|
||||||
expanded[message.id] = view.status.visibility != View.VISIBLE
|
expanded[it.id] = view.status.visibility != View.VISIBLE
|
||||||
notifyItemChanged(adapterPosition)
|
notifyItemChanged(adapterPosition)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
view.setOnLongClickListener {
|
view.setOnLongClickListener {
|
||||||
val message = getItem(adapterPosition) ?: return@setOnLongClickListener true
|
getItem(adapterPosition)?.let {
|
||||||
toggleSelection(message.id)
|
toggleSelection(it.id)
|
||||||
view.isActivated = isSelected(message.id)
|
view.isActivated = isSelected(it.id)
|
||||||
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -193,208 +218,246 @@ class MessagesAdapter @Inject constructor(
|
|||||||
false -> colors.theme(contactCache[message.address])
|
false -> colors.theme(contactCache[message.address])
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.parts.adapter = partsAdapterProvider.get().apply {
|
|
||||||
contextMenuValue = message.id
|
|
||||||
clicks.subscribe(partClicks) // part clicks gets passed back to compose view model
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the selected state
|
// Update the selected state
|
||||||
holder.containerView.isActivated = isSelected(message.id) || highlight == message.id
|
holder.containerView.isActivated = isSelected(message.id) || highlight == message.id
|
||||||
|
|
||||||
// Bind the cancelFrame (cancel button) view
|
// Bind the cancelFrame (cancel button) view
|
||||||
if (holder.cancelFrame != null) {
|
holder.cancelFrame?.let {
|
||||||
holder.cancelFrame.let { cancelFrame ->
|
val isCancellable = message.isSending() && message.date > System.currentTimeMillis()
|
||||||
val isCancellable = message.isSending() && message.date > System.currentTimeMillis()
|
it.visibility = if (isCancellable) View.VISIBLE else View.GONE
|
||||||
cancelFrame.visibility = if (isCancellable) View.VISIBLE else View.GONE
|
it.let {
|
||||||
cancelFrame.clicks().subscribe { cancelSendingClicks.onNext(message.id) }
|
it.clicks().subscribe { cancelSendingClicks.onNext(message.id) }
|
||||||
cancelFrame.cancel.progress = 2
|
}
|
||||||
|
it.cancel.progress = 2
|
||||||
|
|
||||||
if (isCancellable) {
|
if (isCancellable) {
|
||||||
val delay = when (prefs.sendDelay.get()) {
|
val delay = when (prefs.sendDelay.get()) {
|
||||||
Preferences.SEND_DELAY_SHORT -> 3000
|
Preferences.SEND_DELAY_SHORT -> 3000
|
||||||
Preferences.SEND_DELAY_MEDIUM -> 5000
|
Preferences.SEND_DELAY_MEDIUM -> 5000
|
||||||
Preferences.SEND_DELAY_LONG -> 10000
|
Preferences.SEND_DELAY_LONG -> 10000
|
||||||
else -> 0
|
else -> 0
|
||||||
}
|
|
||||||
val progress =
|
|
||||||
(1 - (message.date - System.currentTimeMillis()) / delay.toFloat()) * 100
|
|
||||||
|
|
||||||
ObjectAnimator.ofInt(cancelFrame.cancel, "progress", progress.toInt(), 100)
|
|
||||||
.setDuration(message.date - System.currentTimeMillis())
|
|
||||||
.start()
|
|
||||||
}
|
}
|
||||||
|
val progress =
|
||||||
|
(1 - (message.date - System.currentTimeMillis()) / delay.toFloat()) * 100
|
||||||
|
|
||||||
|
ObjectAnimator.ofInt(it.cancel, "progress", progress.toInt(), 100)
|
||||||
|
.setDuration(message.date - System.currentTimeMillis())
|
||||||
|
.start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// bind the send now icon view
|
// bind the send now icon view
|
||||||
if (holder.sendNowIcon != null) {
|
holder.sendNowIcon?.let {
|
||||||
holder.sendNowIcon.let { sendNowIcon ->
|
if (message.isSending() && message.date > System.currentTimeMillis()) {
|
||||||
if (message.isSending() && message.date > System.currentTimeMillis()) {
|
it.visibility = View.VISIBLE
|
||||||
sendNowIcon.visibility = View.VISIBLE
|
it.clicks().subscribe { sendNowClicks.onNext(message.id) }
|
||||||
sendNowIcon.clicks().subscribe { sendNowClicks.onNext(message.id) }
|
} else
|
||||||
} else
|
it.visibility = View.GONE
|
||||||
sendNowIcon.visibility = View.GONE
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// bind the resend icon view
|
// bind the resend icon view
|
||||||
if (holder.resendIcon != null) {
|
holder.resendIcon?.let { resendIcon ->
|
||||||
holder.resendIcon.let { resendIcon ->
|
if (message.isFailedMessage()) {
|
||||||
if (message.isFailedMessage()) {
|
resendIcon.visibility = View.VISIBLE
|
||||||
resendIcon.visibility = View.VISIBLE
|
resendIcon.clicks().subscribe {
|
||||||
resendIcon.clicks().subscribe {
|
resendClicks.onNext(message.id)
|
||||||
resendClicks.onNext(message.id)
|
|
||||||
resendIcon.visibility = View.GONE
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
resendIcon.visibility = View.GONE
|
resendIcon.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
} else
|
||||||
|
resendIcon.visibility = View.GONE
|
||||||
|
}
|
||||||
|
|
||||||
|
val subject = message.getCleansedSubject()
|
||||||
|
|
||||||
|
var isMsgTextTruncated = false
|
||||||
|
|
||||||
|
// get message text to display, which may need to be truncated
|
||||||
|
val displayText = subject.joinTo(message.getText(false), "\n").let {
|
||||||
|
isMsgTextTruncated = (it.length > MAX_MESSAGE_DISPLAY_LENGTH)
|
||||||
|
|
||||||
|
// make subject sub-string bold, if subject is not blank
|
||||||
|
if (subject.isNotBlank())
|
||||||
|
SpannableString(it.truncateWithEllipses(MAX_MESSAGE_DISPLAY_LENGTH)).apply {
|
||||||
|
setSpan(
|
||||||
|
StyleSpan(Typeface.BOLD),
|
||||||
|
0,
|
||||||
|
subject.length,
|
||||||
|
Spannable.SPAN_INCLUSIVE_EXCLUSIVE
|
||||||
|
)
|
||||||
|
}
|
||||||
|
else
|
||||||
|
it.truncateWithEllipses(MAX_MESSAGE_DISPLAY_LENGTH)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bind the message status
|
// Bind the message status
|
||||||
bindStatus(holder, message, next)
|
bindStatus(holder, isMsgTextTruncated, message, next)
|
||||||
|
|
||||||
// Bind the timestamp
|
// Bind the timestamp
|
||||||
val timeSincePrevious = TimeUnit.MILLISECONDS.toMinutes(message.date - (previous?.date ?: 0))
|
val subscription = subs.find { it.subscriptionId == message.subId }
|
||||||
val subscription = subs.find { sub -> sub.subscriptionId == message.subId }
|
|
||||||
|
holder.timestamp.apply {
|
||||||
|
text = dateFormatter.getMessageTimestamp(message.date)
|
||||||
|
setVisible(
|
||||||
|
((message.date - (previous?.date ?: 0))
|
||||||
|
.millisecondsToMinutes() >= BubbleUtils.TIMESTAMP_THRESHOLD) ||
|
||||||
|
(message.subId != previous?.subId) &&
|
||||||
|
(subscription != null)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
holder.timestamp.text = dateFormatter.getMessageTimestamp(message.date)
|
|
||||||
holder.simIndex.text = subscription?.simSlotIndex?.plus(1)?.toString()
|
holder.simIndex.text = subscription?.simSlotIndex?.plus(1)?.toString()
|
||||||
|
|
||||||
holder.timestamp.setVisible(timeSincePrevious >= BubbleUtils.TIMESTAMP_THRESHOLD
|
((message.subId != previous?.subId) && (subscription != null) && (subs.size > 1)).also {
|
||||||
|| message.subId != previous?.subId && subscription != null)
|
holder.sim.setVisible(it)
|
||||||
|
holder.simIndex.setVisible(it)
|
||||||
holder.sim.setVisible(message.subId != previous?.subId && subscription != null && subs.size > 1)
|
}
|
||||||
holder.simIndex.setVisible(message.subId != previous?.subId && subscription != null && subs.size > 1)
|
|
||||||
|
|
||||||
// Bind the grouping
|
// Bind the grouping
|
||||||
val media = message.parts.filter { !it.isSmil() && !it.isText() }
|
holder.containerView.setPadding(
|
||||||
holder.containerView.setPadding(bottom = if (canGroup(message, next)) 0 else 16.dpToPx(context))
|
bottom = if (canGroup(message, next)) 0 else 16.dpToPx(context)
|
||||||
|
)
|
||||||
|
|
||||||
// Bind the avatar and bubble colour
|
// Bind the avatar and bubble colour
|
||||||
if (!message.isMe()) {
|
if (!message.isMe()) {
|
||||||
holder.avatar.setRecipient(contactCache[message.address])
|
holder.avatar.apply {
|
||||||
holder.avatar.setVisible(!canGroup(message, next), View.INVISIBLE)
|
setRecipient(contactCache[message.address])
|
||||||
|
setVisible(!canGroup(message, next), View.INVISIBLE)
|
||||||
holder.body.setTextColor(theme.textPrimary)
|
|
||||||
holder.body.setBackgroundTint(theme.theme)
|
|
||||||
holder.body.highlightColor = R.attr.bubbleColor.withAlpha(0x5d)
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
||||||
holder.body.textSelectHandle?.setTint(R.attr.bubbleColor.withAlpha(0x7d))
|
|
||||||
holder.body.textSelectHandleLeft?.setTint(R.attr.bubbleColor.withAlpha(0x7d))
|
|
||||||
holder.body.textSelectHandleRight?.setTint(R.attr.bubbleColor.withAlpha(0x7d))
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
holder.body.highlightColor = theme.theme.withAlpha(0x5d)
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
||||||
holder.body.textSelectHandle?.setTint(theme.theme.withAlpha(0xad))
|
|
||||||
holder.body.textSelectHandleLeft?.setTint(theme.theme.withAlpha(0xad))
|
|
||||||
holder.body.textSelectHandleRight?.setTint(theme.theme.withAlpha(0xad))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bind the body text
|
holder.body.apply {
|
||||||
val messageText = when (message.isSms()) {
|
setTextColor(theme.textPrimary)
|
||||||
true -> message.body
|
setBackgroundTint(theme.theme)
|
||||||
false -> {
|
highlightColor = R.attr.bubbleColor.withAlpha(0x5d)
|
||||||
val subject = message.getCleansedSubject()
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
val body = message.parts
|
textSelectHandle?.setTint(R.attr.bubbleColor.withAlpha(0x7d))
|
||||||
.filter { part -> part.isText() }
|
textSelectHandleLeft?.setTint(R.attr.bubbleColor.withAlpha(0x7d))
|
||||||
.mapNotNull { part -> part.text }
|
textSelectHandleRight?.setTint(R.attr.bubbleColor.withAlpha(0x7d))
|
||||||
.filter { text -> text.isNotBlank() }
|
}
|
||||||
.joinToString("\n")
|
}
|
||||||
|
} else
|
||||||
when {
|
holder.body.apply {
|
||||||
subject.isNotBlank() -> {
|
highlightColor = theme.theme.withAlpha(0x5d)
|
||||||
val spannable = SpannableString(if (body.isNotBlank()) "$subject\n$body" else subject)
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
spannable.setSpan(StyleSpan(Typeface.BOLD), 0, subject.length,
|
textSelectHandle?.setTint(theme.theme.withAlpha(0xad))
|
||||||
Spannable.SPAN_INCLUSIVE_EXCLUSIVE)
|
textSelectHandleLeft?.setTint(theme.theme.withAlpha(0xad))
|
||||||
spannable
|
textSelectHandleRight?.setTint(theme.theme.withAlpha(0xad))
|
||||||
}
|
|
||||||
else -> body
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
val emojiOnly = messageText.isNotBlank() && messageText.matches(EMOJI_REGEX)
|
|
||||||
textViewStyler.setTextSize(holder.body, when (emojiOnly) {
|
|
||||||
true -> TextViewStyler.SIZE_EMOJI
|
|
||||||
false -> TextViewStyler.SIZE_PRIMARY
|
|
||||||
})
|
|
||||||
|
|
||||||
val spanString = SpannableStringBuilder(messageText)
|
// Bind the body text
|
||||||
|
val emojiOnly = (displayText.isNotBlank()) &&
|
||||||
|
(displayText.matches(EMOJI_REGEX))
|
||||||
|
textViewStyler.setTextSize(
|
||||||
|
holder.body,
|
||||||
|
when (emojiOnly) {
|
||||||
|
true -> TextViewStyler.SIZE_EMOJI
|
||||||
|
false -> TextViewStyler.SIZE_PRIMARY
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
val spanString = SpannableStringBuilder(displayText)
|
||||||
|
|
||||||
when (prefs.messageLinkHandling.get()) {
|
when (prefs.messageLinkHandling.get()) {
|
||||||
Preferences.MESSAGE_LINK_HANDLING_BLOCK -> holder.body.autoLinkMask = 0
|
Preferences.MESSAGE_LINK_HANDLING_BLOCK -> holder.body.autoLinkMask = 0
|
||||||
Preferences.MESSAGE_LINK_HANDLING_ASK -> {
|
Preferences.MESSAGE_LINK_HANDLING_ASK -> {
|
||||||
// manually handle link clicks if user has set to ask before opening links
|
// manually handle link clicks if user has set to ask before opening links
|
||||||
holder.body.isClickable = false
|
holder.body.apply {
|
||||||
holder.body.linksClickable = false
|
isClickable = false
|
||||||
holder.body.movementMethod = LinkMovementMethod.getInstance()
|
linksClickable = false
|
||||||
|
movementMethod = LinkMovementMethod.getInstance()
|
||||||
|
|
||||||
Linkify.addLinks(spanString, holder.body.autoLinkMask)
|
Linkify.addLinks(spanString, autoLinkMask)
|
||||||
|
}
|
||||||
|
|
||||||
for (span in spanString.getSpans(
|
spanString.apply {
|
||||||
0,
|
for (span in getSpans(0, length, URLSpan::class.java)) {
|
||||||
spanString.length,
|
// set handler for when user touches a link into new span
|
||||||
URLSpan::class.java)
|
setSpan(
|
||||||
) {
|
object : ClickableSpan() {
|
||||||
// set handler for when user touches a link into new span
|
override fun onClick(widget: View) {
|
||||||
spanString.setSpan(
|
messageLinkClicks.onNext(span.url.toUri())
|
||||||
object : ClickableSpan() {
|
}
|
||||||
override fun onClick(widget: View) {
|
},
|
||||||
messageLinkClicks.onNext(Uri.parse(span.url))
|
getSpanStart(span),
|
||||||
}
|
getSpanEnd(span),
|
||||||
},
|
getSpanFlags(span)
|
||||||
spanString.getSpanStart(span),
|
)
|
||||||
spanString.getSpanEnd(span),
|
|
||||||
spanString.getSpanFlags(span)
|
|
||||||
)
|
|
||||||
|
|
||||||
// remove original span
|
// remove original span
|
||||||
spanString.removeSpan(span)
|
removeSpan(span)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else -> holder.body.movementMethod = LinkMovementMethod.getInstance()
|
else -> holder.body.movementMethod = LinkMovementMethod.getInstance()
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.body.text = spanString
|
holder.body.apply {
|
||||||
holder.body.setVisible(message.isSms() || spanString.isNotBlank())
|
text = spanString
|
||||||
|
setVisible(message.isSms() || spanString.isNotBlank())
|
||||||
|
|
||||||
holder.body.setBackgroundResource(getBubble(
|
setBackgroundResource(
|
||||||
emojiOnly = emojiOnly,
|
getBubble(
|
||||||
canGroupWithPrevious = canGroup(message, previous) || media.isNotEmpty(),
|
emojiOnly = emojiOnly,
|
||||||
canGroupWithNext = canGroup(message, next),
|
canGroupWithPrevious = canGroup(message, previous) ||
|
||||||
isMe = message.isMe()))
|
message.parts.any { !it.isSmil() && !it.isText() },
|
||||||
|
canGroupWithNext = canGroup(message, next),
|
||||||
// Bind the parts
|
isMe = message.isMe()
|
||||||
val partsAdapter = (holder.parts.adapter as PartsAdapter)
|
)
|
||||||
partsAdapter.theme = theme
|
)
|
||||||
partsAdapter.setData(message, previous, next, holder, audioState)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun bindStatus(holder: QkViewHolder, message: Message, next: Message?) {
|
|
||||||
val age = TimeUnit.MILLISECONDS.toMinutes(System.currentTimeMillis() - message.date)
|
|
||||||
|
|
||||||
holder.status.text = when {
|
|
||||||
message.isSending() -> context.getString(R.string.message_status_sending)
|
|
||||||
message.isDelivered() -> context.getString(R.string.message_status_delivered,
|
|
||||||
dateFormatter.getTimestamp(message.dateSent))
|
|
||||||
message.isFailedMessage() -> context.getString(R.string.message_status_failed)
|
|
||||||
!message.isMe() && (conversation?.recipients?.size ?: 0) > 1 -> { // incoming group message
|
|
||||||
"${contactCache[message.address]?.getDisplayName()} • ${dateFormatter.getTimestamp(message.date)}"
|
|
||||||
}
|
|
||||||
else -> dateFormatter.getTimestamp(message.date)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.status.setVisible(when {
|
// Bind the parts
|
||||||
expanded[message.id] == true -> true
|
holder.parts.adapter = partsAdapterProvider.get().apply {
|
||||||
message.isSending() -> true
|
this.theme = theme
|
||||||
message.isFailedMessage() -> true
|
setData(message, previous, next, holder, audioState)
|
||||||
expanded[message.id] == false -> false
|
contextMenuValue = message.id
|
||||||
(conversation?.recipients?.size ?: 0) > 1 && !message.isMe() && next?.compareSender(message) != true -> true
|
clicks.subscribe(partClicks) // part clicks gets passed back to compose view model
|
||||||
message.isDelivered() && next?.isDelivered() != true && age <= BubbleUtils.TIMESTAMP_THRESHOLD -> true
|
}
|
||||||
else -> false
|
}
|
||||||
})
|
|
||||||
|
private fun bindStatus(
|
||||||
|
holder: QkViewHolder,
|
||||||
|
bodyTextTruncated: Boolean,
|
||||||
|
message: Message,
|
||||||
|
next: Message?
|
||||||
|
) {
|
||||||
|
holder.status.apply {
|
||||||
|
text = when {
|
||||||
|
message.isSending() -> context.getString(R.string.message_status_sending)
|
||||||
|
message.isDelivered() -> context.getString(
|
||||||
|
R.string.message_status_delivered,
|
||||||
|
dateFormatter.getTimestamp(message.dateSent)
|
||||||
|
)
|
||||||
|
message.isFailedMessage() -> context.getString(R.string.message_status_failed)
|
||||||
|
bodyTextTruncated -> context.getString(R.string.message_body_too_long_to_display)
|
||||||
|
(!message.isMe() && (conversation?.recipients?.size ?: 0) > 1) ->
|
||||||
|
// incoming group message
|
||||||
|
"${contactCache[message.address]?.getDisplayName()} • ${
|
||||||
|
dateFormatter.getTimestamp(message.date)}"
|
||||||
|
else -> dateFormatter.getTimestamp(message.date)
|
||||||
|
}
|
||||||
|
|
||||||
|
val age = TimeUnit.MILLISECONDS.toMinutes(
|
||||||
|
System.currentTimeMillis() - message.date
|
||||||
|
)
|
||||||
|
|
||||||
|
setVisible(
|
||||||
|
when {
|
||||||
|
expanded[message.id] == true -> true
|
||||||
|
message.isSending() -> true
|
||||||
|
message.isFailedMessage() -> true
|
||||||
|
bodyTextTruncated -> true
|
||||||
|
expanded[message.id] == false -> false
|
||||||
|
((conversation?.recipients?.size ?: 0) > 1) &&
|
||||||
|
!message.isMe() && next?.compareSender(message) != true -> true
|
||||||
|
(message.isDelivered() &&
|
||||||
|
(next?.isDelivered() != true) &&
|
||||||
|
(age <= BubbleUtils.TIMESTAMP_THRESHOLD)) -> true
|
||||||
|
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemId(position: Int): Long {
|
override fun getItemId(position: Int): Long {
|
||||||
@@ -410,7 +473,7 @@ class MessagesAdapter @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun expandMessages(messageIds: List<Long>, expand: Boolean) {
|
fun expandMessages(messageIds: List<Long>, expand: Boolean) {
|
||||||
messageIds.forEach { messageId -> expanded[messageId] = expand }
|
messageIds.forEach { expanded[it] = expand }
|
||||||
notifyDataSetChanged()
|
notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -419,11 +482,14 @@ class MessagesAdapter @Inject constructor(
|
|||||||
* a reference to the contact.
|
* a reference to the contact.
|
||||||
*/
|
*/
|
||||||
private inner class ContactCache : HashMap<String, Recipient?>() {
|
private inner class ContactCache : HashMap<String, Recipient?>() {
|
||||||
|
|
||||||
override fun get(key: String): Recipient? {
|
override fun get(key: String): Recipient? {
|
||||||
if (super.get(key)?.isValid != true) {
|
if (super.get(key)?.isValid != true)
|
||||||
set(key, conversation?.recipients?.firstOrNull { phoneNumberUtils.compare(it.address, key) })
|
set(
|
||||||
}
|
key,
|
||||||
|
conversation?.recipients?.firstOrNull {
|
||||||
|
phoneNumberUtils.compare(it.address, key)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
return super.get(key)?.takeIf { it.isValid }
|
return super.get(key)?.takeIf { it.isValid }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,6 +67,13 @@
|
|||||||
android:visible="false"
|
android:visible="false"
|
||||||
app:showAsAction="ifRoom" />
|
app:showAsAction="ifRoom" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/share"
|
||||||
|
android:icon="@android:drawable/ic_menu_share"
|
||||||
|
android:title="@string/compose_menu_share"
|
||||||
|
android:visible="false"
|
||||||
|
app:showAsAction="ifRoom" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/forward"
|
android:id="@+id/forward"
|
||||||
android:icon="@drawable/ic_forward_black_24dp"
|
android:icon="@drawable/ic_forward_black_24dp"
|
||||||
|
|||||||
@@ -142,6 +142,7 @@
|
|||||||
<string name="compose_hint">Write a message…</string>
|
<string name="compose_hint">Write a message…</string>
|
||||||
<string name="compose_no_valid_recipients">Can\'t send to other participants</string>
|
<string name="compose_no_valid_recipients">Can\'t send to other participants</string>
|
||||||
<string name="compose_menu_copy">Copy text</string>
|
<string name="compose_menu_copy">Copy text</string>
|
||||||
|
<string name="compose_menu_share">Share text</string>
|
||||||
<string name="compose_menu_forward">Forward</string>
|
<string name="compose_menu_forward">Forward</string>
|
||||||
<string name="compose_menu_show_status">Show status</string>
|
<string name="compose_menu_show_status">Show status</string>
|
||||||
<string name="compose_menu_delete">Delete</string>
|
<string name="compose_menu_delete">Delete</string>
|
||||||
@@ -189,6 +190,7 @@
|
|||||||
<string name="message_status_sending">Sending…</string>
|
<string name="message_status_sending">Sending…</string>
|
||||||
<string name="message_status_delivered">Delivered %s</string>
|
<string name="message_status_delivered">Delivered %s</string>
|
||||||
<string name="message_status_failed">Failed to send. Tap to try again</string>
|
<string name="message_status_failed">Failed to send. Tap to try again</string>
|
||||||
|
<string name="message_body_too_long_to_display">⚠ Message is long. Copy or Save for the full text</string>
|
||||||
|
|
||||||
<string name="info_title">Details</string>
|
<string name="info_title">Details</string>
|
||||||
<string name="info_copied_address">Address copied</string>
|
<string name="info_copied_address">Address copied</string>
|
||||||
@@ -570,4 +572,6 @@
|
|||||||
<string name="messageLinkHandling_dialog_negative">No</string>
|
<string name="messageLinkHandling_dialog_negative">No</string>
|
||||||
<string name="stt_toast_no_provider">No speech-to-text service available</string>
|
<string name="stt_toast_no_provider">No speech-to-text service available</string>
|
||||||
<string name="stt_toast_extra_prompt">Speak your message</string>
|
<string name="stt_toast_extra_prompt">Speak your message</string>
|
||||||
|
|
||||||
|
<string name="messages_text_share_file_error">Oops! Something went wrong while sharing</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user