package com.navinfo.outdoor.fragment;

import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.media.MediaMetadataRetriever;
import android.net.Uri;
import android.os.Bundle;
import android.os.Message;
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.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
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.github.lazylibrary.util.FileUtils;
import com.github.lazylibrary.util.StringUtils;
import com.github.lazylibrary.util.ZipUtil;
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.activity.PictureActivity;
import com.navinfo.outdoor.activity.PicturesActivity;
import com.navinfo.outdoor.api.Constant;
import com.navinfo.outdoor.base.BaseDrawerFragment;
import com.navinfo.outdoor.bean.OtherUploadPicBean;
import com.navinfo.outdoor.bean.PoiSaveBean;
import com.navinfo.outdoor.bean.PoiVideoBean;
import com.navinfo.outdoor.bean.RoadExtend;
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.AWMp4ParserHelper;
import com.navinfo.outdoor.util.GeometryTools;
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.Date;
import java.util.List;

/**
 * 寻宝-点击上传弹窗-poi录像
 */

public class PoiVideoFragment extends BaseDrawerFragment implements View.OnClickListener {
    private TextView tvPictures;
    private EditText etRoadName;
    private ImageView ivPoiVideoPicture;
    private RadioButton rbCar;
    private RadioButton rbBicycle;
    private RadioButton rbWalking;
    private EditText etDesc;
    private Button btnRoadSave;
    private RadioGroup rgType;
    private PoiDatabase poiDatabase;
    private PoiDao poiDao;
    private Button btnPoiVideoUpload;
    private String videoPath;
    private File fileZip;
    private FrameLayout fmPoiVideoPic;
    private NestedScrollView nestedScrollView;
    private LatLng latLng;
    private Marker markerPoiVideo;

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

    @Override
    protected int getLayout() {
        return R.layout.poi_video_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.poi_video_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();
        tvPictures = (TextView) findViewById(R.id.tv_pictures);
        tvPictures.setOnClickListener(this::onClick);
        setSlidingUpPanelLayout(Constant.SLIDING_LAYOUT);
        nestedScrollView = findViewById(R.id.nested_scroll_view);
        if (slidingPaneLayout != null) {
            slidingPaneLayout.setScrollableView(nestedScrollView);
        }
        etRoadName = (EditText) findViewById(R.id.et_poi_video_name);
        ivPoiVideoPicture = (ImageView) findViewById(R.id.iv_poi_video_picture);
        rbCar = (RadioButton) findViewById(R.id.rb_car);
        rbBicycle = (RadioButton) findViewById(R.id.rb_bicycle);
        rbWalking = (RadioButton) findViewById(R.id.rb_walking);
        etDesc = (EditText) findViewById(R.id.et_desc);
        fmPoiVideoPic = findViewById(R.id.fm_poi_video_picture);
        btnRoadSave = (Button) findViewById(R.id.btn_poi_video_save);
        btnRoadSave.setOnClickListener(this::onClick);
        btnPoiVideoUpload = findViewById(R.id.btn_poi_video_upload);
        btnPoiVideoUpload.setOnClickListener(this::onClick);
        rgType = (RadioGroup) findViewById(R.id.rg_type);
        fmPoiVideoPic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (v.getTag() == null || ((List<File>) v.getTag()).size() == 0) {
                    Toast.makeText(getActivity(), "还没有拍摄视频！", Toast.LENGTH_SHORT).show();
                    return;
                }

                File finalFile = AWMp4ParserHelper.getInstance().obtainMp4FilePath(new File(Constant.PICTURE_FOLDER, showPoiEntity.getId()).getAbsolutePath());
                Intent intent = new Intent(getContext(), PictureActivity.class);
                // intent.putExtra("uuId", showPoiEntity.getId());
                intent.putExtra("poiEntity", showPoiEntity);
                intent.putExtra(Constant.INTENT_VIDEO_PATH, finalFile.getAbsolutePath());
                startActivityForResult(intent, 0x101);
            }
        });
        fmPoiVideoPic.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) {
                        List<File> videoFileListByUUID = AWMp4ParserHelper.getInstance().getVideoFileListByUUID(showPoiEntity.getId());
                        for (int i = 0; i < videoFileListByUUID.size(); i++) {
                            videoFileListByUUID.get(i).delete();
                        }
                        ivPoiVideoPicture.setImageDrawable(null);
                        return false;
                    }
                });
                return false;
            }
        });
        //添加数据
        initShowPoi();
    }

    private void initShowPoi() {
        // 添加信息：
        showPoiEntity = (PoiEntity) getArguments().getSerializable("poiEntity");
        if (showPoiEntity != null) {
            String name = showPoiEntity.getName();//名称
            if (name != null && !name.equals("")) {
                etRoadName.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.drawable.poi_video_bag);
                markerPoiVideo = tencentMap.addMarker(new MarkerOptions(latLng).icon(pileDescriptor) .anchor(0.5f,1.0f));
                markerPoiVideo.setZIndex(4);
                moveLatlng(latLng,null);
            }
            int work_type = showPoiEntity.getWork_type();
            showPictureType(work_type);
            String describe = showPoiEntity.getMemo();//任务描述
            if (describe != null && !describe.equals("")) {
                etDesc.setText(describe + "");
            }
            String photoList = showPoiEntity.getPhoto();
            if (!StringUtils.isEmpty(photoList)) {
                String[] photos = photoList.split(",");
                List<File> videoFileList = new ArrayList<>();
                boolean isImageLoad = false;
                if (photos != null && photos.length > 0) {
                    for (int i = 0; i < photos.length; i++) {
                        String photo = photos[i];
                        if (!StringUtils.isEmpty(photo)) {
                            File videoFile = new File(photo);
                            videoFileList.add(new File(photo));
                            if (videoFile.getPath().contains("0.mp4") && !videoFile.getPath().contains("0.mp4.txt")) {
                                if (videoFile.exists() && !isImageLoad) {
                                    // 使用glide加载视频的第一帧
                                    AWMp4ParserHelper.getInstance().loadFirstWithGlide(getActivity(), Uri.fromFile(videoFile).toString(), ivPoiVideoPicture, 500);
                                    isImageLoad = true;
                                }
                            }

                        }
                    }
                    fmPoiVideoPic.setTag(videoFileList);
                }
            }
        }
        //判断是否是已做完任务并保存成功
        if (showPoiEntity.getTaskStatus() == 3) {
            disables();//禁用所有可操作的控件
        }
    }

    private void disables() {
        etRoadName.setEnabled(false);
        rgType.setEnabled(false);
        ivPoiVideoPicture.setEnabled(false);
        tvPictures.setEnabled(false);
        etDesc.setEnabled(false);
        btnRoadSave.setEnabled(false);
        rbCar.setEnabled(false);
        rbWalking.setEnabled(false);
        rbBicycle.setEnabled(false);
    }

    @Subscribe
    public void onEvent(Message data) {
        if (data.what == Constant.PICTURE_VIDEO_WORD) {
            if ((boolean) data.obj) {

                initPoiVideoSharePre();
            }
        }
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_poi_video_save:
                initPoiSaveLocal(false);
                break;
            case R.id.tv_pictures:
                // 根据用户点击的时间为视频名称赋值
//                DateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
//                String videoFormatName = formatter.format(new Date());
                Intent intent = new Intent(getContext(), PictureActivity.class);
                File finalFile = AWMp4ParserHelper.getInstance().obtainMp4FilePath(new File(Constant.PICTURE_FOLDER, showPoiEntity.getId()).getAbsolutePath());
                intent.putExtra(Constant.INTENT_VIDEO_PATH, finalFile.getAbsolutePath());
                intent.putExtra("poiEntity", showPoiEntity);
                startActivityForResult(intent, 0x101);
                break;

            case R.id.btn_poi_video_upload:
                showLoadingDialog();
                setLoadingDialogText("压缩中...");
                if (fmPoiVideoPic.getTag() != null) {
                    List<File> videoFileList = (List<File>) fmPoiVideoPic.getTag();
                    fileZip = new File(Constant.PICTURE_FOLDER, "files" + ".zip");
                    new Thread(new Runnable() {
                        @Override
                        public void run() {
                            ZipUtil.zipFiles(videoFileList, fileZip, null);
                            PoiEntity poiDaoPoiEntity = poiDao.getPoiEntity(showPoiEntity.getId());
                            if (poiDaoPoiEntity == null || poiDaoPoiEntity.getTaskStatus() == 1 || poiDaoPoiEntity.getTaskStatus() == 2 || poiDaoPoiEntity.getTaskStatus() == 0 || poiDaoPoiEntity.getTaskStatus() == 5) {
                                getActivity().runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        dismissLoadingDialog();
                                        initPoiSaveLocal(true);
                                    }
                                });
                            } else {
                                getActivity().runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        dismissLoadingDialog();
                                        poiVideoUpload(poiDaoPoiEntity.getBodyId(), fileZip);
                                    }
                                });
                            }

                        }
                    }).start();
                } else {
                    dismissLoadingDialog();
                    Toast.makeText(getActivity(), "请录像", Toast.LENGTH_SHORT).show();
                    return;
                }
                break;
        }
    }

    public void initPoiSaveLocal(boolean isLocal) {
        XXPermissions.with(getContext())
                .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() {
                                            poiVideoSave(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 poiVideoUpload(int poiVideoBody, File fileZip) {
        if (poiVideoBody == 0) {
            Toast.makeText(getActivity(), "请先保存本地在上传", Toast.LENGTH_SHORT).show();
            return;
        }
        if (fileZip == null) {
            Toast.makeText(getActivity(), "未压缩完成", Toast.LENGTH_SHORT).show();
            return;
        }
        HttpParams httpParams = new HttpParams();
        httpParams.put("auditId", poiVideoBody);
        long time = System.currentTimeMillis();
        httpParams.put("datetime", time);
        httpParams.put("file", fileZip);
        showLoadingDialog();
        setLoadingDialogText("上传中...");
        OkGoBuilder.getInstance()
                .Builder(getActivity())
                .url(HttpInterface.POI_VIDEO_UPLOAD_PIC)
                .cls(OtherUploadPicBean.class)
                .params(httpParams)
                .token(Constant.ACCESS_TOKEN)
                .postRequest(new Callback<OtherUploadPicBean>() {
                    @Override
                    public void onSuccess(OtherUploadPicBean 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(), "上传失败", Toast.LENGTH_SHORT).show();
                        Log.d("TAG", "onError: " + e.getMessage() + "");
                    }
                });
        dismissDialog();
    }

    private void poiVideoSave(PoiEntity poiEntity, boolean isLocal) {

        HttpParams httpParams = new HttpParams();
        httpParams.put("taskId", poiEntity.getTaskId());
        httpParams.put("name", poiEntity.getName());
        httpParams.put("address", poiEntity.getAddress());
        httpParams.put("workType", poiEntity.getWork_type());
        httpParams.put("memo", poiEntity.getMemo());
        showLoadingDialog();
        OkGoBuilder.getInstance()
                .Builder(getActivity())
                .url(HttpInterface.INSIDE_API_LIST)
                .cls(PoiVideoBean.class)
                .params(httpParams)
                .token(Constant.ACCESS_TOKEN)
                .getRequest(new Callback<PoiVideoBean>() {
                    @Override
                    public void onSuccess(PoiVideoBean poiVideoBean, int id) {
                        dismissLoadingDialog();
                        if (poiVideoBean.getCode() == 200) {
                            Integer poiVideoBody = poiVideoBean.getBody();
                            if (poiVideoBody != null && poiVideoBody != 0) {
                                poiEntity.setBodyId(poiVideoBody);
                                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) {
                                                    poiVideoUpload(poiVideoBody, fileZip);
                                                } 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(), "" + poiVideoBean.getMessage(), Toast.LENGTH_SHORT).show();
                            }
                        } else {
                            Toast.makeText(getActivity(), "" + poiVideoBean.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 onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == 0x101 && resultCode == 0x101) {
            if (data != null && data.hasExtra(Constant.INTENT_VIDEO_PATH)) {
                String videoPath = data.getStringExtra(Constant.INTENT_VIDEO_PATH);
                File videoFile = new File(videoPath);
                if (videoFile.exists()) {
                    AWMp4ParserHelper.getInstance().loadFirstWithGlide(getActivity(), Uri.fromFile(videoFile).toString(), ivPoiVideoPicture, 500);
                    List<File> videoFileListByUUID = AWMp4ParserHelper.getInstance().getVideoFileListByUUID(showPoiEntity.getId());
                    fmPoiVideoPic.setTag(videoFileListByUUID);
                }
            }
        }
    }

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

    /**
     * 防止程序崩溃后数据丢失
     */
    public void initPoiVideoSharePre() {
        //获取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", "initRoadSharePre: " + newPoiEntity);
    }


    //获取拍照类型
    private int getPictureType() {
        if (rbCar != null && rbCar.isChecked()) {
            return 0;
        } else if (rbBicycle != null && rbBicycle.isChecked()) {
            return 1;
        } else if (rbWalking != null && rbWalking.isChecked()) {
            return 2;
        }
        return -1;
    }

    private void showPictureType(int type) {
        switch (type) {
            case 0:
                rbCar.setChecked(true);
                break;
            case 1:
                rbBicycle.setChecked(true);
                break;
            case 2:
                rbWalking.setChecked(true);
                break;

        }
    }

    @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 (markerPoiVideo!=null){
            markerPoiVideo.remove();
        }
    }

    @Override
    protected PoiEntity initPoiEntityByUI(PoiEntity poiEntity) {
        String roadName = etRoadName.getText().toString().trim();
        if (roadName != null && !roadName.equals("")) {
            poiEntity.setName(roadName + "");
        } else {
            DateFormat formatters = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
            Calendar calendars = Calendar.getInstance();
            calendars.setTimeInMillis(System.currentTimeMillis());
            String formats = formatters.format(calendars.getTime());
            String city = Constant.currentLocation.getCity();//返回当前位置的城市.
            String district = Constant.currentLocation.getDistrict();//返回当前位置的区县.
            StringBuilder sb = new StringBuilder("poi录像上报");
            if (city != null && !"".equals(city)) {
                sb.append("-");
                sb.append(city);
            }
            if (district != null && !"".equals(district)) {
                sb.append(district);
            }
            sb.append("-").append(formats);
            poiEntity.setName(sb.toString());
            getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    etRoadName.setText(sb);
                    etRoadName.setEnabled(false);
                }
            });
        }
        int pictureType = getPictureType();
        if (pictureType != -1) {
            poiEntity.setWork_type(pictureType);
        }
        String desc = etDesc.getText().toString().trim();
        if (desc != null && !desc.equals("")) {
            poiEntity.setDescribe(desc);
        }
        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(3);
        poiEntity.setTaskStatus(2);
        poiEntity.setIsLocalData(1);
        if (fmPoiVideoPic.getTag() == null) {
            List<File> videoFileListByUUID = AWMp4ParserHelper.getInstance().getVideoFileListByUUID(showPoiEntity.getId());
            if (videoFileListByUUID != null) {
                fmPoiVideoPic.setTag(videoFileListByUUID);
            }
        }
        if (fmPoiVideoPic.getTag() != null && !((List<File>) fmPoiVideoPic.getTag()).isEmpty()) {
            List<LatLng> lineStringByVideoFileList = AWMp4ParserHelper.getInstance().getLineStringByVideoFileList((List<File>) fmPoiVideoPic.getTag());
            String lineString = GeometryTools.getLineString(lineStringByVideoFileList);
            Log.d("TAG", "onGranted: " + lineString);
            String photoStr = AWMp4ParserHelper.getInstance().getVideoFileListStr((List<File>) fmPoiVideoPic.getTag());
            poiEntity.setPhoto(photoStr);
            if (lineString != null) {
                poiEntity.setGeoWkt(lineString);
            }
        }
        return poiEntity;
    }

    @Override
    protected PoiCheckResult checkPoiEntity(PoiEntity entity) {
        PoiCheckResult poiCheckResult = new PoiCheckResult();
        if (entity.getPhoto() == null) {
            poiCheckResult.setCode(1);
            poiCheckResult.setMsg("请录像");
            return poiCheckResult;
        }
        if (entity.getWork_type() == -1) {
            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;
    }
}