// Path: app/src/main/java/moe/yukinoneko/diycode/bean/Sites.java
// public class Sites {
// 
//     @SerializedName("name") public String name;
//     @SerializedName("id") public int id;
//     @SerializedName("sites") public List<Site> sites;
// 
//     public static class Site {
//         @SerializedName("name") public String name;
//         @SerializedName("url") public String url;
//         @SerializedName("avatar_url") public String avatarUrl;
//     }
// }
// 
// Path: app/src/main/java/moe/yukinoneko/diycode/list/BaseRecyclerListAdapter.java
// public abstract class BaseRecyclerListAdapter<T, VH extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<VH> {
//     protected List<T> data = new ArrayList<>();
// 
//     @Override
//     public int getItemCount() {
//         return data.size();
//     }
// 
//     public List<T> getData() {
//         return data;
//     }
// 
//     @UiThread
//     public void setData(List<T> data) {
//         this.data.clear();
//         this.data.addAll(data);
// 
//         notifyDataSetChanged();
//     }
// 
//     public T getItem(int position) {
//         return data.get(position);
//     }
// 
//     @UiThread
//     public BaseRecyclerListAdapter<T, VH> add(@NonNull T item) {
//         data.add(item);
//         notifyItemInserted(data.size() - 1);
//         return this;
//     }
// 
//     @UiThread
//     public BaseRecyclerListAdapter<T, VH> addAll(@NonNull Collection<T> items) {
//         data.addAll(items);
//         notifyItemRangeInserted(data.size() - items.size(), items.size());
//         return this;
//     }
// 
//     @UiThread
//     public BaseRecyclerListAdapter<T, VH> add(int position, @NonNull T item) {
//         data.add(position, item);
//         notifyItemInserted(position);
//         return this;
//     }
// 
//     @UiThread
//     public BaseRecyclerListAdapter<T, VH> remove(int position) {
//         data.remove(position);
//         notifyItemRemoved(position);
//         return this;
//     }
// 
//     @UiThread
//     public BaseRecyclerListAdapter<T, VH> remove(@NonNull T item) {
//         return remove(data.indexOf(item));
//     }
// 
//     @UiThread
//     public BaseRecyclerListAdapter<T, VH> clear() {
//         data.clear();
//         notifyDataSetChanged();
//         return this;
//     }
// 
//     public boolean isEmpty() {
//         return data == null || data.isEmpty();
//     }
// 
// }
// 
// Path: app/src/main/java/moe/yukinoneko/diycode/tool/ImageLoadHelper.java
// public class ImageLoadHelper {
// 
//     public static void loadImage(Context context, String url, ImageView imageView, @Nullable RequestListener<String, GlideDrawable> listener) {
//         Glide.with(context).load(url).diskCacheStrategy(DiskCacheStrategy.SOURCE).listener(listener).into(imageView);
//     }
// 
//     public static void loadAvatar(Context context, String url, ImageView imageView) {
//         Glide.with(context).load(url).placeholder(R.mipmap.default_avatar).dontAnimate().into(imageView);
//     }
// }


import butterknife.ButterKnife;
import moe.yukinoneko.diycode.R;
import moe.yukinoneko.diycode.bean.Sites;
import moe.yukinoneko.diycode.list.BaseRecyclerListAdapter;
import moe.yukinoneko.diycode.tool.ImageLoadHelper;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.widget.AppCompatImageView;
import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import butterknife.BindView;
/*
 * Copyright (c) 2017 SamuelGjk <samuel.alva@outlook.com>
 *
 * This file is part of DiyCode
 *
 * DiyCode is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * DiyCode is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with DiyCode. If not, see <http://www.gnu.org/licenses/>.
 */

package moe.yukinoneko.diycode.module.site;



/**
 * Created by SamuelGjk on 2017/4/27.
 */

public class SitesGridAdapter extends BaseRecyclerListAdapter<Object, RecyclerView.ViewHolder> {
    private static final int VIEW_TYPE_CATEGORY = 10000;
    private static final int VIEW_TYPE_SITE = 10001;

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        if (VIEW_TYPE_CATEGORY == viewType) {
            return new SitesViewHolder(inflater.inflate(R.layout.item_sites, parent, false));
        } else {
            return new SiteViewHolder(inflater.inflate(R.layout.item_site, parent, false));
        }
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof SitesViewHolder) {
// Path: app/src/main/java/moe/yukinoneko/diycode/bean/Sites.java
// public class Sites {
// 
//     @SerializedName("name") public String name;
//     @SerializedName("id") public int id;
//     @SerializedName("sites") public List<Site> sites;
// 
//     public static class Site {
//         @SerializedName("name") public String name;
//         @SerializedName("url") public String url;
//         @SerializedName("avatar_url") public String avatarUrl;
//     }
// }
// 
// Path: app/src/main/java/moe/yukinoneko/diycode/list/BaseRecyclerListAdapter.java
// public abstract class BaseRecyclerListAdapter<T, VH extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<VH> {
//     protected List<T> data = new ArrayList<>();
// 
//     @Override
//     public int getItemCount() {
//         return data.size();
//     }
// 
//     public List<T> getData() {
//         return data;
//     }
// 
//     @UiThread
//     public void setData(List<T> data) {
//         this.data.clear();
//         this.data.addAll(data);
// 
//         notifyDataSetChanged();
//     }
// 
//     public T getItem(int position) {
//         return data.get(position);
//     }
// 
//     @UiThread
//     public BaseRecyclerListAdapter<T, VH> add(@NonNull T item) {
//         data.add(item);
//         notifyItemInserted(data.size() - 1);
//         return this;
//     }
// 
//     @UiThread
//     public BaseRecyclerListAdapter<T, VH> addAll(@NonNull Collection<T> items) {
//         data.addAll(items);
//         notifyItemRangeInserted(data.size() - items.size(), items.size());
//         return this;
//     }
// 
//     @UiThread
//     public BaseRecyclerListAdapter<T, VH> add(int position, @NonNull T item) {
//         data.add(position, item);
//         notifyItemInserted(position);
//         return this;
//     }
// 
//     @UiThread
//     public BaseRecyclerListAdapter<T, VH> remove(int position) {
//         data.remove(position);
//         notifyItemRemoved(position);
//         return this;
//     }
// 
//     @UiThread
//     public BaseRecyclerListAdapter<T, VH> remove(@NonNull T item) {
//         return remove(data.indexOf(item));
//     }
// 
//     @UiThread
//     public BaseRecyclerListAdapter<T, VH> clear() {
//         data.clear();
//         notifyDataSetChanged();
//         return this;
//     }
// 
//     public boolean isEmpty() {
//         return data == null || data.isEmpty();
//     }
// 
// }
// 
// Path: app/src/main/java/moe/yukinoneko/diycode/tool/ImageLoadHelper.java
// public class ImageLoadHelper {
// 
//     public static void loadImage(Context context, String url, ImageView imageView, @Nullable RequestListener<String, GlideDrawable> listener) {
//         Glide.with(context).load(url).diskCacheStrategy(DiskCacheStrategy.SOURCE).listener(listener).into(imageView);
//     }
// 
//     public static void loadAvatar(Context context, String url, ImageView imageView) {
//         Glide.with(context).load(url).placeholder(R.mipmap.default_avatar).dontAnimate().into(imageView);
//     }
// }


// Path: app/src/main/java/moe/yukinoneko/diycode/module/site/SitesGridAdapter.java
import butterknife.ButterKnife;
import moe.yukinoneko.diycode.R;
import moe.yukinoneko.diycode.bean.Sites;
import moe.yukinoneko.diycode.list.BaseRecyclerListAdapter;
import moe.yukinoneko.diycode.tool.ImageLoadHelper;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.widget.AppCompatImageView;
import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import butterknife.BindView;

/*
 * Copyright (c) 2017 SamuelGjk <samuel.alva@outlook.com>
 *
 * This file is part of DiyCode
 *
 * DiyCode is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * DiyCode is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with DiyCode. If not, see <http://www.gnu.org/licenses/>.
 */

package moe.yukinoneko.diycode.module.site;



/**
 * Created by SamuelGjk on 2017/4/27.
 */

public class SitesGridAdapter extends BaseRecyclerListAdapter<Object, RecyclerView.ViewHolder> {
    private static final int VIEW_TYPE_CATEGORY = 10000;
    private static final int VIEW_TYPE_SITE = 10001;

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        if (VIEW_TYPE_CATEGORY == viewType) {
            return new SitesViewHolder(inflater.inflate(R.layout.item_sites, parent, false));
        } else {
            return new SiteViewHolder(inflater.inflate(R.layout.item_site, parent, false));
        }
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof SitesViewHolder) {
            ((SitesViewHolder) holder).sitesCategory.setText(((Sites) data.get(position)).name);