package com.dayu.qihealonelibrary.adapter;
|
|
import android.content.Context;
|
import android.view.LayoutInflater;
|
import android.view.ViewGroup;
|
|
import androidx.annotation.NonNull;
|
import androidx.databinding.DataBindingUtil;
|
import androidx.recyclerview.widget.RecyclerView;
|
|
import com.dayu.baselibrary.databinding.ItemNoMoreBinding;
|
|
import com.dayu.baselibrary.utils.DateUtil;
|
|
import com.dayu.baselibrary.utils.MornyUtil;
|
import com.dayu.qihealonelibrary.R;
|
import com.dayu.qihealonelibrary.databinding.QiheItemRechargeBinding;
|
import com.dayu.qihealonelibrary.dbBean.RechargeBean;
|
|
|
import java.util.List;
|
|
/**
|
* Created by zuoxiao on 2018/12/24.
|
*/
|
|
public class RechargeAdapter extends BaseRecyclerAdapter<RecyclerView.ViewHolder> {
|
|
List<RechargeBean> rechargeList;
|
Context mContext;
|
|
public RechargeAdapter(Context context, List<RechargeBean> rechargeList) {
|
mContext = context;
|
this.rechargeList = rechargeList;
|
}
|
|
|
@NonNull
|
@Override
|
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
if (viewType == VIEW_TYPE_EMPTY) {
|
ItemNoMoreBinding emptyView = DataBindingUtil.inflate((LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE), com.dayu.baselibrary.R.layout.item_no_more, parent, false);
|
return new ViewHolderEmpty(emptyView);
|
} else {
|
QiheItemRechargeBinding binding = DataBindingUtil.inflate((LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE), R.layout.qihe_item_recharge, parent, false);
|
return new ViewHolder(binding);
|
}
|
|
}
|
|
@Override
|
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
if (holder instanceof ViewHolder) {
|
if (rechargeList.size() > 0) {
|
((ViewHolder) holder).getBinding().userName.setText("姓名:" + rechargeList.get(position).getUserName());
|
((ViewHolder) holder).getBinding().userNo.setText("卡号:" + rechargeList.get(position).getCardNumber());
|
((ViewHolder) holder).getBinding().morny.setText("充值金额:" + rechargeList.get(position).getMorny() + " 元");
|
((ViewHolder) holder).getBinding().rachagerWater.setText("充值水量:" + rechargeList.get(position).getRechargeWater() + " 吨");
|
// ((ViewHolder) holder).getBinding().balance.setText("余额:" + rechargeList.get(position).getBalance() + " 元");
|
((ViewHolder) holder).getBinding().surplusWater.setText("剩余水量:" + rechargeList.get(position).getSurplusWater() + " 吨");
|
((ViewHolder) holder).getBinding().date.setText("日期:" + DateUtil.dateToStamp(rechargeList.get(position).getDate(), DateUtil.type1));
|
}
|
}
|
}
|
|
@Override
|
public int getItemCount() {
|
//同时这里也需要添加判断,如果mData.size()为0的话,只引入一个布局,就是emptyView
|
// 那么,这个recyclerView的itemCount为1
|
if (rechargeList.size() == 0) {
|
return 1;
|
}
|
return rechargeList.size();
|
}
|
|
@Override
|
public int getItemViewType(int position) {
|
if (rechargeList.size() == 0) {
|
return VIEW_TYPE_EMPTY;
|
} else {
|
return VIEW_TYPE_ITEM;
|
}
|
}
|
|
|
static class ViewHolder extends RecyclerView.ViewHolder {
|
QiheItemRechargeBinding mBinding;
|
|
public QiheItemRechargeBinding getBinding() {
|
return mBinding;
|
}
|
|
public void setBinding(QiheItemRechargeBinding binding) {
|
this.mBinding = binding;
|
}
|
|
public ViewHolder(QiheItemRechargeBinding itemView) {
|
super(itemView.getRoot());
|
this.mBinding = itemView;
|
|
}
|
}
|
|
|
}
|