package com.gh.gamecenter.adapter.viewholder;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentActivity;

import com.airbnb.lottie.LottieAnimationView;
import com.gh.common.chain.BrowserInstallHandler;
import com.gh.common.chain.CertificationHandler;
import com.gh.common.chain.ChainBuilder;
import com.gh.common.chain.ChainHandler;
import com.gh.common.chain.CheckDownloadHandler;
import com.gh.common.chain.CheckStoragePermissionHandler;
import com.gh.common.chain.DownloadDialogHelperHandler;
import com.gh.common.chain.GamePermissionHandler;
import com.gh.common.chain.OverseaDownloadHandler;
import com.gh.common.chain.PackageCheckHandler;
import com.gh.common.chain.UpdateNewSimulatorHandler;
import com.gh.common.chain.ValidateVSpaceHandler;
import com.gh.common.chain.VersionNumberHandler;
import com.gh.common.constant.Config;
import com.gh.common.dialog.DeviceRemindDialog;
import com.gh.common.dialog.GameOffServiceDialogFragment;
import com.gh.common.exposure.ExposureEvent;
import com.gh.common.filter.RegionSetting;
import com.gh.common.filter.RegionSettingHelper;
import com.gh.common.history.HistoryHelper;
import com.gh.common.simulator.NewSimulatorGameManager;
import com.gh.common.simulator.SimulatorDownloadManager;
import com.gh.common.simulator.SimulatorGameManager;
import com.gh.common.util.CheckLoginUtils;
import com.gh.common.util.DirectUtils;
import com.gh.common.xapk.XapkInstaller;
import com.gh.common.xapk.XapkUnzipStatus;
import com.gh.gamecenter.common.constant.EntranceConsts;
import com.gh.gamecenter.common.utils.DataLogUtils;
import com.gh.common.util.DetailDownloadUtils;
import com.gh.gamecenter.common.utils.DialogHelper;
import com.gh.common.util.DialogUtils;
import com.gh.gamecenter.core.utils.PageSwitchDataHelper;
import com.gh.gamecenter.energy.EnergyBridge;
import com.gh.common.util.LogUtils;
import com.gh.gamecenter.core.utils.MtaHelper;
import com.gh.common.util.PackageInstaller;
import com.gh.common.util.PackageUtils;
import com.gh.gamecenter.common.utils.PermissionHelper;
import com.gh.common.util.ReservationHelper;
import com.gh.common.view.DownloadButton;
import com.gh.download.DownloadManager;
import com.gh.download.dialog.DownloadDialog;
import com.gh.gamecenter.DownloadManagerActivity;
import com.gh.gamecenter.R;
import com.gh.gamecenter.WebActivity;
import com.gh.gamecenter.common.constant.Constants;
import com.gh.gamecenter.core.utils.StringUtils;
import com.gh.gamecenter.entity.ApkEntity;
import com.gh.gamecenter.entity.GameEntity;
import com.gh.gamecenter.common.entity.LinkEntity;
import com.gh.gamecenter.common.eventbus.EBReuse;
import com.gh.gamecenter.entity.SimulatorEntity;
import com.gh.gamecenter.eventbus.EBScroll;
import com.gh.gamecenter.gamedetail.GameDetailFragment;
import com.gh.gamecenter.gamedetail.dialog.GamePermissionDialogFragment;
import com.gh.gamecenter.manager.PackagesManager;
import com.gh.gamecenter.teenagermode.TeenagerModeActivity;
import com.gh.vspace.VDownloadManagerActivity;
import com.gh.vspace.VHelper;
import com.gh.vspace.VSpaceLoadingActivity;
import com.lightgame.download.DownloadEntity;
import com.lightgame.download.FileUtils;
import com.lightgame.utils.Utils;

import org.greenrobot.eventbus.EventBus;

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

/**
 * Created by khy on 27/06/17.
 * 详情页面下载ViewHolder
 */

public class DetailViewHolder {

    public Context context;

    public GameEntity gameEntity;
    public DownloadEntity downloadEntity;
    public ExposureEvent traceEvent;

    public boolean isNewsDetail; // 新闻详情不显示下载的游戏名, 只显示下载状态

    public View downloadBottom;

    public DownloadButton mDownloadPb;
    public LottieAnimationView mDownloadTips;
    public TextView mOverlayTv; // 额外的文字 (用于一些含图片的情况)
    public TextView mMultiVersionDownloadTv; // 多版本下载文字

    // 注意View的命名
    public DetailViewHolder(View view, GameEntity gameEntity, DownloadEntity downloadEntity,
                            boolean isNewsDetail, String entrance, String name, String title, @Nullable ExposureEvent traceEvent) {
        downloadBottom = view.findViewById(R.id.detail_ll_bottom);
        mDownloadPb = view.findViewById(R.id.detail_progressbar);
        mDownloadTips = view.findViewById(R.id.downloadTipsLottie);
        mOverlayTv = view.findViewById(R.id.overlayTv);
        mMultiVersionDownloadTv = view.findViewById(R.id.multiVersionDownloadTv);

        this.gameEntity = gameEntity;
        this.downloadEntity = downloadEntity;
        this.traceEvent = traceEvent;
        this.isNewsDetail = isNewsDetail;
        this.context = view.getContext();

        final OnDetailDownloadClickListener listener = new OnDetailDownloadClickListener(this, entrance, name, title, traceEvent);
        mDownloadPb.setOnClickListener(listener);

        restoreDialogFragment();
    }

    public TextView getOverlayTv() {
        return mOverlayTv;
    }

    private void restoreDialogFragment() {
        DialogFragment gamePermissionDialogFragment =
                (DialogFragment) ((AppCompatActivity) context).getSupportFragmentManager().findFragmentByTag(GamePermissionDialogFragment.class.getName());
        if (gamePermissionDialogFragment != null) {
            gamePermissionDialogFragment.dismissAllowingStateLoss();
        }
    }

    static class OnDetailDownloadClickListener implements View.OnClickListener {
        private DetailViewHolder mViewHolder;
        private GameEntity mGameEntity;
        private DownloadEntity mDownloadEntity;
        private String mEntrance;
        private String mName;
        private String mTitle;
        private ExposureEvent mTraceEvent;

        public OnDetailDownloadClickListener(DetailViewHolder viewHolder, String entrance, String name, String title, ExposureEvent traceEvent) {
            mViewHolder = viewHolder;
            mGameEntity = viewHolder.gameEntity;
            mDownloadEntity = viewHolder.downloadEntity;
            mEntrance = entrance;
            mName = name;
            mTitle = title;
            mTraceEvent = traceEvent;
        }

        @Override
        public void onClick(View v) {
            // 这个 switch 纯粹是为了 MTA和上报光能任务 统计用的
            switch (mViewHolder.mDownloadPb.getButtonStyle()) {
                case DOWNLOADING_PLUGIN:
                    MtaHelper.onEvent("游戏详情_新", "插件化中", mGameEntity.getName());
                    break;
                case DOWNLOADING_NORMAL:
                    MtaHelper.onEvent("游戏详情_新", "下载中", mGameEntity.getName());
                    break;
                case NONE:
                    MtaHelper.onEvent("游戏详情_新", "关闭下载", mGameEntity.getName());
                    break;
                case NORMAL:
                    MtaHelper.onEvent("游戏详情_新", "下载", mGameEntity.getName());
                    break;
                case PLUGIN:
                    MtaHelper.onEvent("游戏详情_新", "插件化", mGameEntity.getName());
                    break;
                case INSTALL_PLUGIN:
                    MtaHelper.onEvent("游戏详情_新", "安装插件化", mGameEntity.getName());
                    break;
                case INSTALL_NORMAL:
                    MtaHelper.onEvent("游戏详情_新", "安装", mGameEntity.getName());
                    break;
                case RESERVABLE:
                    MtaHelper.onEvent("游戏详情_新", "预约", mGameEntity.getName());
                    break;
                case LAUNCH_OR_OPEN:
                    if (!mGameEntity.getApk().isEmpty()) {
                        EnergyBridge.postEnergyTask("play_game", mGameEntity.getId(), mGameEntity.getApk().get(0).getPackageName());
                    }
                    break;
            }
            // 由于部分状态不包含在 downloadType 里，所以还是需要手动获取下载按钮文字判断点击时的状态
            String downloadText = mViewHolder.mDownloadPb.getText().toString();
            if (downloadText.contains("打开")) {
                MtaHelper.onEvent("游戏详情_新", "打开", mGameEntity.getName());
            } else if (downloadText.contains("启动")) {
                MtaHelper.onEvent("游戏详情_新", "启动", mGameEntity.getName());
            } else if (downloadText.contains("更新")) {
                MtaHelper.onEvent("游戏详情_新", "更新", mGameEntity.getName());
            }

            v.setTag(null);

            if (mViewHolder.mDownloadPb.getButtonStyle() != DownloadButton.ButtonStyle.INSTALL_NORMAL
                    && mViewHolder.mDownloadPb.getButtonStyle() != DownloadButton.ButtonStyle.INSTALL_PLUGIN
                    && mViewHolder.mDownloadPb.getButtonStyle() != DownloadButton.ButtonStyle.LAUNCH_OR_OPEN) {

                if (mGameEntity.isVGame() && !VHelper.INSTANCE.shouldLaunchGameAfterInstallation()) {
                    // 畅玩游戏的非真实点击下载按钮下载不需要滚动到特定地方
                } else {
                    EventBus.getDefault().post(new EBScroll(Constants.EB_GAME_DETAIL, mGameEntity.getId()));
                }
            }

            if (mDownloadEntity == null) {
                mDownloadEntity = DownloadManager.getInstance().getDownloadEntitySnapshot(mGameEntity);
            }

            if (mDownloadEntity != null) {
                String xapkStatus = mDownloadEntity.getMeta().get(XapkInstaller.XAPK_UNZIP_STATUS);
                if (XapkUnzipStatus.UNZIPPING.name().equals(xapkStatus)) {
                    XapkInstaller.cancelUnzipTask(mDownloadEntity);
                    return;
                } else if (XapkUnzipStatus.FAILURE.name().equals(xapkStatus)) {
                    PermissionHelper.checkStoragePermissionBeforeAction(mViewHolder.context, () -> {
                        if (mDownloadEntity != null) {
                            final String path = mDownloadEntity.getPath();
                            if (FileUtils.isEmptyFile(path)) {
                                Utils.toast(mViewHolder.context, R.string.install_failure_hint);
                                DownloadManager.getInstance().cancel(mDownloadEntity.getUrl());
                            } else {
                                PackageInstaller.install(mViewHolder.context, mDownloadEntity);
                            }
                        }
                    });
                    return;
                }
            }

            switch (mViewHolder.mDownloadPb.getButtonStyle()) {
                case NONE_WITH_HINT:
                case NONE:
                    String offStatus = mGameEntity.getDownloadOffStatus();
                    if (offStatus != null && !"off".equals(offStatus)) {
                        if ("dialog".equals(offStatus)) {
//                            MtaHelper.onEvent("游戏下载状态按钮", "查看详情", mGameEntity.getName());
                            showOffServiceDialog(mGameEntity.getDownloadOffDialog());
                        } else if ("toast".equals(offStatus)) {
//                            MtaHelper.onEvent("游戏下载状态按钮", "关闭且toast", mGameEntity.getName());
                            EventBus.getDefault().post(new EBReuse(GameDetailFragment.SKIP_RATING));
                            Utils.toast(mViewHolder.context, "该游戏因故暂不提供下载，具体详情可在相关评论中查看，敬请谅解～");
                        }
                    } else {
//                        MtaHelper.onEvent("游戏下载状态按钮", "暂无下载", mGameEntity.getName());
                        Utils.toast(mViewHolder.context, "该游戏已关闭下载");
                    }
                    break;
                case NORMAL:
                    final RegionSetting.GameH5Download gameH5Download = RegionSettingHelper.getGameH5DownloadByGameId(mGameEntity.getId());
                    if (gameH5Download != null) {
                        DialogUtils.showGameH5DownloadDialog(mViewHolder.context, mGameEntity, gameH5Download);
                        break;
                    } else {
                        DataLogUtils.uploadGameLog(mViewHolder.context, mGameEntity.getId(), mGameEntity.getName(), mEntrance);
                    }
                case PLUGIN:


                    ChainBuilder builder = new ChainBuilder();
                    builder.addHandler(new UpdateNewSimulatorHandler());
                    builder.addHandler(new ValidateVSpaceHandler());
                    builder.addHandler(new GamePermissionHandler());
                    builder.addHandler(new CheckStoragePermissionHandler());

                    if (mGameEntity.getApk().size() == 1) {
                        builder.addHandler(new BrowserInstallHandler());
                        builder.addHandler(new PackageCheckHandler());
                        builder.addHandler(new DownloadDialogHelperHandler());
                        builder.addHandler(new CertificationHandler());
                        builder.addHandler(new VersionNumberHandler());
                        builder.addHandler(new OverseaDownloadHandler());
                        builder.addHandler(new CheckDownloadHandler());

                        builder.setProcessEndCallback(o -> {
                            download((boolean) o);
                            return null;
                        });
                        final ChainHandler chainHandler = builder.buildHandlerChain();
                        if (chainHandler != null) {
                            chainHandler.handleRequest(v.getContext(), mGameEntity);
                        }
                    } else {
                        builder.addHandler(new CertificationHandler());
                        builder.addHandler(new VersionNumberHandler());
                        builder.setProcessEndCallback(o -> {
                            DownloadDialog.showDownloadDialog(
                                    mViewHolder.context,
                                    mGameEntity,
                                    mTraceEvent,
                                    StringUtils.buildString(mEntrance, "+(", mName, "[", mTitle, "])"),
                                    mName + ":" + mTitle);
                            return null;
                        });
                        final ChainHandler chainHandler = builder.buildHandlerChain();
                        if (chainHandler != null) {
                            chainHandler.handleRequest(v.getContext(), mGameEntity);
                        }
                    }

                    break;
                case LAUNCH_OR_OPEN:
                    if (mGameEntity.getApk().size() == 1) {
                        //启动模拟器游戏
                        if (SimulatorGameManager.isSimulatorGame(mGameEntity)) {
                            if (NewSimulatorGameManager.shouldShowUpdateNewSimulatorAlert(mViewHolder.context)) {
                                NewSimulatorGameManager.showUpdateNewsSimulator(mViewHolder.context, null);
                                return;
                            }
                            DownloadEntity downloadEntity = SimulatorGameManager.findDownloadEntityByUrl(mGameEntity.getApk().get(0).getUrl());
                            if (downloadEntity != null) {
                                File file = new File(downloadEntity.getPath());
                                if (!file.exists()) {
                                    download(false);
                                    return;
                                }
                                SimulatorGameManager.launchSimulatorGame(downloadEntity, mGameEntity);
                            }
                            return;
                        }

                        if (mGameEntity.isVGame()) {
                            VHelper.installOrLaunch(mViewHolder.context, mGameEntity.getApk().get(0).getPackageName());
                            return;
                        }

                        PackageUtils.launchApplicationByPackageName(mViewHolder.context, mGameEntity.getApk().get(0).getPackageName());
                    } else {
                        GamePermissionDialogFragment.show((AppCompatActivity) mViewHolder.context, mGameEntity, mGameEntity.getInfo(), () -> {
                            PermissionHelper.checkStoragePermissionBeforeAction(mViewHolder.context, () -> {
                                DownloadDialog.showDownloadDialog(
                                        mViewHolder.context,
                                        mGameEntity,
                                        mTraceEvent,
                                        StringUtils.buildString(mEntrance, "+(", mName, "[", mTitle, "])"),
                                        mName + ":" + mTitle);
                            });
                        });
                    }
                    break;
                case INSTALL_PLUGIN:
                case INSTALL_NORMAL:
                    if (mGameEntity.getApk().isEmpty()) return;

                    ApkEntity apk = mGameEntity.getApk().get(0);
                    DownloadEntity downloadEntity = SimulatorGameManager.findDownloadEntityByUrl(apk.getUrl());
                    if (mGameEntity.getSimulator() != null) {
                        boolean isInstalled = PackageUtils.isInstalledFromAllPackage(mViewHolder.context, mGameEntity.getSimulator().getApk().getPackageName());
                        boolean isInstalledNewSimulator = SimulatorGameManager.isNewSimulatorInstalled(mViewHolder.context);
                        boolean isInstalledOldSimulator = SimulatorGameManager.isOldSimulatorInstalled(mViewHolder.context);
                        SimulatorEntity simulator = mGameEntity.getSimulator();
                        SimulatorEntity newSimulator = Config.getNewSimulatorEntitySetting();
                        if (!isInstalledOldSimulator && newSimulator != null) {
                            if (newSimulator.getActive()) {
                                simulator = newSimulator;
                            }
                        }

                        if (downloadEntity != null && SimulatorGameManager.isSimulatorGame(mGameEntity) && !isInstalled && !isInstalledNewSimulator) {
                            SimulatorDownloadManager.getInstance().showDownloadDialog(mViewHolder.context, simulator,
                                    SimulatorDownloadManager.SimulatorLocation.LAUNCH, mGameEntity.getId(), mGameEntity.getName(), null);
                            return;
                        }
                    }

                    if (mGameEntity.isVGame()) {
                        VHelper.installOrLaunch(v.getContext(), mGameEntity.getApk().get(0).getPackageName());
                        return;
                    }

                    PermissionHelper.checkStoragePermissionBeforeAction(mViewHolder.context, () -> {
                        if (mDownloadEntity == null) {
                            mDownloadEntity = DownloadManager.getInstance().getDownloadEntitySnapshot(mGameEntity);
                        }

                        if (mDownloadEntity != null) {
                            final String path = mDownloadEntity.getPath();
                            if (FileUtils.isEmptyFile(path)) {
                                Utils.toast(mViewHolder.context, R.string.install_failure_hint);
                                DownloadManager.getInstance().cancel(mDownloadEntity.getUrl());
                            } else {
                                PackageInstaller.install(mViewHolder.context, mDownloadEntity);
                            }
                        }
                    });
                    break;
                case RESERVABLE:
                    GamePermissionDialogFragment.show((AppCompatActivity) mViewHolder.context, mGameEntity, mGameEntity.getInfo(), () -> {
                        CheckLoginUtils.checkLogin(mViewHolder.context, mEntrance, () -> {
                            ReservationHelper.reserve(mViewHolder.context, mGameEntity.getId(), () -> {
                                LogUtils.logReservation(mGameEntity, mTraceEvent);
                                DetailDownloadUtils.detailInitDownload(mViewHolder, false);
                            });
                        });
                    });
                    break;
                case RESERVED:
                    if ("download".equals(mGameEntity.getReserveStatus())) {
                        ReservationHelper.showDeleteReservationDialog(mViewHolder.context, () -> {
                            ReservationHelper.deleteReservation(mGameEntity, () -> {
                                DetailDownloadUtils.detailInitDownload(mViewHolder, false);
                            });
                        });
                    } else {
                        ReservationHelper.showCancelReservationDialog(mViewHolder.context, () -> {
                            ReservationHelper.cancelReservation(mGameEntity, () -> {
                                DetailDownloadUtils.detailInitDownload(mViewHolder, false);
                            });
                        });
                    }
                    break;
                case H5_GAME:
                    MtaHelper.onEvent("H5页面", "入口", "详情页_" + mGameEntity.getName());
                    LinkEntity linkEntity = mGameEntity.getH5Link();

                    boolean isPlay = "play".equals(linkEntity.getType()); // 是否为开始玩
                    if (isPlay) {
                        HistoryHelper.insertGameEntity(mGameEntity);
                    }

                    GamePermissionDialogFragment.show((AppCompatActivity) mViewHolder.context, mGameEntity, mGameEntity.getInfo(), () -> {
                        Intent i = new Intent(WebActivity.getIntentForWebGame(mViewHolder.context, linkEntity.getLink(), mGameEntity.getName(), isPlay, linkEntity.getCloseButton()));
                        mViewHolder.context.startActivity(i);
                    });
                    break;
                case UPDATING:
                    Utils.toast(mViewHolder.context, "正在加急更新版本，敬请后续留意");
                    break;
                case TEENAGER_MODE:
                    DialogHelper.showCenterDialog(
                            mViewHolder.context,
                            "提示", "当前处于儿童/青少年模式， \n暂不提供游戏下载", "退出青少年模式", "关闭",
                            () -> mViewHolder.context.startActivity(TeenagerModeActivity.getIntent(mViewHolder.context)),
                            () -> {
                            }
                    );
                    break;
                case SPECIAL_DOWNLOAD:
                    RegionSetting.GameSpecialDownloadInfo info = RegionSettingHelper.getGameSpecialDownloadInfo(mGameEntity.getId());
                    if (info != null && !TextUtils.isEmpty(info.getBbsId())) {
                        if (!TextUtils.isEmpty(info.getTopId())) {
                            HashMap<String, String> map = new HashMap<>();
                            map.put(EntranceConsts.KEY_TOP_ID, info.getTopId());
                            PageSwitchDataHelper.pushCurrentPageData(map);
                        }
                        DirectUtils.directForumDetail(mViewHolder.context, info.getBbsId(), mEntrance);
                    }
                    break;
                case WAITING:
                    Utils.toast(mViewHolder.context, "最多只能同时下载三个任务，请稍等");
                    break;
                case DOWNLOADING_NORMAL:
                case DOWNLOADING_PLUGIN:
                    if (mDownloadEntity == null) {
                        mDownloadEntity = DownloadManager.getInstance().getDownloadEntitySnapshot(mGameEntity);
                    }

                    if (mDownloadEntity != null) {
                        if (downloadText.contains("继续加载")) {
                            DownloadManager.getInstance().resume(mDownloadEntity, true);
                        } else {
                            DownloadManager.getInstance().pause(mDownloadEntity.getUrl());
                            mViewHolder.mDownloadPb.setText("继续加载 " + mDownloadEntity.getPercent() + "%");
                        }
                    }
                    break;
                default:
                    if (mGameEntity.isVGame()) {
                        mViewHolder.context.startActivity(VDownloadManagerActivity.getIntent(mViewHolder.context, true));
                    } else if (!mGameEntity.getApk().isEmpty()) {
                        Intent intent = DownloadManagerActivity.getDownloadMangerIntent(mViewHolder.context,
                                mGameEntity.getApk().get(0).getUrl(),
                                StringUtils.buildString(mEntrance, "+(", mName, "[", mTitle, "])"));
                        mViewHolder.context.startActivity(intent);
                    }
                    break;
            }
        }

        private void showOffServiceDialog(GameEntity.Dialog dialog) {
            GameOffServiceDialogFragment dialogFragment = GameOffServiceDialogFragment.getInstance(dialog);
            dialogFragment.show(((FragmentActivity) mViewHolder.context).getSupportFragmentManager(), "off_service_dialog");
        }

        private void download(boolean isSubscribe) {
            String str = mViewHolder.mDownloadPb.getText().toString();
            String method;
            if (str.contains("更新")) {
                method = "更新";
            } else if (str.contains("插件化")) {
                method = "插件化";
            } else {
                method = mViewHolder.context.getString(R.string.download);
            }

            if (mGameEntity.getApk().size() == 0) {
                Utils.toast(mViewHolder.context, "暂时无法下载，请稍后再试");
                return;
            }

            ApkEntity apkEntity = mGameEntity.getApk().get(0);
            String msg = FileUtils.isCanDownload(mViewHolder.context, apkEntity.getSize());
            if (TextUtils.isEmpty(msg)) {
                if (mGameEntity.isVGame() && "更新".equals(method)) {
                    VHelper.updateOrReDownload(mGameEntity);
                } else {
                    DownloadManager.createDownload(mViewHolder.context,
                            apkEntity,
                            mGameEntity,
                            method,
                            StringUtils.buildString(mEntrance, "+(", mName, "[", mTitle, "])"),
                            mName + ":" + mTitle,
                            isSubscribe,
                            mTraceEvent);
                }

                mViewHolder.mDownloadPb.setProgress(0);
                mViewHolder.mDownloadPb.setButtonStyle("插件化".equals(method) ?
                        DownloadButton.ButtonStyle.DOWNLOADING_PLUGIN : DownloadButton.ButtonStyle.DOWNLOADING_NORMAL);
                DeviceRemindDialog.Companion.showDeviceRemindDialog(mViewHolder.context, mGameEntity);

                if (mGameEntity.isVGame() && mViewHolder.context.getString(R.string.download).equals(method) && VHelper.INSTANCE.shouldLaunchGameAfterInstallation()) {
                    mViewHolder.context.startActivity(VSpaceLoadingActivity.getIntent(mViewHolder.context, mGameEntity, false));
                }
            } else {
                Utils.toast(mViewHolder.context, msg);
            }
        }
    }

}
