package com.casic.dcms.ui;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.casic.dcms.R;
import com.casic.dcms.adapter.ImageRecycleViewAdapter;
import com.casic.dcms.base.BaseCaseActivity;
import com.casic.dcms.bean.ActionResultBean;
import com.casic.dcms.bean.CaseDetailBean;
import com.casic.dcms.bean.CaseLargeClassBean;
import com.casic.dcms.bean.CaseNextNodeBean;
import com.casic.dcms.bean.CaseSmallClassBean;
import com.casic.dcms.mvp.presenter.CaseDetailPresenterImpl;
import com.casic.dcms.mvp.presenter.CaseHandlePresenterImpl;
import com.casic.dcms.mvp.presenter.CaseLargeClassPresenterImpl;
import com.casic.dcms.mvp.presenter.CaseNextNodePresenterImpl;
import com.casic.dcms.mvp.presenter.CaseSmallClassPresenterImpl;
import com.casic.dcms.mvp.presenter.UploadImagePresenterImpl;
import com.casic.dcms.mvp.view.ICaseDetailView;
import com.casic.dcms.mvp.view.ICaseHandleView;
import com.casic.dcms.mvp.view.ICaseLargeClassView;
import com.casic.dcms.mvp.view.ICaseNextNodeView;
import com.casic.dcms.mvp.view.ICaseSmallClassView;
import com.casic.dcms.mvp.view.IUploadFileView;
import com.casic.dcms.ui.fragment.verify.CaseVerifiedFragment;
import com.casic.dcms.ui.fragment.verify.CaseVerifyFragment;
import com.casic.dcms.utils.Constant;
import com.casic.dcms.utils.FileUtils;
import com.casic.dcms.utils.GlideLoadEngine;
import com.casic.dcms.utils.ItemDecorationSpace;
import com.casic.dcms.utils.OtherUtils;
import com.casic.dcms.utils.StringHelper;
import com.casic.dcms.utils.ToastHelper;
import com.casic.dcms.widgets.VoicePlayView;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.entity.LocalMedia;
import com.luck.picture.lib.tools.PictureFileUtils;
import com.qmuiteam.qmui.widget.dialog.QMUIBottomSheet;
import com.qmuiteam.qmui.widget.dialog.QMUIDialog;
import com.qmuiteam.qmui.widget.dialog.QMUITipDialog;
import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton;

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

import butterknife.BindView;
import butterknife.OnClick;
import cn.jzvd.Jzvd;
import cn.jzvd.JzvdStd;

public class CaseVerifyDetailActivity extends BaseCaseActivity implements ICaseDetailView, View.OnClickListener,
        ICaseLargeClassView, ICaseSmallClassView, IUploadFileView, ICaseNextNodeView, ICaseHandleView {

    private Context context = CaseVerifyDetailActivity.this;
    @BindView(R.id.caseNumberView)
    TextView caseNumberView;
    @BindView(R.id.caseTypeView)
    TextView caseTypeView;
    @BindView(R.id.caseLargeTypeView)
    TextView caseLargeTypeView;
    @BindView(R.id.caseSmallTypeView)
    TextView caseSmallTypeView;
    @BindView(R.id.caseCommunityView)
    TextView caseCommunityView;
    @BindView(R.id.casePlaceView)
    EditText casePlaceView;
    @BindView(R.id.caseSituationView)
    TextView caseSituationView;
    @BindView(R.id.caseHandleView)
    TextView caseHandleView;
    @BindView(R.id.caseStartTimeView)
    TextView caseStartTimeView;
    @BindView(R.id.caseEndTimeView)
    TextView caseEndTimeView;
    @BindView(R.id.casePicRecyclerView)
    RecyclerView casePicRecyclerView;
    @BindView(R.id.caseAudioButton)
    QMUIRoundButton caseAudioButton;
    @BindView(R.id.videoPlayerView)
    JzvdStd videoPlayerView;
    @BindView(R.id.caseOpinionView)
    TextView caseOpinionView;
    @BindView(R.id.caseConditionView)
    TextView caseConditionView;
    @BindView(R.id.caseVerifyRecyclerView)
    RecyclerView caseVerifyRecyclerView;
    @BindView(R.id.voicePlayView)
    VoicePlayView voicePlayView;
    @BindView(R.id.addImageView)
    ImageView addImageView;
    @BindView(R.id.submitButton)
    QMUIRoundButton submitButton;

    //以下是右边箭头
    @BindView(R.id.i)
    ImageView i;
    @BindView(R.id.ii)
    ImageView ii;
    @BindView(R.id.iii)
    ImageView iii;

    //以下是子布局
    @BindView(R.id.caseClassLayout)
    RelativeLayout caseClassLayout;
    @BindView(R.id.caseLargeClassLayout)
    RelativeLayout caseLargeClassLayout;
    @BindView(R.id.caseSmallClassLayout)
    RelativeLayout caseSmallClassLayout;

    private CaseDetailPresenterImpl caseDetailPresenter;
    private CaseLargeClassPresenterImpl caseLargeClassPresenter;
    private List<CaseLargeClassBean.DataBean> largeClassBeans;
    private CaseSmallClassPresenterImpl caseSmallClassPresenter;
    private List<CaseSmallClassBean.DataBean> smallClassBeans;
    private String id;
    private String eorc;
    private String typeCode;
    private String typeDetailCode;
    private String gridId;//可能来自案卷详情，也可能来自地图选点
    private double longitude, latitude;
    private String changeState;
    private MediaPlayer mediaPlayer;
    private UploadImagePresenterImpl uploadImagePresenter;
    private QMUITipDialog submitDialog;
    private ArrayList<String> realPaths = new ArrayList<>();//真实图片路径
    private List<String> mediaList = new ArrayList<>();//上传到服务器的数据集
    private CaseNextNodePresenterImpl caseNextNodePresenter;
    private CaseHandlePresenterImpl caseHandlePresenter;
    private CaseDetailBean.DataBean data = new CaseDetailBean.DataBean();
    private ImageRecycleViewAdapter verifyImageAdapter;

    @Override
    public int initLayoutView() {
        return R.layout.activity_case_verify_detail;
    }

    @Override
    protected String setTitleName() {
        return "案卷核实";
    }

    @Override
    public void initData() {
        mediaPlayer = new MediaPlayer();
        largeClassBeans = new ArrayList<>();
        smallClassBeans = new ArrayList<>();

        id = getIntent().getStringExtra("id");
        caseDetailPresenter = new CaseDetailPresenterImpl(this);
        caseDetailPresenter.onReadyRetrofitRequest(id);
        caseLargeClassPresenter = new CaseLargeClassPresenterImpl(this);
        caseSmallClassPresenter = new CaseSmallClassPresenterImpl(this);
        uploadImagePresenter = new UploadImagePresenterImpl(this);
        submitDialog = new QMUITipDialog.Builder(this)
                .setIconType(QMUITipDialog.Builder.ICON_TYPE_LOADING)
                .setTipWord("提交中，请稍后")
                .create();
        caseNextNodePresenter = new CaseNextNodePresenterImpl(this);
        caseHandlePresenter = new CaseHandlePresenterImpl(this);

        verifyImageAdapter = new ImageRecycleViewAdapter(this);
        caseVerifyRecyclerView.setLayoutManager(new GridLayoutManager(this, 2));
        caseVerifyRecyclerView.addItemDecoration(new ItemDecorationSpace());
        caseVerifyRecyclerView.setAdapter(verifyImageAdapter);
    }

    @Override
    public void initEvent() {
        submitButton.setChangeAlphaWhenPress(true);
    }

    @Override
    public void obtainCaseDetailData(CaseDetailBean resultBean) {
//        Log.d(TAG, "obtainCaseDetailData: " + gson.toJson(resultBean));
        if (resultBean.isSuccess()) {
            this.data = resultBean.getData().get(0);
            this.gridId = data.getGridId();
            String lng = data.getLng();
            if (!TextUtils.isEmpty(lng)) {
                this.longitude = Double.parseDouble(lng);
            }
            String lat = data.getLat();
            if (!TextUtils.isEmpty(lat)) {
                this.latitude = Double.parseDouble(lat);
            }
            caseNumberView.setText(data.getCaseid());
            caseTypeView.setText(data.getEorcName());
            caseLargeTypeView.setText(data.getCasetypeName());
            caseSmallTypeView.setText(data.getCasetypeDetailName());
            caseCommunityView.setText(data.getCommunityName());
            casePlaceView.setText(StringHelper.filterString(data.getFieldintro()));
            caseHandleView.setText(data.getCaseStateName().equals("") ? "无处理意见" : data.getCaseStateName());
            caseStartTimeView.setText(data.getCreateTime());
            caseEndTimeView.setText(data.getNodeLimittime());
            caseSituationView.setText(StringHelper.filterString(data.getDescription()));

            //根据source判断是否能够修改案卷类型，11/12是公众号和热线电话，其他类型不可修改
            int source = data.getSource();
            if (source != 11 && source != 12) {
                i.setVisibility(View.GONE);
                ii.setVisibility(View.GONE);
                iii.setVisibility(View.GONE);

                caseClassLayout.setClickable(false);
                caseLargeClassLayout.setClickable(false);
                caseSmallClassLayout.setClickable(false);
            }

            //图片
            String images = data.getFileIdVerify();
            if (!TextUtils.isEmpty(images)) {
                ArrayList<String> urls = new ArrayList<>();
                String[] split = images.split(",");
                for (String s : split) {
                    if (s.endsWith(".jpg") || s.contains(".jpeg") || s.contains(".png")) {
                        urls.add(StringHelper.appendCompleteURL(s));
                    }
                }
                ImageRecycleViewAdapter imageAdapter = new ImageRecycleViewAdapter(this);
                imageAdapter.setMediaList(urls);
                casePicRecyclerView.setLayoutManager(new GridLayoutManager(this, 2));
                casePicRecyclerView.addItemDecoration(new ItemDecorationSpace());
                casePicRecyclerView.setAdapter(imageAdapter);
                //九宫格点击事件
                imageAdapter.setOnItemClickListener(new ImageRecycleViewAdapter.OnItemClickListener() {
                    @Override
                    public void onClick(int position) {
                        OtherUtils.showBigImage(context, position, urls);
                    }
                });
                imageAdapter.setDeleteView(false);
            }

            //音频
            String audioFile = data.getAudioIdVerify();
            if (!TextUtils.isEmpty(audioFile)) {
                caseAudioButton.setVisibility(View.VISIBLE);
                try {
                    mediaPlayer.setDataSource(StringHelper.appendCompleteURL(audioFile));
                    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                    mediaPlayer.prepare();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                caseAudioButton.setChangeAlphaWhenPress(true);
                caseAudioButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (!mediaPlayer.isPlaying()) {
                            mediaPlayer.start();
                            voicePlayView.start();
                        }
                    }
                });
                mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                    @Override
                    public void onCompletion(MediaPlayer mp) {
                        voicePlayView.stop();
                    }
                });
            }

            //视频
            String videoFile = data.getVideoIdVerify();
            if (!TextUtils.isEmpty(videoFile)) {
                videoPlayerView.setVisibility(View.VISIBLE);
                String videoUrl = StringHelper.appendCompleteURL(videoFile);
                videoPlayerView.setUp(videoUrl, StringHelper.filterString(data.getDescription()));
                //设置第一帧为封面
                Glide.with(this)
                        .setDefaultRequestOptions(new RequestOptions().frame(4000000))
                        .load(videoUrl)
                        .into(videoPlayerView.posterImageView);
            }
        }
    }

    @OnClick({R.id.caseClassLayout, R.id.caseLargeClassLayout, R.id.caseSmallClassLayout, R.id.locationMapView, R.id.addImageView, R.id.caseConditionLayout, R.id.submitButton})
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.caseClassLayout:
                new QMUIBottomSheet.BottomListSheetBuilder(this)
                        .setTitle("案卷类型")
                        .addItem("事件")
                        .addItem("部件")
                        .setGravityCenter(true)
                        .setOnSheetItemClickListener(new QMUIBottomSheet.BottomListSheetBuilder.OnSheetItemClickListener() {
                            @Override
                            public void onClick(QMUIBottomSheet dialog, View itemView, int position, String tag) {
                                dialog.dismiss();
                                caseTypeView.setText(tag);
                                //获取案卷大类
                                caseLargeClassPresenter.onReadyRetrofitRequest(String.valueOf(position + 1));
                            }
                        }).build().show();
                break;
            case R.id.caseLargeClassLayout:
                if (largeClassBeans != null) {
                    if (largeClassBeans.size() > 1) {
                        QMUIBottomSheet.BottomListSheetBuilder sheetBuilder = new QMUIBottomSheet.BottomListSheetBuilder(this);
                        sheetBuilder.setTitle("案卷大类");
                        for (CaseLargeClassBean.DataBean dataBean : largeClassBeans) {
                            sheetBuilder.addItem(dataBean.getTypeName());
                        }
                        sheetBuilder.setGravityCenter(true).setOnSheetItemClickListener(new QMUIBottomSheet.BottomListSheetBuilder.OnSheetItemClickListener() {
                            @Override
                            public void onClick(QMUIBottomSheet dialog, View itemView, int position, String tag) {
                                dialog.dismiss();
                                typeCode = largeClassBeans.get(position).getTypeCode();

                                caseLargeTypeView.setText(tag);

                                //获取案卷小类
                                CaseLargeClassBean.DataBean dataBean = largeClassBeans.get(position);
                                eorc = dataBean.getEorc();
                                String typeId = dataBean.getId();
                                caseSmallClassPresenter.onReadyRetrofitRequest(eorc, typeId);
                            }
                        }).build().show();
                    }
                }
                break;
            case R.id.caseSmallClassLayout:
                if (smallClassBeans != null) {
                    if (smallClassBeans.size() > 1) {
                        QMUIBottomSheet.BottomListSheetBuilder sheetBuilder = new QMUIBottomSheet.BottomListSheetBuilder(this);
                        sheetBuilder.setTitle("案卷小类");
                        for (CaseSmallClassBean.DataBean dataBean : smallClassBeans) {
                            sheetBuilder.addItem(dataBean.getTypeDetailName());
                        }
                        sheetBuilder.setGravityCenter(true).setOnSheetItemClickListener(new QMUIBottomSheet.BottomListSheetBuilder.OnSheetItemClickListener() {
                            @Override
                            public void onClick(QMUIBottomSheet dialog, View itemView, int position, String tag) {
                                dialog.dismiss();
                                typeDetailCode = smallClassBeans.get(position).getTypeDetailCode();

                                caseSmallTypeView.setText(tag);
                            }
                        }).build().show();
                    }
                }
                break;
            case R.id.locationMapView:
                String type = caseTypeView.getText().toString();
                if (type.equals("请选择")) {
                    ToastHelper.showToast("请先选择案卷类型", ToastHelper.WARING);
                    return;
                }
                int source = data.getSource();
                if (source == 11 || source == 12) {
                    Intent intent = new Intent(this, ArcGISMapActivity.class);
                    intent.putExtra("type", type);
                    startActivityForResult(intent, Constant.REQUEST_MAP_CODE);
                } else {
                    Intent intent = new Intent(this, DisplayMapActivity.class);
                    intent.putExtra("caseType", data.getEorcName());
                    String dataLng = data.getLng();
                    if (TextUtils.isEmpty(dataLng)) {
                        ToastHelper.showToast("案卷经度异常", ToastHelper.ERROR);
                        return;
                    }
                    intent.putExtra("lng", Double.parseDouble(dataLng));
                    String dataLat = data.getLat();
                    if (TextUtils.isEmpty(dataLat)) {
                        ToastHelper.showToast("案卷纬度异常", ToastHelper.ERROR);
                        return;
                    }
                    intent.putExtra("lat", Double.parseDouble(dataLat));
                    startActivity(intent);
                }
                break;
            case R.id.addImageView:
                new QMUIDialog.MenuDialogBuilder(this)
                        .addItem("相册中选取", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                                //选图
                                selectPicture();
                            }
                        })
                        .addItem("相机拍照", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                                //拍照
                                takePicture();
                            }
                        })
                        .create().show();
                break;
            case R.id.caseConditionLayout:
                caseNextNodePresenter.onReadyRetrofitRequest(String.valueOf(data.getCaseState()));
                break;
            case R.id.submitButton:
                submitCase();//案卷提交
                break;
            default:
                break;
        }
    }

    private void submitCase() {
        String remarks = caseOpinionView.getText().toString();
        if (TextUtils.isEmpty(remarks)) {
            ToastHelper.showToast("核实意见不能为空", ToastHelper.WARING);
            return;
        }
        if (TextUtils.isEmpty(changeState)) {
            ToastHelper.showToast("核实情况还未选择", ToastHelper.WARING);
            return;
        }
        int source = data.getSource();
        if (source != 11 && source != 12) {
            //修改案卷
            if (verifyImageAdapter.getItemCount() != 2) {
                ToastHelper.showToast("必须选择两张图片", ToastHelper.WARING);
                return;
            }
            caseHandlePresenter.onReadyRetrofitRequest(data.getProcessId(), id, String.valueOf(data.getCaseState()),
                    changeState, remarks, StringHelper.reformatURL(mediaList));
        } else {
            //补全案卷
            if (TextUtils.isEmpty(gridId)) {
                ToastHelper.showToast("网格ID异常，请重新选择", ToastHelper.WARING);
                return;
            }
            String fieldIntro = casePlaceView.getText().toString();
            if (TextUtils.isEmpty(fieldIntro)) {
                ToastHelper.showToast("案卷地点还未填写", ToastHelper.WARING);
            }
            if (verifyImageAdapter.getItemCount() != 2) {
                ToastHelper.showToast("必须选择两张图片", ToastHelper.WARING);
                return;
            }
            if (longitude == 0 || latitude == 0) {
                ToastHelper.showToast("经纬度异常，请重新选择位置", ToastHelper.WARING);
                return;
            }
            caseHandlePresenter.onReadyRetrofitRequest(data.getProcessId(), id, String.valueOf(data.getCaseState()),
                    changeState, remarks, StringHelper.reformatURL(mediaList),
                    eorc == null ? data.getEorc() : eorc,
                    typeCode == null ? data.getCasetypeCode() : typeCode,
                    typeDetailCode == null ? data.getCasetypeDetailCode() : typeDetailCode,
                    String.valueOf(longitude), String.valueOf(latitude),
                    "1", gridId.substring(0, 6),
                    gridId.substring(0, 9), data.getCommunityCode(), gridId, fieldIntro);
        }
    }


    @Override
    public void obtainCaseHandleResult(ActionResultBean resultBean) {
        if (resultBean.isSuccess()) {
            ToastHelper.showToast("案卷审核成功", ToastHelper.SUCCESS);
            //案卷办完以后通知待办和已办刷新数据
            CaseVerifyFragment.sendEmptyMessage(Constant.CASE_VERIFY_OK);
            CaseVerifiedFragment.sendEmptyMessage(Constant.CASE_VERIFY_OK);
            finish();
        } else {
            ToastHelper.showToast("案卷审核失败，请重试", ToastHelper.ERROR);
        }
    }

    @Override
    public void obtainDataFail() {
        ToastHelper.showToast("操作失败", ToastHelper.ERROR);
    }

    @Override
    public void obtainLargeClassData(CaseLargeClassBean largeClassBean) {
        if (largeClassBean.isSuccess()) {
            //设置大类数据
            this.largeClassBeans = largeClassBean.getData();
            if (largeClassBeans.size() == 0) {
                caseLargeTypeView.setText("无小类");
            } else {
                caseLargeTypeView.setText(largeClassBeans.get(0).getTypeName());//默认选择第一个
            }
            caseSmallTypeView.setText("请选择");
        }
    }

    @Override
    public void obtainSmallClassData(CaseSmallClassBean smallClassBean) {
        if (smallClassBean.isSuccess()) {
            //设置大类数据
            this.smallClassBeans = smallClassBean.getData();
            if (smallClassBeans.size() == 0) {
                caseSmallTypeView.setText("无小类");
            } else {
                caseSmallTypeView.setText(smallClassBeans.get(0).getTypeDetailName());//默认选择第一个
            }
        }
    }

    private void selectPicture() {
        PictureSelector.create(this)
                .openGallery(PictureMimeType.ofImage())
                .imageEngine(GlideLoadEngine.createGlideEngine())
                .maxSelectNum(2)
                .isCompress(true)
                .compressQuality(80)
                .compressSavePath(FileUtils.getImageCompressPath())
                .forResult(PictureConfig.CHOOSE_REQUEST);
    }

    private void takePicture() {
        PictureSelector.create(this)
                .openCamera(PictureMimeType.ofImage())
                .imageEngine(GlideLoadEngine.createGlideEngine())
                .maxSelectNum(1)
                .isCompress(true)
                .compressQuality(80)
                .compressSavePath(FileUtils.getImageCompressPath())
                .forResult(PictureConfig.REQUEST_CAMERA);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
                case PictureConfig.CHOOSE_REQUEST:
                    List<LocalMedia> selectList = PictureSelector.obtainMultipleResult(data);
                    for (LocalMedia media : selectList) {
                        String mediaCompressPath = media.getCompressPath();
                        uploadImagePresenter.onReadyRetrofitRequest(new File(mediaCompressPath));
                    }
                    break;
                case PictureConfig.REQUEST_CAMERA:
                    LocalMedia localMedia = PictureSelector.obtainMultipleResult(data).get(0);
                    uploadImagePresenter.onReadyRetrofitRequest(new File(localMedia.getCompressPath()));
                    break;
                case Constant.REQUEST_MAP_CODE:
                    if (data == null) {
                        return;
                    }
                    longitude = data.getDoubleExtra("longitude", 0);
                    latitude = data.getDoubleExtra("latitude", 0);
                    gridId = data.getStringExtra("gridId");
                    String community = data.getStringExtra("community");
                    String casePlace = data.getStringExtra("pos");
                    caseCommunityView.setText(community);
                    if (TextUtils.isEmpty(casePlace)) {
                        casePlaceView.setText(community);
                    } else {
                        casePlaceView.setText(casePlace);
                    }
                    break;
                default:
                    break;
            }
        }
    }

    @Override
    public void showProgress() {
        submitDialog.show();
    }

    @Override
    public void hideProgress() {
        submitDialog.dismiss();
    }

    @Override
    public void obtainUploadAudioResult(ActionResultBean resultBean) {

    }

    @Override
    public void obtainUploadImageResult(ActionResultBean resultBean) {
        if (resultBean.isSuccess()) {
            PictureFileUtils.deleteAllCacheDirFile(this);
            /**
             * 系统路径static拼接图片返回路径
             * http://111.198.10.15:11409/static/2021-04/000bcf78345f4c1c86484efa3f9d68a2.jpeg
             */
            //2021-04\\000bcf78345f4c1c86484efa3f9d68a2.jpeg
            int sumItemCount = verifyImageAdapter.getItemCount() + 1;//每上传一张图片，图片总数都是在原有的基础上+1
            if (sumItemCount <= 2) {
                String url = resultBean.getData();
                mediaList.add(url);
                realPaths.add(StringHelper.appendCompleteURL(url));
                if (realPaths.size() == 2) {
                    addImageView.setVisibility(View.GONE);
                }
                verifyImageAdapter.setMediaList(realPaths);
                //九宫格点击事件
                verifyImageAdapter.setOnItemClickListener(new ImageRecycleViewAdapter.OnItemClickListener() {
                    @Override
                    public void onClick(int position) {
                        OtherUtils.showBigImage(context, position, realPaths);
                    }
                });
                //删除按钮点击事件
                verifyImageAdapter.setDeleteView(true);
                verifyImageAdapter.setOnDeleteClickListener(new ImageRecycleViewAdapter.OnDeleteItemClickListener() {
                    @Override
                    public void onClick(int position) {
                        realPaths.remove(position);
                        verifyImageAdapter.setMediaList(realPaths);
                        if (realPaths.size() != 2) {
                            addImageView.setVisibility(View.VISIBLE);
                        }
                    }
                });
            } else {
                ToastHelper.showToast("最多只能上传2张图片", ToastHelper.WARING);
            }
        }
    }

    @Override
    public void obtainUploadVideoResult(ActionResultBean resultBean) {

    }

    @Override
    public void obtainNextNodeData(CaseNextNodeBean resultBean) {
        if (resultBean.isSuccess()) {
            List<CaseNextNodeBean.DataBean> dataBeans = resultBean.getData();
            QMUIBottomSheet.BottomListSheetBuilder sheetBuilder = new QMUIBottomSheet.BottomListSheetBuilder(this);
            sheetBuilder.setTitle("核实情况");
            for (CaseNextNodeBean.DataBean dataBean : dataBeans) {
                sheetBuilder.addItem(dataBean.getNextOperation());
            }
            sheetBuilder.setGravityCenter(true).setOnSheetItemClickListener(new QMUIBottomSheet.BottomListSheetBuilder.OnSheetItemClickListener() {
                @Override
                public void onClick(QMUIBottomSheet dialog, View itemView, int position, String tag) {
                    dialog.dismiss();

                    CaseNextNodeBean.DataBean dataBean = dataBeans.get(position);
                    caseOpinionView.setText(dataBean.getNextOperation());
                    caseConditionView.setText(dataBean.getNextOperation());
                    changeState = String.valueOf(dataBean.getNextState());
                }
            }).build().show();
        } else {
            ToastHelper.showToast("该案卷无下级流转节点", ToastHelper.ERROR);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (caseDetailPresenter != null) {
            caseDetailPresenter.disposeRetrofitRequest();
        }
        if (caseLargeClassPresenter != null) {
            caseLargeClassPresenter.disposeRetrofitRequest();
        }
        if (caseSmallClassPresenter != null) {
            caseSmallClassPresenter.disposeRetrofitRequest();
        }
        if (uploadImagePresenter != null) {
            uploadImagePresenter.disposeRetrofitRequest();
        }
        if (caseNextNodePresenter != null) {
            caseNextNodePresenter.disposeRetrofitRequest();
        }
        if (caseHandlePresenter != null) {
            caseHandlePresenter.disposeRetrofitRequest();
        }
        if (mediaPlayer != null) {
            mediaPlayer.reset();
            mediaPlayer.release();
            mediaPlayer = null;
        }
    }

    @Override
    public void onBackPressed() {
        if (Jzvd.backPress()) {
            return;
        }
        super.onBackPressed();
    }

    @Override
    protected void onPause() {
        super.onPause();
        Jzvd.releaseAllVideos();
    }
}
