package ai.pai.client.views;

import android.app.Activity;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;

import com.android.views.popup.BasePopupWindow;

import ai.pai.client.R;
import ai.pai.client.activity.GuideActivity;
import ai.pai.client.db.DBService;
import ai.pai.client.db.Preferences;

/**
 * Created by chengzhenyu on 2016/3/4.
 */
public class SignOutConfirmPopup extends BasePopupWindow implements View.OnClickListener{

    private View popupView;

    public SignOutConfirmPopup(Activity context) {
        super(context);
        bindEvent();
    }

    @Override
    protected Animation getShowAnimation() {
        return getDefaultScaleAnimation();
    }

    @Override
    protected View getClickToDismissView() {
        return popupView.findViewById(R.id.click_to_dismiss);
    }

    @Override
    public View getPopupView() {
        popupView= LayoutInflater.from(mContext).inflate(R.layout.popup_signout_confirm,null);
        return popupView;
    }

    @Override
    public View getAnimaView() {
        return popupView.findViewById(R.id.popup_anima);
    }

    private void bindEvent() {
        if (popupView!=null){
            popupView.findViewById(R.id.btn_cancel_signout).setOnClickListener(this);
            popupView.findViewById(R.id.btn_signout_confirm).setOnClickListener(this);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_cancel_signout:
                dismiss();
                break;
            case R.id.btn_signout_confirm:
                dismiss();
                DBService.getInstance(mContext).clearDB();
                Preferences.getInstance(mContext).clearPrefs();
                mContext.startActivity(new Intent(mContext,GuideActivity.class));
                mContext.finish();
                break;
        }
    }
}
