mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 19:38:52 +01:00
Test stt rebase (#11)
* Update build-on-pull.yml Update's versions. * Update build-on-pull.yml Update Versions and add code to add the signing keys to the build. * Update build-on-pull.yml * Fixes the size of the icon.png. * Update build-on-pull.yml Fixes the formatting of the keystore injections. * Update build-on-pull.yml Changes it to only set up a NoAnalyticsDebug. * Update build-on-pull.yml Remove --stacktrace. * attachment context menu for save, share, forward and open externally remove share icons from audio and file attachment types add forward and open externally to gallery menu so it matches attachment context menu new icon/button for resend message * Update build-and-release.yml * Update build-on-pull.yml * Update PR-deploy.yml * Update build-and-release.yml * Update PR-deploy.yml * fix npe when setting out icons in messagesadapter when in message * Update strings.xml Change to "Leave A Star". * new setting to show/hide new stt button - defaults to 'show' to enable discovery by user. move compose stt feature from double-tap compose entry box to new button on compose activity * change tools view to 'on' for messageList * changes to ingest all attachments in a standard manner. does not change user-facing functionality * changes to make the speed-to-text button drag-and-dropable * rebased to latest master * changes to fix non-reset media player re-use crash * manual update to fix my rebase merge * changes to record audio for audio message from bluetooth sco device (ie bluetooth headset or earbuds) if connected at time of record * changes to fix a bug that appeared to be a race condition between deleting mms parts (attachments) and removing the message data from the realm db when deleting a message. there could be attempts to access part data that no longer exists. protected where the access was being attempted. * Update compose.xml Fixed showing the copy text details, rather than message details. * changes to enable a delete/clear menu icon on compose screen when there is message contents to clear - ie a schedule set, text input or attachments added * changed to reset all necessary state, regardless of editingMode, in clearCurrentMessageIntent handler * changes to make scheduled messages activity ui compliant with the rest of the app message listing activities. now allows sending and deleting multiple scheduled messages at once * fixed title of send now confirm dialog --------- Co-authored-by: octoshrimpy <octoshrimpy@users.noreply.github.com> Co-authored-by: gavine99 <github@xymail.tk>
This commit is contained in:
@@ -20,4 +20,8 @@
|
||||
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
|
||||
</manifest>
|
||||
|
||||
@@ -18,19 +18,24 @@
|
||||
*/
|
||||
package dev.octoshrimpy.quik.extensions
|
||||
|
||||
import android.content.ContentResolver
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import androidx.core.net.toFile
|
||||
|
||||
fun Uri.resourceExists(context: Context): Boolean {
|
||||
// check if resource at uri still exists
|
||||
var retVal: Boolean? = null
|
||||
try {
|
||||
return context.contentResolver.query(
|
||||
this, null, null, null, null
|
||||
)?.use {
|
||||
it.moveToFirst()
|
||||
} ?: false
|
||||
when (this.scheme) {
|
||||
ContentResolver.SCHEME_CONTENT -> {
|
||||
retVal = context.contentResolver.query(
|
||||
this, null, null, null, null
|
||||
)?.use { it.moveToFirst() }
|
||||
}
|
||||
ContentResolver.SCHEME_FILE -> retVal = this.toFile().exists()
|
||||
}
|
||||
} catch (e: Exception) { /* nothing */
|
||||
}
|
||||
catch (e: Exception) { /* nothing */ }
|
||||
|
||||
return false
|
||||
return retVal ?: false
|
||||
}
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Copyright (C) 2025
|
||||
*
|
||||
* This file is part of QUIK.
|
||||
*
|
||||
* QUIK 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.
|
||||
*
|
||||
* QUIK 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 QUIK. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.moez.QKSMS.manager
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.media.AudioDeviceInfo
|
||||
import android.media.AudioManager
|
||||
import android.media.AudioManager.GET_DEVICES_INPUTS
|
||||
|
||||
|
||||
// this class is, by design, as simplistic it can be to support easy and fast connection
|
||||
// for recording from first bluetooth mic found, if any
|
||||
|
||||
class BluetoothMicManager(
|
||||
private val context: Context,
|
||||
private val callbacks: Callbacks
|
||||
)
|
||||
: BroadcastReceiver() {
|
||||
interface Callbacks {
|
||||
fun onNoDeviceFound()
|
||||
fun onDeviceFound(device: AudioDeviceInfo?)
|
||||
fun onConnecting(device: AudioDeviceInfo?)
|
||||
fun onConnected(device: AudioDeviceInfo?)
|
||||
fun onDisconnected(device: AudioDeviceInfo?)
|
||||
}
|
||||
|
||||
init {
|
||||
// register for bluetooth sco broadcast intents
|
||||
context.registerReceiver(this, IntentFilter().apply {
|
||||
addAction(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED)
|
||||
})
|
||||
}
|
||||
|
||||
enum class StartBluetoothDevice {
|
||||
NoDevice,
|
||||
Connecting,
|
||||
Connected
|
||||
}
|
||||
|
||||
var device: AudioDeviceInfo? = null
|
||||
private set
|
||||
|
||||
private var hadFirstStickyIntent: Boolean = false
|
||||
private var closed: Boolean = false
|
||||
|
||||
fun close() {
|
||||
if (closed)
|
||||
return
|
||||
closed = true
|
||||
|
||||
device = null
|
||||
(context.getSystemService(Context.AUDIO_SERVICE) as AudioManager).stopBluetoothSco()
|
||||
context.unregisterReceiver(this)
|
||||
}
|
||||
|
||||
// note: caller may get connected() callback before this method returns if this method is
|
||||
// called from a non-UI thread and the UI thread processes a sticky sco_audio_state_connected
|
||||
fun startBluetoothDevice() {
|
||||
device = null
|
||||
val audioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
||||
|
||||
// get all audio input devices
|
||||
val allAudioInputDevices = audioManager.getDevices(GET_DEVICES_INPUTS)
|
||||
|
||||
// @TODO: below code can be used for BLE headset devices if and when one can be tested
|
||||
// : also need to register for BLE headset intent broadcasts and other things later
|
||||
// // firstly (highest priority), check for a connected BLE headset input device
|
||||
// for (btInputDevice in allAudioInputDevices) {
|
||||
// if (btInputDevice.type == AudioDeviceInfo.TYPE_BLE_HEADSET) {
|
||||
// device = btInputDevice
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
|
||||
// if no ble device found, check if platform supports non-phone-call sco connections
|
||||
if ((device == null) &&
|
||||
(audioManager.isBluetoothScoAvailableOffCall)) {
|
||||
// find first SCO input device
|
||||
for (btInputDevice in allAudioInputDevices) {
|
||||
if (btInputDevice.type == AudioDeviceInfo.TYPE_BLUETOOTH_SCO) {
|
||||
device = btInputDevice
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if no usable device found, callback to caller and return
|
||||
if (device == null) {
|
||||
callbacks.onNoDeviceFound()
|
||||
return
|
||||
}
|
||||
|
||||
// callback that a sco capable bluetooth device was found
|
||||
callbacks.onDeviceFound(device)
|
||||
|
||||
// start sco connection on bluetooth device (even if already started by other app)
|
||||
try { // see https://stackoverflow.com/a/26929741 for try-catch reason
|
||||
audioManager.startBluetoothSco()
|
||||
}
|
||||
catch (e: Exception) { /* nothing */ }
|
||||
|
||||
// if sco device is already on (maybe by another app?) callback now
|
||||
if (audioManager.isBluetoothScoOn)
|
||||
callbacks.onConnected(device)
|
||||
}
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
if (!hadFirstStickyIntent) {
|
||||
hadFirstStickyIntent = true
|
||||
return
|
||||
}
|
||||
|
||||
// if sco connection state has changed
|
||||
val action = intent.action ?: return
|
||||
if (action == AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED) {
|
||||
when (intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, -1)) {
|
||||
AudioManager.SCO_AUDIO_STATE_CONNECTED -> callbacks.onConnected(device)
|
||||
AudioManager.SCO_AUDIO_STATE_CONNECTING -> callbacks.onConnecting(device)
|
||||
AudioManager.SCO_AUDIO_STATE_DISCONNECTED -> {
|
||||
close()
|
||||
callbacks.onDisconnected(device)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright (C) 2025
|
||||
*
|
||||
* This file is part of QUIK.
|
||||
*
|
||||
* QUIK 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.
|
||||
*
|
||||
* QUIK 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 QUIK. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.moez.QKSMS.manager
|
||||
|
||||
import android.content.Context
|
||||
import android.media.AudioDeviceInfo
|
||||
import android.media.MediaRecorder
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import androidx.core.net.toUri
|
||||
import java.io.File
|
||||
import java.util.UUID
|
||||
|
||||
object MediaRecorderManager : MediaRecorder() {
|
||||
|
||||
enum class RecordingState {
|
||||
Initial,
|
||||
DataSourceConfigured,
|
||||
Prepared,
|
||||
Recording,
|
||||
Error
|
||||
}
|
||||
|
||||
const val AUDIO_FILE_PREFIX = "recorded-"
|
||||
const val AUDIO_FILE_SUFFIX = ".3ga"
|
||||
|
||||
var recordingState: RecordingState = RecordingState.Initial
|
||||
private set
|
||||
|
||||
var uri: Uri = Uri.EMPTY
|
||||
private set
|
||||
|
||||
fun stopRecording(): Uri {
|
||||
return try {
|
||||
if (recordingState == RecordingState.Recording)
|
||||
stop()
|
||||
|
||||
reset()
|
||||
recordingState = RecordingState.Initial
|
||||
|
||||
uri
|
||||
}
|
||||
catch (e: Exception) {
|
||||
Uri.EMPTY
|
||||
}
|
||||
}
|
||||
|
||||
fun startRecording(context: Context, preferredAudioDevice: AudioDeviceInfo? = null): Uri {
|
||||
return try {
|
||||
val file = File(
|
||||
context.cacheDir,
|
||||
AUDIO_FILE_PREFIX + UUID.randomUUID() + AUDIO_FILE_SUFFIX
|
||||
)
|
||||
|
||||
// ensure stopped before using again
|
||||
stopRecording()
|
||||
|
||||
// configure
|
||||
setAudioSource(AudioSource.MIC)
|
||||
setOutputFormat(OutputFormat.THREE_GPP)
|
||||
setAudioEncoder(AudioEncoder.AMR_WB)
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
preferredDevice = preferredAudioDevice
|
||||
}
|
||||
|
||||
recordingState = RecordingState.DataSourceConfigured
|
||||
|
||||
setOutputFile(file.path)
|
||||
|
||||
prepare()
|
||||
recordingState = RecordingState.Prepared
|
||||
|
||||
start()
|
||||
recordingState = RecordingState.Recording
|
||||
|
||||
uri = file.toUri()
|
||||
|
||||
uri
|
||||
}
|
||||
catch (e: Exception) {
|
||||
Uri.EMPTY
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -72,6 +72,10 @@ class PermissionManagerImpl @Inject constructor(private val context: Context) :
|
||||
return hasPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||
}
|
||||
|
||||
override fun hasRecordAudio(): Boolean {
|
||||
return hasPermission(Manifest.permission.RECORD_AUDIO)
|
||||
}
|
||||
|
||||
override fun hasExactAlarms(): Boolean {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
|
||||
return true
|
||||
|
||||
@@ -47,6 +47,7 @@ import dev.octoshrimpy.quik.compat.TelephonyCompat
|
||||
import dev.octoshrimpy.quik.extensions.anyOf
|
||||
import dev.octoshrimpy.quik.extensions.isImage
|
||||
import dev.octoshrimpy.quik.extensions.isVideo
|
||||
import dev.octoshrimpy.quik.extensions.resourceExists
|
||||
import dev.octoshrimpy.quik.manager.ActiveConversationManager
|
||||
import dev.octoshrimpy.quik.manager.KeyManager
|
||||
import dev.octoshrimpy.quik.model.Attachment
|
||||
@@ -368,32 +369,35 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
parts += MMSPart("text", ContentType.TEXT_PLAIN, bytes)
|
||||
}
|
||||
|
||||
// Attach those that can't be compressed (ie. everything but not images)
|
||||
// Attach those that can't be compressed (ie. everything but images)
|
||||
parts += attachments
|
||||
// filter out images
|
||||
// filter in non-images only
|
||||
.filter { !it.isImage(context) }
|
||||
// filter out items that have no data available (ie user may have deleted
|
||||
// the file from storage)
|
||||
.filter { it.getResourceBytes(context).isNotEmpty() }
|
||||
// filter in only items that exist (user may have deleted the file)
|
||||
.filter { it.uri.resourceExists(context) }
|
||||
.map {
|
||||
remainingBytes -= it.getResourceBytes(context).size
|
||||
MMSPart(
|
||||
val mmsPart = MMSPart(
|
||||
it.getName(context),
|
||||
it.getType(context),
|
||||
it.getResourceBytes(context)
|
||||
)
|
||||
|
||||
// release the attachment hold on the image bytes so the GC can reclaim
|
||||
it.releaseResourceBytes()
|
||||
|
||||
mmsPart
|
||||
}
|
||||
|
||||
val imageBytesByAttachment = attachments
|
||||
// filter out non-images
|
||||
// filter in images only
|
||||
.filter { it.isImage(context) }
|
||||
// filter out items that have no data available (ie user may have deleted
|
||||
// the file from storage)
|
||||
.filter { it.getResourceBytes(context).isNotEmpty() }
|
||||
// filter in only items that exist (user may have deleted the file)
|
||||
.filter { it.uri.resourceExists(context) }
|
||||
.associateWith {
|
||||
when (it.getType(context) == "image/gif") {
|
||||
true -> ImageUtils.getScaledGif(context, it.getUri(), maxWidth, maxHeight)
|
||||
false -> ImageUtils.getScaledImage(context, it.getUri(), maxWidth, maxHeight)
|
||||
true -> ImageUtils.getScaledGif(context, it.uri, maxWidth, maxHeight)
|
||||
false -> ImageUtils.getScaledImage(context, it.uri, maxWidth, maxHeight)
|
||||
}
|
||||
}
|
||||
.toMutableMap()
|
||||
@@ -401,7 +405,7 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
val imageByteCount = imageBytesByAttachment.values.sumOf { it.size }
|
||||
if (imageByteCount > remainingBytes) {
|
||||
imageBytesByAttachment.forEach { (attachment, originalBytes) ->
|
||||
val uri = attachment.getUri() ?: return@forEach
|
||||
val uri = attachment.uri ?: return@forEach
|
||||
val maxBytes = originalBytes.size / imageByteCount.toFloat() * remainingBytes
|
||||
|
||||
// Get the image dimensions
|
||||
@@ -429,11 +433,14 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
|
||||
attempts++
|
||||
scaledBytes = when (attachment.getType(context) == "image/gif") {
|
||||
true -> ImageUtils.getScaledGif(context, attachment.getUri(), newWidth, newHeight)
|
||||
false -> ImageUtils.getScaledImage(context, attachment.getUri(), newWidth, newHeight)
|
||||
true -> ImageUtils.getScaledGif(context, attachment.uri, newWidth, newHeight)
|
||||
false -> ImageUtils.getScaledImage(context, attachment.uri, newWidth, newHeight)
|
||||
}
|
||||
|
||||
Timber.d("Compression attempt $attempts: ${scaledBytes.size / 1024}/${maxBytes.toInt() / 1024}Kb ($width*$height -> $newWidth*$newHeight)")
|
||||
|
||||
// release the attachment hold on the image bytes so the GC can reclaim
|
||||
attachment.releaseResourceBytes()
|
||||
}
|
||||
|
||||
Timber.v("Compressed ${originalBytes.size / 1024}Kb to ${scaledBytes.size / 1024}Kb with a target size of ${maxBytes.toInt() / 1024}Kb in $attempts attempts")
|
||||
|
||||
@@ -69,6 +69,10 @@ class ScheduledMessageRepositoryImpl @Inject constructor() : ScheduledMessageRep
|
||||
disposables.add(subscription)
|
||||
}
|
||||
|
||||
override fun deleteScheduledMessages(ids: List<Long>) {
|
||||
ids.forEach { deleteScheduledMessage(it) }
|
||||
}
|
||||
|
||||
// Ensure to clear disposables when the repository is no longer needed
|
||||
fun clearDisposables() {
|
||||
disposables.clear()
|
||||
|
||||
Reference in New Issue
Block a user