|
|
@@ -4,13 +4,19 @@ import android.Manifest;
|
|
|
import android.app.Activity;
|
|
|
import android.content.Intent;
|
|
|
import android.os.Bundle;
|
|
|
+import android.support.v7.widget.DefaultItemAnimator;
|
|
|
+import android.support.v7.widget.LinearLayoutManager;
|
|
|
+import android.support.v7.widget.RecyclerView;
|
|
|
import android.text.Html;
|
|
|
+import android.text.TextUtils;
|
|
|
import android.util.Log;
|
|
|
import android.view.Gravity;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
+import android.view.ViewGroup;
|
|
|
import android.widget.ListView;
|
|
|
import android.widget.PopupWindow;
|
|
|
+import android.widget.RelativeLayout;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
import com.afollestad.materialdialogs.MaterialDialog;
|
|
|
@@ -19,18 +25,24 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.common.LogUtil;
|
|
|
import com.common.data.JSONUtil;
|
|
|
+import com.common.data.ListUtils;
|
|
|
import com.common.data.StringUtil;
|
|
|
import com.common.system.DisplayUtil;
|
|
|
import com.core.app.MyApplication;
|
|
|
import com.core.base.BaseActivity;
|
|
|
import com.core.utils.CommonUtil;
|
|
|
import com.core.utils.ToastUtil;
|
|
|
+import com.handmark.pulltorefresh.library.PullToRefreshBase;
|
|
|
+import com.handmark.pulltorefresh.library.PullToRefreshListView;
|
|
|
import com.me.network.app.http.HttpClient;
|
|
|
import com.me.network.app.http.Method;
|
|
|
import com.me.network.app.http.rx.ResultListener;
|
|
|
import com.me.network.app.http.rx.ResultSubscriber;
|
|
|
+import com.module.recyclerlibrary.ui.refresh.BaseRefreshLayout;
|
|
|
+import com.module.recyclerlibrary.ui.refresh.simlpe.SimpleRefreshLayout;
|
|
|
import com.uas.appworks.CRM.erp.adapter.CycleCountAdapter;
|
|
|
import com.uas.appworks.CRM.erp.model.CycleCount;
|
|
|
+import com.uas.appworks.CRM.erp.model.DeviceInfo;
|
|
|
import com.uas.appworks.R;
|
|
|
import com.uuzuche.lib_zxing.activity.CaptureActivity;
|
|
|
import com.uuzuche.lib_zxing.activity.CodeUtils;
|
|
|
@@ -52,7 +64,9 @@ public class DeviceCycleCountInfoActivity extends BaseActivity implements View.O
|
|
|
private TextView centerTv;
|
|
|
private TextView lineTv;
|
|
|
private TextView kindTv;
|
|
|
- private ListView gridList;
|
|
|
+ private RecyclerView gridList;
|
|
|
+ private SimpleRefreshLayout mSimpleRefreshLayout;
|
|
|
+ private int page;
|
|
|
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
@@ -84,10 +98,9 @@ public class DeviceCycleCountInfoActivity extends BaseActivity implements View.O
|
|
|
}
|
|
|
}
|
|
|
loadData(true);
|
|
|
- loadGridData(page);
|
|
|
+ loadGridData(page = 1);
|
|
|
}
|
|
|
|
|
|
- private int page=1;
|
|
|
|
|
|
private void initJSONData(String message) throws Exception {
|
|
|
JSONArray array = JSON.parseArray(message);
|
|
|
@@ -114,6 +127,7 @@ public class DeviceCycleCountInfoActivity extends BaseActivity implements View.O
|
|
|
codeTv = findViewById(R.id.codeTv);
|
|
|
workshopTv = findViewById(R.id.workshopTv);
|
|
|
gridList = findViewById(R.id.gridList);
|
|
|
+ mSimpleRefreshLayout = findViewById(R.id.mSimpleRefreshLayout);
|
|
|
centerTv = findViewById(R.id.centerTv);
|
|
|
lineTv = findViewById(R.id.lineTv);
|
|
|
kindTv = findViewById(R.id.kindTv);
|
|
|
@@ -125,6 +139,22 @@ public class DeviceCycleCountInfoActivity extends BaseActivity implements View.O
|
|
|
findViewById(R.id.cycleBtn).setOnClickListener(this);
|
|
|
findViewById(R.id.deviceAttributeBtn).setOnClickListener(this);
|
|
|
findViewById(R.id.lossDeviceBtn).setOnClickListener(this);
|
|
|
+ mSimpleRefreshLayout.setEnabledPullUp(true);
|
|
|
+ mSimpleRefreshLayout.setEnablePullDown(false);
|
|
|
+ gridList.setItemAnimator(new DefaultItemAnimator());
|
|
|
+ gridList.setLayoutManager(new LinearLayoutManager(ct));
|
|
|
+ mSimpleRefreshLayout.setOnRefreshListener(new BaseRefreshLayout.onRefreshListener() {
|
|
|
+ @Override
|
|
|
+ public void onRefresh() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onLoadMore() {
|
|
|
+ page++;
|
|
|
+ loadGridData(page);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -181,28 +211,25 @@ public class DeviceCycleCountInfoActivity extends BaseActivity implements View.O
|
|
|
}
|
|
|
|
|
|
private void loadGridData(int page) {
|
|
|
- progressDialog.show();
|
|
|
- String condition = "dc_dbid="+id;
|
|
|
+ String condition = "dc_dbid=" + id;
|
|
|
httpClient.Api().send(new HttpClient.Builder()
|
|
|
.url("mobile/common/getGridPanelandDataPage.action")
|
|
|
.add("caller", "DeviceBatch!Stock")
|
|
|
.add("condition", condition)
|
|
|
.add("page", page)
|
|
|
.add("pageSize", 50)
|
|
|
- .method(Method.POST)
|
|
|
+ .method(Method.GET)
|
|
|
.build(), new ResultSubscriber<>(new ResultListener<Object>() {
|
|
|
@Override
|
|
|
public void onResponse(Object o) {
|
|
|
- if (progressDialog != null) {
|
|
|
- progressDialog.dismiss();
|
|
|
- }
|
|
|
try {
|
|
|
- LogUtil.i("o.toString()="+o.toString());
|
|
|
+ handlerGridData(o.toString());
|
|
|
} catch (Exception e) {
|
|
|
if (e != null) {
|
|
|
LogUtil.i("e=" + e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
+ mSimpleRefreshLayout.stopRefresh();
|
|
|
|
|
|
}
|
|
|
}));
|
|
|
@@ -214,7 +241,7 @@ public class DeviceCycleCountInfoActivity extends BaseActivity implements View.O
|
|
|
.url("mobile/device/getDeviceAttribute.action")
|
|
|
.add("caller", "DeviceBatch!Stock")
|
|
|
.add("id", id)
|
|
|
- .method(Method.POST)
|
|
|
+ .method(Method.GET)
|
|
|
.build(), new ResultSubscriber<>(new ResultListener<Object>() {
|
|
|
@Override
|
|
|
public void onResponse(Object o) {
|
|
|
@@ -222,7 +249,7 @@ public class DeviceCycleCountInfoActivity extends BaseActivity implements View.O
|
|
|
progressDialog.dismiss();
|
|
|
}
|
|
|
try {
|
|
|
- handleSubmitCycle(o.toString());
|
|
|
+ handlerAttribute(o.toString());
|
|
|
} catch (Exception e) {
|
|
|
if (e != null) {
|
|
|
LogUtil.i("e=" + e.getMessage());
|
|
|
@@ -239,7 +266,7 @@ public class DeviceCycleCountInfoActivity extends BaseActivity implements View.O
|
|
|
.url("mobile/device/lossDevice.action")
|
|
|
.add("caller", "DeviceBatch!Stock")
|
|
|
.add("id", id)
|
|
|
- .method(Method.POST)
|
|
|
+ .method(Method.GET)
|
|
|
.build(), new ResultSubscriber<>(new ResultListener<Object>() {
|
|
|
@Override
|
|
|
public void onResponse(Object o) {
|
|
|
@@ -247,7 +274,7 @@ public class DeviceCycleCountInfoActivity extends BaseActivity implements View.O
|
|
|
progressDialog.dismiss();
|
|
|
}
|
|
|
try {
|
|
|
- handleSubmitCycle(o.toString());
|
|
|
+ handlerLoss(o.toString());
|
|
|
} catch (Exception e) {
|
|
|
if (e != null) {
|
|
|
LogUtil.i("e=" + e.getMessage());
|
|
|
@@ -258,6 +285,78 @@ public class DeviceCycleCountInfoActivity extends BaseActivity implements View.O
|
|
|
}));
|
|
|
}
|
|
|
|
|
|
+ private void handlerLoss(String message) {
|
|
|
+ JSONObject object = JSON.parseObject(message);
|
|
|
+ if (object.containsKey("exceptionInfo")) {
|
|
|
+ ToastUtil.showToast(ct, JSONUtil.getText(object, "exceptionInfo"));
|
|
|
+ } else {
|
|
|
+ if (JSONUtil.getBoolean(object, "success")) {
|
|
|
+ ToastUtil.showToast(ct, "盘亏成功");
|
|
|
+ loadGridData(page=1);
|
|
|
+ loadData(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ LogUtil.i(message);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void handlerAttribute(String message) {
|
|
|
+ JSONObject object = JSON.parseObject(message);
|
|
|
+ if (object.containsKey("exceptionInfo")) {
|
|
|
+ ToastUtil.showToast(ct, JSONUtil.getText(object, "exceptionInfo"));
|
|
|
+ } else {
|
|
|
+ if (JSONUtil.getBoolean(object, "success")) {
|
|
|
+ loadGridData(page = 1);
|
|
|
+ loadData(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ LogUtil.i(message);
|
|
|
+ }
|
|
|
+
|
|
|
+ private GridAdapter mAdapter = null;
|
|
|
+
|
|
|
+ private void handlerGridData(String message) {
|
|
|
+ JSONObject object = JSON.parseObject(message);
|
|
|
+ if (object.containsKey("exceptionInfo")) {
|
|
|
+ ToastUtil.showToast(ct, JSONUtil.getText(object, "exceptionInfo"));
|
|
|
+ } else {
|
|
|
+ JSONArray array = JSONUtil.getJSONArray(object, "gridItem");
|
|
|
+ JSONArray datas = JSONUtil.getJSONArray(object, "gridData");
|
|
|
+ List<Grid> grids = new ArrayList<>();
|
|
|
+
|
|
|
+ for (int j = 0; j < datas.size(); j++) {
|
|
|
+ JSONObject data = datas.getJSONObject(j);
|
|
|
+ boolean isTop = true;
|
|
|
+ for (int i = 0; i < array.size(); i++) {
|
|
|
+ JSONObject config = array.getJSONObject(i);
|
|
|
+ String dataIndex = JSONUtil.getText(config, "dataIndex");
|
|
|
+ Grid grid = new Grid();
|
|
|
+ grid.caption = JSONUtil.getText(config, "caption");
|
|
|
+ grid.values = JSONUtil.getText(data, dataIndex.toUpperCase());
|
|
|
+ if (!TextUtils.isEmpty(grid.caption) && !TextUtils.isEmpty(grid.values)) {
|
|
|
+ if (isTop) {
|
|
|
+ grid.isTop = isTop;
|
|
|
+ isTop = false;
|
|
|
+ }
|
|
|
+ grids.add(grid);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (mAdapter == null) {
|
|
|
+ mAdapter = new GridAdapter(grids);
|
|
|
+ gridList.setAdapter(mAdapter);
|
|
|
+ } else {
|
|
|
+ if (page <= 1) {
|
|
|
+ mAdapter.setModels(grids);
|
|
|
+ } else {
|
|
|
+ mAdapter.addModels(grids);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ LogUtil.i(message);
|
|
|
+ }
|
|
|
+
|
|
|
private void handleData(String message) throws Exception {
|
|
|
JSONObject object = JSONUtil.getJSONObject(message, "data");
|
|
|
String code = JSONUtil.getText(object, "DB_CODE");
|
|
|
@@ -413,4 +512,68 @@ public class DeviceCycleCountInfoActivity extends BaseActivity implements View.O
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ private class GridAdapter extends RecyclerView.Adapter<GridAdapter.ViewHolder> {
|
|
|
+
|
|
|
+ List<Grid> models;
|
|
|
+
|
|
|
+ public GridAdapter(List<Grid> models) {
|
|
|
+ this.models = models;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setModels(List<Grid> models) {
|
|
|
+ this.models = models;
|
|
|
+ notifyDataSetChanged();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addModels(List<Grid> models) {
|
|
|
+ if (this.models == null) {
|
|
|
+ this.models = new ArrayList<>();
|
|
|
+ }
|
|
|
+ int sizeOld = this.models.size();
|
|
|
+ this.models.addAll(models);
|
|
|
+ notifyItemRangeChanged(sizeOld, this.models.size());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public GridAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
|
+ return new GridAdapter.ViewHolder(parent);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onBindViewHolder(GridAdapter.ViewHolder holder, int position) {
|
|
|
+ Grid model = models.get(position);
|
|
|
+ holder.line.setVisibility(model.isTop ? View.VISIBLE : View.GONE);
|
|
|
+ holder.captionTv.setText(model.caption == null ? "" : model.caption);
|
|
|
+ holder.valuesTv.setText(model.values == null ? "" : model.values);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int getItemCount() {
|
|
|
+ return ListUtils.getSize(models);
|
|
|
+ }
|
|
|
+
|
|
|
+ class ViewHolder extends RecyclerView.ViewHolder {
|
|
|
+ View line;
|
|
|
+ TextView captionTv, valuesTv;
|
|
|
+
|
|
|
+ public ViewHolder(ViewGroup parent) {
|
|
|
+ this(LayoutInflater.from(ct).inflate(R.layout.item_cycle_grid, parent, false));
|
|
|
+ }
|
|
|
+
|
|
|
+ public ViewHolder(View itemView) {
|
|
|
+ super(itemView);
|
|
|
+ line = itemView.findViewById(R.id.line);
|
|
|
+ captionTv = itemView.findViewById(R.id.captionTv);
|
|
|
+ valuesTv = itemView.findViewById(R.id.valuesTv);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private class Grid {
|
|
|
+ boolean isTop;
|
|
|
+ String caption;
|
|
|
+ String values;
|
|
|
+ }
|
|
|
}
|