package com.sheep.gamegroup.view.dialog;

import android.app.Activity;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.text.Html;
import android.view.View;
import android.widget.TextView;

import com.sheep.gamegroup.model.entity.NewbieTask;
import com.sheep.gamegroup.model.entity.NewbieTaskRecord;
import com.sheep.gamegroup.util.Jump2View;
import com.sheep.gamegroup.util.MyDbManager;
import com.sheep.gamegroup.util.UMConfigUtils;
import com.sheep.jiuyan.samllsheep.R;


public class DialogNewbieTaskRegisterSuccess {

    public static AlertDialog showDialog(final Activity activity, final NewbieTaskRecord newbie_task_record, NewbieTask task) {
        UMConfigUtils.onEvent(UMConfigUtils.Event.SHEEP_NEWBIE_TASK_REGIST_SUCCESS_DIALOG);
        View view = View.inflate(activity, R.layout.dialog_newbie_task_1, null);
        final AlertDialog mAlertDialog = new AlertDialog.Builder(activity, R.style.MyDialogActivityTheme)
                .setView(view)
                .create();
        final TextView dialog_tip = view.findViewById(R.id.dialog_tip);
        String sr = "获得新人注册奖励 "+"<font color='#e2271d'><big>" + task.getAmount() + "</big></font> 元";
        dialog_tip.setText(Html.fromHtml(sr));

        view.findViewById(R.id.dialog_sure_list).setVisibility(View.GONE);
        final TextView dialog_sure = view.findViewById(R.id.dialog_sure);
        dialog_sure.setVisibility(View.VISIBLE);
        dialog_sure.setText("了解小绵羊，领取更多奖励");
        dialog_sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Jump2View.getInstance().goUnderstandSheep(activity, newbie_task_record);
                mAlertDialog.dismiss();
            }
        });
        mAlertDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialogInterface) {

                try {
                    if(newbie_task_record == null)
                        return;
                    newbie_task_record.setDontShowNewbieTaskDialog(true);
                    MyDbManager.getInstance().saveOrUpdate(newbie_task_record);//设置为不再显示新手对话框
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        final View dialog_close = view.findViewById(R.id.dialog_close);
        dialog_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                try {
                    if(newbie_task_record == null)
                        return;
                    mAlertDialog.dismiss();
                    newbie_task_record.setDontShowNewbieTaskDialog(true);
                    MyDbManager.getInstance().saveOrUpdate(newbie_task_record);//设置为不再显示新手对话框
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        try {
            mAlertDialog.show();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return mAlertDialog;
    }
}
