added feature to speak messages aloud via system TTS service. added "Speak" option to message swipe left/right options. swipe inbox message to read aloud. swipe again to interrupt. added widget that speaks unseen messages and marks messages as seen after reading them. needs string translations for settings_swipe_actions (new item "Speak") and speak_no_messages and speak_unseen_messages

This commit is contained in:
gavine99
2025-01-05 20:33:05 +11:00
parent 5ca983172e
commit 6eacfe4610
17 changed files with 306 additions and 13 deletions
@@ -0,0 +1,50 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package dev.octoshrimpy.quik.receiver
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import dev.octoshrimpy.quik.interactor.SpeakThreads
import dagger.android.AndroidInjection
import dev.octoshrimpy.quik.repository.ConversationRepository
import javax.inject.Inject
class SpeakThreadsReceiver : BroadcastReceiver() {
@Inject lateinit var speakThread: SpeakThreads
@Inject lateinit var conversationRepo: ConversationRepository
override fun onReceive(context: Context, intent: Intent) {
AndroidInjection.inject(this, context)
val pendingResult = goAsync()
val threadId = intent.getLongExtra("threadId", 0)
val threads = when {
(threadId == -1L) -> conversationRepo.getUnseenIds()
(threadId == -2L) -> conversationRepo.getUnreadIds()
else -> listOf(threadId)
}
speakThread.execute(threads) { pendingResult.finish() }
}
}
@@ -21,6 +21,7 @@ package dev.octoshrimpy.quik.repository
import android.content.ContentUris
import android.content.Context
import android.provider.Telephony
import android.view.View.OnLongClickListener
import dev.octoshrimpy.quik.compat.TelephonyCompat
import dev.octoshrimpy.quik.extensions.anyOf
import dev.octoshrimpy.quik.extensions.asObservable
@@ -201,10 +202,69 @@ class ConversationRepositoryImpl @Inject constructor(
override fun getConversation(threadId: Long): Conversation? {
return Realm.getDefaultInstance()
.apply { refresh() }
.where(Conversation::class.java)
.equalTo("id", threadId)
.findFirst()
.apply { refresh() }
.where(Conversation::class.java)
.equalTo("id", threadId)
.findFirst()
}
override fun getUnseenIds(archived: Boolean): List<Long> {
val conversationIds = ArrayList<Long>()
Realm.getDefaultInstance()
.where(Conversation::class.java)
.notEqualTo("id", 0L)
.equalTo("archived", archived)
.equalTo("blocked", false)
.equalTo("lastMessage.seen", false)
.sort(
arrayOf("lastMessage.date"),
arrayOf(Sort.DESCENDING)
)
.findAllAsync()
.forEach { conversation -> conversationIds.add(conversation.id) }
return conversationIds
}
override fun getUnreadIds(archived: Boolean): List<Long> {
val conversationIds = ArrayList<Long>()
Realm.getDefaultInstance()
.where(Conversation::class.java)
.notEqualTo("id", 0L)
.equalTo("archived", archived)
.equalTo("blocked", false)
.equalTo("lastMessage.read", false)
.sort(
arrayOf("lastMessage.date"),
arrayOf(Sort.DESCENDING)
)
.findAllAsync()
.forEach { conversation -> conversationIds.add(conversation.id) }
return conversationIds
}
override fun getConversationAndLastSenderContactName(threadId: Long): Pair<Conversation?, String?>? {
val conversation = Realm.getDefaultInstance()
.apply { refresh() }
.where(Conversation::class.java)
.equalTo("id", threadId)
.findFirst()
if (conversation === null)
return null
var conversationLastSmsSender: String? = null
if (conversation !== null) {
conversationLastSmsSender = conversation?.recipients?.find { recipient ->
phoneNumberUtils.compare(recipient.address, conversation.lastMessage!!.address)
}?.contact?.name
}
return return Pair(conversation, conversationLastSmsSender)
}
override fun getConversations(vararg threadIds: Long): RealmResults<Conversation> {
@@ -48,6 +48,12 @@ interface ConversationRepository {
fun getConversation(threadId: Long): Conversation?
fun getUnseenIds(archived: Boolean = false): List<Long>
fun getUnreadIds(archived: Boolean = false): List<Long>
fun getConversationAndLastSenderContactName(threadId: Long): Pair<Conversation?, String?>?
/**
* Returns all conversations with an id in [threadIds]
*/
@@ -47,7 +47,6 @@ class Preferences @Inject constructor(
const val TEXT_SIZE_NORMAL = 1
const val TEXT_SIZE_LARGE = 2
const val TEXT_SIZE_LARGER = 3
const val TEXT_SIZE_SUPER = 4
const val NOTIFICATION_PREVIEWS_ALL = 0
const val NOTIFICATION_PREVIEWS_NAME = 1
@@ -73,6 +72,7 @@ class Preferences @Inject constructor(
const val SWIPE_ACTION_CALL = 4
const val SWIPE_ACTION_READ = 5
const val SWIPE_ACTION_UNREAD = 6
const val SWIPE_ACTION_SPEAK = 7
const val BLOCKING_MANAGER_QKSMS = 0
const val BLOCKING_MANAGER_CC = 1
+23
View File
@@ -175,6 +175,13 @@
<receiver android:name=".receiver.BlockThreadReceiver" />
<receiver android:name=".receiver.MarkSeenReceiver" />
<receiver android:name=".receiver.MarkReadReceiver" />
<receiver
android:name=".receiver.SpeakThreadsReceiver"
android:exported="true">
<intent-filter>
<action android:name="dev.octoshrimpy.quik.intent.action.ACTION_SPEAK_MESSAGES" />
</intent-filter>
</receiver>
<receiver android:name=".receiver.RemoteMessagingReceiver" />
<receiver android:name=".receiver.NightModeReceiver" />
<receiver
@@ -186,6 +193,19 @@
</receiver>
<receiver android:name=".receiver.SendScheduledMessageReceiver" />
<receiver
android:name=".feature.widget.WidgetSpeakUnseenProvider"
android:label="@string/speak_unseen_messages"
android:exported="true">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
<action android:name="dev.octoshrimpy.quik.intent.action.ACTION_NOTIFY_DATASET_CHANGED" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/widget_speak_unseen_info" />
</receiver>
<receiver
android:name=".feature.widget.WidgetProvider"
android:exported="true">
@@ -259,6 +279,9 @@
<package android:name="org.mistergroup.muzutozvednout" />
<package android:name="org.mistergroup.shouldianswer" />
<package android:name="org.mistergroup.shouldianswerpersonal" />
<intent>
<action android:name="android.intent.action.TTS_SERVICE" />
</intent>
</queries>
</manifest>
@@ -25,6 +25,7 @@ import android.content.BroadcastReceiver
import androidx.core.provider.FontRequest
import androidx.emoji.text.EmojiCompat
import androidx.emoji.text.FontRequestEmojiCompatConfig
import com.moez.QKSMS.manager.SpeakManager
import dev.octoshrimpy.quik.R
import dev.octoshrimpy.quik.common.util.CrashlyticsTree
import dev.octoshrimpy.quik.common.util.FileLoggingTree
@@ -43,6 +44,7 @@ import dagger.android.DispatchingAndroidInjector
import dagger.android.HasActivityInjector
import dagger.android.HasBroadcastReceiverInjector
import dagger.android.HasServiceInjector
import dev.octoshrimpy.quik.interactor.SpeakThreads
import io.realm.Realm
import io.realm.RealmConfiguration
import kotlinx.coroutines.Dispatchers
@@ -73,6 +75,12 @@ class QKApplication : Application(), HasActivityInjector, HasBroadcastReceiverIn
override fun onCreate() {
super.onCreate()
// set application context for SpeakManager
SpeakManager.setContext(this)
// set translated "no messages" string for speakThreads interactor
SpeakThreads.setNoMessagesString(getString(R.string.speak_no_messages))
AppComponentManager.init(this)
appComponent.inject(this)
@@ -153,7 +153,6 @@ class TextViewStyler @Inject constructor(
Preferences.TEXT_SIZE_NORMAL -> 16f
Preferences.TEXT_SIZE_LARGE -> 18f
Preferences.TEXT_SIZE_LARGER -> 20f
Preferences.TEXT_SIZE_SUPER -> 40f
else -> 16f
}
@@ -162,7 +161,6 @@ class TextViewStyler @Inject constructor(
Preferences.TEXT_SIZE_NORMAL -> 14f
Preferences.TEXT_SIZE_LARGE -> 16f
Preferences.TEXT_SIZE_LARGER -> 18f
Preferences.TEXT_SIZE_SUPER -> 36f
else -> 14f
}
@@ -171,7 +169,6 @@ class TextViewStyler @Inject constructor(
Preferences.TEXT_SIZE_NORMAL -> 12f
Preferences.TEXT_SIZE_LARGE -> 14f
Preferences.TEXT_SIZE_LARGER -> 16f
Preferences.TEXT_SIZE_SUPER -> 32f
else -> 12f
}
@@ -180,7 +177,6 @@ class TextViewStyler @Inject constructor(
Preferences.TEXT_SIZE_NORMAL -> 20f
Preferences.TEXT_SIZE_LARGE -> 22f
Preferences.TEXT_SIZE_LARGER -> 26f
Preferences.TEXT_SIZE_SUPER -> 52f
else -> 20f
}
@@ -189,7 +185,6 @@ class TextViewStyler @Inject constructor(
Preferences.TEXT_SIZE_NORMAL -> 18f
Preferences.TEXT_SIZE_LARGE -> 20f
Preferences.TEXT_SIZE_LARGER -> 24f
Preferences.TEXT_SIZE_SUPER -> 48f
else -> 18f
}
@@ -198,7 +193,6 @@ class TextViewStyler @Inject constructor(
Preferences.TEXT_SIZE_NORMAL -> 32f
Preferences.TEXT_SIZE_LARGE -> 36f
Preferences.TEXT_SIZE_LARGER -> 40f
Preferences.TEXT_SIZE_SUPER -> 80f
else -> 32f
}
}
@@ -153,6 +153,7 @@ class ConversationItemTouchCallback @Inject constructor(
Preferences.SWIPE_ACTION_CALL -> R.drawable.ic_call_white_24dp
Preferences.SWIPE_ACTION_READ -> R.drawable.ic_check_white_24dp
Preferences.SWIPE_ACTION_UNREAD -> R.drawable.ic_markunread_black_24dp
Preferences.SWIPE_ACTION_SPEAK -> R.drawable.ic_speaker_black_24dp
else -> null
}
@@ -48,6 +48,7 @@ import dev.octoshrimpy.quik.repository.SyncRepository
import dev.octoshrimpy.quik.util.Preferences
import com.uber.autodispose.android.lifecycle.scope
import com.uber.autodispose.autoDisposable
import dev.octoshrimpy.quik.interactor.SpeakThreads
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.rxkotlin.plusAssign
import io.reactivex.rxkotlin.withLatestFrom
@@ -75,6 +76,7 @@ class MainViewModel @Inject constructor(
private val markUnarchived: MarkUnarchived,
private val markUnpinned: MarkUnpinned,
private val markUnread: MarkUnread,
private val speakThreads: SpeakThreads,
private val navigator: Navigator,
private val permissionManager: PermissionManager,
private val prefs: Preferences,
@@ -466,6 +468,7 @@ class MainViewModel @Inject constructor(
Preferences.SWIPE_ACTION_CALL -> conversationRepo.getConversation(threadId)?.recipients?.firstOrNull()?.address?.let(navigator::makePhoneCall)
Preferences.SWIPE_ACTION_READ -> markRead.execute(listOf(threadId))
Preferences.SWIPE_ACTION_UNREAD -> markUnread.execute(listOf(threadId))
Preferences.SWIPE_ACTION_SPEAK -> speakThreads.execute(listOf(threadId))
}
}
@@ -76,6 +76,7 @@ class SwipeActionsPresenter @Inject constructor(
Preferences.SWIPE_ACTION_CALL -> R.drawable.ic_call_white_24dp
Preferences.SWIPE_ACTION_READ -> R.drawable.ic_check_white_24dp
Preferences.SWIPE_ACTION_UNREAD -> R.drawable.ic_markunread_black_24dp
Preferences.SWIPE_ACTION_SPEAK -> R.drawable.ic_speaker_black_24dp
else -> 0
}
@@ -0,0 +1,69 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package dev.octoshrimpy.quik.feature.widget
import android.app.PendingIntent
import android.appwidget.AppWidgetManager
import android.appwidget.AppWidgetProvider
import android.content.Context
import android.content.Intent
import android.widget.ImageView
import android.widget.RemoteViews
import dev.octoshrimpy.quik.R
import dev.octoshrimpy.quik.common.util.extensions.getColorCompat
class WidgetSpeakUnseenProvider : AppWidgetProvider() {
override fun onReceive(context: Context, intent: Intent) {
super.onReceive(context, intent)
}
override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) {
super.onUpdate(context, appWidgetManager, appWidgetIds)
for (appWidgetId in appWidgetIds)
updateWidget(context, appWidgetId)
}
fun updateWidget(context: Context?, appWidgetId: Int) {
super.onEnabled(context)
if (context == null)
return
val remoteViews = RemoteViews(context.packageName, R.layout.widget_speak_unseen)
remoteViews.setImageViewResource(R.id.speakUnseenImage, R.drawable.ic_speak_unseen_widget)
// speak unseen intent
val speakUnseenIntent = Intent("dev.octoshrimpy.quik.intent.action.ACTION_SPEAK_MESSAGES")
.setPackage(context.packageName)
.putExtra("threadId", -1L)
val speakUnseenPendingIntent = PendingIntent.getBroadcast(
context,
0,
speakUnseenIntent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
remoteViews.setOnClickPendingIntent(R.id.speakUnseenImage, speakUnseenPendingIntent)
AppWidgetManager.getInstance(context).updateAppWidget(appWidgetId, remoteViews)
}
}
@@ -40,6 +40,7 @@ import dev.octoshrimpy.quik.receiver.SmsReceiver
import dev.octoshrimpy.quik.receiver.SmsSentReceiver
import dagger.Module
import dagger.android.ContributesAndroidInjector
import dev.octoshrimpy.quik.receiver.SpeakThreadsReceiver
@Module
abstract class BroadcastReceiverBuilderModule {
@@ -68,6 +69,10 @@ abstract class BroadcastReceiverBuilderModule {
@ContributesAndroidInjector()
abstract fun bindMarkReadReceiver(): MarkReadReceiver
@ActivityScope
@ContributesAndroidInjector()
abstract fun bindSpeakThreadsReceiver(): SpeakThreadsReceiver
@ActivityScope
@ContributesAndroidInjector()
abstract fun bindMarkSeenReceiver(): MarkSeenReceiver
Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:viewportWidth="24"
android:viewportHeight="24"
android:width="24dp"
android:height="24dp">
<path
android:pathData="M13 3.7446C13 3.27314 12.8728 2.50021 12.1657 2.14424C11.4151 1.76635 10.7163 2.19354 10.3623 2.51158L4.94661 7.43717H3C1.89543 7.43717 1 8.3326 1 9.43717L1.00001 14.6248C1.00001 15.7293 1.89544 16.6248 3.00001 16.6248H4.95001L10.3623 21.4891C10.7175 21.8081 11.416 22.2331 12.1656 21.8554C12.8717 21.4998 13 20.7286 13 20.2561V3.7446Z"
android:fillColor="#000000" />
</vector>
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2019 Moez Bhatti <moez.bhatti@gmail.com>
~
~ This file is part of QKSMS.
~
~ QKSMS is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ QKSMS is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/speakUnseenImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="2dp"
android:paddingTop="2dp"
android:paddingRight="2dp"
android:paddingBottom="2dp"
android:visibility="visible" />
</FrameLayout>
+3 -2
View File
@@ -255,6 +255,7 @@
<item>Call</item>
<item>Mark read</item>
<item>Mark unread</item>
<item>Speak</item>
</string-array>
<string name="settings_delivery_title">Delivery confirmations</string>
<string name="settings_delivery_summary">Confirm that messages were sent successfully</string>
@@ -450,7 +451,6 @@
<item>Normal</item>
<item>Large</item>
<item>Larger</item>
<item>Super</item>
</string-array>
<string-array name="delayed_sending_labels">
@@ -496,5 +496,6 @@
<item>LOL</item>
<item>That\'s okay</item>
</string-array>
<string name="speak_no_messages">No Messages</string>
<string name="speak_unseen_messages">Speak unseen messages</string>
</resources>
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2019 Moez Bhatti <moez.bhatti@gmail.com>
~
~ This file is part of QKSMS.
~
~ QKSMS is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ QKSMS is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
-->
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:initialLayout="@layout/widget_speak_unseen"
android:targetCellWidth="1"
android:targetCellHeight="1"
android:previewImage="@drawable/ic_speak_unseen_widget"
android:resizeMode="horizontal|vertical"
android:updatePeriodMillis="0"
android:widgetCategory="home_screen|keyguard" />