package com.navinfo.outdoor.fragment;

import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Point;
import android.net.Uri;
import android.os.Bundle;
import android.os.Message;
import android.provider.MediaStore;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.widget.NestedScrollView;

import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.hjq.permissions.OnPermissionCallback;
import com.hjq.permissions.Permission;
import com.hjq.permissions.XXPermissions;
import com.kongzue.dialog.interfaces.OnDialogButtonClickListener;
import com.kongzue.dialog.util.BaseDialog;
import com.kongzue.dialog.util.DialogSettings;
import com.kongzue.dialog.v3.MessageDialog;
import com.lzy.okgo.model.HttpParams;
import com.navinfo.outdoor.R;
import com.navinfo.outdoor.activity.FragmentManagement;
import com.navinfo.outdoor.api.Constant;
import com.navinfo.outdoor.base.BaseDrawerFragment;
import com.navinfo.outdoor.bean.ChargingPileSaveBean;
import com.navinfo.outdoor.bean.PoiSaveBean;
import com.navinfo.outdoor.http.Callback;
import com.navinfo.outdoor.http.HttpInterface;
import com.navinfo.outdoor.http.OkGoBuilder;
import com.navinfo.outdoor.room.ChargingPileDao;
import com.navinfo.outdoor.room.ChargingPileEntity;
import com.navinfo.outdoor.room.InsertAndUpdateUtils;
import com.navinfo.outdoor.room.PoiDatabase;
import com.navinfo.outdoor.room.PoiEntity;
import com.navinfo.outdoor.util.Geohash;
import com.navinfo.outdoor.util.GeometryTools;
import com.navinfo.outdoor.util.MapManager;
import com.navinfo.outdoor.util.PhotoPathUtil;
import com.navinfo.outdoor.util.PhotoUtils;
import com.navinfo.outdoor.util.PictureUtil;
import com.navinfo.outdoor.util.ToastUtil;
import com.sothree.slidinguppanel.SlidingUpPanelLayout;
import com.tencent.tencentmap.mapsdk.maps.CameraUpdate;
import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory;
import com.tencent.tencentmap.mapsdk.maps.TencentMap;
import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptor;
import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory;
import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition;
import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
import com.tencent.tencentmap.mapsdk.maps.model.Marker;
import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions;
import com.vividsolutions.jts.geom.impl.PackedCoordinateSequence;


import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import static android.app.Activity.RESULT_OK;

/**
 * 充电站中的充电桩的Fragment
 * 2021-5-25
 */
public class ChargingPileFragment extends BaseDrawerFragment implements View.OnClickListener {
    private EditText editDescribe;
    private TextView tvNameContent;
    private Button btnSaveLocal;
    private PoiDatabase poiDatabase;
    private CheckBox checkBoxLife, checkBoxRight;
    private Spinner spinnerType, spinnerScutcheon, spinnerStake;
    String[] type = new String[]{"地上五层", "地上四层", "地上三层", "地上二层", "地上一层", "地下一层", "地下二层", "地下三层", "地下四层", "地下五层"};
    String[] scutcheon = new String[]{"存在", "不存在"};
    String[] stake = new String[]{"可以使用", "不可使用", "维修中", "建设中", "规划中"};
    private ArrayAdapter<String> adapterType, adapterScutcheon, adapterStake;
    private RelativeLayout rlPanorama, rlCoding, rlEquipment, rlFacility, rlUsable, rlAvailable, rlParking, rlNumber, rlScutcheon, rlDevice;
    private ImageView ivPanorama, ivCoding, ivEquipment, ivFacility, ivUsable, ivAvailable, ivParking, ivNumber, ivScutcheon, ivDevice;
    private TextView tvPanorama, tvCoding, tvEquipment, tvFacility, tvUsable, tvAvailable, tvParking, tvNumber, tvScutcheon, tvDevice;
    private ChargingPileDao chargingPileDao;
    private int cp_floor = 1;
    private int sign_exist = 0;
    private int cp_availableState = 0;
    private String buffer1 = "", buffer2 = "", buffer3 = "", buffer4 = "", buffer5 = "";
    private StringBuffer openType = new StringBuffer();
    private CheckBox checkButton1, checkButton2, checkButton3, checkButton4, checkButton5;
    private String pid;
    private String station;
    private LatLng latLng;
    private File file;
    private String takePhotoPath1;
    private String takePhotoPath2;
    private String takePhotoPath3;
    private String takePhotoPath4;
    private String takePhotoPath5;
    private String takePhotoPath6;
    private String takePhotoPath7;
    private String takePhotoPath8;
    private String takePhotoPath9;
    private String takePhotoPath10;
    private int taskId;
    private Integer chargingPileBody;
    private ArrayList<File> phoneLists;
    private NestedScrollView nestedScrollView;
    private Marker markerPile;
    private Point screenPilePositions;
    private ChargingPileEntity chargingPileEntity;

    public static ChargingPileFragment newInstance(Bundle bundle) {
        ChargingPileFragment fragment = new ChargingPileFragment();
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    protected int getLayout() {
        return R.layout.charging_pile_fragment;
    }

    @Override
    public void onStart() {
        super.onStart();
        if (!EventBus.getDefault().isRegistered(this)) {//加上判断
            EventBus.getDefault().register(this);
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        View header = mView.findViewById(R.id.charging_pile_header);
        header.findViewById(R.id.iv_charging_pile_final).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle arguments = getArguments();
                if (arguments != null) {
                    isSliding = arguments.getBoolean("isSliding", true);
                    Log.d("TAG", "onCreatessss: " + isSliding);
                }
                if (isSliding) {
                    // 监听到返回按钮点击事件
                    Message obtain = Message.obtain();
                    obtain.what = Constant.TREASURE_FRAGMENT;
                    obtain.obj = true;
                    EventBus.getDefault().post(obtain);
                } else {
                    Message obtain = Message.obtain();
                    obtain.what = Constant.TREASURE_FRAGMENT;
                    obtain.obj = false;
                    EventBus.getDefault().post(obtain);
                }
                onBackPressed();
            }
        });
        header.findViewById(R.id.tv_charging_pile_explain).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), FragmentManagement.class);
                intent.putExtra("tag", 8);
                startActivity(intent);
            }
        });
        moveLatlng(latLng,null);
    }

    @Override
    protected void initView() {
        super.initView();
        poiDatabase = PoiDatabase.getInstance(getContext());
        chargingPileDao = poiDatabase.getChargingPileDao();
        checkBoxLife = findViewById(R.id.check_pot_life);
        checkBoxRight = findViewById(R.id.check_pot_right);
        checkBoxLife.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    checkBoxLife.setText("保存");
                    checkBoxLife.setTextColor(Color.WHITE);
                    moveLatlng(latLng, new TencentMap.CancelableCallback() {
                        @Override
                        public void onFinish() {
                            screenPilePositions = tencentMap.getProjection().toScreenLocation(latLng);
                            //创建Marker对象之前，设置属性
                            if (markerPile != null) {
                                markerPile.setFixingPoint(screenPilePositions.x, screenPilePositions.y);
                            }
                        }

                        @Override
                        public void onCancel() {
                        }
                    });
                } else {
                    checkBoxLife.setText("编辑");
                    checkBoxLife.setTextColor(Color.BLACK);
                    latLng = tencentMap.getProjection().fromScreenLocation(screenPilePositions);
                    markerPile.setPosition(latLng);
                    markerPile.setFixingPointEnable(false);

                }
            }
        });
        checkBoxRight.setVisibility(View.GONE);
        tvNameContent = findViewById(R.id.tv_name_content);
        checkButton1 = findViewById(R.id.check_button1);
        checkButton1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    buffer1 = "1,";
                    buffer2 = "";
                    buffer3 = "";
                    buffer4 = "";
                    buffer5 = "";
                    checkButton2.setChecked(false);
                    checkButton3.setChecked(false);
                    checkButton4.setChecked(false);
                    checkButton5.setChecked(false);
                }
            }
        });
        checkButton2 = findViewById(R.id.check_button2);
        checkButton2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    buffer2 = "2,";
                    checkButton1.setChecked(false);
                } else {
                    buffer2 = "";
                }
            }
        });
        checkButton3 = findViewById(R.id.check_button3);
        checkButton3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    buffer3 = "3,";
                    checkButton1.setChecked(false);
                } else {
                    buffer3 = "";
                }
            }
        });
        checkButton4 = findViewById(R.id.check_button4);
        checkButton4.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    buffer4 = "4,";
                    checkButton1.setChecked(false);
                } else {
                    buffer4 = "";
                }
            }
        });
        checkButton5 = findViewById(R.id.check_button5);
        checkButton5.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    buffer5 = "5,";
                    checkButton1.setChecked(false);
                } else {
                    buffer5 = "";
                }
            }
        });
        spinnerType = findViewById(R.id.spinner_type);
        adapterType = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, type);
        adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);     //设置下拉列表框的下拉选项样式
        spinnerType.setAdapter(adapterType);
        spinnerType.setSelection(4, true);
        spinnerType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                switch (position) {
                    case 0:
                        cp_floor = 5;
                        break;
                    case 1:
                        cp_floor = 4;
                        break;
                    case 2:
                        cp_floor = 3;
                        break;
                    case 3:
                        cp_floor = 2;
                        break;
                    case 4:
                        cp_floor = 1;
                        break;
                    case 5:
                        cp_floor = -1;
                        break;
                    case 6:
                        cp_floor = -2;
                        break;
                    case 7:
                        cp_floor = -3;
                        break;
                    case 8:
                        cp_floor = -4;
                        break;
                    case 9:
                        cp_floor = -5;
                        break;
                }

            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
            }
        });
        spinnerScutcheon = findViewById(R.id.spinner_scutcheon);
        adapterScutcheon = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, scutcheon);
        adapterScutcheon.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);     //设置下拉列表框的下拉选项样式
        spinnerScutcheon.setAdapter(adapterScutcheon);
        spinnerScutcheon.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                switch (position) {
                    case 0:
                        rlFacility.setBackgroundColor(Color.parseColor("#EFEDED"));
                        rlScutcheon.setVisibility(View.GONE);
                        rlDevice.setVisibility(View.GONE);
                        sign_exist = 0;
                        break;
                    case 1:
                        rlFacility.setBackgroundColor(Color.parseColor("#03A9F4"));
                        rlScutcheon.setVisibility(View.VISIBLE);
                        rlDevice.setVisibility(View.VISIBLE);
                        sign_exist = 1;
                        break;
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
        spinnerStake = findViewById(R.id.spinner_stake);
        adapterStake = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, stake);
        adapterStake.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);     //设置下拉列表框的下拉选项样式
        spinnerStake.setAdapter(adapterStake);
        spinnerStake.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                switch (position) {
                    case 0:
                        cp_availableState = 0;
                        break;
                    case 1:
                        cp_availableState = 1;
                        break;
                    case 2:
                        cp_availableState = 2;
                        break;
                    case 3:
                        cp_availableState = 3;
                        break;
                    case 4:
                        cp_availableState = 4;
                        break;
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
        setSlidingUpPanelLayout(Constant.SLIDING_LAYOUT);
        nestedScrollView = findViewById(R.id.nested_scroll_view);
        if (slidingPaneLayout != null) {
            slidingPaneLayout.setScrollableView(nestedScrollView);
        }
        rlPanorama = findViewById(R.id.rl_panorama);
        rlPanorama.setOnClickListener(this::onClick);
        ivPanorama = findViewById(R.id.iv_panorama);
        tvPanorama = findViewById(R.id.tv_panorama);
        rlCoding = findViewById(R.id.rl_coding);
        rlCoding.setOnClickListener(this::onClick);
        ivCoding = findViewById(R.id.iv_coding);
        tvCoding = findViewById(R.id.tv_coding);
        rlEquipment = findViewById(R.id.rl_equipment);
        rlEquipment.setOnClickListener(this::onClick);
        ivEquipment = findViewById(R.id.iv_equipment);
        tvEquipment = findViewById(R.id.tv_equipment);
        rlFacility = findViewById(R.id.rl_facility);
        rlFacility.setOnClickListener(this::onClick);
        ivFacility = findViewById(R.id.iv_facility);
        tvFacility = findViewById(R.id.tv_facility);
        rlUsable = findViewById(R.id.rl_usable);
        rlUsable.setOnClickListener(this::onClick);
        ivUsable = findViewById(R.id.iv_usable);
        tvUsable = findViewById(R.id.tv_usable);
        rlAvailable = findViewById(R.id.rl_available);
        rlAvailable.setOnClickListener(this::onClick);
        ivAvailable = findViewById(R.id.iv_available);
        tvAvailable = findViewById(R.id.tv_available);
        rlParking = findViewById(R.id.rl_parking);
        rlParking.setOnClickListener(this::onClick);
        ivParking = findViewById(R.id.iv_parking);
        tvParking = findViewById(R.id.tv_parking);
        rlNumber = findViewById(R.id.rl_number);
        rlNumber.setOnClickListener(this::onClick);
        ivNumber = findViewById(R.id.iv_number);
        tvNumber = findViewById(R.id.tv_number);
        rlScutcheon = findViewById(R.id.rl_scutcheon);
        rlScutcheon.setOnClickListener(this::onClick);
        ivScutcheon = findViewById(R.id.iv_scutcheon);
        tvScutcheon = findViewById(R.id.tv_scutcheon);
        rlDevice = findViewById(R.id.rl_device);
        rlDevice.setOnClickListener(this::onClick);
        ivDevice = findViewById(R.id.iv_device);
        tvDevice = findViewById(R.id.tv_device);
        editDescribe = findViewById(R.id.edit_describe);
        btnSaveLocal = findViewById(R.id.btn_save_local);
        btnSaveLocal.setOnClickListener(this::onClick);
        //展示数据
        initShowPileSharePre();
        onLongDelPic();
    }

    private void onLongDelPic() {
        rlAvailable.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE;
                MessageDialog.show((AppCompatActivity) getContext(), "提示", "是否删除", "确定", "取消").setOkButton(new OnDialogButtonClickListener() {
                    @Override
                    public boolean onClick(BaseDialog baseDialog, View v) {
                        ivAvailable.setImageDrawable(null);
                        return false;
                    }
                });
                return false;
            }
        });
        rlUsable.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE;
                MessageDialog.show((AppCompatActivity) getContext(), "提示", "是否删除", "确定", "取消").setOkButton(new OnDialogButtonClickListener() {
                    @Override
                    public boolean onClick(BaseDialog baseDialog, View v) {
                        ivUsable.setImageDrawable(null);
                        return false;
                    }
                });
                return false;
            }
        });
        rlScutcheon.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE;
                MessageDialog.show((AppCompatActivity) getContext(), "提示", "是否删除", "确定", "取消").setOkButton(new OnDialogButtonClickListener() {
                    @Override
                    public boolean onClick(BaseDialog baseDialog, View v) {
                        ivScutcheon.setImageDrawable(null);
                        return false;
                    }
                });
                return false;
            }
        });
        rlParking.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE;
                MessageDialog.show((AppCompatActivity) getContext(), "提示", "是否删除", "确定", "取消").setOkButton(new OnDialogButtonClickListener() {
                    @Override
                    public boolean onClick(BaseDialog baseDialog, View v) {
                        ivParking.setImageDrawable(null);
                        return false;
                    }
                });
                return false;
            }
        });
        rlPanorama.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE;
                MessageDialog.show((AppCompatActivity) getContext(), "提示", "是否删除", "确定", "取消").setOkButton(new OnDialogButtonClickListener() {
                    @Override
                    public boolean onClick(BaseDialog baseDialog, View v) {
                        ivPanorama.setImageDrawable(null);
                        return false;
                    }
                });
                return false;
            }
        });
        rlNumber.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE;
                MessageDialog.show((AppCompatActivity) getContext(), "提示", "是否删除", "确定", "取消").setOkButton(new OnDialogButtonClickListener() {
                    @Override
                    public boolean onClick(BaseDialog baseDialog, View v) {
                        ivNumber.setImageDrawable(null);
                        return false;
                    }
                });
                return false;
            }
        });
        rlFacility.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE;
                MessageDialog.show((AppCompatActivity) getContext(), "提示", "是否删除", "确定", "取消").setOkButton(new OnDialogButtonClickListener() {
                    @Override
                    public boolean onClick(BaseDialog baseDialog, View v) {
                        ivFacility.setImageDrawable(null);
                        return false;
                    }
                });
                return false;
            }
        });
        rlEquipment.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE;
                MessageDialog.show((AppCompatActivity) getContext(), "提示", "是否删除", "确定", "取消").setOkButton(new OnDialogButtonClickListener() {
                    @Override
                    public boolean onClick(BaseDialog baseDialog, View v) {
                        ivEquipment.setImageDrawable(null);
                        return false;
                    }
                });
                return false;
            }
        });
        rlDevice.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE;
                MessageDialog.show((AppCompatActivity) getContext(), "提示", "是否删除", "确定", "取消").setOkButton(new OnDialogButtonClickListener() {
                    @Override
                    public boolean onClick(BaseDialog baseDialog, View v) {
                        ivDevice.setImageDrawable(null);
                        return false;
                    }
                });
                return false;
            }
        });
        rlCoding.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE;
                MessageDialog.show((AppCompatActivity) getContext(), "提示", "是否删除", "确定", "取消").setOkButton(new OnDialogButtonClickListener() {
                    @Override
                    public boolean onClick(BaseDialog baseDialog, View v) {
                        ivCoding.setImageDrawable(null);
                        return false;
                    }
                });
                return false;
            }
        });
    }

    private void initShowPileSharePre() {
        station = getArguments().getString("station");
        if (station != null) {
            PoiEntity showPoiEntity = new Gson().fromJson(station, PoiEntity.class);
            pid = showPoiEntity.getId();
            taskId = showPoiEntity.getTaskId();
        }
        // 添加信息：
        chargingPileEntity = (ChargingPileEntity) getArguments().getSerializable("chargingPileEntity");
        if (chargingPileEntity != null) {
            String name = chargingPileEntity.getName();//名称
            if (name != null) {
                tvNameContent.setText(name + "");
            }

            String p = chargingPileEntity.getP();
            if (p != null) {
                // 解密geo
                String decodeGeometry = Geohash.getInstance().decode(p);
                latLng = GeometryTools.createLatLng(decodeGeometry);
                BitmapDescriptor pileDescriptor = BitmapDescriptorFactory.fromResource(R.mipmap.datouzhen);
                markerPile = tencentMap.addMarker(new MarkerOptions(latLng).icon(pileDescriptor).anchor(0.5f,1.0f));
                markerPile.setZIndex(4);
                moveLatlng(latLng, null);
            }
            String memo = chargingPileEntity.getMemo();
            if (memo != null && !memo.equals("")) {
                editDescribe.setText(memo);
            }
            String fid = chargingPileEntity.getFid();
            if (fid != null) {
                pid = fid;
            }
            int sign_exist = chargingPileEntity.getSign_exist();
            spinnerScutcheon.setSelection(sign_exist, true);
            if (sign_exist == 0) {
                rlFacility.setBackgroundColor(Color.parseColor("#EFEDED"));
                rlScutcheon.setVisibility(View.GONE);
                rlDevice.setVisibility(View.GONE);
            } else if (sign_exist == 1) {
                rlFacility.setBackgroundColor(Color.parseColor("#03A9F4"));
                rlScutcheon.setVisibility(View.VISIBLE);
                rlDevice.setVisibility(View.VISIBLE);
            }
            int cp_availableState = chargingPileEntity.getCp_availableState();
            spinnerStake.setSelection(cp_availableState, true);
            String cp_openType = chargingPileEntity.getCp_openType();
            if (cp_openType!=null&&!cp_openType.equals("")){
                String[] split = cp_openType.split(",");
                for (int i = 0; i < split.length; i++) {
                    if (Integer.valueOf(split[i])==1){
                        checkButton1.setChecked(true);
                    }else if (Integer.valueOf(split[i])==2){
                        checkButton2.setChecked(true);
                    }else if (Integer.valueOf(split[i])==3){
                        checkButton3.setChecked(true);
                    }else if (Integer.valueOf(split[i])==4){
                        checkButton4.setChecked(true);
                    }else if (Integer.valueOf(split[i])==5){
                        checkButton5.setChecked(true);
                    }
                }
            }
            int cp_floor = chargingPileEntity.getCp_floor();
            //"地上五层", "地上四层", "地上三层", "地上二层", "地上一层", "地下一层", "地下二层", "地下三层", "地下四层", "地下五层"};
            if (cp_floor==0){
                spinnerType.setSelection(4, true);
            }else if (cp_floor==1){
                spinnerType.setSelection(4, true);
            }else if (cp_floor==2){
                spinnerType.setSelection(3, true);
            }else if (cp_floor==3){
                spinnerType.setSelection(2, true);
            }else if (cp_floor==4){
                spinnerType.setSelection(1, true);
            }else if (cp_floor==5){
                spinnerType.setSelection(0, true);
            }else if (cp_floor==-1){
                spinnerType.setSelection(5, true);
            }else if (cp_floor==-2){
                spinnerType.setSelection(6, true);
            }else if (cp_floor==-3){
                spinnerType.setSelection(7, true);
            }else if (cp_floor==-4){
                spinnerType.setSelection(8, true);
            }else if (cp_floor==-5){
                spinnerType.setSelection(9, true);
            }
            if (chargingPileEntity.getPhotos() != null) {
                ArrayList<String> cList = new ArrayList<>();
                ArrayList<String> dList = new ArrayList<>();
                ArrayList<String> eList = new ArrayList<>();
                for (int i = 0; i < chargingPileEntity.getPhotos().size(); i++) {
                    String photo = chargingPileEntity.getPhotos().get(i);
                    String[] split = photo.split("/");
                    if (split[split.length - 1].startsWith("a")) {
                        Glide.with(getActivity()).load(photo).into(ivPanorama);
                        tvPanorama.setTag(photo);
                    } else if (split[split.length - 1].startsWith("b")) {
                        Glide.with(getActivity()).load(photo).into(ivCoding);
                        tvCoding.setTag(photo);
                    } else if (split[split.length - 1].startsWith("c")) {
                        cList.add(photo);
                    } else if (split[split.length - 1].startsWith("d")) {
                        dList.add(photo);
                    } else if (split[split.length - 1].startsWith("e")) {
                        eList.add(photo);
                    }
                }
                setCList(cList);
                setDList(dList);
                setEList(eList);
            }
        }
    }



 /*   private void initPileMarker(LatLng latLng) {
        BitmapDescriptor pileDescriptor = BitmapDescriptorFactory.fromResource(R.mipmap.datouzhen);
        if (markerPile == null) {
            markerPile = tencentMap.addMarker(new MarkerOptions(latLng).icon(pileDescriptor));
            markerPile.setZIndex(MARKER_BIG);
        }

        CameraUpdate cameraSigma = CameraUpdateFactory.newCameraPosition(new CameraPosition(
                latLng, //中心点坐标，地图目标经纬度
                tencentMap.getCameraPosition().zoom,  //目标缩放级别
                tencentMap.getCameraPosition().tilt, //目标倾斜角[0.0 ~ 45.0] (垂直地图时为0)
                tencentMap.getCameraPosition().bearing)); //目标旋转角 0~360° (正北方为0)
        tencentMap.animateCamera(cameraSigma, new TencentMap.CancelableCallback() {
            @Override
            public void onFinish() {
                screenPilePositions = tencentMap.getProjection().toScreenLocation(latLng);
                sliding_layout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
                //创建Marker对象之前，设置属性
                if (markerPile != null) {
                    markerPile.setFixingPoint(screenPosition.x, screenPosition.y);
                }
            }

            @Override
            public void onCancel() {
            }
        });
    }

    private void initCheckedPileMarker(int poiWord) {
        if (screenPilePositions != null) {
            sliding_layout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
            LatLng latLng = tencentMap.getProjection().fromScreenLocation(screenPilePositions);
            markerPile.setPosition(latLng);
            markerPile.setFixingPointEnable(false);
            Constant.markerLatlng = latLng;
            Message obtain = Message.obtain();
            obtain.what = poiWord;
            obtain.obj = latLng;
            EventBus.getDefault().post(obtain);
        }
    }*/

    public void setCList(ArrayList<String> list) {
        switch (list.size()) {
            case 1:
                Glide.with(getActivity()).load(list.get(0)).into(ivEquipment);
                tvEquipment.setTag(list.get(0));
                break;
            case 2:
                Glide.with(getActivity()).load(list.get(0)).into(ivEquipment);
                tvEquipment.setTag(list.get(0));
                Glide.with(getActivity()).load(list.get(1)).into(ivFacility);
                tvFacility.setTag(list.get(1));
                break;
            case 3:
                Glide.with(getActivity()).load(list.get(0)).into(ivEquipment);
                tvEquipment.setTag(list.get(0));
                Glide.with(getActivity()).load(list.get(1)).into(ivFacility);
                tvFacility.setTag(list.get(1));
                Glide.with(getActivity()).load(list.get(2)).into(ivScutcheon);
                tvScutcheon.setTag(list.get(2));
                break;
            case 4:
                Glide.with(getActivity()).load(list.get(0)).into(ivEquipment);
                tvEquipment.setTag(list.get(0));
                Glide.with(getActivity()).load(list.get(1)).into(ivFacility);
                tvFacility.setTag(list.get(1));
                Glide.with(getActivity()).load(list.get(2)).into(ivScutcheon);
                tvScutcheon.setTag(list.get(2));
                Glide.with(getActivity()).load(list.get(3)).into(ivDevice);
                tvDevice.setTag(list.get(3));
                break;
        }
    }

    public void setDList(ArrayList<String> list) {
        switch (list.size()) {
            case 1:
                Glide.with(getActivity()).load(list.get(0)).into(ivUsable);
                tvUsable.setTag(list.get(0));
                break;
            case 2:
                Glide.with(getActivity()).load(list.get(0)).into(ivUsable);
                tvUsable.setTag(list.get(0));
                Glide.with(getActivity()).load(list.get(1)).into(ivAvailable);
                tvAvailable.setTag(list.get(1));
                break;
        }
    }

    public void setEList(ArrayList<String> list) {
        switch (list.size()) {
            case 1:
                Glide.with(getActivity()).load(list.get(0)).into(ivParking);
                tvParking.setTag(list.get(0));
                break;
            case 2:
                Glide.with(getActivity()).load(list.get(0)).into(ivParking);
                tvParking.setTag(list.get(0));
                Glide.with(getActivity()).load(list.get(1)).into(ivNumber);
                tvNumber.setTag(list.get(1));
                break;
        }
    }


    //禁用所有可操作性控件
    private void disables() {
        checkBoxLife.setEnabled(false);
        tvNameContent.setEnabled(false);
        checkButton1.setEnabled(false);//开放状态1
        checkButton2.setEnabled(false);//开放状态2
        checkButton3.setEnabled(false);//开放状态3
        checkButton4.setEnabled(false);//开放状态4
        checkButton5.setEnabled(false);//开放状态5
        spinnerType.setEnabled(false);//充电地面层
        rlPanorama.setEnabled(false);//全景照片
        rlCoding.setEnabled(false);//充电桩编码
        spinnerScutcheon.setEnabled(false);//设备标牌下拉框
        rlEquipment.setEnabled(false);//(蓝色色)设备标牌
        rlFacility.setEnabled(false);//(白色)设备标牌
        spinnerStake.setEnabled(false);//桩可用状态
        rlUsable.setEnabled(false);//(蓝色)可用状态
        rlAvailable.setEnabled(false);//(白色)可用状态
        rlParking.setEnabled(false);//(蓝色)停车位编号
        rlNumber.setEnabled(false);//(白色)停车位编号
        editDescribe.setEnabled(false);//任务描述
        btnSaveLocal.setEnabled(false);//保存
    }

    @Override
    protected void initData() {
        super.initData();
    }


    @Subscribe
    public void onEvent(Message data) {
        if (data.what == Constant.CHARGING_PILE_WORD) {
            latLng = (LatLng) data.obj;
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_save_local:
                XXPermissions.with(this)
                        //读写权限
                        .permission(Permission.MANAGE_EXTERNAL_STORAGE)
                        .request(new OnPermissionCallback() {
                            @Override
                            public void onGranted(List<String> permissions, boolean all) {
                                if (all) {
                                    //保存数据库：
                                    chargingPileEntity = initChargingPileEntityByUI(chargingPileEntity);
                                    PoiCheckResult poiCheckResult = checkChargingPileEntity(chargingPileEntity);
                                    if (poiCheckResult.getCode() == 1) {
                                        Toast.makeText(getActivity(), poiCheckResult.getMsg() + "", Toast.LENGTH_SHORT).show();
                                        return;
                                    }
                                    new Thread(new Runnable() {
                                        @Override
                                        public void run() {
                                            long[] result = InsertAndUpdateUtils.getInstance().insertOrUpdateChargingPile(getActivity(), chargingPileEntity);
                                            getActivity().runOnUiThread(new Runnable() {
                                                @Override
                                                public void run() {
                                                    if (result[0] != 0) {
                                                        chargingPileEntity.setPileId(result[0]);
                                                        ToastUtil.showShort(getActivity(), "充电桩保存成功");
                                                        Message obtain = Message.obtain();
                                                        obtain.what = Constant.CHARGING_PILE_STATION;
                                                        obtain.obj = chargingPileEntity;
                                                        EventBus.getDefault().post(obtain);

                                                        Message obtains = Message.obtain();
                                                        obtains.what = Constant.PILE_MARKER_SHOW;
                                                        obtains.obj = true;
                                                        EventBus.getDefault().post(obtains);
//                                    chargingPileByWork(chargingPileEntity);
                                                        getActivity().onBackPressed();
                                                    } else {
                                                        ToastUtil.showShort(getActivity(), "充电桩保存失败，请重试！");
                                                    }

                                                }
                                            });
                                        }
                                    }).start();

                                } else {
                                    Toast.makeText(getActivity(), "没有申请权限，请手动申请", Toast.LENGTH_SHORT).show();
                                }
                            }

                            @Override
                            public void onDenied(List<String> permissions, boolean never) {
                                if (never) {
                                    Toast.makeText(getActivity(), "被永久拒绝授权，请手动授予权限", Toast.LENGTH_SHORT).show();
                                    // 如果是被永久拒绝就跳转到应用权限系统设置页面
                                    XXPermissions.startPermissionActivity(getActivity(), permissions);
                                }
                            }
                        });
                break;
            case R.id.rl_panorama:
                Intent intentPanorama = new Intent("android.media.action.IMAGE_CAPTURE");
                file = PhotoUtils.showPhotoFile("a", latLng);
                intentPanorama.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
                startActivityForResult(intentPanorama, 101);
                break;
            case R.id.rl_coding:
                Intent intentCoding = new Intent("android.media.action.IMAGE_CAPTURE");
                file = PhotoUtils.showPhotoFile("b", latLng);
                intentCoding.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
                startActivityForResult(intentCoding, 102);
                break;
            case R.id.rl_equipment:
                Intent intentEquipment = new Intent("android.media.action.IMAGE_CAPTURE");
                file = PhotoUtils.showPhotoFile("c", latLng);
                intentEquipment.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
                startActivityForResult(intentEquipment, 103);

                break;
            case R.id.rl_facility:
                Intent intentFacility = new Intent("android.media.action.IMAGE_CAPTURE");
                file = PhotoUtils.showPhotoFile("c", latLng);
                intentFacility.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
                startActivityForResult(intentFacility, 104);
                break;
            case R.id.rl_scutcheon:
                Intent intentScutcheon = new Intent("android.media.action.IMAGE_CAPTURE");
                file = PhotoUtils.showPhotoFile("c", latLng);
                intentScutcheon.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
                startActivityForResult(intentScutcheon, 105);
                break;
            case R.id.rl_device:
                Intent intentDevice = new Intent("android.media.action.IMAGE_CAPTURE");
                file = PhotoUtils.showPhotoFile("c", latLng);
                intentDevice.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
                startActivityForResult(intentDevice, 106);
                break;
            case R.id.rl_usable:
                Intent intentUsable = new Intent("android.media.action.IMAGE_CAPTURE");
                file = PhotoUtils.showPhotoFile("d", latLng);
                intentUsable.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
                startActivityForResult(intentUsable, 107);
                break;
            case R.id.rl_available:
                Intent intentAvailable = new Intent("android.media.action.IMAGE_CAPTURE");
                file = PhotoUtils.showPhotoFile("d", latLng);
                intentAvailable.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
                startActivityForResult(intentAvailable, 108);
                break;
            case R.id.rl_parking:
                Intent intentParking = new Intent("android.media.action.IMAGE_CAPTURE");
                file = PhotoUtils.showPhotoFile("e", latLng);
                intentParking.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
                startActivityForResult(intentParking, 109);
                break;
            case R.id.rl_number:
                Intent intentNumber = new Intent("android.media.action.IMAGE_CAPTURE");
                file = PhotoUtils.showPhotoFile("e", latLng);
                intentNumber.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
                startActivityForResult(intentNumber, 110);
                break;

        }
    }

//    private void chargingPileByWork(ChargingPileEntity chargingPileEntity) {
//        showLoadingDialog();
//        HttpParams httpParams = new HttpParams();
//        httpParams.put("taskId", taskId);
//        httpParams.put("name", chargingPileEntity.getName());
//        httpParams.put("existence", chargingPileEntity.getExist());
//        httpParams.put("geo", chargingPileEntity.getP());
//        httpParams.put("memo", chargingPileEntity.getMemo());
//        httpParams.put("ffid", chargingPileEntity.getFid());
//        HashMap<String, Object> hashMap = new HashMap<>();
//        hashMap.put("cp_openType",chargingPileEntity.getCp_openType());
//        hashMap.put("cp_floor",chargingPileEntity.getCp_floor());
//        hashMap.put("cp_availableState",chargingPileEntity.getCp_availableState());
//        hashMap.put("sign_exist",chargingPileEntity.getSign_exist());
//        httpParams.put("detail", String.valueOf(hashMap));
//        OkGoBuilder.getInstance()
//                .Builder(getActivity())
//                .url(HttpInterface.SUBMIT_CSTASK)
//                .method(OkGoBuilder.GET)
//                .cls(ChargingPileSaveBean.class)
//                .params(httpParams)
//                .callback(new Callback<ChargingPileSaveBean>() {
//                    @Override
//                    public void onSuccess(ChargingPileSaveBean chargingPileSaveBean, int id) {
//                        dismissLoadingDialog();
//                        chargingPileBody = chargingPileSaveBean.getBody();
//                        Toast.makeText(getActivity(), "保存成功", Toast.LENGTH_SHORT).show();
//                        Log.d("TAG", "onSuccess: " + chargingPileSaveBean.getBody());
//                        phoneList();
//                        Message obtain = Message.obtain();
//                        obtain.what = Constant.CHARGING_PILE_BODY;
//                        obtain.obj = chargingPileBody;
//                        EventBus.getDefault().post(obtain);
//
//                        Message obtain1 = Message.obtain();
//                        obtain1.what = Constant.CHARGING_PILE_PHOTO;
//                        obtain1.obj = phoneLists;
//                        EventBus.getDefault().post(obtain1);
//                        getActivity().onBackPressed();
//
//                    }
//
//                    @Override
//                    public void onError(Throwable e, int id) {
//                        dismissLoadingDialog();
//                        Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
//                        Log.d("TAG", "onError: " + e.getMessage());
//                    }
//                }).build();
//    }


    @Override
    public void onSaveInstanceState(@NonNull Bundle outState) {
        super.onSaveInstanceState(outState);
        initPileSharePre();
    }

    /**
     * 防止当页面崩溃后出现数据丢失
     */
    public void initPileSharePre() {
        //获取SharedPreferences对象，方法中两个参数的意思为：第一个name
        //表示文件名，系统将会在/dada/dada/包名/shared_prefs目录下生成
        //一个以该参数命名的.xml文件。第二个mode表示创建的模式，通过查看
        //方法注释得知，建议以0或者MODE_PRIVATE为默认值。
        SharedPreferences poi = getActivity().getSharedPreferences(Constant.DATA_FILE, 0);
        //获取Editor对象
        SharedPreferences.Editor edit = poi.edit();
        //根据要保存的数据的类型，调用对应的put方法,
        ChargingPileEntity chargingPileEntity = initChargingPileEntityByUI(new ChargingPileEntity());
        String newChargingPileEntity = new Gson().toJson(chargingPileEntity);
        //以键值对的形式添加新值。
        edit.putString("chargingPileEntity", newChargingPileEntity);
        if (station != null) {
            edit.putString("poiEntity", station);
        }
        //提交新值。必须执行，否则前面的操作都无效。
        edit.commit();
        Log.d("TAG", "initPileSharePre: " + newChargingPileEntity);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 101 && resultCode == RESULT_OK) {
            if (file == null || !file.exists()) {
                Toast.makeText(getActivity(), "没有拍摄照片", Toast.LENGTH_SHORT).show();
                return;

            } else {
                String s = PhotoUtils.showPhotoAndGetPath(file, ivPanorama);
                tvPanorama.setTag(s);
            }
            file = null;
           /* int height = bitmap.getHeight();
            int width = bitmap.getWidth();
            if (height > width) {
                DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE;
                MessageDialog.show((AppCompatActivity) getContext(), "提示", "请重新拍照，要求横屏拍照", "确定").setOkButton(new OnDialogButtonClickListener() {
                    @Override
                    public boolean onClick(BaseDialog baseDialog, View v) {
                        Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
                        startActivityForResult(intent, 101);
                        return false;
                    }
                });
            } else {

            }*/
        } else if (requestCode == 102 && resultCode == RESULT_OK) {
            if (file == null || !file.exists()) {
                Toast.makeText(getActivity(), "没有拍摄照片", Toast.LENGTH_SHORT).show();
                return;

            } else {
                String s = PhotoUtils.showPhotoAndGetPath(file, ivCoding);
                tvCoding.setTag(s);
            }
            file = null;
           /* int height = bitmap.getHeight();
            int width = bitmap.getWidth();
            if (height > width) {
                DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE;
                MessageDialog.show((AppCompatActivity) getContext(), "提示", "请重新拍照，要求横屏拍照", "确定").setOkButton(new OnDialogButtonClickListener() {
                    @Override
                    public boolean onClick(BaseDialog baseDialog, View v) {
                        Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
                        startActivityForResult(intent, 102);
                        return false;
                    }
                });
            } else {

            }*/
        } else if (requestCode == 103 && resultCode == RESULT_OK) {
            if (file == null || !file.exists()) {
                Toast.makeText(getActivity(), "没有拍摄照片", Toast.LENGTH_SHORT).show();
                return;

            } else {
                String s = PhotoUtils.showPhotoAndGetPath(file, ivEquipment);
                tvEquipment.setTag(s);
            }
            file = null;

          /*  int height = bitmap.getHeight();
            int width = bitmap.getWidth();
            if (height > width) {
                DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE;
                MessageDialog.show((AppCompatActivity) getContext(), "提示", "请重新拍照，要求横屏拍照", "确定").setOkButton(new OnDialogButtonClickListener() {
                    @Override
                    public boolean onClick(BaseDialog baseDialog, View v) {
                        Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
                        startActivityForResult(intent, 103);
                        return false;
                    }
                });
            } else {

            }*/
        } else if (requestCode == 104 && resultCode == RESULT_OK) {
            if (file == null || !file.exists()) {
                Toast.makeText(getActivity(), "没有拍摄照片", Toast.LENGTH_SHORT).show();
                return;

            } else {
                String s = PhotoUtils.showPhotoAndGetPath(file, ivFacility);
                tvFacility.setTag(s);
            }
            file = null;
           /* int height = bitmap.getHeight();
            int width = bitmap.getWidth();
            if (height > width) {
                DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE;
                MessageDialog.show((AppCompatActivity) getContext(), "提示", "请重新拍照，要求横屏拍照", "确定").setOkButton(new OnDialogButtonClickListener() {
                    @Override
                    public boolean onClick(BaseDialog baseDialog, View v) {
                        Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
                        startActivityForResult(intent, 104);
                        return false;
                    }
                });
            } else {

            }*/
        } else if (requestCode == 105 && resultCode == RESULT_OK) {
            if (file == null || !file.exists()) {
                Toast.makeText(getActivity(), "没有拍摄照片", Toast.LENGTH_SHORT).show();
                return;

            } else {
                String s = PhotoUtils.showPhotoAndGetPath(file, ivScutcheon);
                tvScutcheon.setTag(s);
            }
            file = null;

           /* int height = bitmap.getHeight();
            int width = bitmap.getWidth();
            if (height > width) {
                DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE;
                MessageDialog.show((AppCompatActivity) getContext(), "提示", "请重新拍照，要求横屏拍照", "确定").setOkButton(new OnDialogButtonClickListener() {
                    @Override
                    public boolean onClick(BaseDialog baseDialog, View v) {
                        Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
                        startActivityForResult(intent, 105);
                        return false;
                    }
                });
            } else {

            }*/
        } else if (requestCode == 106 && resultCode == RESULT_OK) {
            if (file == null || !file.exists()) {
                Toast.makeText(getActivity(), "没有拍摄照片", Toast.LENGTH_SHORT).show();
                return;

            } else {
                String s = PhotoUtils.showPhotoAndGetPath(file, ivDevice);
                tvDevice.setTag(s);
            }

            file = null;
          /*  int height = bitmap.getHeight();
            int width = bitmap.getWidth();
            if (height > width) {
                DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE;
                MessageDialog.show((AppCompatActivity) getContext(), "提示", "请重新拍照，要求横屏拍照", "确定").setOkButton(new OnDialogButtonClickListener() {
                    @Override
                    public boolean onClick(BaseDialog baseDialog, View v) {
                        Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
                        startActivityForResult(intent, 106);
                        return false;
                    }
                });
            } else {

            }*/
        } else if (requestCode == 107 && resultCode == RESULT_OK) {
            if (file == null || !file.exists()) {
                Toast.makeText(getActivity(), "没有拍摄照片", Toast.LENGTH_SHORT).show();
                return;

            } else {
                String s = PhotoUtils.showPhotoAndGetPath(file, ivUsable);
                tvUsable.setTag(s);
            }
            file = null;
           /* int height = bitmap.getHeight();
            int width = bitmap.getWidth();
            if (height > width) {
                DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE;
                MessageDialog.show((AppCompatActivity) getContext(), "提示", "请重新拍照，要求横屏拍照", "确定").setOkButton(new OnDialogButtonClickListener() {
                    @Override
                    public boolean onClick(BaseDialog baseDialog, View v) {
                        Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
                        startActivityForResult(intent, 107);
                        return false;
                    }
                });
            } else {

            }*/
        } else if (requestCode == 108 && resultCode == RESULT_OK) {
            if (file == null || !file.exists()) {
                Toast.makeText(getActivity(), "没有拍摄照片", Toast.LENGTH_SHORT).show();
                return;

            } else {
                String s = PhotoUtils.showPhotoAndGetPath(file, ivAvailable);
                tvAvailable.setTag(s);
            }
            file = null;
           /* int height = bitmap.getHeight();
            int width = bitmap.getWidth();
            if (height > width) {
                DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE;
                MessageDialog.show((AppCompatActivity) getContext(), "提示", "请重新拍照，要求横屏拍照", "确定").setOkButton(new OnDialogButtonClickListener() {
                    @Override
                    public boolean onClick(BaseDialog baseDialog, View v) {
                        Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
                        startActivityForResult(intent, 108);
                        return false;
                    }
                });
            } else {

            }*/
        } else if (requestCode == 109 && resultCode == RESULT_OK) {
            if (file == null || !file.exists()) {
                Toast.makeText(getActivity(), "没有拍摄照片", Toast.LENGTH_SHORT).show();
                return;

            } else {
                String s = PhotoUtils.showPhotoAndGetPath(file, ivParking);
                tvParking.setTag(s);
            }
            file = null;
           /* int height = bitmap.getHeight();
            int width = bitmap.getWidth();
            if (height > width) {
                DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE;
                MessageDialog.show((AppCompatActivity) getContext(), "提示", "请重新拍照，要求横屏拍照", "确定").setOkButton(new OnDialogButtonClickListener() {
                    @Override
                    public boolean onClick(BaseDialog baseDialog, View v) {
                        Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
                        startActivityForResult(intent, 109);
                        return false;
                    }
                });
            } else {

            }*/
        } else if (requestCode == 110 && resultCode == RESULT_OK) {
            if (file == null || !file.exists()) {
                Toast.makeText(getActivity(), "没有拍摄照片", Toast.LENGTH_SHORT).show();
                return;

            } else {
                String s = PhotoUtils.showPhotoAndGetPath(file, ivNumber);
                tvNumber.setTag(s);
            }
            file = null;
/*            int height = bitmap.getHeight();
            int width = bitmap.getWidth();
            if (height > width) {
                DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE;
                MessageDialog.show((AppCompatActivity) getContext(), "提示", "请重新拍照，要求横屏拍照", "确定").setOkButton(new OnDialogButtonClickListener() {
                    @Override
                    public boolean onClick(BaseDialog baseDialog, View v) {
                        Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
                        startActivityForResult(intent, 110);
                        return false;
                    }
                });
            } else {

            }*/
        }
    }


    @Override
    public void onDestroy() {
        if (EventBus.getDefault().isRegistered(this))//加上判断
            EventBus.getDefault().unregister(this);
        super.onDestroy();
        if (markerPile!=null){
            markerPile.remove();
        }
    }


    @Override
    protected ChargingPileEntity initChargingPileEntityByUI(ChargingPileEntity chargingPileEntity) {
        ArrayList<String> photo = new ArrayList<>();
        if (latLng != null) {
            String encode = Geohash.getInstance().encode(latLng.latitude, latLng.longitude);
            chargingPileEntity.setP(encode);
        }
        String name = tvNameContent.getText().toString().trim();//名称
        if (name != null && !name.equals("")) {
            chargingPileEntity.setName(name);
        }
        if (cp_floor != 0) {
            chargingPileEntity.setCp_floor(cp_floor);
        }
        String tagPanorama = (String) tvPanorama.getTag();
        if (tagPanorama != null && !tagPanorama.equals("")) {
            photo.add(tagPanorama);
        }
        String tagCoding = (String) tvCoding.getTag();
        if (tagCoding != null && !tagCoding.equals("")) {
            photo.add(tagCoding);
        }
        String tagEquipment = (String) tvEquipment.getTag();
        if (tagEquipment != null && !tagEquipment.equals("")) {
            photo.add(tagEquipment);
        }
        String tagFacility = (String) tvFacility.getTag();
        if (tagFacility != null && !tagFacility.equals("")) {
            photo.add(tagFacility);
        }
        String tagScutcheon = (String) tvScutcheon.getTag();
        if (tagScutcheon != null && !tagScutcheon.equals("")) {
            photo.add(tagScutcheon);
        }
        String tagDevice = (String) tvDevice.getTag();
        if (tagDevice != null && !tagDevice.equals("")) {
            photo.add(tagDevice);
        }
        String tagUsable = (String) tvUsable.getTag();
        if (tagUsable != null && !tagUsable.equals("")) {
            photo.add(tagUsable);
        }
        String tagAvailable = (String) tvAvailable.getTag();
        if (tagAvailable != null && !tagAvailable.equals("")) {
            photo.add(tagAvailable);
        }
        String tagParking = (String) tvParking.getTag();
        if (tagParking != null && !tagParking.equals("")) {
            photo.add(tagParking);
        }
        String tagNumber = (String) tvNumber.getTag();
        if (tagNumber != null && !tagNumber.equals("")) {
            photo.add(tagNumber);
        }
        chargingPileEntity.setPhotos(photo);
        chargingPileEntity.setSign_exist(sign_exist);
        chargingPileEntity.setCp_availableState(cp_availableState);
        String describe = editDescribe.getText().toString().trim();
        if (describe != null && !describe.equals("")) {
            chargingPileEntity.setMemo(describe);
        }
        if (pid != null) {
            chargingPileEntity.setFid(pid);
        }
        if (buffer1 != null && !buffer1.equals("")) {
            chargingPileEntity.setCp_openType(buffer1);
        } else {
            openType.reverse();
            openType.append(buffer2);
            openType.append(buffer3);
            openType.append(buffer4);
            openType.append(buffer5);
            if (openType != null && !"".equals(openType) && openType.length() > 0) {
                String charAt = openType.deleteCharAt(openType.length() - 1).toString();
                chargingPileEntity.setCp_openType(charAt);
            } else {
                chargingPileEntity.setCp_openType("");
            }
        }
        return chargingPileEntity;
    }

    @Override
    protected PoiCheckResult checkChargingPileEntity(ChargingPileEntity entity) {
        PoiCheckResult poiCheckResult = new PoiCheckResult();
        if (entity.getP() == null) {
            poiCheckResult.setCode(1);
            poiCheckResult.setMsg("请确定点位");
            return poiCheckResult;
        }
        if (entity.getName() == null) {
            poiCheckResult.setCode(1);
            poiCheckResult.setMsg("请输入 名称");
            return poiCheckResult;
        }
        if (entity.getCp_openType() == null) {
            poiCheckResult.setCode(1);
            poiCheckResult.setMsg("开放状态未勾选");
            return poiCheckResult;
        }
        if (tvPanorama.getTag() == null) {
            poiCheckResult.setCode(1);
            poiCheckResult.setMsg("请拍照 全景图");
            return poiCheckResult;
        }
        if (tvCoding.getTag() == null) {
            poiCheckResult.setCode(1);
            poiCheckResult.setMsg("请拍照 充电桩编码");
            return poiCheckResult;
        }
        if (tvEquipment.getTag() == null) {
            poiCheckResult.setCode(1);
            poiCheckResult.setMsg("请拍照 设备标牌");
            return poiCheckResult;
        }
        if (sign_exist != 0) {
            if (tvFacility.getTag() == null) {
                poiCheckResult.setCode(1);
                poiCheckResult.setMsg("请拍照 设备标牌");
                return poiCheckResult;
            }
        }
        if (sign_exist == 1) {
            if (tvScutcheon.getTag() == null) {
                poiCheckResult.setCode(1);
                poiCheckResult.setMsg("请拍照 设备标牌");
                return poiCheckResult;
            }
            if (tvDevice.getTag() == null) {
                poiCheckResult.setCode(1);
                poiCheckResult.setMsg("请拍照 设备标牌");
                return poiCheckResult;
            }
        }
        if (tvUsable.getTag() == null) {
            poiCheckResult.setCode(1);
            poiCheckResult.setMsg("请拍照 可用状态");
            return poiCheckResult;
        }
        if (tvParking.getTag() == null) {
            poiCheckResult.setCode(1);
            poiCheckResult.setMsg("请拍照 停车位编号");
            return poiCheckResult;
        }
        return poiCheckResult;
    }

    @Override
    protected PoiEntity initPoiEntityByUI(PoiEntity entity) {
        return null;
    }

    @Override
    protected PoiCheckResult checkPoiEntity(PoiEntity entity) {
        return null;
    }
}