package com.danding.yang800;

import android.content.Context;
import android.content.SharedPreferences;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.danding.yang800.Presenter.RealNameActivityPresenter;
import com.danding.yang800.Util.StatusColorUtil;
import com.danding.yang800.View.AuthCodeCountDown;
import com.yanzhenjie.sofia.Sofia;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class RealNameActivity extends AppCompatActivity {
    @BindView(R.id.realName_nameEdit)
    EditText realName_nameEdit;
    @BindView(R.id.realName_codeEdit)
    EditText realName_codeEdit;
    @BindView(R.id.realName_backTv)
    TextView realName_backTv;
    RealNameActivityPresenter presenter;
    SharedPreferences sp;
    @BindView(R.id.realName_phoneNumberTv)
    TextView realName_phoneNumberTv;
    @BindView(R.id.realName_codeTv)
    TextView realName_codeTv;
    @BindView(R.id.realName_saveTv)
    TextView realName_saveTv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        int type = StatusColorUtil.StatusBarLightMode(this);
//        if (type > 0) {
//            StatusColorUtil.setStatusBarColor(this, R.color.white);
//            StatusColorUtil.StatusBarLightMode(this, type);
//        }
        setContentView(R.layout.activity_real_name);
        Sofia.with(this).statusBarDarkFont().statusBarBackground(ContextCompat.getColor(this, R.color.white));
        sp = getSharedPreferences("variable", Context.MODE_PRIVATE);
        ButterKnife.bind(this);
        realName_codeEdit.requestFocus();
        presenter = new RealNameActivityPresenter(this);
        presenter.getmobile(sp.getInt("userId", 0) + "");

    }

    @OnClick({R.id.realName_backTv, R.id.realName_codeTv, R.id.realName_saveTv})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.realName_backTv:
                finish();
                break;
            case R.id.realName_codeTv:
                presenter.smsSend(realName_phoneNumberTv.getText().toString());
                break;
            case R.id.realName_saveTv:
                presenter.updateRealname(realName_nameEdit.getText().toString().trim(), realName_codeEdit.getText().toString().trim());
                break;
        }
    }

    public void initData(String mobile) {
        realName_phoneNumberTv.setText(mobile);
    }

    public void sendSuccess() {
        AuthCodeCountDown mAuthCodeDown = new AuthCodeCountDown(60 * 1000 + 1100, realName_codeTv);
        mAuthCodeDown.start();
        realName_codeTv.setEnabled(false);
    }
}
