package xn.hxp.base;

import com.blankj.utilcode.util.StringUtils;
import com.blankj.utilcode.util.ThreadUtils;
import com.hjq.toast.ToastParams;
import com.hjq.toast.Toaster;
import com.hjq.toast.style.CustomToastStyle;
import com.kongzue.dialogx.DialogX;
import com.kongzue.dialogx.dialogs.PopTip;
import com.kongzue.dialogx.dialogs.WaitDialog;

import java.util.concurrent.TimeUnit;

import xn.hxp.R;

public class BaseActivityHelp {
    private BaseActivity baseActivity;
    private ThreadUtils.SimpleTask<Object> cdDismissTask;
    private ThreadUtils.SimpleTask<Object> cdErrDismissTask;

    public BaseActivityHelp(BaseActivity baseActivity) {
        this.baseActivity = baseActivity;
    }

    public void onDestroy() {
        ThreadUtils.cancel(cdDismissTask);
    }

    public void showLoading(String msg) {
        ThreadUtils.cancel(cdDismissTask);
        if (StringUtils.isEmpty(msg)) {
            msg = "请稍等...";
        }
        WaitDialog.show(msg).setCancelable(DialogX.cancelable);
        ThreadUtils.executeByCachedWithDelay(cdDismissTask = new ThreadUtils.SimpleTask<Object>() {
            @Override
            public Object doInBackground() throws Throwable {
                return null;
            }

            @Override
            public void onSuccess(Object result) {
                WaitDialog.dismiss();
            }
        }, 20, TimeUnit.SECONDS);
    }

    public void dismissLoading() {
        ThreadUtils.cancel(cdDismissTask);
        WaitDialog.dismiss();
    }

    public void showToast(String msg) {
        Toaster.setView(R.layout.toast);
        Toaster.show(msg);
    }

    public void showErr(String msg) {
        Toaster.setView(R.layout.toast_err);
        Toaster.show(msg);
    }

    public void showSuccess(String msg) {
        Toaster.setView(R.layout.toast_success);
        Toaster.show(msg);
    }

    public void showErr(String msg, String hint) {
        PopTip.show(msg).iconError();
        PopTip.show(hint);
    }

    public void showWarn() {

    }
}
