package com.mjsheng.myappstore.dialog;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.mjsheng.myappstore.R;
import com.mjsheng.myappstore.image.ImageLoader;
import com.mjsheng.myappstore.widget.Sound;


/**
 * Created by Administrator on 2016/7/5.
 */
public class ExitDialog extends ShowDiaLog implements View.OnClickListener {

    private Context mContext;
    private PriorityListener listener;
    private Button mSureBtn, mCancleBtn;


    private Sound sound;

    public ExitDialog(Context context, PriorityListener listener) {
        super(context, R.style.password_dialog_style);
        this.mContext = context;
        this.listener = listener;

        sound = new Sound(context);
        init();
    }

    private void init() {

        View view = LayoutInflater.from(mContext).inflate(
                R.layout.main_exitapp_layout, null);
        setContentView(view);

        ImageLoader.getDefault().load(mContext, R.drawable.date_back_background,  (ImageView) view.findViewById(R.id.main_exitapp_panda));

        mSureBtn = (Button) view.findViewById(R.id.main_exitapp_sure);
        mCancleBtn = (Button) view.findViewById(R.id.main_exitapp_cancle);

        mSureBtn.setOnClickListener(this);
        mCancleBtn.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        sound.playSoundEffect();
        switch (v.getId()) {
            case R.id.main_exitapp_sure:
                listener.refreshPriorityUI("YES");
                dismiss();
                break;
            case R.id.main_exitapp_cancle:
                listener.refreshPriorityUI("NO");
                dismiss();
                break;
        }
    }

    @Override
    public void dismiss() {
        super.dismiss();
    }

    /**
     * 自定义Dialog监听器
     */
    public interface PriorityListener {
        /**
         * 回调函数，用于在Dialog的监听事件触发后刷新Activity的UI显示
         */
        public void refreshPriorityUI(String string);
    }
}

