medyo / Fancybuttons

Icons, Borders, Radius ... for Android buttons
1.77k stars 397 forks source link

fancy:fb_focusColor dont work on Adapter #87

Closed pishguy closed 6 years ago

pishguy commented 7 years ago

when i use this widget on android recyclerview adapter and setting setOnClickListener for that i dont see color on fancy:fb_focusColor, clicking on that dont work

medyo commented 7 years ago

Hi @MahdiPishguy,

Could you share a sample of your code?

pishguy commented 7 years ago

@medyo yes, please let me to send that for you

medyo commented 7 years ago

you can paste it here (not the whole code), just Fancybuttons implementation

pishguy commented 7 years ago

@medyo ok no problem

My Adapter:

public class MoviesAdapter extends RecyclerView.Adapter<MoviesAdapter.MyViewHolder> {
    private List<Movie> moviesList;
    private Activity    activity;
    private Context     context;
    private Map<String, Boolean> checkBoxStates = new HashMap<>();
    private boolean checkedState;

    public MoviesAdapter(Activity mActivity, List<Movie> moviesList, Context mContext) {
        this.moviesList = moviesList;
        activity = mActivity;
        context = mContext;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.cafe_web_items, parent, false);

        return new MyViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, final int position) {
        holder.postMoreOptions.setOnClickListener(null);

        checkedState = checkBoxStates.containsKey(position + "") ? checkBoxStates.get(position + "") : false;

        if (checkedState) {
            holder.sliderTestPages.openLayer(false);
        } else {
            holder.sliderTestPages.closeLayer(false);
        }

        holder.postMoreOptions.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                changeCheckedContacts(holder, position);
            }
        });

        holder.postVisitCount.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                changeCheckedContacts(holder, position);
            }
        });
    }

    private void changeCheckedContacts(MyViewHolder holder, int position) {
        checkedState = checkBoxStates.containsKey(position + "") ? checkBoxStates.get(position + "") : false;
        checkedState = !checkedState;
        checkBoxStates.put(position + "", checkedState);

        if (checkedState) {
            holder.sliderTestPages.openLayer(true);
        } else {
            holder.sliderTestPages.closeLayer(true);
        }

        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        return moviesList.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.postVoteUp)
        FancyButton postVoteUp;

        @BindView(R.id.postVoteCount)
        TextView postVoteCount;

        @BindView(R.id.postVoteDown)
        FancyButton postVoteDown;

        @BindView(R.id.postVisitCount)
        FancyButton postVisitCount;

        @BindView(R.id.postMoreOptions)
        FancyButton postMoreOptions;

        @BindView(R.id.sliderTestPages)
        SlidingLayer sliderTestPages;

        public MyViewHolder(View view) {
            super(view);

            ButterKnife.bind(this, view);

            postVoteUp.setFontIconSize((int) AndroidUtilities.getAdjustTextSize(activity, context) + 19);
            postVoteCount.setTextSize(AndroidUtilities.getAdjustTextSize(activity, context) * 1.4f);
            postVoteDown.setFontIconSize((int) AndroidUtilities.getAdjustTextSize(activity, context) + 19);

            postMoreOptions.setFontIconSize((int) AndroidUtilities.getAdjustTextSize(activity, context) + 3);

            postVisitCount.setFontIconSize((int) AndroidUtilities.getAdjustTextSize(activity, context) + 3);

        }
    }

}

adapter xml layout:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:fancy="http://schemas.android.com/apk/res-auto"
    xmlns:slidingLayer="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:layout_marginBottom="10dp"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"
    card_view:cardBackgroundColor="@color/white"
    card_view:cardCornerRadius="2dp"
    card_view:cardElevation="1dp">

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

        <FrameLayout
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:elevation="2dp">

            <ir.pishguy.cafealachiqpro.Libraries.SlidingLayer.SlidingLayer
                android:id="@+id/sliderTestPages"
                android:layout_width="match_parent"
                android:layout_height="120dp"
                android:layout_below="@+id/contentToolbar"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginTop="45dp"
                android:elevation="1dp"
                app:stickTo="top"
                slidingLayer:changeStateOnTap="false">

                <ir.pishguy.cafealachiqpro.Libraries.RoundView.RoundLinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:orientation="vertical"
                    android:paddingLeft="10dp"
                    android:paddingRight="10dp"
                    android:textColor="#ffffff"
                    app:rv_backgroundColor="@color/colorPrimary"
                    app:rv_cornerRadius_BL="5dp"
                    app:rv_cornerRadius_BR="5dp"
                    app:rv_cornerRadius_TL="0dp"
                    app:rv_cornerRadius_TR="0dp">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:orientation="vertical">

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

                            <LinearLayout
                                android:layout_width="0dp"
                                android:layout_height="match_parent"
                                android:layout_marginRight="10dp"
                                android:layout_weight="1"
                                android:orientation="vertical">

                                <TextView
                                    android:id="@+id/textChannelName"
                                    android:layout_width="match_parent"
                                    android:layout_height="0dp"
                                    android:layout_weight="1"
                                    android:gravity="right|center"
                                    android:text="SALAM"
                                    android:textColor="@color/white"/>

                                <TextView
                                    android:id="@+id/textView9"
                                    android:layout_width="match_parent"
                                    android:layout_height="1dp"
                                    android:background="@color/colorPrimaryDark"/>

                                <TextView
                                    android:id="@+id/textChannelDescription"
                                    android:layout_width="match_parent"
                                    android:layout_height="0dp"
                                    android:layout_weight="1"
                                    android:gravity="right|center"
                                    android:text="SALAM"
                                    android:textColor="@color/white"/>
                            </LinearLayout>

                            <TextView
                                android:layout_width="1dp"
                                android:layout_height="match_parent"
                                android:layout_marginBottom="10dp"
                                android:layout_marginRight="10dp"
                                android:layout_marginTop="10dp"
                                android:background="@color/colorPrimaryDark"/>

                            <RelativeLayout
                                xmlns:android="http://schemas.android.com/apk/res/android"
                                xmlns:fancy="http://schemas.android.com/apk/res-auto"
                                android:layout_width="50dp"
                                android:layout_height="match_parent"
                                android:padding="2dp"
                                android:gravity="center">

                                <mehdi.sakout.fancybuttons.FancyButton
                                    android:id="@+id/postVoteUp"
                                    android:layout_width="40dp"
                                    android:layout_height="40dp"
                                    android:gravity="center"
                                    android:textColor="@color/white"
                                    fancy:fb_defaultColor="@android:color/transparent"
                                    fancy:fb_focusColor="@color/colorPrimary"
                                    fancy:fb_fontIconResource="@string/icon_voteUp"
                                    fancy:fb_radius="30dp"
                                    fancy:fb_text=""
                                    fancy:fb_textColor="@color/white"/>

                                <TextView
                                    android:id="@+id/postVoteCount"
                                    android:layout_width="40dp"
                                    android:layout_height="wrap_content"
                                    android:layout_below="@+id/postVoteUp"
                                    android:gravity="center"
                                    android:text="5"
                                    android:textColor="@color/white"/>

                                <mehdi.sakout.fancybuttons.FancyButton
                                    android:id="@+id/postVoteDown"
                                    android:layout_width="40dp"
                                    android:layout_height="40dp"
                                    android:layout_below="@+id/postVoteCount"
                                    android:gravity="center"
                                    android:textColor="@color/white"
                                    fancy:fb_defaultColor="@android:color/transparent"
                                    fancy:fb_focusColor="@color/colorPrimary"
                                    fancy:fb_fontIconResource="@string/icon_voteDown"
                                    fancy:fb_radius="30dp"
                                    fancy:fb_text=""
                                    fancy:fb_textColor="@color/white"/>
                            </RelativeLayout>

                        </LinearLayout>

                    </LinearLayout>
                </ir.pishguy.cafealachiqpro.Libraries.RoundView.RoundLinearLayout>
            </ir.pishguy.cafealachiqpro.Libraries.SlidingLayer.SlidingLayer>

            <android.support.v7.widget.Toolbar
                android:id="@+id/contentToolbar"
                android:layout_width="match_parent"
                android:layout_height="45dp"
                android:background="@color/white"
                android:elevation="2dp"
                android:gravity="center_vertical">

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

                    <mehdi.sakout.fancybuttons.FancyButton
                        android:id="@+id/postVisitCount"
                        android:layout_width="50dp"
                        android:layout_height="50dp"
                        fancy:fb_defaultColor="@android:color/transparent"
                        fancy:fb_focusColor="@color/colorPrimary"
                        fancy:fb_fontIconResource="@string/icon_visit_post"
                        fancy:fb_radius="30dp"
                        fancy:fb_text=""
                        fancy:fb_textColor="@color/gray"/>

                    <android.support.v4.widget.Space
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"/>

                    <mehdi.sakout.fancybuttons.FancyButton
                        android:id="@+id/postMoreOptions"
                        android:layout_width="50dp"
                        android:layout_height="50dp"
                        fancy:fb_defaultColor="@android:color/transparent"
                        fancy:fb_focusColor="@color/colorPrimary"
                        fancy:fb_fontIconResource="@string/icon_horizontal_menu"
                        fancy:fb_radius="30dp"
                        fancy:fb_text=""
                        fancy:fb_textColor="@color/gray"/>
                </LinearLayout>
            </android.support.v7.widget.Toolbar>

        </FrameLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="-5dp"
            android:layout_marginLeft="50dp"
            android:layout_marginRight="50dp"
            android:background="@drawable/sheet_shadow"
            android:elevation="2dp"
            android:orientation="vertical"
            android:visibility="gone">

        </LinearLayout>

    </RelativeLayout>

    <TextView
        android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="@dimen/default_textview_height"
        android:visibility="gone"/>
</android.support.v7.widget.CardView>
pishguy commented 7 years ago

@medyo this code resolve my problem

   new Handler().postDelayed(new Runnable() {
       @Override
       public void run() {
           //
       }
   }, 300);