|
@@ -0,0 +1,630 @@
|
|
|
+package com.uas.ruiziuasmes.fragment;
|
|
|
+
|
|
|
+import android.annotation.SuppressLint;
|
|
|
+import android.app.Activity;
|
|
|
+import android.content.Context;
|
|
|
+import android.content.Intent;
|
|
|
+import android.graphics.drawable.BitmapDrawable;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.support.v7.widget.DefaultItemAnimator;
|
|
|
+import android.support.v7.widget.DividerItemDecoration;
|
|
|
+import android.support.v7.widget.LinearLayoutManager;
|
|
|
+import android.support.v7.widget.RecyclerView;
|
|
|
+import android.util.Log;
|
|
|
+import android.util.SparseBooleanArray;
|
|
|
+import android.view.Gravity;
|
|
|
+import android.view.KeyEvent;
|
|
|
+import android.view.LayoutInflater;
|
|
|
+import android.view.View;
|
|
|
+import android.view.ViewGroup;
|
|
|
+import android.widget.ArrayAdapter;
|
|
|
+import android.widget.Button;
|
|
|
+import android.widget.CheckBox;
|
|
|
+import android.widget.LinearLayout;
|
|
|
+import android.widget.ListView;
|
|
|
+import android.widget.PopupWindow;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.android.volley.Request;
|
|
|
+import com.android.volley.toolbox.StringRequest;
|
|
|
+import com.uas.ruiziuasmes.R;
|
|
|
+import com.uas.ruiziuasmes.activity.FunctionActivity;
|
|
|
+import com.uas.ruiziuasmes.bean.CaiPiBlueBean;
|
|
|
+import com.uas.ruiziuasmes.bean.MaintainitemBean;
|
|
|
+import com.uas.ruiziuasmes.global.GloableParams;
|
|
|
+import com.uas.ruiziuasmes.tools.SharedPreUtil;
|
|
|
+import com.uas.ruiziuasmes.util.CommonUtil;
|
|
|
+import com.uas.ruiziuasmes.util.Constants;
|
|
|
+import com.uas.ruiziuasmes.util.FastjsonUtil;
|
|
|
+import com.uas.ruiziuasmes.util.FragmentUtils;
|
|
|
+import com.uas.ruiziuasmes.util.HttpCallback;
|
|
|
+import com.uas.ruiziuasmes.util.HttpParams;
|
|
|
+import com.uas.ruiziuasmes.util.LogUtil;
|
|
|
+import com.uas.ruiziuasmes.util.PrintUtils;
|
|
|
+import com.uas.ruiziuasmes.util.StringUtil;
|
|
|
+import com.uas.ruiziuasmes.util.VolleyRequest;
|
|
|
+import com.uas.ruiziuasmes.util.VollyRequest;
|
|
|
+import com.uas.ruiziuasmes.view.ClearableEditText;
|
|
|
+import com.vincent.filepicker.ToastUtil;
|
|
|
+
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by RaoMeng on 2024/05/27
|
|
|
+ * Desc: 预加工报工
|
|
|
+ */
|
|
|
+public class PreProcessingReportFragment extends BaseFragment implements View.OnClickListener{
|
|
|
+
|
|
|
+ private RecyclerView mRecyclerView;
|
|
|
+ private ArrayList<MaintainitemBean> mFeededList;
|
|
|
+ private SelectAdapter myAdapter;
|
|
|
+ private Button jlt_storage_in_barcode_save_btn;
|
|
|
+ private StringRequest mStringRequest;
|
|
|
+ private String ma_code;
|
|
|
+ private String sc_code;
|
|
|
+ private TextView tv_ma_code;
|
|
|
+ private ClearableEditText ct_qty;
|
|
|
+ private ClearableEditText ct_sum;
|
|
|
+ private List<CaiPiBlueBean.DataBean> messages = new ArrayList<>();
|
|
|
+ private PopupWindow splitPop;
|
|
|
+ private boolean isConnected = false;
|
|
|
+ private boolean isPrinting = false;
|
|
|
+ private int mPrintDpi = 203;
|
|
|
+ private JSONArray dataArray;
|
|
|
+ private Button btn_oneprint;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected int getLayout() {
|
|
|
+ return R.layout.fragment_pre_processing_report;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void initViews() {
|
|
|
+ setTitle("预加工报工");
|
|
|
+ ((FunctionActivity) getActivity()).setMoreBtnVisible(false);
|
|
|
+ mRecyclerView = root.findViewById(R.id.feeded_rv);
|
|
|
+ tv_ma_code = root.findViewById(R.id.tv_ma_code);
|
|
|
+ ct_qty = root.findViewById(R.id.ct_qty);
|
|
|
+ ct_sum = root.findViewById(R.id.ct_sum);
|
|
|
+ btn_oneprint = root.findViewById(R.id.btn_oneprint);
|
|
|
+ jlt_storage_in_barcode_save_btn = root.findViewById(R.id.jlt_storage_in_barcode_save_btn);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static String removeBrackets(String input) {
|
|
|
+ // 去除前后的中括号
|
|
|
+ if (input.startsWith("[") && input.endsWith("]")) {
|
|
|
+ input = input.substring(1, input.length() - 1);
|
|
|
+ }
|
|
|
+ return input;
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ protected void initEvents() {
|
|
|
+ getPrintTemplate();
|
|
|
+ btn_oneprint.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+
|
|
|
+
|
|
|
+ if (dataArray != null && dataArray.size() > 0) {
|
|
|
+ printEvent(dataArray);
|
|
|
+ }else {
|
|
|
+ CommonUtil.toastNoRepeat(mActivity, "数据为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ jlt_storage_in_barcode_save_btn.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ if (StringUtil.isEmpty(ct_sum.getText().toString().trim())){
|
|
|
+ CommonUtil.toastNoRepeat(mActivity, "请输入报工数");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ ArrayList<MaintainitemBean> selectedItem = myAdapter.getSelectedItem();
|
|
|
+ if (selectedItem==null||selectedItem.size()==0){
|
|
|
+ CommonUtil.toastNoRepeat(mActivity, "请选择料号");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String sunmdata = "";
|
|
|
+ for (int i=0;i<selectedItem.size();i++){
|
|
|
+ MaintainitemBean maintainitemBean = selectedItem.get(i);
|
|
|
+ sunmdata+=maintainitemBean.getMM_PRODCODE()+",";
|
|
|
+ }
|
|
|
+ Log.e("liao_code",sunmdata);
|
|
|
+
|
|
|
+ getNewsave(sunmdata);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ ma_code = SharedPreUtil.getString(mActivity, "MA_CODE", null);
|
|
|
+ sc_code = SharedPreUtil.getString(mActivity, "SC_CODE", null);
|
|
|
+ tv_ma_code.setText(ma_code);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void initDatas() {
|
|
|
+ mFeededList = new ArrayList<>();
|
|
|
+ myAdapter = new SelectAdapter(mFeededList);
|
|
|
+ mRecyclerView = root.findViewById(R.id.feeded_rv);
|
|
|
+ mRecyclerView.addItemDecoration(new DividerItemDecoration(mActivity, LinearLayout.VERTICAL));
|
|
|
+ mRecyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
|
|
|
+ //设置Item增加、移除动画
|
|
|
+ mRecyclerView.setItemAnimator(new DefaultItemAnimator());
|
|
|
+ setAdapter(mFeededList);
|
|
|
+ mRecyclerView.setAdapter(myAdapter);
|
|
|
+ getNewVersionMsg();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getNewVersionMsg() {
|
|
|
+ progressDialog.show();
|
|
|
+ VollyRequest.getInstance().stringRequest(mStringRequest,
|
|
|
+ new HttpParams.Builder()
|
|
|
+ .url(GloableParams.ADDRESS_GETMAKEMATERIAL)
|
|
|
+ .method(Request.Method.GET)
|
|
|
+ .addParam("ma_code",ma_code)
|
|
|
+ .addParam("sc_code",sc_code)
|
|
|
+ .build(), new HttpCallback() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(int flag, Object o) throws Exception {
|
|
|
+ progressDialog.dismiss();
|
|
|
+ String result = o.toString();
|
|
|
+ JSONArray dataArray = FastjsonUtil.getJSONArray(result, "data");
|
|
|
+ handleFeededData(dataArray);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFail(int flag, String failStr) throws Exception {
|
|
|
+ progressDialog.dismiss();
|
|
|
+ CommonUtil.toastNoRepeat(mActivity, failStr);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ private void handleFeededData(JSONArray dataArray) {
|
|
|
+ MaintainitemBean bean;
|
|
|
+ mFeededList.clear();
|
|
|
+ for (Object index : dataArray) {
|
|
|
+ JSONObject data = (JSONObject) index;
|
|
|
+ bean= new MaintainitemBean(
|
|
|
+ data.getString("MM_PRODCODE"),
|
|
|
+ data.getString("PR_DETAIL"),
|
|
|
+ data.getString("PR_SPEC"));
|
|
|
+ mFeededList.add(bean);
|
|
|
+ }
|
|
|
+ setAdapter(mFeededList);
|
|
|
+ }
|
|
|
+ private void setAdapter(ArrayList<MaintainitemBean> mList) {
|
|
|
+ LogUtil.i("mList", JSON.toJSONString(mList));
|
|
|
+ myAdapter = new SelectAdapter(mList);
|
|
|
+ mRecyclerView.setAdapter(myAdapter);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存
|
|
|
+ */
|
|
|
+ private void getNewsave(String prods) {
|
|
|
+ progressDialog.show();
|
|
|
+ VollyRequest.getInstance().stringRequest(mStringRequest,
|
|
|
+ new HttpParams.Builder()
|
|
|
+ .url(GloableParams.ADDRESS_MODIFYMAPRODS)
|
|
|
+ .method(Request.Method.GET)
|
|
|
+ .addParam("ma_code",ma_code)
|
|
|
+ .addParam("sc_code",sc_code)
|
|
|
+ .addParam("prods",prods)
|
|
|
+ .addParam("decode",ct_qty.getText().toString().trim())
|
|
|
+ .addParam("reportqty",ct_sum.getText().toString().trim())
|
|
|
+ .build(), new HttpCallback() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(int flag, Object o) throws Exception {
|
|
|
+ progressDialog.dismiss();
|
|
|
+
|
|
|
+ dataArray = FastjsonUtil.getJSONArray(o.toString(), "data");
|
|
|
+
|
|
|
+ ToastUtil.getInstance(mActivity).showToast("报工成功");
|
|
|
+// initBreakPopupWindow(dataArray);
|
|
|
+ printEvent(dataArray);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFail(int flag, String failStr) throws Exception {
|
|
|
+ progressDialog.dismiss();
|
|
|
+ CommonUtil.toastNoRepeat(mActivity, failStr);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ //org.json.
|
|
|
+ protected void initBreakPopupWindow(JSONArray listArray) {
|
|
|
+ messages.clear();
|
|
|
+ for (int i = 1; i < listArray.size(); i++) {
|
|
|
+ try {
|
|
|
+ JSONObject barcodeObject = listArray.getJSONObject(i);
|
|
|
+
|
|
|
+ if (barcodeObject != null) {
|
|
|
+ CaiPiBlueBean.DataBean dataBean=new CaiPiBlueBean.DataBean();
|
|
|
+// dataBean.setLotno(JsonUtils.optStringNotNull(barcodeObject, "LOTNO"));
|
|
|
+// dataBean.setQty(JsonUtils.optStringNotNull(barcodeObject, "QTY"));
|
|
|
+ dataBean.setLotno(barcodeObject.getString("LOTNO"));
|
|
|
+ dataBean.setQty(barcodeObject.getString("QTY"));
|
|
|
+ messages.add(dataBean);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ View popView = LayoutInflater.from(getActivity()).inflate(R.layout.popupwindow_whbreaking_batch, null);
|
|
|
+ ListView listView = (ListView) popView.findViewById(R.id.list_view);
|
|
|
+ Button btnPrintf = (Button) popView.findViewById(R.id.btn_print);
|
|
|
+ Button btnPrintfSet = (Button) popView.findViewById(R.id.btn_print_setting);
|
|
|
+ Button btnClose = (Button) popView.findViewById(R.id.btn_close);
|
|
|
+ Button btnBack = (Button) popView.findViewById(R.id.btn_back);
|
|
|
+
|
|
|
+ btnBack.setVisibility(View.GONE);
|
|
|
+ btnClose.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ closeSplitPopupWindow();
|
|
|
+// }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ btnPrintf.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ if (isConnected) {
|
|
|
+ progressDialog.show();
|
|
|
+ listArray.remove(0);
|
|
|
+ printEvent(listArray);
|
|
|
+ } else {
|
|
|
+ closeSplitPopupWindow();
|
|
|
+ BlueToothPrintFragment blueToothPrintFragment = new BlueToothPrintFragment();
|
|
|
+
|
|
|
+ Bundle bundle = new Bundle();
|
|
|
+ bundle.putString(Constants.KEY.BARCODE_PRINT_ARRAY, listArray.toString());
|
|
|
+ Log.e("listArrayone",listArray.toString());
|
|
|
+ blueToothPrintFragment.setArguments(bundle);
|
|
|
+ FragmentUtils.switchFragment(PreProcessingReportFragment.this, blueToothPrintFragment);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ btnPrintfSet.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ closeSplitPopupWindow();
|
|
|
+ BlueToothPrintFragment blueToothPrintFragment = new BlueToothPrintFragment();
|
|
|
+
|
|
|
+ Bundle bundle = new Bundle();
|
|
|
+ bundle.putString(Constants.KEY.BARCODE_PRINT_ARRAY, listArray.toString());
|
|
|
+ Log.e("listArraytwo",listArray.toString());
|
|
|
+ blueToothPrintFragment.setArguments(bundle);
|
|
|
+ FragmentUtils.switchFragment(PreProcessingReportFragment.this, blueToothPrintFragment);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ MyAdapter adapter = new MyAdapter(getActivity(), R.layout.item_list_whbreakingbatchfragment, messages);
|
|
|
+ listView.setAdapter(adapter);
|
|
|
+ //当只有一条数据的时候可以加上
|
|
|
+ /*
|
|
|
+ if (messages.size()>1){
|
|
|
+ btnBack.setVisibility(View.GONE);
|
|
|
+ }*/
|
|
|
+ // PopupWindow实例化,参数的意思是 view,长(不包括状态栏),高(不包括状态栏),是否聚焦
|
|
|
+ splitPop = new PopupWindow(popView, LinearLayout.LayoutParams.WRAP_CONTENT,
|
|
|
+ LinearLayout.LayoutParams.WRAP_CONTENT, true);
|
|
|
+ splitPop.setAnimationStyle(R.style.MenuAnimationFade);
|
|
|
+ splitPop.setBackgroundDrawable(new BitmapDrawable());
|
|
|
+ // 弹出窗口显示内容视图,默认以锚定视图的左下角为起点,这里为点击按钮
|
|
|
+ splitPop.showAtLocation(getActivity().getWindow().getDecorView(), Gravity.CENTER, 0, 0);
|
|
|
+ splitPop.setOnDismissListener(new PopupWindow.OnDismissListener() {
|
|
|
+ @Override
|
|
|
+ public void onDismiss() {
|
|
|
+ closeSplitPopupWindow();
|
|
|
+// specialOut();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ CommonUtil.setBackgroundAlpha(mActivity, 0.5f);
|
|
|
+
|
|
|
+ }
|
|
|
+ private void closeSplitPopupWindow() {
|
|
|
+ if (splitPop != null) {
|
|
|
+ splitPop.dismiss();
|
|
|
+ splitPop = null;
|
|
|
+ CommonUtil.setBackgroundAlpha(mActivity, 1f);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private void getPrintTemplate() {
|
|
|
+ VolleyRequest.getInstance().stringRequest(mStringRequest,
|
|
|
+ new HttpParams.Builder()
|
|
|
+ .url(GloableParams.ADDRESS_BARINFO_PRINTMODEL)
|
|
|
+ .method(Request.Method.GET)
|
|
|
+ .flag(0)
|
|
|
+ .tag("barinfoPrint")
|
|
|
+ .addParam("caller", "PreBarcode")//Barcode!PDAPrint仓库
|
|
|
+ .build(), new HttpCallback() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(int flag, Object o) throws Exception {
|
|
|
+ try {
|
|
|
+ String result = o.toString();
|
|
|
+ Log.e("prints", result);
|
|
|
+ if (FastjsonUtil.validate(result)) {
|
|
|
+ JSONObject resultObject = JSON.parseObject(result);
|
|
|
+ JSONArray dataArray = resultObject.getJSONArray("data");
|
|
|
+ if (dataArray != null && dataArray.size() > 0) {
|
|
|
+ SharedPreUtil.saveString(mActivity, Constants.FLAG.PRINT_TEMPLATE_CACHE, dataArray.toJSONString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFail(int flag, String failStr) throws Exception {
|
|
|
+ Log.e("printf", failStr);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void printEvent(JSONArray printArray) {
|
|
|
+ if (isPrinting) {
|
|
|
+ CommonUtil.toastNoRepeat(mActivity, "正在打印中,请勿重复操作");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ isPrinting = true;
|
|
|
+ if (printArray != null && printArray.size() > 0) {
|
|
|
+ boolean isFail = false;
|
|
|
+ for (int i = 0; i < printArray.size(); i++) {
|
|
|
+ try {
|
|
|
+ JSONObject printObject = printArray.getJSONObject(i);
|
|
|
+ int printResult = PrintUtils.printBar(mActivity, printObject.toString(), mPrintDpi, null);
|
|
|
+ if (printResult <= 0) {
|
|
|
+ isFail = true;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ closeSplitPopupWindow();
|
|
|
+ progressDialog.dismiss();
|
|
|
+ if (isFail) {
|
|
|
+ isConnected = false;
|
|
|
+ SharedPreUtil.saveInt(mActivity, "printConnect", 0);
|
|
|
+ CommonUtil.toastNoRepeat(mActivity, "打印失败,请重新连接打印机");
|
|
|
+
|
|
|
+ BlueToothPrintFragment blueToothPrintFragment = new BlueToothPrintFragment();
|
|
|
+
|
|
|
+ Bundle bundle = new Bundle();
|
|
|
+ bundle.putString(Constants.KEY.BARCODE_PRINT_ARRAY, printArray.toString());
|
|
|
+ Log.e("listArraythree",printArray.toString());
|
|
|
+ blueToothPrintFragment.setArguments(bundle);
|
|
|
+ FragmentUtils.switchFragment(PreProcessingReportFragment.this, blueToothPrintFragment);
|
|
|
+ } else {
|
|
|
+ CommonUtil.toastNoRepeat(mActivity, "打印成功");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ CommonUtil.toastNoRepeat(mActivity, "打印失败,条码数据为空");
|
|
|
+ }
|
|
|
+ isPrinting = false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private class MyAdapter extends ArrayAdapter<CaiPiBlueBean.DataBean> {
|
|
|
+ private int resourceId;
|
|
|
+
|
|
|
+ public MyAdapter(Context context, int resource, List<CaiPiBlueBean.DataBean> objects) {
|
|
|
+ super(context, resource, objects);
|
|
|
+ resourceId = resource;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public View getView(int position, View convertView, ViewGroup parent) {
|
|
|
+ CaiPiBlueBean.DataBean person = getItem(position);
|
|
|
+ convertView = LayoutInflater.from(getContext()).inflate(resourceId,
|
|
|
+ null);
|
|
|
+ TextView tv_bar_code = (TextView) convertView.findViewById(R.id.tv_bar_code);
|
|
|
+ TextView tv_bar_remain = (TextView) convertView.findViewById(R.id.tv_bar_remain);
|
|
|
+ tv_bar_code.setText(person.getLotno());
|
|
|
+ tv_bar_remain.setText(person.getQty());
|
|
|
+ return convertView;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public void onHiddenChanged(boolean hidden) {
|
|
|
+ super.onHiddenChanged(hidden);
|
|
|
+ if (!hidden) {
|
|
|
+ setTitle("预加工报工");
|
|
|
+ ((FunctionActivity) getActivity()).setMoreBtnVisible(true);
|
|
|
+ } else {
|
|
|
+ ((FunctionActivity) getActivity()).setMoreBtnVisible(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean onFragmentBackPressed() {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onDestroyView() {
|
|
|
+ super.onDestroyView();
|
|
|
+ ((FunctionActivity) getActivity()).setMoreBtnVisible(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ @SuppressLint("NonConstantResourceId")
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
+ super.onActivityResult(requestCode, resultCode, data);
|
|
|
+ if (resultCode != Activity.RESULT_OK) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ public class SelectAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
|
|
+
|
|
|
+ private ArrayList<MaintainitemBean> mList = new ArrayList<>();
|
|
|
+ private SparseBooleanArray mSelectedPositions = new SparseBooleanArray();
|
|
|
+ private boolean mIsSelectable = false;
|
|
|
+
|
|
|
+
|
|
|
+ public SelectAdapter(ArrayList<MaintainitemBean> list) {
|
|
|
+ if (list == null) {
|
|
|
+ throw new IllegalArgumentException("model Data must not be null");
|
|
|
+ }
|
|
|
+ mList = list;
|
|
|
+ }
|
|
|
+
|
|
|
+ //更新adpter的数据和选择状态
|
|
|
+ public void updateDataSet(ArrayList<MaintainitemBean> list) {
|
|
|
+ this.mList = list;
|
|
|
+ mSelectedPositions = new SparseBooleanArray();
|
|
|
+// ab.setTitle("已选择" + 0 + "项");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //获得选中条目的结果
|
|
|
+ public ArrayList<MaintainitemBean> getSelectedItem() {
|
|
|
+ ArrayList<MaintainitemBean> selectList = new ArrayList<>();
|
|
|
+ for (int i = 0; i < mList.size(); i++) {
|
|
|
+ if (isItemChecked(i)) {
|
|
|
+ selectList.add(mList.get(i));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return selectList;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
|
|
|
+ View itemView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.recyclerview_item2, viewGroup, false);
|
|
|
+ return new ListItemViewHolder(itemView);
|
|
|
+ }
|
|
|
+
|
|
|
+ //设置给定位置条目的选择状态
|
|
|
+ private void setItemChecked(int position, boolean isChecked) {
|
|
|
+ mSelectedPositions.put(position, isChecked);
|
|
|
+ }
|
|
|
+
|
|
|
+ //根据位置判断条目是否选中
|
|
|
+ private boolean isItemChecked(int position) {
|
|
|
+ return mSelectedPositions.get(position);
|
|
|
+ }
|
|
|
+
|
|
|
+ //根据位置判断条目是否可选
|
|
|
+ private boolean isSelectable() {
|
|
|
+ return mIsSelectable;
|
|
|
+ }
|
|
|
+ //设置给定位置条目的可选与否的状态
|
|
|
+ private void setSelectable(boolean selectable) {
|
|
|
+ mIsSelectable = selectable;
|
|
|
+ }
|
|
|
+
|
|
|
+ //绑定界面,设置监听
|
|
|
+ @Override
|
|
|
+ public void onBindViewHolder(final RecyclerView.@NotNull ViewHolder holder, @SuppressLint("RecyclerView") int i) {
|
|
|
+ //设置条目状态
|
|
|
+ ((ListItemViewHolder) holder).tv_liaocode.setText("物料编号:"+mList.get(i).getMM_PRODCODE());
|
|
|
+ ((ListItemViewHolder) holder).tv_liaotetall.setText("物料名称:"+mList.get(i).getPR_DETAIL());
|
|
|
+ ((ListItemViewHolder) holder).tv_liaospec.setText("物料规格:"+mList.get(i).getPR_SPEC());
|
|
|
+
|
|
|
+
|
|
|
+ ((ListItemViewHolder) holder).checkBox.setChecked(isItemChecked(i));
|
|
|
+// if (i%2==0){
|
|
|
+// ((ListItemViewHolder) holder).line_color.setBackgroundColor(getResources().getColor(R.color.button_normal));
|
|
|
+// }else {
|
|
|
+// ((ListItemViewHolder) holder).line_color.setBackgroundColor(Color.WHITE);
|
|
|
+// }
|
|
|
+ //checkBox的监听
|
|
|
+ ((ListItemViewHolder) holder).checkBox.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ if (isItemChecked(i)) {
|
|
|
+ setItemChecked(i, false);
|
|
|
+ } else {
|
|
|
+ setItemChecked(i, true);
|
|
|
+ }
|
|
|
+// for (int i2=0;i2<mList.size();i2++){
|
|
|
+// setItemChecked(i2, true);
|
|
|
+// }
|
|
|
+
|
|
|
+// ab.setTitle("已选择" + getSelectedItem().size() + "项");
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ //条目view的监听
|
|
|
+ ((ListItemViewHolder) holder).itemView.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ if (isItemChecked(i)) {
|
|
|
+ setItemChecked(i, false);
|
|
|
+ } else {
|
|
|
+ setItemChecked(i, true);
|
|
|
+ }
|
|
|
+// notifyItemChanged(i);
|
|
|
+// if (!StringUtil.isEmpty(mList.get(i).getDI_REMARK())){
|
|
|
+// ((ListItemViewHolder) holder).tv_remark.setText("点检值:"+mList.get(i).getDI_REMARK());
|
|
|
+// }
|
|
|
+
|
|
|
+// ab.setTitle("已选择" + getSelectedItem().size() + "项");
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int getItemCount() {
|
|
|
+ return mList == null ? 0 : mList.size();
|
|
|
+ }
|
|
|
+
|
|
|
+ public class ListItemViewHolder extends RecyclerView.ViewHolder{
|
|
|
+ //ViewHolder
|
|
|
+ CheckBox checkBox;
|
|
|
+ TextView tv_liaocode;
|
|
|
+ TextView tv_liaotetall;
|
|
|
+ TextView tv_liaospec;
|
|
|
+ ListItemViewHolder(View view) {
|
|
|
+ super(view);
|
|
|
+ this.tv_liaocode = (TextView) view.findViewById(R.id.tv_liaocode);
|
|
|
+ this.tv_liaotetall = (TextView) view.findViewById(R.id.tv_liaotetall);
|
|
|
+ this.tv_liaospec = (TextView) view.findViewById(R.id.tv_liaospec);
|
|
|
+ this.checkBox = (CheckBox) view.findViewById(R.id.select_checkbox);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|