完成 仓库下拉加载的测试

master
wangh 7 months ago
parent 8a9763ddb3
commit 6140048236

@ -43,19 +43,21 @@ public class InventoryTaskCreateActivity extends BaseActivity implements Adapter
private List<HouseLocation> list; private List<HouseLocation> list;
private Map<String, Object> map; private Map<String, Object> map;
private int pageNum = 1; private int pageNum = 1;
private int pageSize = 1;
private int warehouseId; private int warehouseId;
private Intent intent; private Intent intent;
private String warehouseName;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
binding = DataBindingUtil.setContentView(this, R.layout.activity_inventory_task_create); binding = DataBindingUtil.setContentView(this, R.layout.activity_inventory_task_create);
adapter = new InventoryLocationAdapter(this); adapter = new InventoryLocationAdapter(this);
list = new ArrayList<>();
adapter.setList(list);
binding.setAdapter(adapter); binding.setAdapter(adapter);
binding.inventoryCreateRefresh.setOnLoadMoreListener(this); binding.inventoryCreateRefresh.setOnLoadMoreListener(this);
intent = new Intent(this, InventoryWorkActivity.class); intent = new Intent(this, InventoryWorkActivity.class);
map = new HashMap<>(); map = new HashMap<>();
lpw = new ListPopupWindow(this); lpw = new ListPopupWindow(this);
lpw.setAnchorView(binding.inventoryCreateHouse); lpw.setAnchorView(binding.inventoryCreateHouse);
@ -67,8 +69,9 @@ public class InventoryTaskCreateActivity extends BaseActivity implements Adapter
if (warehouseId == 0) { if (warehouseId == 0) {
initRequest(); initRequest();
} else { } else {
var warehouseName = intent.getStringExtra("warehouseName"); warehouseName = intent.getStringExtra("warehouseName");
createLocation(warehouseId, warehouseName); list.clear();
createLocation(1);
} }
} }
@ -103,32 +106,39 @@ public class InventoryTaskCreateActivity extends BaseActivity implements Adapter
warehouseId = warehouseBeen.getWarehouseId(); warehouseId = warehouseBeen.getWarehouseId();
lpw.dismiss(); lpw.dismiss();
pageNum = 1; pageNum = 1;
createLocation(warehouseId, warehouseBeen.getWarehouseName()); warehouseName = warehouseBeen.getWarehouseName();
createLocation(pageNum);
} }
private int total;
// 请求库位 // 请求库位
private void createLocation(int warehouseId, String warehouseName) { private void createLocation(int pageNum) {
binding.inventoryCreateHouse.setText(warehouseName); binding.inventoryCreateHouse.setText(warehouseName);
map.put("warehouseId", warehouseId); map.put("warehouseId", warehouseId);
OkGo.<MyResult>get(url + "/wms/mobile/getLocations").tag(this) OkGo.<MyResult>get(url + "/wms/mobile/getLocations").tag(this)
.headers("Authorization", SharedPreferencesUtils.getstring("access_token", "")) .headers("Authorization", SharedPreferencesUtils.getstring("access_token", ""))
.params("warehouseId", warehouseId) .params("warehouseId", warehouseId)
.params("pageNum", pageNum) .params("pageNum", pageNum)
.params("pagesize", 10) .params("pageSize", pageSize)
.execute(new MyRecultCall(dialog, this) { .execute(new MyRecultCall(dialog, this) {
@SuppressLint("NotifyDataSetChanged") @SuppressLint("NotifyDataSetChanged")
@Override @Override
public void onSuccess(Response<MyResult> response) { public void onSuccess(Response<MyResult> response) {
super.onSuccess(response); super.onSuccess(response);
var body = response.body(); var body = response.body();
if (body.getTotal() == 0) {
total = body.getTotal();
if (total == 0) {
list.clear();
adapter.notifyDataSetChanged();
Toast.makeText(context, body.getCode() == 200 ? "暂无记录" : body.getMsg(), Toast.LENGTH_SHORT).show(); Toast.makeText(context, body.getCode() == 200 ? "暂无记录" : body.getMsg(), Toast.LENGTH_SHORT).show();
return; return;
} }
list = gson.fromJson(gson.toJson(body.getRows()), new TypeToken<List<HouseLocation>>() { binding.inventoryCreateRefresh.finishLoadMore(500);
}.getType()); list.addAll(gson.fromJson(gson.toJson(body.getRows()), new TypeToken<List<HouseLocation>>() {
adapter.setList(list); }.getType()));
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
} }
}); });
@ -157,7 +167,6 @@ public class InventoryTaskCreateActivity extends BaseActivity implements Adapter
super.onSuccess(response); super.onSuccess(response);
var body = response.body(); var body = response.body();
if (body.getCode() == 200) { if (body.getCode() == 200) {
intent.putExtra("inventoryCheckId", (int) Double.parseDouble(body.getData().toString())); intent.putExtra("inventoryCheckId", (int) Double.parseDouble(body.getData().toString()));
// intent.putExtra("checkStatus",); // intent.putExtra("checkStatus",);
startActivity(intent); startActivity(intent);
@ -170,8 +179,13 @@ public class InventoryTaskCreateActivity extends BaseActivity implements Adapter
@Override @Override
public void onLoadMore(@NonNull RefreshLayout refreshLayout) { public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
if (pageNum*pageSize>=total){
binding.inventoryCreateRefresh.finishLoadMore(false);
Toast.makeText(context, "列表加载完成", Toast.LENGTH_SHORT).show();
return;
}
pageNum++; pageNum++;
// createLocation(); createLocation(pageNum);
Log.e("TAG", "onLoadMore"); Log.e("TAG", "onLoadMore");
} }
} }

@ -63,14 +63,15 @@
app:srlEnableRefresh="false" app:srlEnableRefresh="false"
> >
<!-- --> <!-- app:srlEnableLoadMoreWhenContentNotFull="false" -->
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:adapter="@{adapter}" android:adapter="@{adapter}"
android:background="@color/white" android:background="@color/white"
android:overScrollMode="never" android:overScrollMode="never"
android:padding="5dp" app:srlEnableLoadMoreWhenContentNotFull="false" android:padding="5dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" /> app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
<com.scwang.smart.refresh.footer.ClassicsFooter <com.scwang.smart.refresh.footer.ClassicsFooter

Loading…
Cancel
Save