better messages highlighting

This commit is contained in:
kosyak 2023-10-30 21:32:42 +01:00
parent 1d7bd8f8da
commit 356d1e146e
5 changed files with 100 additions and 10 deletions

View file

@ -75,6 +75,7 @@ import androidx.appcompat.content.res.AppCompatResources;
import androidx.core.view.inputmethod.InputConnectionCompat; import androidx.core.view.inputmethod.InputConnectionCompat;
import androidx.core.view.inputmethod.InputContentInfoCompat; import androidx.core.view.inputmethod.InputContentInfoCompat;
import androidx.databinding.DataBindingUtil; import androidx.databinding.DataBindingUtil;
import androidx.interpolator.view.animation.FastOutSlowInInterpolator;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.viewpager.widget.PagerAdapter; 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.ShareUtil;
import eu.siacs.conversations.ui.util.ViewUtil; import eu.siacs.conversations.ui.util.ViewUtil;
import eu.siacs.conversations.ui.widget.EditMessage; 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.ui.widget.TabLayout;
import eu.siacs.conversations.utils.AccountUtils; import eu.siacs.conversations.utils.AccountUtils;
import eu.siacs.conversations.utils.Compatibility; import eu.siacs.conversations.utils.Compatibility;
@ -1581,16 +1583,11 @@ public class ConversationFragment extends XmppFragment
} }
View view = ListViewUtils.getViewByPosition(actualIndex, binding.messagesView); View view = ListViewUtils.getViewByPosition(actualIndex, binding.messagesView);
View messageBox = view.findViewById(R.id.message_box); HighlighterView highlighter = view.findViewById(R.id.highlighter);
if (messageBox != null) { if (highlighter != null) {
messageBox.animate() highlighter.setVisibility(View.VISIBLE);
.scaleX(1.03f)
.scaleY(1.03f)
.setInterpolator(new CycleInterpolator(0.5f))
.setDuration(300L)
.start();
} }
}, 300L); }, 200L);
} }
private void updateSelection(String uuid, Integer offsetFormTop, Runnable selectionUpdatedRunnable, boolean populateFromMam, boolean recursiveFetch) { private void updateSelection(String uuid, Integer offsetFormTop, Runnable selectionUpdatedRunnable, boolean populateFromMam, boolean recursiveFetch) {

View file

@ -787,6 +787,11 @@ public class MessageAdapter extends ArrayAdapter<Message> {
} }
} }
View highlighter = view.findViewById(R.id.highlighter);
if (highlighter != null) {
highlighter.setVisibility(View.INVISIBLE);
}
boolean darkBackground = type == RECEIVED && (!isInValidSession || mUseGreenBackground) || activity.isDarkTheme(); boolean darkBackground = type == RECEIVED && (!isInValidSession || mUseGreenBackground) || activity.isDarkTheme();
if (type == DATE_SEPARATOR) { if (type == DATE_SEPARATOR) {

View file

@ -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);
}
}
}

View file

@ -4,11 +4,24 @@
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
android:clipToPadding="false"
android:paddingBottom="4dp" android:paddingBottom="4dp"
android:paddingLeft="8dp" android:paddingLeft="8dp"
android:paddingRight="8dp" android:paddingRight="8dp"
android:paddingTop="4dp"> android:paddingTop="4dp">
<eu.siacs.conversations.ui.widget.HighlighterView
android:id="@+id/highlighter"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignBottom="@id/message_box"
android:background="?color_message_selection"
android:layout_marginLeft="-8dp"
android:layout_marginRight="-8dp"
android:alpha="0"
android:visibility="invisible"/>
<com.makeramen.roundedimageview.RoundedImageView <com.makeramen.roundedimageview.RoundedImageView
android:id="@+id/message_photo" android:id="@+id/message_photo"
android:layout_width="48dp" android:layout_width="48dp"

View file

@ -4,11 +4,24 @@
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
android:clipToPadding="false"
android:paddingLeft="8dp" android:paddingLeft="8dp"
android:paddingTop="4dp" android:paddingTop="4dp"
android:paddingRight="8dp" android:paddingRight="8dp"
android:paddingBottom="4dp"> android:paddingBottom="4dp">
<eu.siacs.conversations.ui.widget.HighlighterView
android:id="@+id/highlighter"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignBottom="@id/message_box"
android:background="?color_message_selection"
android:layout_marginLeft="-8dp"
android:layout_marginRight="-8dp"
android:alpha="0"
android:visibility="invisible"/>
<com.makeramen.roundedimageview.RoundedImageView <com.makeramen.roundedimageview.RoundedImageView
android:id="@+id/message_photo" android:id="@+id/message_photo"
android:layout_width="48dp" android:layout_width="48dp"
@ -93,7 +106,6 @@
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
<View <View
android:id="@+id/clicks_interceptor" android:id="@+id/clicks_interceptor"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -101,4 +113,5 @@
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
android:layout_alignBottom="@id/message_box" android:layout_alignBottom="@id/message_box"
android:visibility="gone"/> android:visibility="gone"/>
</RelativeLayout> </RelativeLayout>