version:1.0.9
fix: update:更新资源,增加登录,增加检测更新
This commit is contained in:
98
app/src/main/java/com/xwad/os/adapter/VipAdapter.java
Normal file
98
app/src/main/java/com/xwad/os/adapter/VipAdapter.java
Normal file
@@ -0,0 +1,98 @@
|
||||
package com.xwad.os.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Paint;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.xwad.os.R;
|
||||
import com.xwad.os.bean.VipInfo;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class VipAdapter extends RecyclerView.Adapter<VipAdapter.VipHolder> {
|
||||
private Context mContext;
|
||||
|
||||
private List<VipInfo> mVipInfos;
|
||||
private String mSelectId = "";
|
||||
|
||||
public void setVipInfos(List<VipInfo> vipInfos) {
|
||||
mVipInfos = vipInfos;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public interface VipSelectListener {
|
||||
void onVipSelect(VipInfo vipInfo);
|
||||
}
|
||||
|
||||
private VipSelectListener mVipSelectListener;
|
||||
|
||||
public void setVipSelectListener(VipSelectListener vipSelectListener) {
|
||||
mVipSelectListener = vipSelectListener;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public VipHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
mContext = parent.getContext();
|
||||
return new VipHolder(LayoutInflater.from(mContext).inflate(R.layout.item_vip, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull VipHolder holder, int position) {
|
||||
VipInfo vipInfo = mVipInfos.get(position);
|
||||
String id = vipInfo.getId();
|
||||
String name = vipInfo.getName();
|
||||
int year = vipInfo.getYear();
|
||||
String price = vipInfo.getPrice();
|
||||
String origin_price = vipInfo.getOrigin_price();
|
||||
|
||||
holder.tv_combo_name.setText(name);
|
||||
holder.tv_year.setText(String.format(mContext.getString(R.string.validity_period), year));
|
||||
holder.tv_price.setText("现价:¥" + price);
|
||||
holder.tv_origin_price.setText("原价:¥" + origin_price);
|
||||
|
||||
holder.tv_origin_price.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
|
||||
holder.root.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
mSelectId = id;
|
||||
if (mVipSelectListener != null) {
|
||||
mVipSelectListener.onVipSelect(vipInfo);
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
if (Objects.equals(mSelectId, id)) {
|
||||
holder.root.setBackground(mContext.getDrawable(R.drawable.bg_vip_select));
|
||||
} else {
|
||||
holder.root.setBackground(mContext.getDrawable(R.drawable.bg_vip_unselect));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mVipInfos == null ? 0 : mVipInfos.size();
|
||||
}
|
||||
|
||||
public class VipHolder extends RecyclerView.ViewHolder {
|
||||
LinearLayout root;
|
||||
TextView tv_combo_name, tv_year, tv_price, tv_origin_price;
|
||||
|
||||
public VipHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
root = itemView.findViewById(R.id.root);
|
||||
tv_combo_name = itemView.findViewById(R.id.tv_combo_name);
|
||||
tv_year = itemView.findViewById(R.id.tv_year);
|
||||
tv_price = itemView.findViewById(R.id.tv_price);
|
||||
tv_origin_price = itemView.findViewById(R.id.tv_origin_price);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user