新增 选择机台

master
wanghao 2 months ago
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());
}
}
});
}
}

@ -42,6 +42,7 @@ public class BaseActivity extends AppCompatActivity implements MyScannerCall {
public static final int CAMERA_PHOTO = 1;
public static String url = "http://10.11.180.67:6080";
// public static String url = "http://1.13.177.47:6080";
public ProgressDialog dialog;
public Gson gson;
public MediaType JSON = MediaType.parse("application/json; charset=utf-8");

@ -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;
}
}

@ -1,77 +1,115 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ConfigActivity">
xmlns:tools="http://schemas.android.com/tools">
<include
layout="@layout/toolbar"
app:title='@{title??"机台配置"}' />
<data>
<variable
name="title"
type="String" />
<variable
name="data"
type="java.util.List" />
<variable
name="item"
type="com.example.haiwei_mom.data.MachineInfo" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="4dp">
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ConfigActivity">
<TextView
style="@style/text_title"
android:layout_width="100dp"
android:layout_height="match_parent"
android:text="选择机台:" />
<include
layout="@layout/toolbar"
app:title='@{title??"机台配置"}' />
<Spinner
style="@style/spinner_style"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:entries="@array/class_item"
android:text="@{user.nickName}" />
</LinearLayout>
android:layout_height="45dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="4dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="4dp">
<TextView
style="@style/text_title"
android:layout_width="100dp"
android:layout_height="match_parent"
android:text="选择机台:" />
<TextView
style="@style/text_title"
android:layout_width="100dp"
android:layout_height="match_parent"
android:text="机台名称:" />
<Spinner
android:id="@+id/config_spinner"
style="@style/spinner_style"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:entries="@{data}" />
</LinearLayout>
<TextView
style="@style/text_info"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@{been.companyName}" />
</LinearLayout>
android:layout_height="45dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="4dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="4dp">
<TextView
style="@style/text_title"
android:layout_width="100dp"
android:layout_height="match_parent"
android:text="机台编码:" />
<TextView
style="@style/text_title"
android:layout_width="100dp"
android:layout_height="match_parent"
android:text="服务地址:" />
<TextView
style="@style/text_info"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@{item.machineCode}" />
</LinearLayout>
<TextView
style="@style/text_info"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@{been.companyName}" />
</LinearLayout>
android:layout_height="45dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="4dp">
<Button
style="@style/button_submit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="提交" />
</LinearLayout>
<TextView
style="@style/text_title"
android:layout_width="100dp"
android:layout_height="match_parent"
android:text="机台名称:" />
<TextView
style="@style/text_info"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@{item.machineName}" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="4dp">
<TextView
style="@style/text_title"
android:layout_width="100dp"
android:layout_height="match_parent"
android:text="服务地址:" />
<TextView
style="@style/text_info"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@{item.machineIp}" />
</LinearLayout>
<Button
android:onClick="configSubmit"
android:layout_marginTop="200dp"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
style="@style/button_style"
android:text="保存" />
</LinearLayout>
</layout>
Loading…
Cancel
Save