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.OkGo;
import com.lzy.okgo.model.HttpParams;
import com.lzy.okgo.model.Response;
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.Info;
import com.navinfo.outdoor.bean.OtherUploadPicBean;
import com.navinfo.outdoor.bean.PoiSaveBean;
import com.navinfo.outdoor.bean.PoiUploadBean;
import com.navinfo.outdoor.http.Callback;
import com.navinfo.outdoor.http.DialogCallback;
import com.navinfo.outdoor.http.HttpInterface;
import com.navinfo.outdoor.http.OkGoBuilder;
import com.navinfo.outdoor.room.ChargingPileEntity;
import com.navinfo.outdoor.room.InsertAndUpdateUtils;
import com.navinfo.outdoor.room.PoiDao;
import com.navinfo.outdoor.room.PoiDatabase;
import com.navinfo.outdoor.room.PoiEntity;
import com.navinfo.outdoor.util.Geohash;
import com.navinfo.outdoor.util.PhotoPathUtil;
import com.navinfo.outdoor.util.PhotoUtils;
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.LatLng;
import com.tencent.tencentmap.mapsdk.maps.model.Marker;
import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions;

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

import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import static android.app.Activity.RESULT_OK;

/**
 * 寻宝-上报-其他的fragment
 */
public class OtherFragment extends BaseDrawerFragment implements View.OnClickListener {


    private Spinner spinnerOther;
    String[] others = new String[]{"门牌", "公交", "情报"};//  //门牌:5 公交:6 情报:7 现在其他任务类型里就这三种
    private EditText editTaskName, editOtherDescribe;
    private RelativeLayout rlPicture;
    private ImageView ivPicture;
    private TextView tvPicture;
    private RelativeLayout rlPictures;
    private ImageView ivPictures;
    private TextView tvPictures;
    private Button btnOtherLocal;
    private Button btnOtherUploading;
    private PoiDatabase poiDatabase;
    private PoiDao poiDao;
    private LatLng latLng;
    private int station_type = 5;
    private ArrayList<File> otherUploadList;
    private CheckBox checkPot;
    private File file;
    private NestedScrollView nestedScrollView;
    private Marker markerOther;
    private Point screenOtherPositions;

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

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

    @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.other_header);
        header.findViewById(R.id.iv_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 = isSliding;
                    EventBus.getDefault().post(obtain);
                }
                onBackPressed();
            }
        });
        header.findViewById(R.id.tv_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());
        poiDao = poiDatabase.getPoiDao();
        spinnerOther = findViewById(R.id.spinner_other);
        ArrayAdapter<String> adapterOthers = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, others);
        adapterOthers.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);     //设置下拉列表框的下拉选项样式
        spinnerOther.setAdapter(adapterOthers);
        spinnerOther.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                switch (position) {
                    case 0:
                        station_type = 5;
                        break;
                    case 1:
                        station_type = 6;
                        break;
                    case 2:
                        station_type = 7;
                        break;
                }
            }

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

            }
        });
        checkPot = findViewById(R.id.check_pot);
        checkPot.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    checkPot.setText("保存");
                    checkPot.setTextColor(Color.WHITE);
                    moveLatlng(latLng, new TencentMap.CancelableCallback() {
                        @Override
                        public void onFinish() {
                            screenOtherPositions = tencentMap.getProjection().toScreenLocation(latLng);
                            //创建Marker对象之前，设置属性
                            if (markerOther != null) {
                                markerOther.setFixingPoint(screenOtherPositions.x, screenOtherPositions.y);
                            }
                        }

                        @Override
                        public void onCancel() {
                        }
                    });
                } else {
                    checkPot.setText("编辑");
                    checkPot.setTextColor(Color.BLACK);
                    latLng = tencentMap.getProjection().fromScreenLocation(screenOtherPositions);
                    markerOther.setPosition(latLng);
                    markerOther.setFixingPointEnable(false);
                }
            }
        });
        nestedScrollView = findViewById(R.id.nested_scroll_view);
        if (slidingPaneLayout != null) {
            slidingPaneLayout.setScrollableView(nestedScrollView);
        }
        editTaskName = findViewById(R.id.et_task_name);
        rlPicture = findViewById(R.id.rl_picture);
        rlPicture.setOnClickListener(this::onClick);
        ivPicture = findViewById(R.id.iv_picture);
        tvPicture = findViewById(R.id.tv_picture);
        tvPictures = findViewById(R.id.tv_pictures);
        rlPictures = findViewById(R.id.rl_pictures);
        rlPictures.setOnClickListener(this::onClick);
        ivPictures = findViewById(R.id.iv_pictures);
        editOtherDescribe = findViewById(R.id.edit_other_describe);
        btnOtherLocal = findViewById(R.id.btn_other_local);
        btnOtherLocal.setOnClickListener(this::onClick);
        btnOtherUploading = findViewById(R.id.btn_other_uploading);
        btnOtherUploading.setOnClickListener(this::onClick);
        //数据展示
        initShowPoi();
        //禁用所有操作控件
        //disables();
        //长按刪除
        onLongDelPic();

    }

    private void onLongDelPic() {
        rlPicture.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) {
                        ivPicture.setImageDrawable(null);
                        return false;
                    }
                });
                return false;
            }
        });

        rlPictures.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) {
                        ivPictures.setImageDrawable(null);
                        return false;
                    }
                });
                return false;
            }
        });
    }

    private void disables() {
        spinnerOther.setEnabled(false);
        checkPot.setEnabled(false);
        editTaskName.setEnabled(false);
        rlPicture.setEnabled(false);
        rlPictures.setEnabled(false);
        editOtherDescribe.setEnabled(false);
        btnOtherLocal.setEnabled(false);
    }

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

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

    private void initShowPoi() {
        // 添加信息：
        showPoiEntity = (PoiEntity) getArguments().getSerializable("poiEntity");
        if (showPoiEntity != null) {
            String name = showPoiEntity.getName();//名称
            if (name != null && !name.equals("")) {
                editTaskName.setText(name + "");
            }
            String x = showPoiEntity.getX();
            String y = showPoiEntity.getY();
            if (x != null && y != null) {
                latLng = new LatLng();
                latLng.setLongitude(Double.parseDouble(x));
                latLng.setLatitude(Double.parseDouble(y));
                BitmapDescriptor pileDescriptor = BitmapDescriptorFactory.fromResource(R.mipmap.datouzhen);
                markerOther = tencentMap.addMarker(new MarkerOptions(latLng).icon(pileDescriptor) .anchor(0.5f,1.0f));
                markerOther.setZIndex(4);
                moveLatlng(latLng, null);
            }
            String describe = showPoiEntity.getMemo();//任务描述
            if (describe != null && !describe.equals("")) {
                editOtherDescribe.setText(describe);
            }
            int station_type = showPoiEntity.getStation_type();
            if (station_type == 5) {
                spinnerOther.setSelection(0, true);
            } else if (station_type == 6) {
                spinnerOther.setSelection(1, true);
            } else if (station_type == 7) {
                spinnerOther.setSelection(2, true);
            }
            if (showPoiEntity.getPhotoInfo() != null) {
                for (int i = 0; i < showPoiEntity.getPhotoInfo().size(); i++) {
                    String photo = showPoiEntity.getPhotoInfo().get(i).getPhoto();
                    String[] split = photo.split("/");
                    if (split[split.length - 1].startsWith("a")) {
                        Glide.with(getActivity()).load(photo).into(ivPicture);
                        tvPicture.setTag(photo);
                    } else if (split[split.length - 1].startsWith("b")) {
                        Glide.with(getActivity()).load(photo).into(ivPictures);
                        tvPictures.setTag(photo);
                    }
                }
            }
        }
        //判断是否是已完成作业并保存成功
        if (showPoiEntity.getTaskStatus() == 3) {
            disables();
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.rl_picture:
                Intent intentPicture = new Intent("android.media.action.IMAGE_CAPTURE");
                file = PhotoUtils.showPhotoFile("a", latLng);
                intentPicture.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
                startActivityForResult(intentPicture, 101);
                break;
            case R.id.rl_pictures:
                Intent intentPictures = new Intent("android.media.action.IMAGE_CAPTURE");
                file = PhotoUtils.showPhotoFile("b", latLng);
                intentPictures.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
                startActivityForResult(intentPictures, 102);
                break;
            case R.id.btn_other_local:
                initPoiSaveLocal(false);
                break;
            case R.id.btn_other_uploading:
                otherUploadList = new ArrayList<>();
                String name = editTaskName.getText().toString().trim();//名称
                if (name == null || name.equals("")) {
                    Toast.makeText(getActivity(), "请输入poi 名称", Toast.LENGTH_SHORT).show();
                    return;
                }
                if (latLng == null) {
                    Toast.makeText(getActivity(), "请确定点位", Toast.LENGTH_SHORT).show();
                    return;
                }
                String tagPicture = (String) tvPicture.getTag();
                if (tagPicture == null) {
                    Toast.makeText(getActivity(), "请拍照", Toast.LENGTH_SHORT).show();
                    return;
                } else {
                    otherUploadList.add(new File(tagPicture));
                }
                String tagPictures = (String) tvPictures.getTag();
                if (tagPictures == null) {
                    Toast.makeText(getActivity(), "请拍照", Toast.LENGTH_SHORT).show();
                    return;
                } else {
                    otherUploadList.add(new File(tagPictures));
                }
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        PoiEntity poiDaoPoiEntity = poiDao.getPoiEntity(showPoiEntity.getId());
                        if (poiDaoPoiEntity == null || poiDaoPoiEntity.getTaskStatus() == 1 || poiDaoPoiEntity.getTaskStatus() == 2 || poiDaoPoiEntity.getTaskStatus() == 0 || poiDaoPoiEntity.getTaskStatus() == 5) {
                            initPoiSaveLocal(true);
                        } else {
                            getActivity().runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    otherUploadByNet(poiDaoPoiEntity.getBodyId(), otherUploadList);
                                }
                            });
                        }

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

    public void initPoiSaveLocal(boolean isLocal) {
        XXPermissions.with(this)
                //读写权限
                .permission(Permission.MANAGE_EXTERNAL_STORAGE)
                .request(new OnPermissionCallback() {
                    @Override
                    public void onGranted(List<String> permissions, boolean all) {
                        if (all) {
                            //保存数据库：
                            PoiEntity poiEntity = initPoiEntityByUI(showPoiEntity);
                            PoiCheckResult poiCheckResult = checkPoiEntity(poiEntity);
                            if (poiCheckResult.getCode() == 1) {
                                Toast.makeText(getActivity(), poiCheckResult.getMsg() + "", Toast.LENGTH_SHORT).show();
                                return;
                            }
                            new Thread(new Runnable() {
                                @Override
                                public void run() {
                                    InsertAndUpdateUtils.getInstance().insertOrUpdate(getContext(), poiEntity);
                                    getActivity().runOnUiThread(new Runnable() {
                                        @Override
                                        public void run() {
                                            otherSaveByNetWork(poiEntity, isLocal);
                                        }
                                    });

                                }
                            }).start();
                            // onBackPressed();
                        } 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);
                        }
                    }
                });
    }

    private void otherUploadByNet(int body, List<File> otherUploadList) {
        if (body == 0) {
            Toast.makeText(getActivity(), "没有保存本地", Toast.LENGTH_SHORT).show();
            Log.e("TAG", "poiUploadByNetWork: " + body + otherUploadList);
            return;
        }

        HttpParams httpParams = new HttpParams();
        httpParams.put("auditId", body);
        showLoadingDialog();
        setLoadingDialogText("上传中...");
        OkGoBuilder.getInstance()
                .Builder(getActivity())
                .url(HttpInterface.OTHER_TASK_UPLOAD_PIC)
                .fileList(otherUploadList)
                .token(Constant.ACCESS_TOKEN)
                .params(httpParams)
                .cls(PoiUploadBean.class)
                .postFileAsynchronous(new Callback<PoiUploadBean>() {
                    @Override
                    public void onSuccess(PoiUploadBean response, int id) {
                        dismissLoadingDialog();
                        if (response.getCode() == 200) {
                            new Thread(new Runnable() {
                                @Override
                                public void run() {
                                    PoiEntity poiDaoPoiEntity = poiDao.getPoiEntity(showPoiEntity.getId());
                                    poiDao.deletePoiEntity(poiDaoPoiEntity);
                                    getActivity().runOnUiThread(new Runnable() {
                                        @Override
                                        public void run() {
                                            Toast.makeText(getActivity(), "上传成功", Toast.LENGTH_SHORT).show();
                                            Message obtain = Message.obtain();
                                            obtain.what = Constant.JOB_WORD_MONITOR;
                                            obtain.obj = true;
                                            EventBus.getDefault().post(obtain);
                                            getActivity().onBackPressed();//回退
                                        }
                                    });
                                }
                            }).start();
                        } else {
                            Toast.makeText(getActivity(), response.getMessage(), Toast.LENGTH_SHORT).show();
                        }

                    }

                    @Override
                    public void onError(Throwable e, int id) {
                        dismissLoadingDialog();
                        Toast.makeText(getActivity(), e.getMessage() + "", Toast.LENGTH_SHORT).show();
                        Log.d("TAG", "onError: " + e.getMessage() + "");
                    }
                });
        dismissDialog();
    }

    private void otherSaveByNetWork(PoiEntity poiEntity, boolean isLocal) {
        showLoadingDialog();
        setLoadingDialogText("保存中...");
        HttpParams httpParams = new HttpParams();
        httpParams.put("type", poiEntity.getStation_type());
        httpParams.put("taskId", poiEntity.getTaskId());
        httpParams.put("name", poiEntity.getName());
        httpParams.put("existence", poiEntity.getExistence());
        httpParams.put("geo", poiEntity.getGeoWkt());
        httpParams.put("memo", poiEntity.getMemo());
        OkGoBuilder.getInstance()
                .Builder(getActivity())
                .url(HttpInterface.SUBMIT_OTHER_TASK)
                .cls(PoiSaveBean.class)
                .params(httpParams)
                .token(Constant.ACCESS_TOKEN)
                .getRequest(new Callback<PoiSaveBean>() {
                    @Override
                    public void onSuccess(PoiSaveBean poiSaveBean, int id) {
                        dismissLoadingDialog();
                        if (poiSaveBean.getCode() == 200) {
                            Integer body = poiSaveBean.getBody();
                            if (body != null && body != 0) {
                                poiEntity.setBodyId(body);
                                poiEntity.setTaskStatus(3);
                                new Thread(new Runnable() {
                                    @Override
                                    public void run() {
                                        InsertAndUpdateUtils.getInstance().insertOrUpdate(getContext(), poiEntity);
                                        getActivity().runOnUiThread(new Runnable() {
                                            @Override
                                            public void run() {
                                                if (isLocal) {
                                                    otherUploadByNet(body, otherUploadList);
                                                } else {
                                                    Toast.makeText(getActivity(), "保存成功", Toast.LENGTH_SHORT).show();
                                                    Message obtain = Message.obtain();
                                                    obtain.what = Constant.JOB_WORD_MONITOR;
                                                    obtain.obj = true;
                                                    EventBus.getDefault().post(obtain);
                                                    getActivity().onBackPressed();
                                                }
                                            }
                                        });
                                    }
                                }).start();
                            } else {
                                Toast.makeText(getActivity(), "" + poiSaveBean.getMessage(), Toast.LENGTH_SHORT).show();

                            }
                        } else {
                            Toast.makeText(getActivity(), "" + poiSaveBean.getMessage(), Toast.LENGTH_SHORT).show();
                        }


                    }

                    @Override
                    public void onError(Throwable e, int id) {
                        dismissLoadingDialog();
                        Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
                        Log.d("TAG", "onError: " + e.getMessage());
                    }
                });
        dismissDialog();
    }

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

    /**
     * 防止当页面崩溃后出现数据丢失
     */
    public void initOtherSharePre() {
        //获取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方法,
        PoiEntity poiEntity = initPoiEntityByUI(showPoiEntity);
        String newPoiEntity = new Gson().toJson(poiEntity);
        //以键值对的形式添加新值。
        edit.putString("poiEntity", newPoiEntity);
        //提交新值。必须执行，否则前面的操作都无效。
        edit.commit();
        Log.d("TAG", "initPoiSharePre: " + newPoiEntity);
    }

    @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, ivPicture);
                tvPicture.setTag(s);
            }
            file = null;
        } 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, ivPictures);
                tvPictures.setTag(s);
            }
            file = null;
        }
    }

    @Override
    public void onDestroy() {
        if (EventBus.getDefault().isRegistered(this))//加上判断
            EventBus.getDefault().unregister(this);
        super.onDestroy();
        if (showPoiEntity != null) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    PoiEntity poiDaoPoiEntity = poiDao.getPoiEntity(showPoiEntity.getId());
                    if (poiDaoPoiEntity != null) {
                        if (poiDaoPoiEntity.getTaskStatus() == 5) {
                            poiDao.deletePoiEntity(poiDaoPoiEntity);
                        }

                    }
                }
            }).start();
        }
        if (markerOther != null) {
            markerOther.remove();
        }
    }

    @Override
    protected PoiEntity initPoiEntityByUI(PoiEntity poiEntity) {
        ArrayList<Info> arrayList = new ArrayList<>();
        String name = editTaskName.getText().toString().trim();//名称
        if (name != null && !name.equals("")) {
            poiEntity.setName(name);
        }
        if (latLng != null) {
            String encode = Geohash.getInstance().encode(latLng.latitude, latLng.longitude);
            poiEntity.setGeoWkt(encode);
            poiEntity.setX(String.valueOf(latLng.longitude));
            poiEntity.setY(String.valueOf(latLng.latitude));
        }
        String describe = editOtherDescribe.getText().toString().trim();
        if (describe != null && !describe.equals("")) {
            poiEntity.setMemo(describe);
        }
        String tagPicture = (String) tvPicture.getTag();
        if (tagPicture != null && !tagPicture.equals("")) {
            arrayList.add(new Info(tagPicture));
        }
        String tagPictures = (String) tvPictures.getTag();
        if (tagPictures != null && !tagPictures.equals("")) {
            arrayList.add(new Info(tagPictures));
        }
        poiEntity.setPhotoInfo(arrayList);
        poiEntity.setStation_type(station_type);
        DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());
        String format = formatter.format(calendar.getTime());
        poiEntity.setCreateTime(format);
        poiEntity.setType(5);
        poiEntity.setTaskStatus(2);
        poiEntity.setIsLocalData(1);
        return poiEntity;
    }

    @Override
    protected PoiCheckResult checkPoiEntity(PoiEntity entity) {
        PoiCheckResult poiCheckResult = new PoiCheckResult();
        if (entity.getName() == null) {
            poiCheckResult.setCode(1);
            poiCheckResult.setMsg("请输入 名称");
            return poiCheckResult;
        }
        if (tvPicture.getTag() == null) {
            poiCheckResult.setCode(1);
            poiCheckResult.setMsg("请 拍照");
            return poiCheckResult;
        }
        if (tvPictures.getTag() == null) {
            poiCheckResult.setCode(1);
            poiCheckResult.setMsg("请 拍照");
            return poiCheckResult;
        }
        if (entity.getX() == null && entity.getY() == null) {
            poiCheckResult.setCode(1);
            poiCheckResult.setMsg("请确定点位");
            return poiCheckResult;
        }
        return poiCheckResult;
    }

    @Override
    protected ChargingPileEntity initChargingPileEntityByUI(ChargingPileEntity entity) {
        return null;
    }

    @Override
    protected PoiCheckResult checkChargingPileEntity(ChargingPileEntity entity) {
        return null;
    }

}