测试 巡检
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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue