mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 19:38:52 +01:00
Add block/archive notification actions, and block swipe action
Closes #1575, closes #943
This commit is contained in:
@@ -45,7 +45,9 @@ import com.moez.QKSMS.feature.compose.ComposeActivity
|
||||
import com.moez.QKSMS.feature.qkreply.QkReplyActivity
|
||||
import com.moez.QKSMS.manager.PermissionManager
|
||||
import com.moez.QKSMS.mapper.CursorToPartImpl
|
||||
import com.moez.QKSMS.receiver.BlockThreadReceiver
|
||||
import com.moez.QKSMS.receiver.DeleteMessagesReceiver
|
||||
import com.moez.QKSMS.receiver.MarkArchivedReceiver
|
||||
import com.moez.QKSMS.receiver.MarkReadReceiver
|
||||
import com.moez.QKSMS.receiver.MarkSeenReceiver
|
||||
import com.moez.QKSMS.receiver.RemoteMessagingReceiver
|
||||
@@ -227,9 +229,36 @@ class NotificationManagerImpl @Inject constructor(
|
||||
.distinct()
|
||||
.mapNotNull { action ->
|
||||
when (action) {
|
||||
Preferences.NOTIFICATION_ACTION_ARCHIVE -> {
|
||||
val intent = Intent(context, MarkArchivedReceiver::class.java).putExtra("threadId", threadId)
|
||||
val pi = PendingIntent.getBroadcast(context, threadId.toInt() + 30000, intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
NotificationCompat.Action.Builder(R.drawable.ic_archive_white_24dp, actionLabels[action], pi)
|
||||
.setSemanticAction(NotificationCompat.Action.SEMANTIC_ACTION_ARCHIVE).build()
|
||||
}
|
||||
|
||||
Preferences.NOTIFICATION_ACTION_DELETE -> {
|
||||
val messageIds = messages.map { it.id }.toLongArray()
|
||||
val intent = Intent(context, DeleteMessagesReceiver::class.java)
|
||||
.putExtra("threadId", threadId)
|
||||
.putExtra("messageIds", messageIds)
|
||||
val pi = PendingIntent.getBroadcast(context, threadId.toInt() + 40000, intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
NotificationCompat.Action.Builder(R.drawable.ic_delete_white_24dp, actionLabels[action], pi)
|
||||
.setSemanticAction(NotificationCompat.Action.SEMANTIC_ACTION_DELETE).build()
|
||||
}
|
||||
|
||||
Preferences.NOTIFICATION_ACTION_BLOCK -> {
|
||||
val intent = Intent(context, BlockThreadReceiver::class.java).putExtra("threadId", threadId)
|
||||
val pi = PendingIntent.getBroadcast(context, threadId.toInt() + 50000, intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
NotificationCompat.Action.Builder(R.drawable.ic_block_white_24dp, actionLabels[action], pi)
|
||||
.setSemanticAction(NotificationCompat.Action.SEMANTIC_ACTION_MUTE).build()
|
||||
}
|
||||
|
||||
Preferences.NOTIFICATION_ACTION_READ -> {
|
||||
val intent = Intent(context, MarkReadReceiver::class.java).putExtra("threadId", threadId)
|
||||
val pi = PendingIntent.getBroadcast(context, threadId.toInt() + 30000, intent,
|
||||
val pi = PendingIntent.getBroadcast(context, threadId.toInt() + 60000, intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
NotificationCompat.Action.Builder(R.drawable.ic_check_white_24dp, actionLabels[action], pi)
|
||||
.setSemanticAction(NotificationCompat.Action.SEMANTIC_ACTION_MARK_AS_READ).build()
|
||||
@@ -240,7 +269,7 @@ class NotificationManagerImpl @Inject constructor(
|
||||
getReplyAction(threadId)
|
||||
} else {
|
||||
val intent = Intent(context, QkReplyActivity::class.java).putExtra("threadId", threadId)
|
||||
val pi = PendingIntent.getActivity(context, threadId.toInt() + 40000, intent,
|
||||
val pi = PendingIntent.getActivity(context, threadId.toInt() + 70000, intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
NotificationCompat.Action
|
||||
.Builder(R.drawable.ic_reply_white_24dp, actionLabels[action], pi)
|
||||
@@ -252,23 +281,12 @@ class NotificationManagerImpl @Inject constructor(
|
||||
val address = conversation.recipients[0]?.address
|
||||
val intentAction = if (permissions.hasCalling()) Intent.ACTION_CALL else Intent.ACTION_DIAL
|
||||
val intent = Intent(intentAction, Uri.parse("tel:$address"))
|
||||
val pi = PendingIntent.getActivity(context, threadId.toInt() + 50000, intent,
|
||||
val pi = PendingIntent.getActivity(context, threadId.toInt() + 80000, intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
NotificationCompat.Action.Builder(R.drawable.ic_call_white_24dp, actionLabels[action], pi)
|
||||
.setSemanticAction(NotificationCompat.Action.SEMANTIC_ACTION_CALL).build()
|
||||
}
|
||||
|
||||
Preferences.NOTIFICATION_ACTION_DELETE -> {
|
||||
val messageIds = messages.map { it.id }.toLongArray()
|
||||
val intent = Intent(context, DeleteMessagesReceiver::class.java)
|
||||
.putExtra("threadId", threadId)
|
||||
.putExtra("messageIds", messageIds)
|
||||
val pi = PendingIntent.getBroadcast(context, threadId.toInt() + 60000, intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
NotificationCompat.Action.Builder(R.drawable.ic_delete_white_24dp, actionLabels[action], pi)
|
||||
.setSemanticAction(NotificationCompat.Action.SEMANTIC_ACTION_DELETE).build()
|
||||
}
|
||||
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -147,8 +147,9 @@ class ConversationItemTouchCallback @Inject constructor(
|
||||
|
||||
private fun iconForAction(action: Int, tint: Int): Bitmap? {
|
||||
val res = when (action) {
|
||||
Preferences.SWIPE_ACTION_ARCHIVE -> R.drawable.ic_archive_black_24dp
|
||||
Preferences.SWIPE_ACTION_ARCHIVE -> R.drawable.ic_archive_white_24dp
|
||||
Preferences.SWIPE_ACTION_DELETE -> R.drawable.ic_delete_white_24dp
|
||||
Preferences.SWIPE_ACTION_BLOCK -> R.drawable.ic_block_white_24dp
|
||||
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
|
||||
|
||||
@@ -423,6 +423,7 @@ class MainViewModel @Inject constructor(
|
||||
when (action) {
|
||||
Preferences.SWIPE_ACTION_ARCHIVE -> markArchived.execute(listOf(threadId)) { view.showArchivedSnackbar() }
|
||||
Preferences.SWIPE_ACTION_DELETE -> view.showDeleteDialog(listOf(threadId))
|
||||
Preferences.SWIPE_ACTION_BLOCK -> view.showBlockingDialog(listOf(threadId), true)
|
||||
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))
|
||||
|
||||
+2
-1
@@ -70,8 +70,9 @@ class SwipeActionsPresenter @Inject constructor(
|
||||
|
||||
@DrawableRes
|
||||
private fun iconForAction(action: Int) = when (action) {
|
||||
Preferences.SWIPE_ACTION_ARCHIVE -> R.drawable.ic_archive_black_24dp
|
||||
Preferences.SWIPE_ACTION_ARCHIVE -> R.drawable.ic_archive_white_24dp
|
||||
Preferences.SWIPE_ACTION_DELETE -> R.drawable.ic_delete_white_24dp
|
||||
Preferences.SWIPE_ACTION_BLOCK -> R.drawable.ic_block_white_24dp
|
||||
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
|
||||
|
||||
+2
-2
@@ -22,9 +22,9 @@ import androidx.annotation.DrawableRes
|
||||
import com.moez.QKSMS.R
|
||||
|
||||
data class SwipeActionsState(
|
||||
@DrawableRes val rightIcon: Int = R.drawable.ic_archive_black_24dp,
|
||||
@DrawableRes val rightIcon: Int = R.drawable.ic_archive_white_24dp,
|
||||
val rightLabel: String = "",
|
||||
|
||||
@DrawableRes val leftIcon: Int = R.drawable.ic_archive_black_24dp,
|
||||
@DrawableRes val leftIcon: Int = R.drawable.ic_archive_white_24dp,
|
||||
val leftLabel: String = ""
|
||||
)
|
||||
+10
@@ -20,9 +20,11 @@ package com.moez.QKSMS.injection.android
|
||||
|
||||
import com.moez.QKSMS.feature.widget.WidgetProvider
|
||||
import com.moez.QKSMS.injection.scope.ActivityScope
|
||||
import com.moez.QKSMS.receiver.BlockThreadReceiver
|
||||
import com.moez.QKSMS.receiver.BootReceiver
|
||||
import com.moez.QKSMS.receiver.DefaultSmsChangedReceiver
|
||||
import com.moez.QKSMS.receiver.DeleteMessagesReceiver
|
||||
import com.moez.QKSMS.receiver.MarkArchivedReceiver
|
||||
import com.moez.QKSMS.receiver.MarkReadReceiver
|
||||
import com.moez.QKSMS.receiver.MarkSeenReceiver
|
||||
import com.moez.QKSMS.receiver.MmsReceivedReceiver
|
||||
@@ -42,6 +44,10 @@ import dagger.android.ContributesAndroidInjector
|
||||
@Module
|
||||
abstract class BroadcastReceiverBuilderModule {
|
||||
|
||||
@ActivityScope
|
||||
@ContributesAndroidInjector()
|
||||
abstract fun bindBlockThreadReceiver(): BlockThreadReceiver
|
||||
|
||||
@ActivityScope
|
||||
@ContributesAndroidInjector()
|
||||
abstract fun bindBootReceiver(): BootReceiver
|
||||
@@ -54,6 +60,10 @@ abstract class BroadcastReceiverBuilderModule {
|
||||
@ContributesAndroidInjector()
|
||||
abstract fun bindDeleteMessagesReceiver(): DeleteMessagesReceiver
|
||||
|
||||
@ActivityScope
|
||||
@ContributesAndroidInjector
|
||||
abstract fun bindMarkArchivedReceiver(): MarkArchivedReceiver
|
||||
|
||||
@ActivityScope
|
||||
@ContributesAndroidInjector()
|
||||
abstract fun bindMarkReadReceiver(): MarkReadReceiver
|
||||
|
||||
Reference in New Issue
Block a user