chthai64 / SwipeRevealLayout

Easy, flexible and powerful Swipe Layout for Android
MIT License
1.57k stars 394 forks source link

Delete and other layouts are clickable even before revealing them #44

Open Odaym opened 7 years ago

Odaym commented 7 years ago

Video which shows the bug: https://dl.dropboxusercontent.com/u/19390574/reveal_layouts_clickable_bug.mp4

RecyclerViewHolder where the binding of the layouts is done:

private class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
    private SwipeRevealLayout swipeLayout;
    private View deleteLayout, deactivate_layout;
    private TextView medicineNameTV, medicineDescriptionTV, medicineIntakeDetailsTV;

    public ViewHolder(View itemView) {
      super(itemView);

      swipeLayout = (SwipeRevealLayout) itemView.findViewById(R.id.swipe_layout);
      deleteLayout = itemView.findViewById(R.id.delete_layout);
      deactivate_layout = itemView.findViewById(R.id.deactivate_layout);
      medicineNameTV = (TextView) itemView.findViewById(R.id.medicineNameTV);
      medicineDescriptionTV = (TextView) itemView.findViewById(R.id.medicineDescriptionTV);
      medicineIntakeDetailsTV = (TextView) itemView.findViewById(R.id.medicineIntakeDetailsTV);
    }

    public void bind(Medication medicationItem) {
      deleteLayout.setOnClickListener(new View.OnClickListener() {
        @Override public void onClick(View v) {
          medicationDAO.delete(medicationsList.get(getAdapterPosition()));
          medicationsList.remove(getAdapterPosition());
          notifyItemRemoved(getAdapterPosition());
        }
      });

      medicineNameTV.setText(WordUtils.capitalizeFully(medicationItem.getName()));
      medicineDescriptionTV.setText(medicationItem.getDescription());
      medicineIntakeDetailsTV.setText(medicationItem.getDosage()
          + " - "
          + medicationItem.getWhen()
          + " - "
          + medicationItem.getFrequency());
    }
  }

XML holding the layout for each of the recyclerview's items:

<?xml version="1.0" encoding="utf-8"?>
<com.chauthai.swipereveallayout.SwipeRevealLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/swipe_layout"
    android:layout_width="match_parent"
    android:layout_height="@dimen/medications_list_row_item_height"
    android:background="@color/white"
    android:clickable="false"
    android:focusable="true"
    app:dragEdge="right"
    app:mode="normal"
    >

  <LinearLayout
      android:layout_width="wrap_content"
      android:layout_height="match_parent"
      android:orientation="horizontal"
      >

    <RelativeLayout
        android:id="@+id/deactivate_layout"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="@color/camera_gray_color"
        android:gravity="center"
        android:paddingEnd="@dimen/default_margin_1"
        android:paddingStart="@dimen/default_margin_1"
        >

      <ImageView
          android:id="@+id/deactivateImageIV"
          android:layout_width="@dimen/action_items_delete_deactivate_icons"
          android:layout_height="@dimen/action_items_delete_deactivate_icons"
          android:layout_centerInParent="true"
          android:src="@drawable/ic_deactivate_medication"
          />

      <TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@+id/deactivateImageIV"
          android:layout_centerHorizontal="true"
          android:gravity="center"
          android:text="Deactivate"
          android:textColor="@android:color/white"
          />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/delete_layout"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="@color/medication_list_delete_action_layout_red"
        android:gravity="center"
        android:paddingEnd="@dimen/default_margin_2"
        android:paddingStart="@dimen/default_margin_2"
        >

      <ImageView
          android:id="@+id/deleteImageIV"
          android:layout_width="@dimen/action_items_delete_deactivate_icons"
          android:layout_height="@dimen/action_items_delete_deactivate_icons"
          android:layout_centerInParent="true"
          android:src="@drawable/ic_delete_medication"
          />

      <TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@+id/deleteImageIV"
          android:layout_centerHorizontal="true"
          android:gravity="center"
          android:text="Delete"
          android:textColor="@android:color/white"
          />
    </RelativeLayout>
  </LinearLayout>

  <RelativeLayout
      android:layout_width="match_parent"
      android:layout_height="@dimen/medications_list_row_item_height"
      android:background="@color/white"
      >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:paddingStart="@dimen/default_margin_2"
        android:paddingTop="@dimen/default_margin_2"
        >

      <TextView
          android:id="@+id/medicineNameTV"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:paddingBottom="@dimen/default_margin_1"
          android:textColor="@android:color/black"
          />

      <TextView
          android:id="@+id/medicineDescriptionTV"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:textColor="@color/medication_list_item_name_gray"
          />

      <TextView
          android:id="@+id/medicineIntakeDetailsTV"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:textColor="@color/medication_list_item_name_gray"
          />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/arrowLayout"
        android:layout_width="@dimen/right_arrow_layout_width"
        android:layout_height="match_parent"
        android:layout_alignParentEnd="true"
        android:background="@color/much_lighter_gray"
        android:gravity="center"
        >

      <ImageView
          android:layout_width="@dimen/far_right_arrow_icon_dimens"
          android:layout_height="@dimen/far_right_arrow_icon_dimens"
          android:src="@drawable/ic_arrow_right_blue"
          />
    </LinearLayout>

    <ImageView
        android:id="@+id/reminderStatusIV"
        android:layout_width="@dimen/reminder_status_icon_dimens"
        android:layout_height="@dimen/reminder_status_icon_dimens"
        android:layout_centerVertical="true"
        android:layout_gravity="end|center_vertical"
        android:layout_marginEnd="@dimen/default_margin_1"
        android:layout_toStartOf="@+id/arrowLayout"
        android:src="@drawable/ic_reminder_active"
        />

  </RelativeLayout>
</com.chauthai.swipereveallayout.SwipeRevealLayout>

Any help with this? Thanks for a cool lib

wittkamp commented 7 years ago

Hi Odaym, I came across the same thing. A workaround is to set android:onClick="@{(View) -> void}" for your main layout (the one that is in front of your delete etc buttons layout).