package com.sheep.gamegroup.view.dialog;

import android.app.Activity;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.sheep.gamegroup.event.BigEvent;
import com.sheep.gamegroup.event.EventTypes;
import com.sheep.gamegroup.greendao.download.DownLoadInfo;
import com.sheep.gamegroup.util.DownloadUtil;
import com.sheep.gamegroup.util.Jump2View;
import com.sheep.jiuyan.samllsheep.R;
import com.sheep.jiuyan.samllsheep.utils.SpUtils;

import org.greenrobot.eventbus.EventBus;

public class DialogAccountAbnormal {


    public static AlertDialog showDialog(final Activity activity) {
            View view = View.inflate(activity, R.layout.diag_account_abnormal, null);
        final AlertDialog mAlertDialog = new AlertDialog.Builder(activity, R.style.MyDialogActivityTheme)
                    .setView(view)
                    .create();
        view.findViewById(R.id.dialog_sure)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mAlertDialog.dismiss();
                    }
                });
        view.findViewById(R.id.dialog_close)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mAlertDialog.dismiss();
                    }
                });
        view.findViewById(R.id.dialog_action)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mAlertDialog.dismiss();
                        Jump2View.getInstance().goGuideDeArchive(activity, null);
                    }
                });
        try {
            mAlertDialog.show();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return mAlertDialog;
    }
    public static boolean showDialog(final Activity activity, String title, String content, String cancel, String sure, final DownLoadInfo downLoadInfo) {
        final boolean[] flag = {false};

        final DownloadUtil mDownloadTaskService = new DownloadUtil();

            View view = View.inflate(activity, R.layout.diag_account_abnormal, null);
        final AlertDialog mAlertDialog = new AlertDialog.Builder(activity)
                    .setView(view)
                    .create();
        if(TextUtils.isEmpty(title)){
            view.findViewById(R.id.title_tv).setVisibility(View.GONE);
        }else{
            ((TextView)view.findViewById(R.id.title_tv)).setText(title);
        }
        if(TextUtils.isEmpty(content)){
            view.findViewById(R.id.content_tv).setVisibility(View.GONE);
        }else{
            ((TextView)view.findViewById(R.id.content_tv)).setText(content);
        }
        TextView dialog_sure = view.findViewById(R.id.dialog_sure);
        dialog_sure.setText(sure+"");
        dialog_sure.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mAlertDialog.dismiss();
                        flag[0] = true;
                        SpUtils.saveDownNotice(activity, 2);
                        mDownloadTaskService.start(downLoadInfo);
                    }
                });
        ImageView dialog_close = view.findViewById(R.id.dialog_close);
        dialog_close.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mAlertDialog.dismiss();
                        flag[0] = false;
                        SpUtils.saveDownNotice(activity, 1);
                    }
                });
        TextView dialog_action = view.findViewById(R.id.dialog_action);
        dialog_action.setText(cancel+"");
        dialog_action.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mAlertDialog.dismiss();
                        flag[0] = false;
                        SpUtils.saveDownNotice(activity, 1);
                        mDownloadTaskService.start(downLoadInfo);

//                        EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.DIALOG_ACTIVITY_DOWNLOAD_FILE));
                    }
                });
        try {
            mAlertDialog.show();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag[0];
    }

    public static AlertDialog showDialogs(final Activity activity,String title, String content, String cancel, String sure) {
            View view = View.inflate(activity, R.layout.diag_account_abnormal, null);
        final AlertDialog mAlertDialog = new AlertDialog.Builder(activity, R.style.MyDialogActivityTheme)
                .setView(view)
                .create();
        if(TextUtils.isEmpty(title)){
            view.findViewById(R.id.title_tv).setVisibility(View.GONE);
        }else{
            ((TextView)view.findViewById(R.id.title_tv)).setText(title);
        }
        if(TextUtils.isEmpty(content)){
            view.findViewById(R.id.content_tv).setVisibility(View.GONE);
        }else{
            ((TextView)view.findViewById(R.id.content_tv)).setText(content);
        }
        TextView dialog_sure = view.findViewById(R.id.dialog_sure);
        dialog_sure.setText(cancel+"");
        dialog_sure.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mAlertDialog.dismiss();
                    }
                });
        ImageView dialog_close = view.findViewById(R.id.dialog_close);
        dialog_close.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mAlertDialog.dismiss();
                    }
                });
        TextView dialog_action = view.findViewById(R.id.dialog_action);
        dialog_action.setText(sure+"");
        dialog_action.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mAlertDialog.dismiss();

                        EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.DIALOG_ACTIVITY_DOWNLOAD_FILE));
                    }
                });
        try {
            mAlertDialog.show();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return mAlertDialog;
    }
}
