From f3dd48247623110ef7fd977c6a84fc21c86e2edf Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Wed, 9 Jun 2021 10:50:26 +0200 Subject: [PATCH 1/6] link swipe-to-reply to messages replyable-flag Signed-off-by: Andy Scherzinger --- .../messages/MagicIncomingTextMessageViewHolder.kt | 12 ++++++------ .../messages/MagicOutcomingTextMessageViewHolder.kt | 12 ++++++++---- .../messages/MagicPreviewMessageViewHolder.java | 4 ++++ .../messages/MagicSystemMessageViewHolder.java | 4 ++++ .../talk/ui/recyclerview/MessageSwipeCallback.kt | 11 ++++------- app/src/main/res/values/strings.xml | 1 + 6 files changed, 27 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicIncomingTextMessageViewHolder.kt b/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicIncomingTextMessageViewHolder.kt index 3b2a8cf33..abf27d53a 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicIncomingTextMessageViewHolder.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicIncomingTextMessageViewHolder.kt @@ -45,6 +45,7 @@ import com.nextcloud.talk.R import com.nextcloud.talk.application.NextcloudTalkApplication import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication import com.nextcloud.talk.models.json.chat.ChatMessage +import com.nextcloud.talk.ui.recyclerview.MessageSwipeCallback import com.nextcloud.talk.utils.ApiUtils import com.nextcloud.talk.utils.DisplayUtils import com.nextcloud.talk.utils.TextMatchers @@ -53,8 +54,8 @@ import com.stfalcon.chatkit.messages.MessageHolders import javax.inject.Inject @AutoInjector(NextcloudTalkApplication::class) -class MagicIncomingTextMessageViewHolder(incomingView: View) : MessageHolders -.IncomingTextMessageViewHolder(incomingView) { +class MagicIncomingTextMessageViewHolder(itemView: View) : MessageHolders +.IncomingTextMessageViewHolder(itemView) { @JvmField @BindView(R.id.messageAuthor) @@ -101,10 +102,7 @@ class MagicIncomingTextMessageViewHolder(incomingView: View) : MessageHolders var appPreferences: AppPreferences? = null init { - ButterKnife.bind( - this, - itemView - ) + ButterKnife.bind(this, itemView) } override fun onBind(message: ChatMessage) { @@ -257,5 +255,7 @@ class MagicIncomingTextMessageViewHolder(incomingView: View) : MessageHolders } else { quotedChatMessageView?.visibility = View.GONE } + + itemView.setTag(MessageSwipeCallback.REPLYABLE_VIEW_TAG, message.isReplyable) } } diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicOutcomingTextMessageViewHolder.kt b/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicOutcomingTextMessageViewHolder.kt index 852985ebe..a573c4956 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicOutcomingTextMessageViewHolder.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicOutcomingTextMessageViewHolder.kt @@ -42,6 +42,7 @@ import com.nextcloud.talk.application.NextcloudTalkApplication import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication import com.nextcloud.talk.models.json.chat.ChatMessage import com.nextcloud.talk.models.json.chat.ReadStatus +import com.nextcloud.talk.ui.recyclerview.MessageSwipeCallback import com.nextcloud.talk.utils.ApiUtils import com.nextcloud.talk.utils.DisplayUtils.getMessageSelector import com.nextcloud.talk.utils.DisplayUtils.searchAndReplaceWithMentionSpan @@ -89,6 +90,12 @@ class MagicOutcomingTextMessageViewHolder(itemView: View) : OutcomingTextMessage var context: Context? = null private val realView: View + + init { + ButterKnife.bind(this, itemView) + this.realView = itemView + } + override fun onBind(message: ChatMessage) { super.onBind(message) sharedApplication!!.componentApplication.inject(this) @@ -208,10 +215,7 @@ class MagicOutcomingTextMessageViewHolder(itemView: View) : OutcomingTextMessage } checkMark?.setContentDescription(readStatusContentDescriptionString) - } - init { - ButterKnife.bind(this, itemView) - this.realView = itemView + itemView.setTag(MessageSwipeCallback.REPLYABLE_VIEW_TAG, message.isReplyable) } } diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicPreviewMessageViewHolder.java b/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicPreviewMessageViewHolder.java index d0ee7abe9..eecc8d31b 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicPreviewMessageViewHolder.java +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicPreviewMessageViewHolder.java @@ -79,6 +79,8 @@ import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; import okhttp3.OkHttpClient; +import static com.nextcloud.talk.ui.recyclerview.MessageSwipeCallback.REPLYABLE_VIEW_TAG; + @AutoInjector(NextcloudTalkApplication.class) public class MagicPreviewMessageViewHolder extends MessageHolders.IncomingImageMessageViewHolder { @@ -194,6 +196,8 @@ public class MagicPreviewMessageViewHolder extends MessageHolders.IncomingImageM } messageText.setText(""); } + + itemView.setTag(REPLYABLE_VIEW_TAG, message.isReplyable()); } private void openOrDownloadFile(ChatMessage message) { diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicSystemMessageViewHolder.java b/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicSystemMessageViewHolder.java index 301a7397d..be079c009 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicSystemMessageViewHolder.java +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicSystemMessageViewHolder.java @@ -41,6 +41,8 @@ import javax.inject.Inject; import androidx.core.view.ViewCompat; import autodagger.AutoInjector; +import static com.nextcloud.talk.ui.recyclerview.MessageSwipeCallback.REPLYABLE_VIEW_TAG; + @AutoInjector(NextcloudTalkApplication.class) public class MagicSystemMessageViewHolder extends MessageHolders.IncomingTextMessageViewHolder { @@ -85,5 +87,7 @@ public class MagicSystemMessageViewHolder extends MessageHolders.IncomingTextMes } text.setText(messageString); + + itemView.setTag(REPLYABLE_VIEW_TAG, message.isReplyable()); } } diff --git a/app/src/main/java/com/nextcloud/talk/ui/recyclerview/MessageSwipeCallback.kt b/app/src/main/java/com/nextcloud/talk/ui/recyclerview/MessageSwipeCallback.kt index a28a66239..4ed198033 100644 --- a/app/src/main/java/com/nextcloud/talk/ui/recyclerview/MessageSwipeCallback.kt +++ b/app/src/main/java/com/nextcloud/talk/ui/recyclerview/MessageSwipeCallback.kt @@ -43,9 +43,6 @@ import androidx.recyclerview.widget.ItemTouchHelper.ACTION_STATE_SWIPE import androidx.recyclerview.widget.ItemTouchHelper.RIGHT import androidx.recyclerview.widget.RecyclerView import com.nextcloud.talk.R -import com.nextcloud.talk.adapters.messages.MagicIncomingTextMessageViewHolder -import com.nextcloud.talk.adapters.messages.MagicOutcomingTextMessageViewHolder -import com.nextcloud.talk.adapters.messages.MagicPreviewMessageViewHolder import kotlin.math.abs import kotlin.math.ceil import kotlin.math.min @@ -76,11 +73,10 @@ class MessageSwipeCallback(private val context: Context, private val messageSwip private var startTracking = false override fun getMovementFlags(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder): Int { - if (viewHolder is MagicPreviewMessageViewHolder || - viewHolder is MagicIncomingTextMessageViewHolder || - viewHolder is MagicOutcomingTextMessageViewHolder + view = viewHolder.itemView + if (viewHolder.itemView.getTag(REPLYABLE_VIEW_TAG) != null && + viewHolder.itemView.getTag(REPLYABLE_VIEW_TAG) as Boolean ) { - view = viewHolder.itemView imageDrawable = AppCompatResources.getDrawable(context, R.drawable.ic_reply)!! shareRound = AppCompatResources.getDrawable(context, R.drawable.round_bgnd)!! return makeMovementFlags(ACTION_STATE_IDLE, RIGHT) @@ -296,5 +292,6 @@ class MessageSwipeCallback(private val context: Context, private val messageSwip const val ICON_BOUNDS_PIXEL_TOP: Int = 13 const val ICON_BOUNDS_PIXEL_RIGHT: Int = 12 const val ICON_BOUNDS_PIXEL_BOTTOM: Int = 11 + const val REPLYABLE_VIEW_TAG: Int = R.string.replyable_message_view_tag } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b79ba575d..ef7af6d7e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -422,6 +422,7 @@ 999+ + REPLYABLE_TAG Open main menu Failed to save %1$s From cf24965f7f1c66cac158da61dd9cd41f9570cea2 Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Wed, 9 Jun 2021 11:51:13 +0200 Subject: [PATCH 2/6] code formatting, make TAG final Signed-off-by: Andy Scherzinger --- .../messages/MagicPreviewMessageViewHolder.java | 2 +- .../messages/MagicSystemMessageViewHolder.java | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicPreviewMessageViewHolder.java b/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicPreviewMessageViewHolder.java index eecc8d31b..8c70f226e 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicPreviewMessageViewHolder.java +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicPreviewMessageViewHolder.java @@ -84,7 +84,7 @@ import static com.nextcloud.talk.ui.recyclerview.MessageSwipeCallback.REPLYABLE_ @AutoInjector(NextcloudTalkApplication.class) public class MagicPreviewMessageViewHolder extends MessageHolders.IncomingImageMessageViewHolder { - private static String TAG = "MagicPreviewMessageViewHolder"; + private static final String TAG = "MagicPreviewMessageViewHolder"; @BindView(R.id.messageText) EmojiTextView messageText; diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicSystemMessageViewHolder.java b/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicSystemMessageViewHolder.java index be079c009..38e6098e1 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicSystemMessageViewHolder.java +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicSystemMessageViewHolder.java @@ -66,7 +66,6 @@ public class MagicSystemMessageViewHolder extends MessageHolders.IncomingTextMes int pressedColor; int mentionColor; - pressedColor = normalColor; mentionColor = resources.getColor(R.color.textColorMaxContrast); @@ -80,8 +79,13 @@ public class MagicSystemMessageViewHolder extends MessageHolders.IncomingTextMes if (message.messageParameters != null && message.messageParameters.size() > 0) { for (String key : message.messageParameters.keySet()) { Map individualHashMap = message.messageParameters.get(key); - if (individualHashMap != null && (individualHashMap.get("type").equals("user") || individualHashMap.get("type").equals("guest") || individualHashMap.get("type").equals("call"))) { - messageString = DisplayUtils.searchAndColor(messageString, "@" + individualHashMap.get("name"), mentionColor); + if (individualHashMap != null && + (individualHashMap.get("type").equals("user") || + individualHashMap.get("type").equals("guest") || + individualHashMap.get("type").equals("call"))) { + messageString = DisplayUtils.searchAndColor( + messageString, "@" + individualHashMap.get("name"), + mentionColor); } } } From 893f015edf7d91abe4a6c4ba457da7c744478df6 Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Wed, 9 Jun 2021 12:18:10 +0200 Subject: [PATCH 3/6] shorten Log Tag Signed-off-by: Andy Scherzinger --- .../talk/adapters/messages/MagicPreviewMessageViewHolder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicPreviewMessageViewHolder.java b/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicPreviewMessageViewHolder.java index 8c70f226e..6f899c11a 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicPreviewMessageViewHolder.java +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicPreviewMessageViewHolder.java @@ -84,7 +84,7 @@ import static com.nextcloud.talk.ui.recyclerview.MessageSwipeCallback.REPLYABLE_ @AutoInjector(NextcloudTalkApplication.class) public class MagicPreviewMessageViewHolder extends MessageHolders.IncomingImageMessageViewHolder { - private static final String TAG = "MagicPreviewMessageViewHolder"; + private static final String TAG = "PreviewMsgViewHolder"; @BindView(R.id.messageText) EmojiTextView messageText; From 047372ad378e691b0462d43e65597eb0aeb9a50e Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Wed, 9 Jun 2021 12:24:39 +0200 Subject: [PATCH 4/6] flip string com pare for null-safety Signed-off-by: Andy Scherzinger --- .../messages/MagicSystemMessageViewHolder.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicSystemMessageViewHolder.java b/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicSystemMessageViewHolder.java index 38e6098e1..1592a5247 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicSystemMessageViewHolder.java +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicSystemMessageViewHolder.java @@ -80,12 +80,12 @@ public class MagicSystemMessageViewHolder extends MessageHolders.IncomingTextMes for (String key : message.messageParameters.keySet()) { Map individualHashMap = message.messageParameters.get(key); if (individualHashMap != null && - (individualHashMap.get("type").equals("user") || - individualHashMap.get("type").equals("guest") || - individualHashMap.get("type").equals("call"))) { + ("user".equals(individualHashMap.get("type")) || + "guest".equals(individualHashMap.get("type")) || + "call".equals(individualHashMap.get("type")) + )) { messageString = DisplayUtils.searchAndColor( - messageString, "@" + individualHashMap.get("name"), - mentionColor); + messageString, "@" + individualHashMap.get("name"), mentionColor); } } } From 5d41b0fae27b3ce97e2f4d2886ab8095e3cd6d8c Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Wed, 9 Jun 2021 12:37:06 +0200 Subject: [PATCH 5/6] rename HashMap Signed-off-by: Andy Scherzinger --- .../messages/MagicSystemMessageViewHolder.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicSystemMessageViewHolder.java b/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicSystemMessageViewHolder.java index 1592a5247..cedf5e2b5 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicSystemMessageViewHolder.java +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicSystemMessageViewHolder.java @@ -56,7 +56,7 @@ public class MagicSystemMessageViewHolder extends MessageHolders.IncomingTextMes super(itemView); NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); } - + @Override public void onBind(ChatMessage message) { super.onBind(message); @@ -78,14 +78,14 @@ public class MagicSystemMessageViewHolder extends MessageHolders.IncomingTextMes if (message.messageParameters != null && message.messageParameters.size() > 0) { for (String key : message.messageParameters.keySet()) { - Map individualHashMap = message.messageParameters.get(key); - if (individualHashMap != null && - ("user".equals(individualHashMap.get("type")) || - "guest".equals(individualHashMap.get("type")) || - "call".equals(individualHashMap.get("type")) + Map individualMap = message.messageParameters.get(key); + if (individualMap != null && + ("user".equals(individualMap.get("type")) || + "guest".equals(individualMap.get("type")) || + "call".equals(individualMap.get("type")) )) { messageString = DisplayUtils.searchAndColor( - messageString, "@" + individualHashMap.get("name"), mentionColor); + messageString, "@" + individualMap.get("name"), mentionColor); } } } From f7e926244a2788987d1eaa84bcab06647b2f9993 Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Wed, 9 Jun 2021 12:45:55 +0200 Subject: [PATCH 6/6] Drone: update FindBugs results to reflect reduced error/warning count [skip ci] Signed-off-by: Andy Scherzinger --- scripts/analysis/findbugs-results.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/analysis/findbugs-results.txt b/scripts/analysis/findbugs-results.txt index e966f9075..2415c0659 100644 --- a/scripts/analysis/findbugs-results.txt +++ b/scripts/analysis/findbugs-results.txt @@ -1 +1 @@ -450 \ No newline at end of file +448 \ No newline at end of file