ReceiptDetailView.java
5.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package com.huaheng.mobilewms.refactor;
import android.content.Context;
import android.graphics.Color;
import android.support.v7.app.AlertDialog;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.huaheng.mobilewms.R;
import com.huaheng.mobilewms.bean.ReceiptDetail;
public class ReceiptDetailView extends LinearLayout implements View.OnLongClickListener, View.OnClickListener{
private Context context;
TextView materialNameView;
TextView materialCodeView;
TextView materialQtyView;
private ReceiptDetail receiptDetail;
public ReceiptDetail getReceiptDetail() {
return receiptDetail;
}
public ReceiptDetailView(Context context) {
super(context, null);
this.context = context;
LayoutInflater.from(context).inflate(R.layout.view_receipt_detail, this);
materialNameView = findViewById(R.id.materialName);
materialCodeView = findViewById(R.id.materialCode);
materialQtyView = findViewById(R.id.materialQty);
setOnLongClickListener(this);
setOnClickListener(this);
}
public ReceiptDetailView(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
}
public void init(ReceiptDetail receiptDetail) {
this.receiptDetail = receiptDetail;
materialNameView.setText(receiptDetail.getMaterialName());
materialCodeView.setText(receiptDetail.getMaterialCode());
updateQtyLabel();
setViewSelected(receiptDetail.isSelected());
setGrayIfZero();
}
public void setGrayIfZero(){
if(receiptDetail.tobeCollectQty() == 0){
int gray = Color.rgb(160, 160, 160);
materialNameView.setTextColor(gray);
materialCodeView.setTextColor(gray);
materialQtyView.setTextColor(gray);
}else{
int black = Color.rgb(0, 0, 0);
materialNameView.setTextColor(black);
materialCodeView.setTextColor(black);
materialQtyView.setTextColor(black);
}
}
private void setBoldFont(TextView view){
TextPaint tp = view.getPaint();
tp.setFakeBoldText(true);
}
private void setBlueText(TextView view){
int blue = Color.rgb(0, 0, 255);
view.setTextColor(blue);
}
public void setAutoSelectColor(){
// this.setBackgroundResource(R.color.colorPrimary);
// setBoldFont(this.materialQtyView);
// setBoldFont(this.materialNameView);
// setBoldFont(this.materialCodeView);
setBlueText(this.materialQtyView);
setBlueText(this.materialNameView);
setBlueText(this.materialCodeView);
}
/**在选中与不选之间切换**/
public void selectAll() {
if(receiptDetail.tobeCollectQty() == 0){
return;
}
// WMSUtils.showShort(receiptDetail.getMaterialName() + " " + receiptDetail.getQty());
if (receiptDetail.isSelected()) {
receiptDetail.setQtySelected(0);
setViewSelected(false);
} else {
receiptDetail.selectAll();
setViewSelected(true);
}
}
/**选中某条item,并在bean中记录用户设置的数量**/
public void selectByQty(int qty){
if (qty>0){
receiptDetail.setQtySelected(qty);
setViewSelected(true);
}else{
receiptDetail.setQtySelected(0);
setViewSelected(false);
}
}
/**设置选中的状态颜色**/
public void setViewSelected(boolean selected) {
updateQtyLabel();
//更新view状态后同步更新提交按钮状态
((NewReceiptDetailActivity)context).switchButton();
if (selected) {
this.setBackgroundResource(R.color.tobe_color);
} else {
this.setBackgroundResource(R.color.white);
}
}
/**根据收货数量显示不同格式的文字**/
public void updateQtyLabel(){
int qty = receiptDetail.getQtySelected();
String unit = "";
if (receiptDetail.getUnit() != null) {
unit = receiptDetail.getUnit();
}
String labelStr = receiptDetail.tobeCollectQty() + unit;
if(qty == receiptDetail.tobeCollectQty() || qty == 0) {
materialQtyView.setText(labelStr);
}else{
labelStr = qty + " / " + labelStr;
materialQtyView.setText(labelStr);
}
}
public boolean isViewSelected() {
return this.receiptDetail.isSelected();
}
public void openQtyDialog() {
if(receiptDetail.tobeCollectQty() == 0){
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(context);
ReceiptQtySelectorView view = new ReceiptQtySelectorView(context, receiptDetail);
// builder.setTitle("请选择收货数量 " + receiptDetail.getMaterialCode());
builder.setView(view);
AlertDialog dialog = builder.show();
view.setParentDialog(dialog);
view.setParentView(this);
}
@Override
public boolean onLongClick(View v) {
openQtyDialog();
return true;
}
@Override
public void onClick(View v) {
selectAll();
}
}