From 6957dd3b0cd8d20980d3aad3210ddafd4e4dd841 Mon Sep 17 00:00:00 2001 From: Arne Date: Sat, 31 Aug 2024 21:04:00 +0200 Subject: [PATCH] apply monocles swipe feature --- build.gradle | 1 + .../ui/adapter/MessageAdapter.java | 62 ++++++++++++++++++- src/main/res/layout/item_message_received.xml | 23 ++++++- src/main/res/layout/item_message_sent.xml | 24 ++++++- 4 files changed, 101 insertions(+), 9 deletions(-) diff --git a/build.gradle b/build.gradle index 1a63bc19e..3da11e99c 100644 --- a/build.gradle +++ b/build.gradle @@ -121,6 +121,7 @@ dependencies { implementation 'com.github.Priyansh-Kedia:OpenGraphParser:2.5.6' implementation 'me.xdrop:fuzzywuzzy:1.4.0' implementation 'net.fellbaum:jemoji:1.4.1' + implementation "com.daimajia.swipelayout:library:1.2.0@aar" } ext { 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 edd7b0ab5..19fade47f 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -68,6 +68,7 @@ import com.google.common.base.Strings; import com.google.common.collect.ImmutableList; import com.lelloman.identicon.view.GithubIdenticonView; +import com.daimajia.swipe.SwipeLayout; import io.ipfs.cid.Cid; @@ -1325,9 +1326,64 @@ public class MessageAdapter extends ArrayAdapter { MessageAdapter.this.mOnMessageBoxSwipedListener.onContactPictureClicked(message); } }); - viewHolder.message_box.setOnTouchListener(swipeDetector); - viewHolder.image.setOnTouchListener(swipeDetector); - viewHolder.time.setOnTouchListener(swipeDetector); + + + + // monocles swipe feature + SwipeLayout swipeLayout = view.findViewById(R.id.layout_swipe); + + //set show mode. + swipeLayout.setShowMode(SwipeLayout.ShowMode.PullOut); + + //add drag edge.(If the BottomView has 'layout_gravity' attribute, this line is unnecessary) + swipeLayout.addDrag(SwipeLayout.DragEdge.Left, view.findViewById(R.id.bottom_wrapper)); + + swipeLayout.addSwipeListener(new SwipeLayout.SwipeListener() { + @Override + public void onClose(SwipeLayout layout) { + swipeLayout.refreshDrawableState(); + swipeLayout.clearAnimation(); + //when the SurfaceView totally cover the BottomView. + } + + @Override + public void onUpdate(SwipeLayout layout, int leftOffset, int topOffset) { + swipeLayout.setClickToClose(true); + //you are swiping. + } + + @Override + public void onStartOpen(SwipeLayout layout) { + swipeLayout.setClickToClose(true); + + } + + @Override + public void onOpen(SwipeLayout layout) { + swipeLayout.refreshDrawableState(); + //when the BottomView totally show. + if (mOnMessageBoxSwipedListener != null) mOnMessageBoxSwipedListener.onContactPictureClicked(message); + swipeLayout.close(true); + swipeLayout.setClickToClose(true); + } + + @Override + public void onStartClose(SwipeLayout layout) { + swipeLayout.close(true); + swipeLayout.setClickToClose(true); + } + + @Override + public void onHandRelease(SwipeLayout layout, float xvel, float yvel) { + swipeLayout.refreshDrawableState(); + swipeLayout.close(true); + } + }); + + + + + // Treat touch-up as click so we don't have to touch twice // (touch twice is because it's waiting to see if you double-touch for text selection) diff --git a/src/main/res/layout/item_message_received.xml b/src/main/res/layout/item_message_received.xml index 2d5941a35..4b2fb6407 100644 --- a/src/main/res/layout/item_message_received.xml +++ b/src/main/res/layout/item_message_received.xml @@ -1,7 +1,24 @@ - + xmlns:tools="http://schemas.android.com/tools" + android:layout_height="wrap_content" + android:layout_width="match_parent" + app:drag_edge="left" + app:show_mode="pull_out" + android:id="@+id/layout_swipe" + android:orientation="vertical" > + + + - + diff --git a/src/main/res/layout/item_message_sent.xml b/src/main/res/layout/item_message_sent.xml index 0d667eb30..6769ad5b8 100644 --- a/src/main/res/layout/item_message_sent.xml +++ b/src/main/res/layout/item_message_sent.xml @@ -1,6 +1,24 @@ - + + + + - +