package com.danding.yang800;

import android.content.Context;
import android.content.Intent;
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.Adapter.AbstractWheelTextAdapter;
import com.danding.yang800.General.Yang800App;
import com.danding.yang800.Presenter.ProvePhoneActivityPresenter;
import com.danding.yang800.Util.StatusColorUtil;
import com.danding.yang800.Util.ToastUtil;
import com.danding.yang800.View.AuthCodeCountDown;
import com.danding.yang800.View.NetworkProgressDialog;
import com.yanzhenjie.sofia.Sofia;

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

public class ProvePhoneActivity extends BaseActivity {
    @BindView(R.id.provephone_saveTv)
    TextView provephone_saveTv;
    @BindView(R.id.provephone_changePhoneTv)
    TextView provephone_changePhoneTv;
    @BindView(R.id.provePhone_backTv)
    TextView provePhone_backTv;
    @BindView(R.id.provePhone_codeTv)
    TextView provePhone_codeTv;
    @BindView(R.id.provePhone_codeEdit)
    EditText provePhone_codeEdit;
    @BindView(R.id.provePhone_phoneNumberTv)
    TextView provePhone_phoneNumberTv;
    private NetworkProgressDialog pd;
    ProvePhoneActivityPresenter presenter;
    SharedPreferences sp;
    @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_prove_phone);
        Sofia.with(this).statusBarDarkFont().statusBarBackground(ContextCompat.getColor(this, R.color.white));
        sp = getSharedPreferences("variable", Context.MODE_PRIVATE);
        ButterKnife.bind(this);
        presenter = new ProvePhoneActivityPresenter(this);
        presenter.getInfo(sp.getInt("userId", 0)+"");
    }

    @OnClick({R.id.provephone_saveTv, R.id.provephone_changePhoneTv, R.id.provePhone_backTv, R.id.provePhone_codeTv})
    public void onViewClicked(View view) {
        if (view.getId() != R.id.provePhone_backTv) {
            if (!Yang800App.wifiConnect) {
                ToastUtil.show(this, "当前无网络");
                return;
            }
        }
        switch (view.getId()) {
            case R.id.provephone_saveTv:
                presenter.messageCode(sp.getInt("userId", 0)+"", provePhone_codeEdit.getText().toString().trim());
                break;
            case R.id.provephone_changePhoneTv:
                startActivity(CheckTakePassActivity.class);
                finish();
                break;
            case R.id.provePhone_backTv:
                finish();
                break;
            case R.id.provePhone_codeTv:
                presenter.getMobileCode(sp.getInt("userId", 0)+"");
                break;
        }
    }

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

    public void messageCodeSuccess() {
        startActivity(ChangePhoneActivity.class);
        finish();
    }

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

    public void initDialog() {
        if (pd == null) {
            pd = NetworkProgressDialog.createDialog(this);
            if (!pd.isShowing()) {
                pd.show();
            }
        }
    }

    public void dismissDialog() {
        if (pd != null) {
            pd.dismiss();
            pd = null;
            NetworkProgressDialog.clear();
        }
    }

}
