package com.jimind.sportdemo;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.jimind.sportdemo.base.BaseActivity;
import com.jimind.sportdemo.utils.CommonUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 系统配置
 *
 * @author Any
 */
public class SettingActivity extends BaseActivity {

    @BindView(R.id.fl_setting)
    FrameLayout flTitleBar;
    @BindView(R.id.tv_bar_title)
    TextView tvBarTitle;
    @BindView(R.id.et_ip)
    EditText etIp;

    @Override
    protected int getLayoutResource() {
        return R.layout.activity_setting;
    }

    @Override
    protected void initView() {
        CommonUtils.initTitleBar(this, flTitleBar);
        tvBarTitle.setText("系统设置");
    }

    @OnClick({R.id.ib_bar_back, R.id.bt_sure})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ib_bar_back:
                showTip();
                Intent intent=new Intent();
                intent.putExtra("ip",etIp.getText().toString());
                setResult(200,intent);
                finish();
                break;
            case R.id.bt_sure:
                showTip();
                break;
            default:
        }
    }

    /**
     * 显示提示
     */
    private void showTip() {
        String ip = etIp.getText().toString();
        if (TextUtils.isEmpty(ip)) {
            Toast.makeText(SettingActivity.this, "您还没有设置IP！", Toast.LENGTH_SHORT).show();
        }
        MyApplication.getInstance().setHost(ip);
        Toast.makeText(SettingActivity.this, "设置成功", Toast.LENGTH_SHORT).show();
    }
}
