You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.9 KiB
Java
83 lines
2.9 KiB
Java
package com.example.haiwei_mom;
|
|
|
|
import android.os.Bundle;
|
|
import android.view.View;
|
|
import android.widget.AdapterView;
|
|
import android.widget.Toast;
|
|
|
|
import androidx.databinding.DataBindingUtil;
|
|
|
|
import com.example.haiwei_mom.base.BaseActivity;
|
|
import com.example.haiwei_mom.base.MyRecultCall;
|
|
import com.example.haiwei_mom.base.MyResult;
|
|
import com.example.haiwei_mom.data.MachineInfo;
|
|
import com.example.haiwei_mom.databinding.ActivityConfigBinding;
|
|
import com.example.haiwei_mom.uitls.SharedPreferencesUtils;
|
|
import com.google.gson.reflect.TypeToken;
|
|
import com.lzy.okgo.OkGo;
|
|
import com.lzy.okgo.model.Response;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class ConfigActivity extends BaseActivity {
|
|
private List<MachineInfo> machineInfoList;
|
|
private List<String> stringList;
|
|
private ActivityConfigBinding binding;
|
|
private MachineInfo machineInfo;
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
binding = DataBindingUtil.setContentView(this, R.layout.activity_config);
|
|
binding.configSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
|
@Override
|
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
|
machineInfo = machineInfoList.get(position);
|
|
binding.setItem(machineInfo);
|
|
}
|
|
|
|
@Override
|
|
public void onNothingSelected(AdapterView<?> parent) {
|
|
|
|
}
|
|
});
|
|
initRequest();
|
|
}
|
|
|
|
public void configSubmit(View view) {
|
|
if (machineInfo == null || machineInfo.getMachineIp().equals(":")) {
|
|
return;
|
|
}
|
|
SharedPreferencesUtils.putstring("machineIp", machineInfo.getMachineIp());
|
|
SharedPreferencesUtils.putstring("machineNo", machineInfo.getMachineCode());
|
|
SharedPreferencesUtils.putLong("machineId", machineInfo.getMachineId());
|
|
Toast.makeText(context, "保存成功", Toast.LENGTH_SHORT).show();
|
|
finish();
|
|
}
|
|
|
|
|
|
private void initRequest() {
|
|
|
|
OkGo.<MyResult>post(url + "/wms/pda/selectMachineInfo").tag(this).execute(new MyRecultCall(dialog, this) {
|
|
@Override
|
|
public void onSuccess(Response<MyResult> response) {
|
|
super.onSuccess(response);
|
|
var body = response.body();
|
|
if (body.getCode() == 200) {
|
|
|
|
machineInfoList = gson.fromJson(body.getDataJson(), new TypeToken<List<MachineInfo>>() {
|
|
}.getType());
|
|
stringList = new ArrayList<>(machineInfoList.size());
|
|
machineInfoList.forEach(t -> {
|
|
stringList.add(t.getMachineName());
|
|
|
|
});
|
|
binding.setData(stringList);
|
|
} else {
|
|
myToastUitls.show(body.getMsg());
|
|
}
|
|
}
|
|
});
|
|
}
|
|
} |