// Path: app/src/main/java/com/hut/zero/bean/ZhihuDailyNews.java
// public class ZhihuDailyNews {
// 
//     private String date;
//     private ArrayList<Question> stories;
// 
//     public String getDate() {
//         return date;
//     }
// 
//     public void setDate(String date) {
//         this.date = date;
//     }
// 
//     public ArrayList<Question> getStories() {
//         return stories;
//     }
// 
//     public void setStories(ArrayList<Question> stories) {
//         this.stories = stories;
//     }
// 
//     public class Question {
// 
//         private ArrayList<String> images;
//         private int type;
//         private int id;
//         private String ga_prefix;
//         private String title;
// 
//         public ArrayList<String> getImages() {
//             return images;
//         }
// 
//         public void setImages(ArrayList<String> images) {
//             this.images = images;
//         }
// 
//         public int getType() {
//             return type;
//         }
// 
//         public void setType(int type) {
//             this.type = type;
//         }
// 
//         public int getId() {
//             return id;
//         }
// 
//         public void setId(int id) {
//             this.id = id;
//         }
// 
//         public String getGa_prefix() {
//             return ga_prefix;
//         }
// 
//         public void setGa_prefix(String ga_prefix) {
//             this.ga_prefix = ga_prefix;
//         }
// 
//         public String getTitle() {
//             return title;
//         }
// 
//         public void setTitle(String title) {
//             this.title = title;
//         }
//     }
// 
// }
// 
// Path: app/src/main/java/com/hut/zero/other/OnRecyclerViewOnClickListener.java
// @FunctionalInterface
// public interface OnRecyclerViewOnClickListener {
// 
//     void onItemClick(View v, int position);
// 
// }
// 
// Path: app/src/main/java/com/hut/zero/other/BaseViewHolder.java
// public class BaseViewHolder extends RecyclerView.ViewHolder {
//     private final ViewDataBinding binding;
// 
// 
//     public BaseViewHolder(ViewDataBinding binding) {
//         super(binding.getRoot());
//         this.binding=binding;
//     }
// 
//     public ViewDataBinding getBinding() {
//         return binding;
//     }
// }
// 
// Path: app/src/main/java/com/hut/zero/other/DataBindingCustomAttr.java
// public class DataBindingCustomAttr {
//     public static final String NO_LOAD="NO_LOAD";
// 
//     @BindingAdapter({"imageUrl"})
//     public static void loadImage(ImageView view, String url) {
//         //在设置imageUrl的值之前，会存在null的情况，所以需要加上判空的操作
//         if (TextUtils.isEmpty(url)||url.equals(NO_LOAD)) view.setImageResource(R.drawable.placeholder);
//         else Glide.with(view.getContext()).load(url)
//                 .asBitmap()
//                 .placeholder(R.drawable.placeholder)
//                 .diskCacheStrategy(DiskCacheStrategy.SOURCE)
//                 .error(R.drawable.placeholder)
//                 .centerCrop()
//                 .into(view);
//     }
// }
// 
// Path: app/src/main/java/com/hut/zero/other/WithListenerViewHolder.java
// public class WithListenerViewHolder extends BaseViewHolder implements View.OnClickListener {
//     private final OnRecyclerViewOnClickListener listener;
// 
//     public WithListenerViewHolder(ViewDataBinding binding,OnRecyclerViewOnClickListener listener) {
//         super(binding);
//         this.listener=listener;
//         binding.getRoot().setOnClickListener(this);
//     }
// 
//     @Override
//     public void onClick(View v) {
//         if (listener != null){
//             listener.onItemClick(v,getLayoutPosition());
//         }
//     }
// }


import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import com.hut.zero.BR;
import com.hut.zero.R;
import com.hut.zero.bean.ZhihuDailyNews;
import com.hut.zero.other.OnRecyclerViewOnClickListener;
import com.hut.zero.other.BaseViewHolder;
import com.hut.zero.other.DataBindingCustomAttr;
import com.hut.zero.other.WithListenerViewHolder;
import java.util.List;
package com.hut.zero.adapter;




/**
 * Created by Zero on 2017/4/3.
 */

public class ZhihuDailyNewsAdapter extends RecyclerView.Adapter<BaseViewHolder> {
    private static final int TYPE_NORMAL = 0;
    private static final int TYPE_FOOTER = 1;

    private OnRecyclerViewOnClickListener mListener;

    private List<ZhihuDailyNews.Question> data;

    public ZhihuDailyNewsAdapter(List<ZhihuDailyNews.Question> data) {
        this.data = data;
    }

    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        switch (viewType) {
            case TYPE_NORMAL:
                return new WithListenerViewHolder(
                        DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.home_list_item_layout, parent, false),
                        mListener);
            case TYPE_FOOTER:
                return new BaseViewHolder(
                        DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.home_list_item_layout, parent, false));
        }
        return null;
    }

    @Override
    public void onBindViewHolder(BaseViewHolder holder, int position) {
        if (holder instanceof WithListenerViewHolder) {//holder instanceof NormalViewHolder
            ZhihuDailyNews.Question item = data.get(position);

            //DataBindingCustomAttr.DataBindingCustomAttr()
// Path: app/src/main/java/com/hut/zero/bean/ZhihuDailyNews.java
// public class ZhihuDailyNews {
// 
//     private String date;
//     private ArrayList<Question> stories;
// 
//     public String getDate() {
//         return date;
//     }
// 
//     public void setDate(String date) {
//         this.date = date;
//     }
// 
//     public ArrayList<Question> getStories() {
//         return stories;
//     }
// 
//     public void setStories(ArrayList<Question> stories) {
//         this.stories = stories;
//     }
// 
//     public class Question {
// 
//         private ArrayList<String> images;
//         private int type;
//         private int id;
//         private String ga_prefix;
//         private String title;
// 
//         public ArrayList<String> getImages() {
//             return images;
//         }
// 
//         public void setImages(ArrayList<String> images) {
//             this.images = images;
//         }
// 
//         public int getType() {
//             return type;
//         }
// 
//         public void setType(int type) {
//             this.type = type;
//         }
// 
//         public int getId() {
//             return id;
//         }
// 
//         public void setId(int id) {
//             this.id = id;
//         }
// 
//         public String getGa_prefix() {
//             return ga_prefix;
//         }
// 
//         public void setGa_prefix(String ga_prefix) {
//             this.ga_prefix = ga_prefix;
//         }
// 
//         public String getTitle() {
//             return title;
//         }
// 
//         public void setTitle(String title) {
//             this.title = title;
//         }
//     }
// 
// }
// 
// Path: app/src/main/java/com/hut/zero/other/OnRecyclerViewOnClickListener.java
// @FunctionalInterface
// public interface OnRecyclerViewOnClickListener {
// 
//     void onItemClick(View v, int position);
// 
// }
// 
// Path: app/src/main/java/com/hut/zero/other/BaseViewHolder.java
// public class BaseViewHolder extends RecyclerView.ViewHolder {
//     private final ViewDataBinding binding;
// 
// 
//     public BaseViewHolder(ViewDataBinding binding) {
//         super(binding.getRoot());
//         this.binding=binding;
//     }
// 
//     public ViewDataBinding getBinding() {
//         return binding;
//     }
// }
// 
// Path: app/src/main/java/com/hut/zero/other/DataBindingCustomAttr.java
// public class DataBindingCustomAttr {
//     public static final String NO_LOAD="NO_LOAD";
// 
//     @BindingAdapter({"imageUrl"})
//     public static void loadImage(ImageView view, String url) {
//         //在设置imageUrl的值之前，会存在null的情况，所以需要加上判空的操作
//         if (TextUtils.isEmpty(url)||url.equals(NO_LOAD)) view.setImageResource(R.drawable.placeholder);
//         else Glide.with(view.getContext()).load(url)
//                 .asBitmap()
//                 .placeholder(R.drawable.placeholder)
//                 .diskCacheStrategy(DiskCacheStrategy.SOURCE)
//                 .error(R.drawable.placeholder)
//                 .centerCrop()
//                 .into(view);
//     }
// }
// 
// Path: app/src/main/java/com/hut/zero/other/WithListenerViewHolder.java
// public class WithListenerViewHolder extends BaseViewHolder implements View.OnClickListener {
//     private final OnRecyclerViewOnClickListener listener;
// 
//     public WithListenerViewHolder(ViewDataBinding binding,OnRecyclerViewOnClickListener listener) {
//         super(binding);
//         this.listener=listener;
//         binding.getRoot().setOnClickListener(this);
//     }
// 
//     @Override
//     public void onClick(View v) {
//         if (listener != null){
//             listener.onItemClick(v,getLayoutPosition());
//         }
//     }
// }


// Path: app/src/main/java/com/hut/zero/adapter/ZhihuDailyNewsAdapter.java
import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import com.hut.zero.BR;
import com.hut.zero.R;
import com.hut.zero.bean.ZhihuDailyNews;
import com.hut.zero.other.OnRecyclerViewOnClickListener;
import com.hut.zero.other.BaseViewHolder;
import com.hut.zero.other.DataBindingCustomAttr;
import com.hut.zero.other.WithListenerViewHolder;
import java.util.List;

package com.hut.zero.adapter;




/**
 * Created by Zero on 2017/4/3.
 */

public class ZhihuDailyNewsAdapter extends RecyclerView.Adapter<BaseViewHolder> {
    private static final int TYPE_NORMAL = 0;
    private static final int TYPE_FOOTER = 1;

    private OnRecyclerViewOnClickListener mListener;

    private List<ZhihuDailyNews.Question> data;

    public ZhihuDailyNewsAdapter(List<ZhihuDailyNews.Question> data) {
        this.data = data;
    }

    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        switch (viewType) {
            case TYPE_NORMAL:
                return new WithListenerViewHolder(
                        DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.home_list_item_layout, parent, false),
                        mListener);
            case TYPE_FOOTER:
                return new BaseViewHolder(
                        DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.home_list_item_layout, parent, false));
        }
        return null;
    }

    @Override
    public void onBindViewHolder(BaseViewHolder holder, int position) {
        if (holder instanceof WithListenerViewHolder) {//holder instanceof NormalViewHolder
            ZhihuDailyNews.Question item = data.get(position);

            //DataBindingCustomAttr.DataBindingCustomAttr()
            holder.getBinding().setVariable(BR.imgUrl,(item.getImages().get(0) == null? DataBindingCustomAttr.NO_LOAD:item.getImages().get(0)));