diff --git a/app/src/main/java/com/example/beijing_daxing/CheckActivity.java b/app/src/main/java/com/example/beijing_daxing/CheckActivity.java index 85ffec0..d61aa0f 100644 --- a/app/src/main/java/com/example/beijing_daxing/CheckActivity.java +++ b/app/src/main/java/com/example/beijing_daxing/CheckActivity.java @@ -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 list; + private List 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.post(url + "/xj/select").params("user", SharedPreferencesUtils.getstring("user", "")).execute(new MyRecultCall(dialog, this) { + @Override + public void onSuccess(Response response) { + super.onSuccess(response); + var body = response.body(); + if (body.getCode() == 0) { + list = gson.fromJson(body.getData().toString(), new TypeToken>() { + }.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 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.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(); + } + + } \ No newline at end of file diff --git a/app/src/main/java/com/example/beijing_daxing/adapter/CheckAdapter.java b/app/src/main/java/com/example/beijing_daxing/adapter/CheckAdapter.java new file mode 100644 index 0000000..bc1a359 --- /dev/null +++ b/app/src/main/java/com/example/beijing_daxing/adapter/CheckAdapter.java @@ -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 { + private Context context; + private List 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 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; + } + } +} diff --git a/app/src/main/res/layout/activity_check.xml b/app/src/main/res/layout/activity_check.xml index ca0e4e9..12d86e8 100644 --- a/app/src/main/res/layout/activity_check.xml +++ b/app/src/main/res/layout/activity_check.xml @@ -4,7 +4,15 @@ xmlns:tools="http://schemas.android.com/tools"> + + + + @@ -62,15 +72,18 @@ android:text="选择原因:" /> @@ -81,11 +94,12 @@ android:text="输入原因:" /> + android:minHeight="48dp"/>