Skip to content
Snippets Groups Projects
Unverified Commit fb8c7940 authored by Daniel Gultsch's avatar Daniel Gultsch
Browse files

simplify swipe code

parent 2140c278
No related branches found
No related tags found
No related merge requests found
......@@ -45,6 +45,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.LinearLayoutManager;
......@@ -90,42 +91,36 @@ public class ConversationsOverviewFragment extends XmppFragment {
private FragmentConversationsOverviewBinding binding;
private ConversationAdapter conversationsAdapter;
private XmppActivity activity;
private float mSwipeEscapeVelocity = 0f;
private final PendingActionHelper pendingActionHelper = new PendingActionHelper();
private final ItemTouchHelper.SimpleCallback callback = new ItemTouchHelper.SimpleCallback(0,LEFT|RIGHT) {
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
//todo maybe we can manually changing the position of the conversation
public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) {
return false;
}
@Override
public float getSwipeEscapeVelocity (float defaultValue) {
return mSwipeEscapeVelocity;
public void onChildDraw(@NonNull Canvas c, @NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder,
float dX, float dY, int actionState, boolean isCurrentlyActive) {
if (viewHolder instanceof ConversationAdapter.ConversationViewHolder conversationViewHolder) {
getDefaultUIUtil().onDraw(c,recyclerView,conversationViewHolder.binding.frame,dX,dY,actionState,isCurrentlyActive);
}
}
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder,
float dX, float dY, int actionState, boolean isCurrentlyActive) {
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
if(actionState != ItemTouchHelper.ACTION_STATE_IDLE){
Paint paint = new Paint();
paint.setColor(MaterialColors.getColor(viewHolder.itemView, com.google.android.material.R.attr.colorSecondaryFixedDim));
paint.setStyle(Paint.Style.FILL);
c.drawRect(viewHolder.itemView.getLeft(),viewHolder.itemView.getTop()
,viewHolder.itemView.getRight(),viewHolder.itemView.getBottom(), paint);
public void clearView(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) {
if (viewHolder instanceof ConversationAdapter.ConversationViewHolder conversationViewHolder) {
getDefaultUIUtil().clearView(conversationViewHolder.binding.frame);
}
}
@Override
public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
super.clearView(recyclerView, viewHolder);
viewHolder.itemView.setAlpha(1f);
public float getSwipeEscapeVelocity(final float defaultEscapeVelocity) {
return 32 * defaultEscapeVelocity;
}
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
public void onSwiped(final RecyclerView.ViewHolder viewHolder, final int direction) {
pendingActionHelper.execute();
int position = viewHolder.getLayoutPosition();
try {
......@@ -285,7 +280,6 @@ public class ConversationsOverviewFragment extends XmppFragment {
@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
this.mSwipeEscapeVelocity = getResources().getDimension(R.dimen.swipe_escape_velocity);
this.binding = DataBindingUtil.inflate(inflater, R.layout.fragment_conversations_overview, container, false);
this.binding.fab.setOnClickListener((view) -> StartConversationActivity.launch(getActivity()));
......
......@@ -272,8 +272,8 @@ public class ConversationAdapter
void onConversationClick(View view, Conversation conversation);
}
static class ConversationViewHolder extends RecyclerView.ViewHolder {
private final ItemConversationBinding binding;
public static class ConversationViewHolder extends RecyclerView.ViewHolder {
public final ItemConversationBinding binding;
private ConversationViewHolder(final ItemConversationBinding binding) {
super(binding.getRoot());
......
......@@ -3,11 +3,13 @@
xmlns:tools="http://schemas.android.com/tools">
<FrameLayout
android:background="?colorSecondaryFixedDim"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants">
<FrameLayout
android:background="?colorSurface"
android:id="@+id/frame"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
......
......@@ -35,8 +35,6 @@
<dimen name="scan_laser_width">4dp</dimen>
<dimen name="scan_dot_size">8dp</dimen>
<dimen name="swipe_escape_velocity">1200dp</dimen> <!-- android default is 120dp -->
<dimen name="background_image_opacity">0.12</dimen>
<dimen name="sd_label_max_width">256dp</dimen>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment