From 6475f28304b024a6a7e9230baa9f5a0449682d1e Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Mon, 16 May 2022 21:17:17 +0200 Subject: [PATCH] add silent send option Signed-off-by: Marcel Hibbe --- .../java/com/nextcloud/talk/api/NcApi.java | 3 +- .../talk/controllers/ChatController.kt | 43 ++++++++++++++++--- .../talk/receivers/DirectReplyReceiver.kt | 2 +- .../ic_baseline_notifications_off_24.xml | 26 +++++++++++ app/src/main/res/menu/chat_send_menu.xml | 26 +++++++++++ app/src/main/res/values/strings.xml | 1 + app/src/main/res/values/styles.xml | 11 +++++ 7 files changed, 105 insertions(+), 7 deletions(-) create mode 100644 app/src/main/res/drawable/ic_baseline_notifications_off_24.xml create mode 100644 app/src/main/res/menu/chat_send_menu.xml diff --git a/app/src/main/java/com/nextcloud/talk/api/NcApi.java b/app/src/main/java/com/nextcloud/talk/api/NcApi.java index 857eabecc..20a1969a5 100644 --- a/app/src/main/java/com/nextcloud/talk/api/NcApi.java +++ b/app/src/main/java/com/nextcloud/talk/api/NcApi.java @@ -338,7 +338,8 @@ public interface NcApi { @Url String url, @Field("message") CharSequence message, @Field("actorDisplayName") String actorDisplayName, - @Field("replyTo") Integer replyTo); + @Field("replyTo") Integer replyTo, + @Field("silent") Boolean sendWithoutNotification); @GET Observable> getSharedItems(@Header("Authorization") String authorization, @Url String url, diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt index 4bec27819..f781b9160 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt @@ -57,6 +57,7 @@ import android.text.TextUtils import android.text.TextWatcher import android.util.Log import android.util.TypedValue +import android.view.Gravity import android.view.Menu import android.view.MenuInflater import android.view.MenuItem @@ -68,8 +69,10 @@ import android.view.animation.LinearInterpolator import android.widget.AbsListView import android.widget.ImageButton import android.widget.ImageView +import android.widget.PopupMenu import android.widget.RelativeLayout import android.widget.Toast +import androidx.appcompat.view.ContextThemeWrapper import androidx.core.content.ContextCompat import androidx.core.content.FileProvider import androidx.core.content.PermissionChecker @@ -835,7 +838,14 @@ class ChatController(args: Bundle) : activity?.let { AttachmentDialog(it, this).show() } } - binding.messageInputView.button.setOnClickListener { v -> submitMessage() } + binding.messageInputView.button.setOnClickListener { submitMessage(false) } + + if (CapabilitiesUtil.hasSpreedFeatureCapability(conversationUser, "silent-send")) { + binding.messageInputView.button.setOnLongClickListener { + showSendButtonMenu() + true + } + } binding.messageInputView.button.contentDescription = resources?.getString( R.string @@ -858,6 +868,27 @@ class ChatController(args: Bundle) : super.onViewBound(view) } + private fun showSendButtonMenu() { + val popupMenu = PopupMenu( + ContextThemeWrapper(view?.context, R.style.ChatSendButtonMenu), + binding.messageInputView.button, + Gravity.END + ) + popupMenu.inflate(R.menu.chat_send_menu) + + popupMenu.setOnMenuItemClickListener { item: MenuItem -> + when (item.itemId) { + R.id.send_without_notification -> submitMessage(true) + } + true + } + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + popupMenu.setForceShowIcon(true) + } + popupMenu.show() + } + private fun startPlayback(message: ChatMessage) { if (!this.isAttached) { @@ -1879,7 +1910,7 @@ class ChatController(args: Bundle) : }) } - private fun submitMessage() { + private fun submitMessage(sendWithoutNotification: Boolean) { if (binding.messageInputView.inputEditText != null) { val editable = binding.messageInputView.inputEditText!!.editableText val mentionSpans = editable.getSpans( @@ -1904,13 +1935,14 @@ class ChatController(args: Bundle) : view ?.findViewById(R.id.quotedChatMessageView) ?.visibility == View.VISIBLE - ) replyMessageId else null + ) replyMessageId else null, + sendWithoutNotification ) cancelReply() } } - private fun sendMessage(message: CharSequence, replyTo: Int?) { + private fun sendMessage(message: CharSequence, replyTo: Int?, sendWithoutNotification: Boolean) { if (conversationUser != null) { val apiVersion = ApiUtils.getChatApiVersion(conversationUser, intArrayOf(1)) @@ -1920,7 +1952,8 @@ class ChatController(args: Bundle) : ApiUtils.getUrlForChat(apiVersion, conversationUser.baseUrl, roomToken), message, conversationUser.displayName, - replyTo + replyTo, + sendWithoutNotification ) ?.subscribeOn(Schedulers.io()) ?.observeOn(AndroidSchedulers.mainThread()) diff --git a/app/src/main/java/com/nextcloud/talk/receivers/DirectReplyReceiver.kt b/app/src/main/java/com/nextcloud/talk/receivers/DirectReplyReceiver.kt index 26caea024..95e81a1e8 100644 --- a/app/src/main/java/com/nextcloud/talk/receivers/DirectReplyReceiver.kt +++ b/app/src/main/java/com/nextcloud/talk/receivers/DirectReplyReceiver.kt @@ -90,7 +90,7 @@ class DirectReplyReceiver : BroadcastReceiver() { val apiVersion = ApiUtils.getChatApiVersion(currentUser, intArrayOf(1)) val url = ApiUtils.getUrlForChat(apiVersion, currentUser.baseUrl, roomToken) - ncApi!!.sendChatMessage(credentials, url, replyMessage, currentUser.displayName, null) + ncApi!!.sendChatMessage(credentials, url, replyMessage, currentUser.displayName, null, false) ?.subscribeOn(Schedulers.io()) ?.observeOn(AndroidSchedulers.mainThread()) ?.subscribe(object : Observer { diff --git a/app/src/main/res/drawable/ic_baseline_notifications_off_24.xml b/app/src/main/res/drawable/ic_baseline_notifications_off_24.xml new file mode 100644 index 000000000..bc7324637 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_notifications_off_24.xml @@ -0,0 +1,26 @@ + + + + diff --git a/app/src/main/res/menu/chat_send_menu.xml b/app/src/main/res/menu/chat_send_menu.xml new file mode 100644 index 000000000..51d73aa01 --- /dev/null +++ b/app/src/main/res/menu/chat_send_menu.xml @@ -0,0 +1,26 @@ + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b94aa7bd1..a6d4d94ba 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -519,5 +519,6 @@ Attachments All + Send without notification diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index bf492330e..6d010315e 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -41,6 +41,7 @@ @style/Nextcloud.Material.Incoming.SeekBar @style/Nextcloud.Material.Incoming.SeekBar @style/ThemeOverlay.App.BottomSheetDialog + @style/ChatSendButtonMenu + +