新增 选择机台
parent
9d6ecd4a21
commit
e43428fc7e
@ -1,16 +1,81 @@
|
||||
package com.example.haiwei_mom;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
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;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_config);
|
||||
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();
|
||||
}
|
||||
private MachineInfo machineInfo;
|
||||
public void configSubmit(View view) {
|
||||
if (machineInfo==null|| machineInfo.getMachineIp().equals(":")){
|
||||
return;
|
||||
}
|
||||
SharedPreferencesUtils.putstring("machineIp", machineInfo.getMachineIp());
|
||||
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());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.example.haiwei_mom.data;
|
||||
|
||||
|
||||
public class MachineInfo {
|
||||
private String machineCode,
|
||||
machineName,
|
||||
machineIp;
|
||||
|
||||
|
||||
public String getMachineCode() {
|
||||
return machineCode;
|
||||
}
|
||||
|
||||
public void setMachineCode(String machineCode) {
|
||||
this.machineCode = machineCode;
|
||||
}
|
||||
|
||||
public String getMachineName() {
|
||||
return machineName;
|
||||
}
|
||||
|
||||
public void setMachineName(String machineName) {
|
||||
this.machineName = machineName;
|
||||
}
|
||||
|
||||
public String getMachineIp() {
|
||||
return machineIp;
|
||||
}
|
||||
|
||||
public void setMachineIp(String machineIp) {
|
||||
this.machineIp = machineIp;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue