package com.qhclh.ytzh.home;

import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.qhclh.ytzh.R;
import com.qhclh.ytzh.base.BaseActivity;
import com.qhclh.ytzh.configs.ConfigUtil;
import com.qhclh.ytzh.configs.ServerConfig;
import com.qhclh.ytzh.utils.DialogUtil;
import com.qhclh.ytzh.utils.StringUtil;

import butterknife.BindView;

/**
 * Created by 青花瓷 on 2018/1/10.
 */

public class SetUrlActivity extends BaseActivity {
    @BindView(R.id.toolbar)
    Toolbar mToolbar;
    @BindView(R.id.et_url)
    EditText et_url;
    @BindView(R.id.btn_url)
    Button btn_url;

    private ServerConfig config;
    @Override
    protected int setLayoutId() {
        return R.layout.act_seturl;
    }

    @Override
    protected void initView() {
        initToolbar(mToolbar, "设置服务器地址", new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        config = new ServerConfig(this);
        ConfigUtil.Fill(config);
        if (config.getServerUri()!=null && !"".equals(config.getServerUri())) {
            et_url.setText(config.getServerUri());
        }else {
            et_url.setText("http://47.104.88.50/B3/");
        }
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initOper() {
        btn_url.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String url = et_url.getText().toString();
                if (StringUtil.IsNullOrEmpty(url)) {
                    DialogUtil.AutoHiddenAlert(SetUrlActivity.this, "服务器地址不能为空");
                    return;
                }
                config.setServerUri(url);
                ConfigUtil.Save(config);
                DialogUtil.AutoHiddenAlert(SetUrlActivity.this, "设置完成");
                finish();
            }
        });
    }
}
