package com.danding.yang800;

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

import com.danding.yang800.Presenter.SetTakePassActivityPresenter;
import com.danding.yang800.Util.MD5Util;
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 SetTakePassActivity extends BaseActivity {
    @BindView(R.id.setTakePass_saveTv)
    TextView setTakePass_saveTv;
    @BindView(R.id.setTakePass_backTv)
    TextView setTakePass_backTv;
    @BindView(R.id.setTakePass_passEdit)
    EditText setTakePass_passEdit;
    @BindView(R.id.setTakePass_passAgainEdit)
    EditText setTakePass_passAgainEdit;
    private NetworkProgressDialog pd;
    SetTakePassActivityPresenter presenter;
    private boolean profit;
    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_set_take_pass);
        Sofia.with(this).statusBarDarkFont().statusBarBackground(ContextCompat.getColor(this, R.color.white));
        sp = getSharedPreferences("variable", Context.MODE_PRIVATE);
        ButterKnife.bind(this);
        Intent intent = getIntent();
        profit = intent.getBooleanExtra("profit", false);
        setTakePass_passEdit.requestFocus();
        if (profit) {
            setTakePass_passEdit.setHint("请输入新的提现密码");
            setTakePass_passAgainEdit.setHint("请再次输入新的提现密码");
        } else {
            setTakePass_passEdit.setHint("请输入您的提现密码");
            setTakePass_passAgainEdit.setHint("请再次输入您的提现密码");
        }
        presenter = new SetTakePassActivityPresenter(this);
    }

    @OnClick({R.id.setTakePass_saveTv, R.id.setTakePass_backTv})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.setTakePass_saveTv:
                presenter.updateWithdrawCashPassword(sp.getInt("userId", 0)+"", setTakePass_passEdit.getText().toString().trim(),
                        setTakePass_passAgainEdit.getText().toString().trim());
                //  startActivity(ChangeTakePassActivity.class);
                break;
            case R.id.setTakePass_backTv:
                finish();
                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() {

    }
}
