测试 巡检

idata
wangh 1 year ago
parent 35a44b4000
commit 2bba5688aa

@ -1,17 +1,137 @@
package com.example.beijing_daxing;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.BaseObservable;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ObservableBoolean;
import androidx.databinding.ObservableField;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.Toast;
import com.example.beijing_daxing.adapter.CheckAdapter;
import com.example.beijing_daxing.base.AdapterClickCall;
import com.example.beijing_daxing.base.BaseActivity;
import com.example.beijing_daxing.base.MyRecultCall;
import com.example.beijing_daxing.base.MyResult;
import com.example.beijing_daxing.been.Stock;
import com.example.beijing_daxing.databinding.ActivityCheckBinding;
import com.example.beijing_daxing.uitls.SharedPreferencesUtils;
import com.google.gson.reflect.TypeToken;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
public class CheckActivity extends AppCompatActivity {
import java.util.Arrays;
import java.util.List;
public class CheckActivity extends BaseActivity implements AdapterClickCall {
private ActivityCheckBinding binding;
private CheckAdapter adapter;
private List<Stock> list;
private List<String> selectList;
private ObservableBoolean state;
private AlertDialog.Builder inputDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivityCheckBinding binding= DataBindingUtil.setContentView(this,R.layout.activity_check);
binding = DataBindingUtil.setContentView(this, R.layout.activity_check);
adapter = new CheckAdapter(this, this);
state = new ObservableBoolean();
binding.setAdapter(adapter);
binding.setState(state);
selectList = Arrays.asList(getResources().getStringArray(R.array.check_item));
binding.checkItemSelect.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
var selectItem = selectList.get(position);
state.set(selectItem.equals("正常"));
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
initRequest();
initAlertDialog();
}
private void initAlertDialog() {
final EditText editText = new EditText(this);
inputDialog = new AlertDialog.Builder(this);
inputDialog.setTitle("输入跳过原因").setView(editText);
inputDialog.setPositiveButton("确定", (dialog, which) -> {
var stock = list.get(tag);
stock.setState("跳过");
stock.setRemark(editText.getText().toString());
adapter.notifyItemChanged(tag);
});
}
private void initRequest() {
OkGo.<MyResult>post(url + "/xj/select").params("user", SharedPreferencesUtils.getstring("user", "")).execute(new MyRecultCall(dialog, this) {
@Override
public void onSuccess(Response<MyResult> response) {
super.onSuccess(response);
var body = response.body();
if (body.getCode() == 0) {
list = gson.fromJson(body.getData().toString(), new TypeToken<List<Stock>>() {
}.getType());
adapter.setList(list);
adapter.notifyDataSetChanged();
return;
}
Toast.makeText(CheckActivity.this, body.getMsg(), Toast.LENGTH_SHORT).show();
}
});
}
private int subIndex=-1;
@Override
protected void sanRfid(List<String> epcs) {
var text = epcs.get(0);
binding.checkEpc.setText(text);
Stock stock=new Stock();
stock.setEpcCode(text);
var index = list.indexOf(stock);
if (index==-1){
Toast.makeText(this, "轮挡扫描错误", Toast.LENGTH_SHORT).show();
return;
}
subIndex=index;
}
public void check_submit(View view) {
list.forEach(t->{
if (t.getState().equals("未检")) return;
});
// OkGo.<MyResult>pos
}
public void check_stock(View view) {
if (subIndex==-1) return;
var stock = list.get(subIndex);
stock.setState(binding.checkItemSelect.getSelectedItem().toString());
stock.setRemark(binding.checkRemark.getText().toString());
adapter.notifyItemChanged(subIndex);
binding.checkRemark.setText(null);
binding.checkEpc.setText(null);
}
private int tag;
@Override
public void clickItem(int index) {
tag = index;
inputDialog.show();
}
}

@ -0,0 +1,68 @@
package com.example.beijing_daxing.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;
import com.example.beijing_daxing.BR;
import com.example.beijing_daxing.R;
import com.example.beijing_daxing.base.AdapterClickCall;
import com.example.beijing_daxing.been.Stock;
import com.example.beijing_daxing.databinding.ItemCheckBinding;
import com.example.beijing_daxing.databinding.ItemStoreCheckBinding;
import java.util.List;
/**
* @author wanghao
* @date 2024/1/19 14:32
*/
public class CheckAdapter extends RecyclerView.Adapter<CheckAdapter.MyViewHoder> {
private Context context;
private List<Stock> list;
private LayoutInflater inflater;
private AdapterClickCall call;
public CheckAdapter(Context context,AdapterClickCall call) {
this.context = context;
inflater = LayoutInflater.from(context);
this.call=call;
}
public void setList(List<Stock> list) {
this.list = list;
}
@Override
public MyViewHoder onCreateViewHolder(ViewGroup parent, int viewType) {
ItemCheckBinding binding = DataBindingUtil.inflate(inflater, R.layout.item_check, parent, false);
return new MyViewHoder(binding);
}
@Override
public void onBindViewHolder(MyViewHoder holder, int position) {
var binding = holder.getBinding();
binding.setVariable(BR.item,list.get(position));
binding.itemCheckClick.setOnClickListener(v -> call.clickItem(position));
}
@Override
public int getItemCount() {
return list==null?0:list.size();
}
public class MyViewHoder extends RecyclerView.ViewHolder {
private ItemCheckBinding binding;
public MyViewHoder( ItemCheckBinding binding) {
super(binding.getRoot());
this.binding = binding;
}
public ItemCheckBinding getBinding() {
return binding;
}
}
}

@ -4,7 +4,15 @@
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="adapter"
type="com.example.beijing_daxing.adapter.CheckAdapter" />
<variable
name="state"
type="androidx.databinding.ObservableBoolean" />
<import type="android.view.View"/>
</data>
<LinearLayout
@ -26,8 +34,9 @@
android:layout_marginTop="10dp"/>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="500dp"
android:background="@color/white"
android:layout_height="450dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:adapter="@{adapter}"
android:padding="10dp" />
<LinearLayout
@ -42,6 +51,7 @@
android:text="扫描RFID:" />
<TextView
android:id="@+id/check_epc"
style="@style/san_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -49,7 +59,7 @@
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_height="48dp"
android:layout_marginEnd="10dp"
android:background="@color/white"
android:layout_marginTop="10dp">
@ -62,15 +72,18 @@
android:text="选择原因:" />
<Spinner
android:id="@+id/check_item_select"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:entries="@array/check_item"
android:textAlignment="center"/>
</LinearLayout>
<LinearLayout
android:id="@+id/check_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:visibility='@{state ? View.GONE :View.VISIBLE }'
android:focusable="true"
android:focusableInTouchMode="true">
@ -81,11 +94,12 @@
android:text="输入原因:" />
<EditText
android:id="@+id/check_remark"
style="@style/info_text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:minHeight="45dp"/>
android:minHeight="48dp"/>
</LinearLayout>
<Button
@ -93,6 +107,16 @@
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:onClick="check_stock"
android:text="提交" />
<Button
style="@style/button_style"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:onClick="check_submit"
android:backgroundTint="#009688"
android:text="完成巡检" />
</LinearLayout>
</layout>

@ -14,6 +14,7 @@
android:layout_height="wrap_content"
android:background="@drawable/info_text_bg"
android:orientation="vertical"
android:layout_marginTop="5dp"
android:padding="8dp">
<TextView
@ -78,7 +79,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="left|center"
android:text="@{item.createTime}" />
android:text="@{item.remark}" />
</LinearLayout>
<View
@ -114,10 +115,12 @@
android:background="@color/bg1" />
<TextView
android:id="@+id/item_check_click"
style="@style/item_text_style"
android:layout_width="100dp"
android:layout_height="match_parent"
android:letterSpacing="0.5"
android:visibility='@{item.state.equals("未检") ? View.VISIBLE :View.GONE}'
android:text="跳过"
android:textColor="@color/blue" />
</LinearLayout>

@ -9,5 +9,6 @@
<color name="bg1">#F2F3F5</color>
<color name="yellow">#FFC107</color>
<color name="green">#ADDCA7</color>
<color name="item_bg">#DEE3E6</color>
</resources>
Loading…
Cancel
Save