package com.bearneck.parking.Adapters;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.support.design.widget.Snackbar;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.bearneck.parking.Bean.Picture;
import com.bearneck.parking.R;
import com.bumptech.glide.Glide;
import com.makeramen.roundedimageview.RoundedImageView;
import java.util.ArrayList;
import java.util.List;
import de.hdodenhof.circleimageview.CircleImageView;
import static com.makeramen.roundedimageview.RoundedImageView.TAG;
public class PictureAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private Context mContext;
private List<Picture> mPictureList;
private LayoutInflater mLayoutInflater;
private int normalType = 0; // 第一种ViewType,正常的item
private int footType = 1; // 第二种ViewType,底部的提示View
private boolean hasMore = true; // 变量,是否有更多数据
private boolean fadeTips = false; // 变量,是否隐藏了底部的提示
private Handler mHandler = new Handler(Looper.getMainLooper()); //获取主线程的Handler
public PictureAdapter(List<Picture> pictureList, Context context, boolean hasMore){
mPictureList = pictureList;
this.mContext = context;
this.hasMore = hasMore;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// if (mContext == null){
// mContext = parent.getContext();
// }
// View view = LayoutInflater.from(mContext).inflate(R.layout.picture_item,parent,false);
// return new ViewHolder(view);
// 根据返回的ViewType,绑定不同的布局文件,这里只有两种
View view;
if (viewType == normalType) {
return new NormalHolder(LayoutInflater.from(mContext).inflate(R.layout.picture_item, parent,false));
}
else {
return new FootHolder(LayoutInflater.from(mContext).inflate(R.layout.bottom_item, parent,false));
}
}
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
// 如果是正常的imte,直接设置TextView的值
if (holder instanceof NormalHolder) {
// ((NormalHolder) holder).textView.setText(datas.get(position));
final Picture picture = mPictureList.get(position);
((NormalHolder) holder).id.setText((position+1)+"");
((NormalHolder) holder).userName.setText(picture.getUserName());
((NormalHolder) holder).realName.setText(picture.getRealName());
((NormalHolder) holder).phone.setText(picture.getPhone());
((NormalHolder) holder).shiruType .setText(picture.getShiruType());
((NormalHolder) holder).shifoushenhe.setText(picture.getShifoushenhe());
((NormalHolder) holder).shiruTime.setText(picture.getShiruTime());
((NormalHolder) holder).shichuTime.setText(picture.getShichuTime());
((NormalHolder) holder).yuyueTime.setText(picture.getYuyueTime());
// ((NormalHolder) holder).content.setText(picture.getContent());
// ((NormalHolder) holder).zannum.setText(picture.getZannum() + " ");//int不能直接转换成string
// ((NormalHolder) holder).contentnum.setText(picture.getContentnum() + " ");
// ((NormalHolder) holder).sharenum.setText(picture.getSharenum() + " ");
// ((NormalHolder) holder).detail.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
//// Intent intent = new Intent(mContext, detail.class);
//// Bundle bundle = new Bundle();
//// bundle.putString(detail.IMAGE_URL, picture.getImageId());
//// bundle.putString(detail.ICON_URL, picture.getIconId());
//// bundle.putInt(detail.ZAN_URL, picture.getZannum());
//// bundle.putInt(detail.SHARE_URL, picture.getSharenum());
//// bundle.putString(detail.CONTEXT_URL, picture.getContent());
//// bundle.putInt(detail.CONTENT_id, picture.getSoureid());
//// intent.putExtras(bundle);
//// mContext.startActivity(intent);//启动TwoActivity活动
// }
// });
// Glide.with(mContext).load(picture.getIconId()).error(R.drawable.jiqiren).into(((NormalHolder) holder).iconId);
//图片优化
// Glide.with(mContext).load(picture.getImageId())
// .error(R.drawable.jiqiren)
// .thumbnail(0.1f)
// .into(((NormalHolder) holder).imageId);
((NormalHolder) holder).deleteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mPictureList.size() == 1) {
Snackbar.make(v, "再删就没有了", Snackbar.LENGTH_SHORT).show();
} else {
//删除自带默认动画
removeData(position);
}
}
});
// ((NormalHolder) holder).upview.setOnClickListener(new View.OnClickListener() {
// @SuppressLint({"ResourceAsColor", "ResourceType"})
// @Override
// public void onClick(View v) {
// int zannew = picture.getZannum() + 1;
// ((NormalHolder) holder).zannum.setText(zannew + " ");
// ((NormalHolder) holder).zannum.setTextColor(R.color.likeColor);
// ((NormalHolder) holder).zanimage.setImageResource(R.drawable.up);
// }
// });
// ((NormalHolder) holder).imageId.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
//// Intent intent = new Intent(mContext, activity_image.class);
//// intent.putExtra(activity_image.IMAGE_URL, picture.getImageId());
//// mContext.startActivity(intent);
// }
// });
// ((NormalHolder) holder).contentview.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
//// Intent intent = new Intent(mContext, detail.class);
//// Bundle bundle = new Bundle();
//// bundle.putString(detail.IMAGE_URL, picture.getImageId());
//// bundle.putString(detail.ICON_URL, picture.getIconId());
//// bundle.putInt(detail.ZAN_URL, picture.getZannum());
//// bundle.putInt(detail.SHARE_URL, picture.getSharenum());
//// bundle.putString(detail.CONTEXT_URL, picture.getContent());
//// intent.putExtras(bundle);
////
//// mContext.startActivity(intent);//启动TwoActivity活动
// }
// });
}
// else {
// // 之所以要设置可见,是因为我在没有更多数据时会隐藏了这个footView
// ((FootHolder) holder).tips.setVisibility(View.VISIBLE);
// // 只有获取数据为空时,hasMore为false,所以当我们拉到底部时基本都会首先显示“正在加载更多...”
// if (hasMore == true) {
// // 不隐藏footView提示
//