|
|
@@ -1,224 +0,0 @@
|
|
|
-package com.silence.commonframe.adapter;
|
|
|
-
|
|
|
-import android.content.Context;
|
|
|
-import android.content.Intent;
|
|
|
-import android.content.res.Resources;
|
|
|
-import android.graphics.Color;
|
|
|
-import android.os.Bundle;
|
|
|
-import android.support.annotation.NonNull;
|
|
|
-import android.support.v7.widget.RecyclerView;
|
|
|
-import android.view.LayoutInflater;
|
|
|
-import android.view.View;
|
|
|
-import android.view.ViewGroup;
|
|
|
-import android.widget.CheckBox;
|
|
|
-import android.widget.CompoundButton;
|
|
|
-import android.widget.TextView;
|
|
|
-
|
|
|
-import com.silence.commonframe.R;
|
|
|
-import com.silence.commonframe.activity.DevicedetailActivity;
|
|
|
-import com.silence.commonframe.activity.NewDeviceDetailActivity;
|
|
|
-import com.silence.commonframe.example.ActivityGuideDeviceCamera;
|
|
|
-import com.silence.commonframe.utils.Data;
|
|
|
-
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
-
|
|
|
-/**
|
|
|
- * 关联设备构造器
|
|
|
- * @author 郑嘉明
|
|
|
- */
|
|
|
-public class DeviceContextAdapter extends RecyclerView.Adapter<DeviceContextAdapter.MyViewHolder> {
|
|
|
-
|
|
|
- private Context context;
|
|
|
- private LayoutInflater mInflater;
|
|
|
- private List<HashMap<String,String>> listmap1;
|
|
|
- private Boolean isShow = false; //默认看不到checkbox
|
|
|
-
|
|
|
- private List<String> checkBoxIDList;
|
|
|
-
|
|
|
-
|
|
|
- public DeviceContextAdapter(Context context, List<HashMap<String,String>> listmap){
|
|
|
- this.context = context;
|
|
|
- this.listmap1 = listmap;
|
|
|
- checkBoxIDList = new ArrayList<>();
|
|
|
- mInflater = LayoutInflater.from(context);
|
|
|
- }
|
|
|
-
|
|
|
- @NonNull
|
|
|
- @Override
|
|
|
- public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
|
|
|
- View view = mInflater.inflate(R.layout.item_device_context_manager, viewGroup, false); //实例化自己的界面
|
|
|
- return (new MyViewHolder(view));
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onBindViewHolder(@NonNull final MyViewHolder myViewHolder, int position) {
|
|
|
- final int pos = position;
|
|
|
- myViewHolder.device_context_name.setText(listmap1.get(position).get("deviceName"));
|
|
|
- myViewHolder.device_context_location.setText(listmap1.get(position).get("location"));
|
|
|
-
|
|
|
- String deviceType = listmap1.get(position).get("deviceType");
|
|
|
- Resources res = context.getResources();
|
|
|
- if (res.getString(R.string.device_smokedetector_number).equals(deviceType)){ //判断是烟感还是摄像头
|
|
|
- if ("0".equals(listmap1.get(position).get("status"))){ //判断状态
|
|
|
- myViewHolder.device_context_state.setText(R.string.state_fault);
|
|
|
- myViewHolder.device_context_state.setTextColor(Color.rgb(255,144,0));
|
|
|
- }else if ("1".equals(listmap1.get(position).get("status"))){
|
|
|
- myViewHolder.device_context_state.setText(R.string.state_fire);
|
|
|
- myViewHolder.device_context_state.setTextColor(Color.rgb(243,46,46));
|
|
|
- }else {
|
|
|
- myViewHolder.device_context_state.setText(R.string.state_normal);
|
|
|
- myViewHolder.device_context_state.setTextColor(Color.rgb(78,105,255));
|
|
|
- }
|
|
|
- }else if (res.getString(R.string.device_camera_number).equals(deviceType)){
|
|
|
- if ("0".equals(listmap1.get(position).get("status"))){
|
|
|
- myViewHolder.device_context_state.setText(R.string.state_outline);
|
|
|
- myViewHolder.device_context_state.setTextColor(Color.rgb(204,204,204));
|
|
|
- }else {
|
|
|
- myViewHolder.device_context_state.setText(R.string.state_online);
|
|
|
- myViewHolder.device_context_state.setTextColor(Color.rgb(78,105,255));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if (!isShow){
|
|
|
- myViewHolder.device_context_checkbox.setVisibility(View.GONE);
|
|
|
- checkBoxIDList.clear();
|
|
|
- if (res.getString(R.string.device_smokedetector_number).equals(deviceType)){
|
|
|
- myViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- Intent intent = new Intent(context,NewDeviceDetailActivity.class);
|
|
|
- intent.putExtra("deviceName",listmap1.get(pos).get("deviceName"));
|
|
|
- intent.putExtra("Location",listmap1.get(pos).get("location"));
|
|
|
- intent.putExtra("devicelocation",listmap1.get(pos).get("deviceLocation"));
|
|
|
- intent.putExtra("deviceId",listmap1.get(pos).get("deviceId"));
|
|
|
- context.startActivity(intent);
|
|
|
- }
|
|
|
- });
|
|
|
- }else if (res.getString(R.string.device_camera_number).equals(deviceType)) {
|
|
|
- //摄像头跳转
|
|
|
- myViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- Intent intent = new Intent(context,NewDeviceDetailActivity.class);
|
|
|
- intent.putExtra("deviceName",listmap1.get(pos).get("deviceName"));
|
|
|
- intent.putExtra("Location",listmap1.get(pos).get("location"));
|
|
|
- intent.putExtra("devicelocation",listmap1.get(pos).get("deviceLocation"));
|
|
|
- intent.putExtra("deviceId",listmap1.get(pos).get("deviceId"));
|
|
|
- Data.setDevIdsCamera(listmap1.get(pos).get("deviceId"));
|
|
|
- Intent intent1 = new Intent();
|
|
|
- intent1.setClass(context,ActivityGuideDeviceCamera.class);
|
|
|
-
|
|
|
- Bundle bundle = new Bundle();
|
|
|
-
|
|
|
- int devId = 0;
|
|
|
- if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
|
|
|
- devId = (Objects.requireNonNull(listmap1.get(pos).get("deviceId"))).hashCode();
|
|
|
- }
|
|
|
- bundle.putInt("FUN_DEVICE_ID", devId);
|
|
|
- // intent1.putExtra("deviceId",listCameraId.get(0));
|
|
|
- intent1.putExtras(bundle);
|
|
|
- intent1.putExtra("deviceId",listmap1.get(pos).get("deviceId"));
|
|
|
- Data.setCameraName(listmap1.get(pos).get("deviceName"));
|
|
|
- context.startActivity(intent1);
|
|
|
-// Toast.makeText(context,"摄像头",Toast.LENGTH_SHORT).show();
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- }else {
|
|
|
- myViewHolder.device_context_checkbox.setVisibility(View.VISIBLE);
|
|
|
- myViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- if (myViewHolder.device_context_checkbox.isChecked()){
|
|
|
- myViewHolder.device_context_checkbox.setChecked(false);
|
|
|
- checkBoxIDList.remove(listmap1.get(pos).get("id"));
|
|
|
- }else {
|
|
|
- myViewHolder.device_context_checkbox.setChecked(true);
|
|
|
- checkBoxIDList.add(listmap1.get(pos).get("id"));
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- myViewHolder.device_context_checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
- @Override
|
|
|
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
|
- if (isChecked){
|
|
|
- // checkBoxIDList.add(listmap1.get(pos).get("id"));
|
|
|
-
|
|
|
- if(!listmap1.get(pos).get("id").equals(listmap1.get(pos).get("id"))){
|
|
|
- checkBoxIDList.add(listmap1.get(pos).get("id"));
|
|
|
- }
|
|
|
-
|
|
|
- Data.setCheckBoxIDListData(checkBoxIDList);
|
|
|
-
|
|
|
-
|
|
|
- }else {
|
|
|
- checkBoxIDList.remove(listmap1.get(pos).get("id"));
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- public List<String> getCheckBoxIDList(){
|
|
|
- return checkBoxIDList;
|
|
|
- }
|
|
|
-
|
|
|
- public void setCheckBoxIDList(List<String> checkBoxIDList) {
|
|
|
- this.checkBoxIDList = checkBoxIDList;
|
|
|
- }
|
|
|
-
|
|
|
- public void setIsShow(Boolean isShow){
|
|
|
- this.isShow = isShow;
|
|
|
- notifyDataSetChanged();
|
|
|
- }
|
|
|
-
|
|
|
- public Boolean getShow() {
|
|
|
- return isShow;
|
|
|
- }
|
|
|
-
|
|
|
- public void removeAdapterItem(){
|
|
|
- if (checkBoxIDList.size() > 0){
|
|
|
- for (int i = 0; i<listmap1.size(); i++){
|
|
|
- String id = listmap1.get(i).get("id");
|
|
|
- for (int j = 0; j < checkBoxIDList.size(); j++){
|
|
|
- if (checkBoxIDList.get(j).equals(id)){
|
|
|
- listmap1.remove(i);
|
|
|
- notifyItemRemoved(i);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public int getItemCount() {
|
|
|
- return listmap1.size();
|
|
|
- }
|
|
|
-
|
|
|
- class MyViewHolder extends RecyclerView.ViewHolder {
|
|
|
-
|
|
|
- View itemView;
|
|
|
- CheckBox device_context_checkbox;
|
|
|
- TextView device_context_name;
|
|
|
- TextView device_context_location;
|
|
|
- TextView device_context_state;
|
|
|
-
|
|
|
- public MyViewHolder(@NonNull View itemView) {
|
|
|
- super(itemView);
|
|
|
- this.itemView = itemView;
|
|
|
- device_context_checkbox = (CheckBox) itemView.findViewById(R.id.device_context_checkbox);
|
|
|
- device_context_name = (TextView) itemView.findViewById(R.id.device_context_name);
|
|
|
- device_context_location = (TextView) itemView.findViewById(R.id.device_context_location);
|
|
|
- device_context_state = (TextView) itemView.findViewById(R.id.device_context_state);
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-}
|