package com.stu.assistant.activity;

import android.content.Intent;
import android.content.res.Resources;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.stu.assistant.R;
import com.stu.assistant.base.BaseActivity;
import com.stu.assistant.base.BaseApplion;
import com.stu.assistant.dialog.DiaogUtil;
import com.stu.assistant.dialog.PopWindowUtils;
import com.stu.assistant.uitls.SharedConfig;
import com.stu.assistant.uitls.SharedUtil;

import cn.bmob.v3.BmobUser;

//设置页面
public class SettingActivity extends BaseActivity {

    private TextView accountTv, titleTv;
    private LinearLayout lay, backLay;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_setting;
    }

    @Override
    protected void initView() {
        accountTv = findViewById(R.id.tv_account);
        titleTv = findViewById(R.id.title_tv);
        titleTv.setText("设置");
        backLay = findViewById(R.id.back_lay);
        lay = findViewById(R.id.lay);
    }

    @Override
    protected void initData() {
        accountTv.setText("登录账号:" + SharedUtil.create(SettingActivity.this).getString(SharedConfig.loginName));
    }

    @Override
    protected void initListener() {
        backLay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(SettingActivity.this, MainActivity.class);
                startActivity(intent);
                finish();
            }
        });
    }

    public void BtnOutOnClick(View view) {
        BaseApplion.getActivityManage().finishAll();
        SharedUtil.create(BaseApplion.application).clear();
        BmobUser.logOut();
    }

    @Override
    public void onBackPressed() {
        Intent intent = new Intent(SettingActivity.this, MainActivity.class);
        startActivity(intent);
        finish();
    }

    public void OnColorClick(View view) {
        DiaogUtil.showSelectColorDialog(SettingActivity.this, lay, "", new DiaogUtil.OnNickNameLisenter() {
            @Override
            public void OnOkBtn(String msg, PopWindowUtils popWindow) {

                //自己跳转自己 ，关掉动画 无感处理
                Intent mIntent = getIntent();
                finish();
                //关掉栈中其他的activity ，但主页的不能关掉
                BaseApplion.getActivityManage().finishAct();
                overridePendingTransition(0, 0);
                startActivity(mIntent);
            }
        });
    }

    public void OnBgClick(View view) {
        DiaogUtil.showSelectBgDialog(SettingActivity.this, lay, new DiaogUtil.OnNickNameLisenter() {
            @Override
            public void OnOkBtn(String msg, PopWindowUtils popWindow) {
                Intent intent = new Intent(SettingActivity.this, MainActivity.class);
                startActivity(intent);
                finish();
            }
        });
    }
}