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.ChangeTakePassActivityPresenter;
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 ChangeTakePassActivity extends BaseActivity {
    @BindView(R.id.changeTakePass_backTv)
    TextView changeTakePass_backTv;
    @BindView(R.id.changeTakePass_saveTv)
    TextView changeTakePass_saveTv;
    @BindView(R.id.changeTakePass_OldPassEdit)
    EditText changeTakePass_OldPassEdit;
    @BindView(R.id.changeTakePass_newPassEdit)
    EditText changeTakePass_newPassEdit;
    @BindView(R.id.changeTakePass_newPassAgainEdit)
    EditText changeTakePass_newPassAgainEdit;
    private NetworkProgressDialog pd;
    ChangeTakePassActivityPresenter 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_take_pass);
        Sofia.with(this).statusBarDarkFont().statusBarBackground(ContextCompat.getColor(this, R.color.white));
        sp = getSharedPreferences("variable", Context.MODE_PRIVATE);
        ButterKnife.bind(this);
        presenter = new ChangeTakePassActivityPresenter(this);
    }

    @OnClick({R.id.changeTakePass_backTv, R.id.changeTakePass_saveTv})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.changeTakePass_backTv:
                finish();
                break;
            case R.id.changeTakePass_saveTv:
                presenter.updateWithdrawCashPassword(sp.getInt("userId", 0)+"", changeTakePass_OldPassEdit.getText().toString().trim(),
                        changeTakePass_newPassEdit.getText().toString().trim(), changeTakePass_newPassAgainEdit.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 successData() {
        ToastUtil.show(this, "修改成功");
        finish();
    }
}
