From 356d1e146e9ca1a5b26bbc1612ea6ca5bc5e189d Mon Sep 17 00:00:00 2001 From: kosyak Date: Mon, 30 Oct 2023 21:32:42 +0100 Subject: [PATCH] better messages highlighting --- .../ui/ConversationFragment.java | 15 ++--- .../ui/adapter/MessageAdapter.java | 5 ++ .../ui/widget/HighlighterView.java | 62 +++++++++++++++++++ src/main/res/layout/message_received.xml | 13 ++++ src/main/res/layout/message_sent.xml | 15 ++++- 5 files changed, 100 insertions(+), 10 deletions(-) create mode 100644 src/main/java/eu/siacs/conversations/ui/widget/HighlighterView.java diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 34425eec9..12ee0c763 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -75,6 +75,7 @@ import androidx.appcompat.content.res.AppCompatResources; import androidx.core.view.inputmethod.InputConnectionCompat; import androidx.core.view.inputmethod.InputContentInfoCompat; import androidx.databinding.DataBindingUtil; +import androidx.interpolator.view.animation.FastOutSlowInInterpolator; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.viewpager.widget.PagerAdapter; @@ -143,6 +144,7 @@ import eu.siacs.conversations.ui.util.SendButtonTool; import eu.siacs.conversations.ui.util.ShareUtil; import eu.siacs.conversations.ui.util.ViewUtil; import eu.siacs.conversations.ui.widget.EditMessage; +import eu.siacs.conversations.ui.widget.HighlighterView; import eu.siacs.conversations.ui.widget.TabLayout; import eu.siacs.conversations.utils.AccountUtils; import eu.siacs.conversations.utils.Compatibility; @@ -1581,16 +1583,11 @@ public class ConversationFragment extends XmppFragment } View view = ListViewUtils.getViewByPosition(actualIndex, binding.messagesView); - View messageBox = view.findViewById(R.id.message_box); - if (messageBox != null) { - messageBox.animate() - .scaleX(1.03f) - .scaleY(1.03f) - .setInterpolator(new CycleInterpolator(0.5f)) - .setDuration(300L) - .start(); + HighlighterView highlighter = view.findViewById(R.id.highlighter); + if (highlighter != null) { + highlighter.setVisibility(View.VISIBLE); } - }, 300L); + }, 200L); } private void updateSelection(String uuid, Integer offsetFormTop, Runnable selectionUpdatedRunnable, boolean populateFromMam, boolean recursiveFetch) { diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java index 16ee47b71..e8cf71adf 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -787,6 +787,11 @@ public class MessageAdapter extends ArrayAdapter { } } + View highlighter = view.findViewById(R.id.highlighter); + if (highlighter != null) { + highlighter.setVisibility(View.INVISIBLE); + } + boolean darkBackground = type == RECEIVED && (!isInValidSession || mUseGreenBackground) || activity.isDarkTheme(); if (type == DATE_SEPARATOR) { diff --git a/src/main/java/eu/siacs/conversations/ui/widget/HighlighterView.java b/src/main/java/eu/siacs/conversations/ui/widget/HighlighterView.java new file mode 100644 index 000000000..85ac1a512 --- /dev/null +++ b/src/main/java/eu/siacs/conversations/ui/widget/HighlighterView.java @@ -0,0 +1,62 @@ +package eu.siacs.conversations.ui.widget; + +import android.content.Context; +import android.os.Handler; +import android.os.Looper; +import android.util.AttributeSet; +import android.view.View; + +import androidx.annotation.Nullable; +import androidx.interpolator.view.animation.FastOutSlowInInterpolator; + +public class HighlighterView extends View { + + private Runnable hideHighlight = () -> { + if (getVisibility() == View.INVISIBLE) return; + + animate() + .alpha(0.0f) + .setInterpolator(new FastOutSlowInInterpolator()) + .setDuration(300L) + .withEndAction(() -> setVisibility(View.INVISIBLE)) + .start(); + }; + + private Handler handler = new Handler(Looper.getMainLooper()); + + public HighlighterView(Context context) { + super(context); + } + + public HighlighterView(Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + } + + public HighlighterView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + public HighlighterView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } + + @Override + public void setVisibility(int visibility) { + super.setVisibility(visibility); + + if (visibility != View.VISIBLE) { + handler.removeCallbacks(hideHighlight); + animate().cancel(); + setAlpha(0); + } else { + animate() + .alpha(0.5f) + .setInterpolator(new FastOutSlowInInterpolator()) + .setDuration(300L) + .start(); + + handler.removeCallbacks(hideHighlight); + handler.postDelayed(hideHighlight, 2000); + } + } +} diff --git a/src/main/res/layout/message_received.xml b/src/main/res/layout/message_received.xml index 67e28f143..7028cf52e 100644 --- a/src/main/res/layout/message_received.xml +++ b/src/main/res/layout/message_received.xml @@ -4,11 +4,24 @@ android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" + android:clipToPadding="false" android:paddingBottom="4dp" android:paddingLeft="8dp" android:paddingRight="8dp" android:paddingTop="4dp"> + + + + - + \ No newline at end of file