Add block/archive notification actions, and block swipe action

Closes #1575, closes #943
This commit is contained in:
Moez Bhatti
2020-02-29 19:54:40 -05:00
parent 853acaa42c
commit e2f4b92609
20 changed files with 201 additions and 40 deletions
@@ -149,6 +149,8 @@
<receiver
android:name=".receiver.MmsReceivedReceiver"
android:taskAffinity="com.klinker.android.messaging.MMS_RECEIVED" />
<receiver android:name=".receiver.MarkArchivedReceiver" />
<receiver android:name=".receiver.BlockThreadReceiver" />
<receiver android:name=".receiver.MarkSeenReceiver" />
<receiver android:name=".receiver.MarkReadReceiver" />
<receiver android:name=".receiver.RemoteMessagingReceiver" />
@@ -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
}
}
@@ -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))
@@ -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
@@ -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 = ""
)
@@ -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
@@ -22,6 +22,6 @@
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:fillColor="#FFFFFFFF"
android:pathData="M20.54,5.23l-1.39,-1.68C18.88,3.21 18.47,3 18,3H6c-0.47,0 -0.88,0.21 -1.16,0.55L3.46,5.23C3.17,5.57 3,6.02 3,6.5V19c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2V6.5c0,-0.48 -0.17,-0.93 -0.46,-1.27zM12,17.5L6.5,12H10v-2h4v2h3.5L12,17.5zM5.12,5l0.81,-1h12l0.94,1H5.12z" />
</vector>
@@ -22,6 +22,6 @@
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:fillColor="#FFFFFFFF"
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM4,12c0,-4.42 3.58,-8 8,-8 1.85,0 3.55,0.63 4.9,1.69L5.69,16.9C4.63,15.55 4,13.85 4,12zM12,20c-1.85,0 -3.55,-0.63 -4.9,-1.69L18.31,7.1C19.37,8.45 20,10.15 20,12c0,4.42 -3.58,8 -8,8z" />
</vector>
@@ -48,14 +48,14 @@
android:id="@+id/archive"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:icon="@drawable/ic_archive_black_24dp"
app:icon="@drawable/ic_archive_white_24dp"
app:title="@string/info_archive" />
<com.moez.QKSMS.common.widget.PreferenceView
android:id="@+id/block"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:icon="@drawable/ic_block_black_24dp"
app:icon="@drawable/ic_block_white_24dp"
app:title="@string/info_block" />
<com.moez.QKSMS.common.widget.PreferenceView
@@ -54,7 +54,7 @@
<ImageView
android:id="@+id/archivedIcon"
style="@style/DrawerIcon"
android:src="@drawable/ic_archive_black_24dp"
android:src="@drawable/ic_archive_white_24dp"
tools:tint="?android:attr/textColorSecondary" />
<com.moez.QKSMS.common.widget.QkTextView
@@ -130,7 +130,7 @@
<ImageView
style="@style/DrawerIcon"
android:src="@drawable/ic_block_black_24dp"
android:src="@drawable/ic_block_white_24dp"
android:tint="?android:attr/textColorSecondary" />
<com.moez.QKSMS.common.widget.QkTextView
@@ -232,7 +232,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alpha="0.25"
app:icon="@drawable/ic_block_black_24dp"
app:icon="@drawable/ic_block_white_24dp"
app:summary="@string/qksms_plus_blacklist_summary"
app:title="@string/qksms_plus_blacklist_title" />
@@ -104,7 +104,7 @@
app:layout_constraintStart_toStartOf="@id/rightBackground"
app:layout_constraintTop_toTopOf="@id/rightBackground"
tools:backgroundTint="@color/tools_theme"
tools:src="@drawable/ic_archive_black_24dp"
tools:src="@drawable/ic_archive_white_24dp"
tools:tint="@color/textPrimaryDark" />
<ImageView
@@ -225,7 +225,7 @@
app:layout_constraintEnd_toEndOf="@id/leftBackground"
app:layout_constraintTop_toTopOf="@id/leftBackground"
tools:backgroundTint="@color/tools_theme"
tools:src="@drawable/ic_archive_black_24dp"
tools:src="@drawable/ic_archive_white_24dp"
tools:tint="@color/textPrimaryDark" />
<ImageView
@@ -29,7 +29,7 @@
<item
android:id="@+id/block"
android:icon="@drawable/ic_block_black_24dp"
android:icon="@drawable/ic_block_white_24dp"
android:title="@string/main_menu_block"
android:visible="false"
app:showAsAction="ifRoom" />
+2 -2
View File
@@ -22,7 +22,7 @@
<item
android:id="@+id/archive"
android:icon="@drawable/ic_archive_black_24dp"
android:icon="@drawable/ic_archive_white_24dp"
android:title="@string/main_menu_archive"
android:visible="false"
app:showAsAction="ifRoom" />
@@ -78,7 +78,7 @@
<item
android:id="@+id/block"
android:icon="@drawable/ic_block_black_24dp"
android:icon="@drawable/ic_block_white_24dp"
android:title="@string/main_menu_block"
android:visible="false"
app:showAsAction="ifRoom" />
+5 -2
View File
@@ -243,6 +243,7 @@
<item>None</item>
<item>Archive</item>
<item>Delete</item>
<item>Block</item>
<item>Call</item>
<item>Mark read</item>
<item>Mark unread</item>
@@ -379,10 +380,12 @@
<string-array name="notification_actions">
<item>None</item>
<item>Archive</item>
<item>Delete</item>
<item>Block</item>
<item>Call</item>
<item>Mark read</item>
<item>Reply</item>
<item>Call</item>
<item>Delete</item>
</string-array>
<string name="button_yes">Yes</string>