增加 盘点
parent
38ee648bb1
commit
7aba9a7370
@ -0,0 +1,132 @@
|
||||
package com.example.beijing_daxing;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.databinding.Bindable;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
import androidx.databinding.ObservableBoolean;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.example.beijing_daxing.adapter.StoreCheckAdapter;
|
||||
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.InStoreSelectBody;
|
||||
import com.example.beijing_daxing.been.Stock;
|
||||
import com.example.beijing_daxing.databinding.ActivityStoreCheckBinding;
|
||||
import com.example.beijing_daxing.uitls.SharedPreferencesUtils;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.lzy.okgo.OkGo;
|
||||
import com.lzy.okgo.model.Response;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
public class StoreCheckActivity extends BaseActivity {
|
||||
|
||||
|
||||
private ObservableBoolean checkState;
|
||||
private List<Stock> list;
|
||||
private StoreCheckAdapter checkAdapter;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
ActivityStoreCheckBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_store_check);
|
||||
checkState = new ObservableBoolean();
|
||||
binding.setCheckState(checkState);
|
||||
checkAdapter = new StoreCheckAdapter(this);
|
||||
binding.setAdapter(checkAdapter);
|
||||
initRequest();
|
||||
}
|
||||
private List<String> tagList;
|
||||
@Override
|
||||
protected void sanRfid(List<String> epcs) {
|
||||
epcs.forEach(t -> {
|
||||
if (tagList.contains(t)){
|
||||
tagList.add(t);
|
||||
return;
|
||||
}
|
||||
var stock = new Stock();
|
||||
stock.setEpcCode(t);
|
||||
var index = list.indexOf(stock);
|
||||
if (index != -1) {
|
||||
list.get(index).setState("Y");
|
||||
}
|
||||
});
|
||||
checkAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private void initRequest() {
|
||||
OkGo.<MyResult>post(url + "/storecheck/select").tag(this).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());
|
||||
tagList=new ArrayList<>();
|
||||
checkAdapter.setList(list);
|
||||
checkAdapter.notifyDataSetChanged();
|
||||
} else {
|
||||
Toast.makeText(StoreCheckActivity.this, body.getMsg(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void check_read(View view) {
|
||||
var b = checkState.get();
|
||||
if (b) {
|
||||
handler.removeCallbacks(runnable);
|
||||
} else {
|
||||
handler.postDelayed(runnable, 0);
|
||||
}
|
||||
checkState.set(!b);
|
||||
}
|
||||
|
||||
public void store_check_submit(View view) {
|
||||
handler.removeCallbacks(runnable);
|
||||
OkGo.<MyResult>post(url+"/storecheck/submit")
|
||||
.upRequestBody(RequestBody.create(JSON, gson.toJson(list)))
|
||||
.params("user", SharedPreferencesUtils.getstring("user","test"))
|
||||
.execute(new MyRecultCall(dialog,this){
|
||||
@Override
|
||||
public void onSuccess(Response<MyResult> response) {
|
||||
super.onSuccess(response);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressLint("HandlerLeak")
|
||||
private Handler handler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(@NonNull Message msg) {
|
||||
super.handleMessage(msg);
|
||||
}
|
||||
};
|
||||
private Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
sendBroadcast(broadcastIntent);
|
||||
handler.postDelayed(runnable, 1000);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
handler=null;
|
||||
runnable=null;
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package com.example.beijing_daxing.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.example.beijing_daxing.R;
|
||||
import com.example.beijing_daxing.been.Stock;
|
||||
import com.example.beijing_daxing.databinding.ItemStoreCheckBinding;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author wanghao
|
||||
* @date 2024/1/19 14:32
|
||||
*/
|
||||
public class StoreCheckAdapter extends RecyclerView.Adapter<StoreCheckAdapter.MyViewHoder> {
|
||||
private Context context;
|
||||
private List<Stock> list;
|
||||
private LayoutInflater inflater;
|
||||
|
||||
public StoreCheckAdapter(Context context) {
|
||||
this.context = context;
|
||||
inflater = LayoutInflater.from(context);
|
||||
}
|
||||
|
||||
public void setList(List<Stock> list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyViewHoder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
ItemStoreCheckBinding binding = DataBindingUtil.inflate(inflater, R.layout.item_store_check, parent, false);
|
||||
return new MyViewHoder(binding);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(MyViewHoder holder, int position) {
|
||||
var binding = holder.getBinding();
|
||||
binding.setItem(list.get(position));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return list==null?0:list.size();
|
||||
}
|
||||
|
||||
public class MyViewHoder extends RecyclerView.ViewHolder {
|
||||
private ItemStoreCheckBinding binding;
|
||||
|
||||
public MyViewHoder( ItemStoreCheckBinding binding) {
|
||||
super(binding.getRoot());
|
||||
this.binding = binding;
|
||||
}
|
||||
|
||||
public ItemStoreCheckBinding getBinding() {
|
||||
return binding;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package com.example.beijing_daxing.been;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author wanghao
|
||||
* @date 2024/1/19 13:45
|
||||
*/
|
||||
public class Stock {
|
||||
private int index;
|
||||
private String epcCode;
|
||||
private String locationCode;
|
||||
private String state;
|
||||
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(String state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public void setIndex(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public String getEpcCode() {
|
||||
return epcCode;
|
||||
}
|
||||
|
||||
public void setEpcCode(String epcCode) {
|
||||
this.epcCode = epcCode;
|
||||
}
|
||||
|
||||
public String getLocationCode() {
|
||||
return locationCode;
|
||||
}
|
||||
|
||||
public void setLocationCode(String locationCode) {
|
||||
this.locationCode = locationCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Stock stock = (Stock) o;
|
||||
|
||||
return Objects.equals(epcCode, stock.epcCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return epcCode != null ? epcCode.hashCode() : 0;
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<data>
|
||||
<variable
|
||||
name="checkState"
|
||||
type="androidx.databinding.ObservableBoolean" />
|
||||
<variable
|
||||
name="adapter"
|
||||
type="com.example.beijing_daxing.adapter.StoreCheckAdapter" />
|
||||
</data>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".StoreCheckActivity"
|
||||
android:background="@color/bg1"
|
||||
android:orientation="vertical">
|
||||
<TextView
|
||||
style="@style/title_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="45dp"
|
||||
android:text="仓库盘点" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="10dp"
|
||||
android:background="@color/white"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||
android:adapter="@{adapter}"
|
||||
android:padding="10dp"
|
||||
android:layout_weight="1"/>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="55dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:orientation="horizontal">
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:backgroundTint="@{checkState?@color/yellow:@color/black}"
|
||||
android:layout_marginStart="20dp"
|
||||
android:text='@{checkState?"停止读取":"开始盘点"}'
|
||||
android:textSize="20sp"
|
||||
android:onClick="check_read"
|
||||
android:layout_weight="1"/>
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:onClick="store_check_submit"
|
||||
style="@style/button_style"
|
||||
android:text="提交"/>
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</layout>
|
@ -0,0 +1,76 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<data>
|
||||
|
||||
<variable
|
||||
name="item"
|
||||
type="com.example.beijing_daxing.been.Stock" />
|
||||
|
||||
</data>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="60dp"
|
||||
android:layout_marginTop="2dp"
|
||||
android:background='@{item.state.equals("Y")?@color/green:@color/item_bg}'
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/item_index"
|
||||
style="@style/item_text_style"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="match_parent"
|
||||
android:text='@{String.valueOf(item.index)}' />
|
||||
|
||||
<View
|
||||
android:layout_width="2dp"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/white" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
style="@style/item_text_style"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:gravity="left"
|
||||
android:text="@{item.epcCode}" />
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="@color/white" />
|
||||
|
||||
<TextView
|
||||
style="@style/item_text_style"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="left"
|
||||
android:layout_weight="1"
|
||||
android:text="@{item.locationCode}" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<View
|
||||
android:layout_width="2dp"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/white" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/item_buttom"
|
||||
style="@style/item_text_style"
|
||||
android:layout_width="63dp"
|
||||
android:layout_height="match_parent"
|
||||
android:text='@{item.state.equals("Y")?"已盘点":"未盘点"}'
|
||||
android:textColor='@{item.state.equals("Y")?@color/black:@color/red}' />
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
</layout>
|
Loading…
Reference in New Issue