Click overlay [ImageButton inside a CardView]

0

Hello, I have a CardView with clickListener When I click the button it calls the RecyclerClickListener But I'd like it to call the Button click event when it was clicked by ignoring the RecyclerClickListener

CardView click event:

 recyclerSpells.addOnItemTouchListener(
            new RecyclerClickListener(
                    getContext(),
                    recyclerSpells,
                    new RecyclerClickListener.OnItemClickListener() {
                        @Override
                        public void onItemClick(View view, int position) {
                            List<Spell> updatedSpellList = adapterSpells.getSpellList();

                            Spell clickedSpell = updatedSpellList.get(position);

                            isNew = false;
                            Intent intent = new Intent(getContext(), AddActivity.class);
                            intent.putExtra(IntentExtra.USER.toString(), user);
                            intent.putExtra(IntentExtra.CHARACTER.toString(), character);
                            intent.putExtra(IntentExtra.OBJECT.toString(), clickedSpell);
                            intent.putExtra(IntentExtra.ISNEW.toString(), isNew);
                            startActivity(intent);
                        }

                        @Override
                        public void onLongItemClick(View view, int position) {

                        }

                        @Override
                        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

                        }
                    }
            ));

RecyclerClickListener class:

public class RecyclerClickListener implements RecyclerView.OnItemTouchListener {

private OnItemClickListener mListener;
GestureDetector mGestureDetector;

@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
    View childView = rv.findChildViewUnder(e.getX(), e.getY());
    if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) {
        mListener.onItemClick(childView, rv.getChildAdapterPosition(childView));
        return true;
    }
    return false;
}

@Override
public void onTouchEvent(RecyclerView rv, MotionEvent e) {

}

@Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {

}

public interface OnItemClickListener extends AdapterView.OnItemClickListener {
    public void onItemClick(View view, int position);

    public void onLongItemClick(View view, int position);
}

public RecyclerClickListener(Context context, final RecyclerView recyclerView, OnItemClickListener listener) {
    mListener = listener;
    mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            return true;
        }

        @Override
        public void onLongPress(MotionEvent e) {
            View child = recyclerView.findChildViewUnder(e.getX(), e.getY());
            if (child != null && mListener != null) {
                mListener.onLongItemClick(child, recyclerView.getChildAdapterPosition(child));
            }
        }
    });

}

}

CardView XML:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="15dp"
    android:layout_marginRight="10dp"
    android:layout_marginBottom="15dp"
    android:orientation="vertical">

    <TextView
        android:id="@+id/spell_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="10"
        android:maxLines="1"
        android:paddingBottom="@dimen/spell_values_padding"
        android:text="Item Name"
        android:textColor="@android:color/black"
        android:textSize="20sp"
        android:textStyle="bold" />

    <LinearLayout
        android:id="@+id/desc_linear_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="10"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/spell_description"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="10"
            android:maxLines="1"
            android:paddingBottom="10dp"
            android:text="Item Description"
            android:textSize="16sp" />

        <ImageButton
            android:id="@+id/expand_spells"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@android:color/transparent"

            app:srcCompat="@drawable/ic_arrow_down_black" />

    </LinearLayout>

    <TextView
        android:id="@+id/spell_casting"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="10"
        android:paddingBottom="@dimen/spell_values_padding"
        android:text="@string/spell_castingTime"
        android:textColor="@color/colorBlack" />

    <TextView
        android:id="@+id/spell_critical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="10"
        android:paddingBottom="@dimen/spell_values_padding"
        android:text="@string/spell_critical"
        android:textColor="@color/colorBlack" />

    <TextView
        android:id="@+id/spell_difficulty"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="10"
        android:paddingBottom="@dimen/spell_values_padding"
        android:text="@string/spell_difficulty"
        android:textColor="@color/colorBlack" />

    <TextView
        android:id="@+id/spell_damage"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:maxLines="1"
        android:paddingBottom="@dimen/spell_values_padding"
        android:text="@string/spell_damage"
        android:textAlignment="textStart"
        android:textColor="@color/colorBlack"
        android:textSize="14sp" />

    <TextView
        android:id="@+id/spell_cost"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="10"
        android:text="@string/spell_cost"
        android:textAlignment="textStart"
        android:textColor="@color/colorBlack"
        android:textSize="14sp" />


</LinearLayout>

Button click event:

 @Override
public void onBindViewHolder(MyViewHolder holder, int position) {

    Spell spell = spellList.get(position);
    isSpellExpanded = spell.isExpanded();

    holder.name.setText(spell.getName());

    if (spell.getDamage().isEmpty())
        holder.damage.setVisibility(View.GONE);
    else {
        holder.damage.setVisibility(View.VISIBLE);
        MyTextFormat.adapterBoldText(spell.getDamage(), holder.damage);
    }

    MyTextFormat.adapterBoldText(spell.getDescription(),holder.description, isSpellExpanded);


    if(spell.getCastingTime() == null)
        holder.castingTime.setText("Desatualizado");
    else
        MyTextFormat.adapterBoldText(spell.getCastingTime(), holder.castingTime);

    if(spell.getCritical() == null)
        holder.critical.setText("Desatualizado");
    else
        MyTextFormat.adapterBoldText(spell.getCritical(), holder.critical);


    if(spell.getDifficulty() == null)
        holder.difficulty.setText("Desatualizado");
    else
        MyTextFormat.adapterBoldText(spell.getDifficulty(), holder.difficulty);

    if(spell.getCost() == null)
        holder.cost.setText("Desatualizado");
    else
        MyTextFormat.adapterBoldText(spell.getCost(), holder.cost);



    holder.description.setMaxLines(isSpellExpanded ? 20 : 1);

    if(holder.description.getMaxLines() == 20){
        holder.btn_expand.setImageResource(R.drawable.ic_arrow_up_black_24dp);
    }
    else {
        holder.btn_expand.setImageResource(R.drawable.ic_arrow_down_black);
    }

    holder.btn_expand.setOnClickListener( view -> {
        isSpellExpanded = spell.isExpanded();
        spell.setExpanded(!isSpellExpanded);
        notifyItemChanged(position);
    });
}

How could I solve this?

    
asked by anonymous 05.12.2018 / 16:04

0 answers