package com.example.jingbin.cloudreader.adapter;

import android.app.Activity;
import android.view.View;

import com.example.jingbin.cloudreader.R;
import com.example.jingbin.cloudreader.bean.wanandroid.ArticlesBean;
import com.example.jingbin.cloudreader.data.UserUtil;
import com.example.jingbin.cloudreader.data.model.CollectModel;
import com.example.jingbin.cloudreader.databinding.ItemCategoryArticleBinding;
import com.example.jingbin.cloudreader.utils.PerfectClickListener;
import com.example.jingbin.cloudreader.utils.ToastUtil;
import com.example.jingbin.cloudreader.ui.WebViewActivity;
import com.example.jingbin.cloudreader.viewmodel.wan.WanNavigator;

import me.jingbin.bymvvm.adapter.BaseBindingAdapter;
import me.jingbin.bymvvm.adapter.BaseBindingHolder;

/**
 * Created by jingbin on 2019/01/19.
 */

public class CategoryArticleAdapter extends BaseBindingAdapter<ArticlesBean, ItemCategoryArticleBinding> {

    private CollectModel model;
    private Activity activity;

    public CategoryArticleAdapter(Activity activity) {
        super(R.layout.item_category_article);
        model = new CollectModel();
        this.activity = activity;
    }

    @Override
    protected void bindView(BaseBindingHolder holder, ArticlesBean bean, ItemCategoryArticleBinding binding, int position) {
        if (bean != null) {
            binding.setAdapter(this);
            binding.setBean(bean);
            binding.executePendingBindings();
            binding.vbCollect.setOnClickListener(new PerfectClickListener() {
                @Override
                protected void onNoDoubleClick(View v) {
                    if (UserUtil.isLogin(activity) && model != null) {
                        if (!binding.vbCollect.isChecked()) {
                            model.unCollect(false, bean.getId(), bean.getOriginId(), new WanNavigator.OnCollectNavigator() {
                                @Override
                                public void onSuccess() {
                                    bean.setCollect(binding.vbCollect.isChecked());
                                    ToastUtil.showToastLong("已取消收藏");
                                }

                                @Override
                                public void onFailure() {
                                    bean.setCollect(true);
                                    refreshNotifyItemChanged(position);
                                    ToastUtil.showToastLong("取消收藏失败");
                                }
                            });
                        } else {
                            model.collect(bean.getId(), new WanNavigator.OnCollectNavigator() {
                                @Override
                                public void onSuccess() {
                                    bean.setCollect(true);
                                }

                                @Override
                                public void onFailure() {
                                    bean.setCollect(false);
                                    refreshNotifyItemChanged(position);
                                }
                            });
                        }
                    } else {
                        bean.setCollect(false);
                        refreshNotifyItemChanged(position);
                    }
                }
            });
        }
    }

    public void openDetail(ArticlesBean bean) {
        WebViewActivity.loadUrl(activity, bean.getLink(), bean.getTitle());
    }
}

@@ -68,24 +68,64 @@
 p.Activity;%0A
+import android.content.DialogInterface;%0A
 import andro
@@ -181,16 +181,70 @@
 ader.R;%0A
+import com.example.jingbin.cloudreader.app.Constants;%0A
 import c
@@ -501,16 +501,130 @@
 inding;%0A
+import com.example.jingbin.cloudreader.utils.BaseTools;%0Aimport com.example.jingbin.cloudreader.utils.DialogBuild;%0A
 import c
@@ -678,24 +678,78 @@
 ckListener;%0A
+import com.example.jingbin.cloudreader.utils.SPUtils;%0A
 import com.e
@@ -1761,23 +1761,23 @@
 ner(new 
-Perfect
+View.On
 ClickLis
@@ -1833,32 +1833,21 @@
    p
-rotected void onNoDouble
+ublic void on
 Clic
@@ -3053,32 +3053,1464 @@
 tCollect(true);%0A
+                                    ToastUtil.showToastLong(%22%E6%94%B6%E8%97%8F%E6%88%90%E5%8A%9F%22);%0A                                    v.postDelayed(new Runnable() %7B%0A                                        @Override%0A                                        public void run() %7B%0A                                            if (BaseTools.isApplicationAvilible(activity, %22com.coolapk.market%22)) %7B%0A                                                boolean show = SPUtils.getBoolean(Constants.SHOW_MARKET, false);%0A                                                if (!show) %7B%0A                                                    SPUtils.putBoolean(Constants.SHOW_MARKET, true);%0A                                                    DialogBuild.showCustom(v, 1, %22%E5%BE%88%E9%AB%98%E5%85%B4%E4%BD%A0%E4%BD%BF%E7%94%A8%E4%BA%91%E9%98%85%EF%BC%8C%E5%A6%82%E6%9E%9C%E7%94%A8%E7%9A%84%E6%84%89%E5%BF%AB%E7%9A%84%E8%AF%9D%E5%8F%AF%E4%BB%A5%E5%8E%BB%E9%85%B7%E5%AE%89%E6%94%AF%E6%8C%81%E4%B8%80%E4%B8%8B%E5%93%A6~%22, %22%E5%8E%BB%E6%94%AF%E6%8C%81%22, %22%E5%8F%96%E6%B6%88%22, new DialogInterface.OnClickListener() %7B%0A                                                        @Override%0A                                                        public void onClick(DialogInterface dialog, int which) %7B%0A                                                            BaseTools.launchAppDetail(activity, %22com.example.jingbin.cloudreader%22, %22com.coolapk.market%22);%0A                                                        %7D%0A                                                    %7D);%0A                                                %7D%0A                                            %7D%0A                                        %7D%0A                                    %7D, 200);%0A
                 
@@ -4620,32 +4620,101 @@
 d onFailure() %7B%0A
+                                    ToastUtil.showToastLong(%22%E6%94%B6%E8%97%8F%E5%A4%B1%E8%B4%A5%22);%0A
                 

add category adapter market ratings