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.ChangePhoneActivityPresenter;
import com.danding.yang800.Util.StatusColorUtil;
import com.danding.yang800.Util.ToastUtil;
import com.danding.yang800.View.NetworkProgressDialog;
import com.yanzhenjie.sofia.Sofia;

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

public class ChangePhoneActivity extends BaseActivity {
    @BindView(R.id.changePhone_backTv)
    TextView changePhone_backTv;
    @BindView(R.id.changephone_saveTv)
    TextView changephone_saveTv;
    private NetworkProgressDialog pd;
    @BindView(R.id.changePhone_newPhoneEdit)
    EditText changePhone_newPhoneEdit;
    @BindView(R.id.changePhone_newPhoneAgainEdit)
    EditText changePhone_newPhoneAgainEdit;
    ChangePhoneActivityPresenter 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_change_phone);
        Sofia.with(this).statusBarDarkFont().statusBarBackground(ContextCompat.getColor(this, R.color.white));
        sp = getSharedPreferences("variable", Context.MODE_PRIVATE);
        ButterKnife.bind(this);
        presenter = new ChangePhoneActivityPresenter(this);
        changePhone_newPhoneEdit.requestFocus();
    }

    @OnClick({R.id.changePhone_backTv, R.id.changephone_saveTv})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.changePhone_backTv:
                finish();
                break;
            case R.id.changephone_saveTv:
                presenter.updateMobile(sp.getInt("userId", 0)+"", changePhone_newPhoneEdit.getText().toString().trim(),
                        changePhone_newPhoneAgainEdit.getText().toString().trim());
                break;
        }
    }

    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();
        }
    }

    public void updateMobileSuccess() {
        dismissDialog();
        ToastUtil.show(this, "更改成功");
        finish();
    }
}
