package com.android.launcher3;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.android.launcher3.function.setting.SettingAdminActivity;
import com.android.launcher3.settings.ErrorTimeHelper;
import com.secspace.lib.common.dialog.other.DialogUIUtils;
import com.secspace.lib.common.function.DialogManager;
import com.secspace.lib.common.utils.InputUtil;
import com.secspace.lib.common.utils.Prefs;
import com.secspace.lib.common.utils.ToastUtil;


public class ManagerAuthActivity extends BaseActivity {
    protected Context mAppContext;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_manager_auth);
        mAppContext = this.getApplicationContext();
        showPwdDialog();
    }

    private void showPwdDialog() {
        DialogManager.INSTANCE.showPwdDialog(this, "请输入密码" ,new DialogManager.PwdListener(){

            @Override
            public void onPositive(View view) {
                EditText editText = (EditText) view;
                InputUtil.closeSoftInput(getApplicationContext(), editText);
                boolean canInputPwd = ErrorTimeHelper.getInstance(mAppContext).canInputPwd();
                if (canInputPwd){
                    if (TextUtils.equals(editText.getText().toString(), Prefs.getLoginPwd(mAppContext))) {
                        finish();
                        ErrorTimeHelper.getInstance(mAppContext).resetLockTimeAndCount();
                        Intent intent = new Intent();
                        intent.setClass(mAppContext, SettingAdminActivity.class);
                        startActivity(intent);
                    } else {
                        DialogUIUtils.showToastCenter("密码错误");
                        ErrorTimeHelper.getInstance(mAppContext).addErrorCount();
                        finish();
                    }
                }else {
                    ToastUtil.showShort(mAppContext,"请在"+ ErrorTimeHelper.getInstance(mAppContext).getCountDownTime()+"秒后重试");
                    finish();
                }
            }

            @Override
            public void onNegative() {
            }
        });
    }
}
