package com.danding.yang800;

import android.content.Intent;
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.ChangeNameActivityPresenter;
import com.danding.yang800.Presenter.ShopDescribeActivityPresenter;
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 ShopDescribeActivity extends BaseActivity {
    @BindView(R.id.shodescribe_backTv)
    TextView shodescribe_backTv;
    @BindView(R.id.shodescribe_edit)
    EditText shodescribe_edit;
    @BindView(R.id.shodescribe_tvsure)
    TextView shodescribe_tvsure;
    ShopDescribeActivityPresenter presenter;
    private NetworkProgressDialog pd = null;
    String id;
    String des;
    boolean authentication;

    @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_shop_describe);
        Sofia.with(this).statusBarDarkFont().statusBarBackground(ContextCompat.getColor(this, R.color.white));
        ButterKnife.bind(this);
        presenter = new ShopDescribeActivityPresenter(this);
        Intent intent = getIntent();
        id = intent.getStringExtra("id");
        des = intent.getStringExtra("des");
        authentication = intent.getBooleanExtra("authentication", false);
        if (!des.equals(""))
            shodescribe_edit.setText(des);
    }

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