| | |
| | | package com.hdl.photovoltaic.ui.adapter; |
| | | |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.graphics.drawable.Drawable; |
| | | import android.view.LayoutInflater; |
| | | import android.view.View; |
| | | import android.view.ViewGroup; |
| | |
| | | import android.widget.TextView; |
| | | |
| | | import androidx.annotation.NonNull; |
| | | import androidx.appcompat.content.res.AppCompatResources; |
| | | import androidx.recyclerview.widget.RecyclerView; |
| | | |
| | | import com.bumptech.glide.load.resource.bitmap.RoundedCorners; |
| | | import com.hdl.photovoltaic.R; |
| | | import com.hdl.photovoltaic.ui.bean.HouseIdBean; |
| | | import com.hdl.photovoltaic.utils.GlideUtils; |
| | | |
| | | import java.util.List; |
| | | |
| | | public class HouseInfoAdapter extends RecyclerView.Adapter<HouseInfoAdapter.MyViewHolder> { |
| | | |
| | | private List<HouseIdBean> mList; |
| | | private final Context mContext; |
| | | private OnclickListener noOnclickListener;//点击了的监听器 |
| | | |
| | | public HouseInfoAdapter(List<HouseIdBean> list) { |
| | | public HouseInfoAdapter(List<HouseIdBean> list, Context context) { |
| | | |
| | | this.mList = list; |
| | | this.mContext = context; |
| | | } |
| | | |
| | | @NonNull |
| | |
| | | |
| | | @Override |
| | | public void onBindViewHolder(@NonNull MyViewHolder holder, int position) { |
| | | |
| | | HouseIdBean houseIdBean = this.mList.get(position); |
| | | holder.homeNameTv.setText(houseIdBean.getHomeName()); |
| | | holder.homeNameTv.setText(houseIdBean.getHomeName().trim()); |
| | | //装机容量 |
| | | String capacity = mContext.getString(R.string.my_power_station_installed_capacity) + houseIdBean.getInstalledCapacity() + "kW"; |
| | | holder.capacityTv.setText(capacity); |
| | | String kw = "0.0"; |
| | | try { |
| | | double d = Double.parseDouble(houseIdBean.getPower()); |
| | | int intValue = (int) d; |
| | | int k = intValue / 1000; |
| | | int w = intValue % 1000; |
| | | kw = k + "." + w; |
| | | } catch (Exception ignored) { |
| | | } |
| | | //发电功率 |
| | | String power = mContext.getString(R.string.power_station_generated_power) + kw + "kW"; |
| | | holder.powerTv.setText(power); |
| | | setTextViewStyle(holder.stateTv, houseIdBean.getPowerStationStatus()); |
| | | GlideUtils.getRoundedCornersImage(mContext, houseIdBean.getPowerStationImage(), holder.homeIconIv, new RoundedCorners(4)); |
| | | holder.itemView.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | if (noOnclickListener != null) { |
| | | noOnclickListener.onClick(holder.getAdapterPosition()); |
| | | noOnclickListener.onClick(holder.getAdapterPosition(), houseIdBean); |
| | | } |
| | | } |
| | | }); |
| | |
| | | this.noOnclickListener = onclickListener; |
| | | } |
| | | |
| | | /** |
| | | * 改变组件样式 |
| | | * |
| | | * @param textView 显示组件 |
| | | * @param state_value 电站状态(1:正常(运行),2:离线,3:连接中,4:故障) |
| | | */ |
| | | private void setTextViewStyle(TextView textView, int state_value) { |
| | | String text = mContext.getString(R.string.my_power_station_operation); |
| | | Drawable drawable = AppCompatResources.getDrawable(mContext, R.drawable.state_06b92a); |
| | | switch (state_value) { |
| | | case 1: { |
| | | text = mContext.getString(R.string.my_power_station_operation); |
| | | |
| | | } |
| | | break; |
| | | case 2: { |
| | | text = mContext.getString(R.string.my_power_station_off_line); |
| | | drawable = AppCompatResources.getDrawable(mContext, R.drawable.state_b9b9b9); |
| | | } |
| | | break; |
| | | case 3: { |
| | | text = mContext.getString(R.string.my_power_station_connecting); |
| | | drawable = AppCompatResources.getDrawable(mContext, R.drawable.state_ffb300); |
| | | } |
| | | break; |
| | | case 4: { |
| | | text = mContext.getString(R.string.my_power_station_malfunction); |
| | | drawable = AppCompatResources.getDrawable(mContext, R.drawable.state_e34343); |
| | | } |
| | | break; |
| | | } |
| | | textView.setText(text); |
| | | textView.setBackground(drawable); |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 一行布局容器 |
| | | */ |
| | | static class MyViewHolder extends RecyclerView.ViewHolder { |
| | | |
| | | public ImageView homeIconIv;//住宅图片 |
| | |
| | | } |
| | | |
| | | public interface OnclickListener { |
| | | void onClick(int position); |
| | | void onClick(int position, HouseIdBean houseIdBean); |
| | | } |
| | | } |