AddLineCustomLabelBackendAdapter.java
5.66 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
package etelligens.com.foodsafety.adapter;
import android.annotation.SuppressLint;
import android.content.Context;
import android.text.Editable;
import android.text.Html;
import android.text.TextWatcher;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.net.URLDecoder;
import java.util.ArrayList;
import etelligens.com.foodsafety.R;
import etelligens.com.foodsafety.model.AddLineCustomLabelBackendModal;
public class AddLineCustomLabelBackendAdapter extends RecyclerView.Adapter<AddLineCustomLabelBackendAdapter.AddLineViewHolder> {
Context context;
ArrayList<AddLineCustomLabelBackendModal> lineCustomLabelBackendModals;
int count = 0;
Passitem passitem;
public interface Passitem {
void description(AddLineCustomLabelBackendModal addLineCustomLabelBackendModal, int id);
}
public AddLineCustomLabelBackendAdapter(Context context, ArrayList<AddLineCustomLabelBackendModal> labelBackendModals, Passitem passitem) {
this.context = context;
this.lineCustomLabelBackendModals = labelBackendModals;
this.passitem = passitem;
}
View view;
@NonNull
@Override
public AddLineCustomLabelBackendAdapter.AddLineViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int i) {
view = LayoutInflater.from(context).inflate(R.layout.item_layout_add_line_custom_label, parent, false);
return new AddLineViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull final AddLineCustomLabelBackendAdapter.AddLineViewHolder holder, @SuppressLint("RecyclerView") int i) {
final AddLineCustomLabelBackendModal addLineCustomLabelBackendModal = lineCustomLabelBackendModals.get(i);
String description = addLineCustomLabelBackendModal.getDescription();
if (description != null) {
holder.customdescriptiontext.setText(decodeString(description));
}
String ids = String.valueOf(addLineCustomLabelBackendModal.getId());
for (int j = 0; j < addLineCustomLabelBackendModal.getId(); j++) {
if (j != 0) {
holder.customdeletetext.setVisibility(View.VISIBLE);
}
}
holder.Cpttxt.setText("Pt");
holder.customdescriptiontext.setOnClickListener(v -> {
final int id = addLineCustomLabelBackendModal.getId();
passitem.description(addLineCustomLabelBackendModal, id);
});
holder.customdeletetext.setOnClickListener(v -> {
lineCustomLabelBackendModals.remove(i);
notifyDataSetChanged();
});
holder.custom_boldtext.setOnClickListener(v -> {
String bolddd = holder.customdescriptiontext.getText().toString().trim();
String sourceString = "<b>" + bolddd + "</b> ";
holder.customdescriptiontext.setText(Html.fromHtml(sourceString));
});
holder.custom_italictext.setOnClickListener(view -> {
String bolddd = holder.customdescriptiontext.getText().toString().trim();
String sourceString = "<i>" + bolddd + "</i> ";
holder.customdescriptiontext.setText(Html.fromHtml(sourceString));
});
holder.custom_utext.setOnClickListener(view -> {
String bolddd = holder.customdescriptiontext.getText().toString().trim();
String sourceString = "<u>" + bolddd + "</u> ";
holder.customdescriptiontext.setText(Html.fromHtml(sourceString));
});
holder.Cpttxt.setOnClickListener(view -> {
String bolddd = holder.customdescriptiontext.getText().toString().trim();
holder.customdescriptiontext.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
});
}
private String decodeString(String productPrice) {
String value= URLDecoder.decode(productPrice);
return value;
}
@Override
public int getItemCount() {
return lineCustomLabelBackendModals.size();
}
public class AddLineViewHolder extends RecyclerView.ViewHolder {
TextView customdescriptiontext, custom_boldtext, custom_utext, custom_italictext, Cpttxt;
ImageView customdeletetext;
int maxLength = 30;// 设置最大输入长度为40个字符
public AddLineViewHolder(View itemview) {
super(itemview);
customdescriptiontext = itemview.findViewById(R.id.custom_description_text);
Cpttxt = itemview.findViewById(R.id.custom_pttext);
custom_boldtext = itemview.findViewById(R.id.cus_bold_text);
custom_utext = itemview.findViewById(R.id.custom_under_text);
custom_italictext = itemview.findViewById(R.id.custom_italic_text);
customdeletetext = itemview.findViewById(R.id.custom_delete_text);
customdescriptiontext.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if (s != null && s.length() > maxLength) {
customdescriptiontext.setError("The maximum length limit is exceeded");
} else {
customdescriptiontext.setError(null);
}
}
});
}
}
}