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.ImageView;
import android.widget.TextView;

import com.danding.yang800.Presenter.ChangeNameActivityPresenter;
import com.danding.yang800.Util.StatusColorUtil;
import com.danding.yang800.View.NetworkProgressDialog;
import com.yanzhenjie.sofia.Sofia;

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

public class ChangeShopNameActivity extends BaseActivity {
    @BindView(R.id.shopname_backTv)
    TextView shopname_backTv;
    @BindView(R.id.changenickname_edit)
    EditText changenickname_edit;
    @BindView(R.id.changenickname_tvsure)
    TextView changenickname_tvsure;
    ChangeNameActivityPresenter presenter;
    private NetworkProgressDialog pd = null;
    String storeId = "";
    boolean authentication = false;
    private String shopName = "";
    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_shop_name);
        Sofia.with(this).statusBarDarkFont().statusBarBackground(ContextCompat.getColor(this, R.color.white));
        sp = getSharedPreferences("variable", Context.MODE_PRIVATE);
        ButterKnife.bind(this);
        storeId = sp.getString("storeId", "");
        presenter = new ChangeNameActivityPresenter(this);
        Intent intent = getIntent();
        authentication = intent.getBooleanExtra("authentication", false);
        shopName = intent.getStringExtra("shopName");
        changenickname_edit.setText(shopName);
    }

    @OnClick({R.id.shopname_backTv, R.id.changenickname_tvsure})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.shopname_backTv:
                finish();
                break;
            case R.id.changenickname_tvsure:
                initDialog();
                presenter.updateInfo(storeId, authentication, changenickname_edit.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();
        }
    }
}
