CreateCustomLabelsAdapter.java
9.58 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
package etelligens.com.foodsafety.adapter;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.squareup.picasso.Picasso;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import etelligens.com.foodsafety.R;
import etelligens.com.foodsafety.model.AddNewPrepBackendModal;
import etelligens.com.foodsafety.utils.EndPoint;
public class CreateCustomLabelsAdapter extends RecyclerView.Adapter<CreateCustomLabelsAdapter.AddNewViewHolder> {
Context context;
private ArrayList<AddNewPrepBackendModal> prepBackendModals;
String name = "";
Passdata passdata;
public interface Passdata {
void day(AddNewPrepBackendModal addNewPrepBackendModal);
void hour(AddNewPrepBackendModal addNewPrepBackendModal);
void mint(AddNewPrepBackendModal addNewPrepBackendModal);
void labelName(AddNewPrepBackendModal addNewPrepBackendModal);
void imageData(AddNewPrepBackendModal addNewPrepBackendModal, int data, int position);
void sendUncheckValue(AddNewPrepBackendModal addNewPrepBackendModal, String data, CheckBox checkBox);
}
public CreateCustomLabelsAdapter(Context context, ArrayList<AddNewPrepBackendModal> prepBackendModals, Passdata passdata) {
this.context = context;
this.prepBackendModals = prepBackendModals;
this.passdata = passdata;
}
View view;
@NonNull
@Override
public CreateCustomLabelsAdapter.AddNewViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int i) {
view = LayoutInflater.from(context).inflate(R.layout.item_layout_add_new_prep_product_backend, parent, false);
return new CreateCustomLabelsAdapter.AddNewViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull final CreateCustomLabelsAdapter.AddNewViewHolder holder, final int i) {
final AddNewPrepBackendModal addNewPrepBackendModal = prepBackendModals.get(i);
name = addNewPrepBackendModal.getName();
final String img = addNewPrepBackendModal.getFile();
final String option_image = addNewPrepBackendModal.getOption_image();
if (img != null) {
Bitmap bMap = getBitmap(img);
if (bMap != null) {
holder.uploadImg.setImageBitmap(bMap);
holder.uploadImg.setVisibility(View.VISIBLE);
} else {
holder.uploadImg.setImageBitmap(bMap);
holder.uploadImg.setVisibility(View.VISIBLE);
Bitmap decodedByte = BitmapFactory.decodeFile(img);
holder.uploadImg.setImageBitmap(decodedByte);
holder.uploadImg.setVisibility(View.VISIBLE);
// holder.uploadImg.setImageResource(R.drawable.ic_bluetooth_24dp);
}
} else if (option_image != null) {
holder.uploadImg.setVisibility(View.VISIBLE);
Picasso.get().load(EndPoint.ETE_IMAGE_BASEURL + option_image)
.into(holder.uploadImg);
}
String dayNew = addNewPrepBackendModal.getDate();
String hrNew = addNewPrepBackendModal.getHour();
String minNew = addNewPrepBackendModal.getMin();
if (addNewPrepBackendModal.getIsChecked() != null) {
String isChecked = addNewPrepBackendModal.getIsChecked();
if (isChecked.equalsIgnoreCase("1")) {
holder.labelcheckbox.setChecked(true);
} else {
holder.labelcheckbox.setChecked(false);
}
}
// if (name.equalsIgnoreCase(context.getString(R.string.defrost_txt)) ||
// name.equalsIgnoreCase(context.getString(R.string.opend_txt)) || name.equalsIgnoreCase(context.getString(R.string.thawed_txt))) {
// holder.labelcheckbox.setVisibility(View.GONE);
// holder.rlcrossbtn.setVisibility(View.GONE);
//
// }else {
holder.rlcrossbtn.setVisibility(View.VISIBLE);
holder.labelcheckbox.setVisibility(View.VISIBLE);
//}
holder.labelcheckbox.setOnClickListener(v -> {
// if (name.equalsIgnoreCase(context.getString(R.string.defrost_txt))) {
// holder.labelcheckbox.setChecked(true);
// holder.rlcrossbtn.setVisibility(View.GONE);
// } else if (name.equalsIgnoreCase(context.getString(R.string.opend_txt))) {
// holder.labelcheckbox.setChecked(true);
// holder.rlcrossbtn.setVisibility(View.GONE);
// } else if (name.equalsIgnoreCase(context.getString(R.string.thawed_txt))) {
// holder.labelcheckbox.setChecked(true);
// holder.rlcrossbtn.setVisibility(View.GONE);
// } else
if (holder.labelcheckbox.isChecked()){
// &&
// !name.equalsIgnoreCase(context.getString(R.string.defrost_txt)) &&
// !name.equalsIgnoreCase(context.getString(R.string.opend_txt)) &&
// !name.equalsIgnoreCase(context.getString(R.string.thawed_txt))) {
passdata.sendUncheckValue(addNewPrepBackendModal, "Check", holder.labelcheckbox);
} else if (!holder.labelcheckbox.isChecked() ){
//&&
// !name.equalsIgnoreCase(context.getString(R.string.defrost_txt)) &&
// !name.equalsIgnoreCase(context.getString(R.string.opend_txt)) &&
// !name.equalsIgnoreCase(context.getString(R.string.thawed_txt))) {
passdata.sendUncheckValue(addNewPrepBackendModal, "unCheck", holder.labelcheckbox);
}else {
// do nothing...
// holder.labelcheckbox.setChecked(true);
Toast.makeText(context, "not selectable", Toast.LENGTH_SHORT).show();
}
});
holder.labelNametxt.setOnClickListener(view -> {
// if (!name.equalsIgnoreCase(context.getString(R.string.defrost_txt)) &&
// !name.equalsIgnoreCase(context.getString(R.string.opend_txt)) && !name.equalsIgnoreCase(context.getString(R.string.thawed_txt))) {
passdata.labelName(addNewPrepBackendModal);
//}
});
if (name != null) {
holder.labelNametxt.setText(name);
}
if (dayNew != null) {
holder.day.setText(dayNew);
}
if (minNew != null) {
holder.mins.setText(minNew);
}
if (hrNew != null) {
holder.hours.setText(hrNew);
}
holder.day.setOnClickListener(v -> passdata.day(addNewPrepBackendModal));
holder.hours.setOnClickListener(v -> passdata.hour(addNewPrepBackendModal));
holder.mins.setOnClickListener(v -> passdata.mint(addNewPrepBackendModal));
holder.lluploadImglayout.setOnClickListener(view -> passdata.imageData(addNewPrepBackendModal, 1, i));
holder.rlcrossbtn.setOnClickListener(v -> {
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(holder.ll_parent_label_value.getWindowToken(), 0);
prepBackendModals.remove(i);
notifyDataSetChanged();
});
}
public Bitmap getBitmap(String path) {
Bitmap bitmap = null;
try {
File f = new File(path);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
bitmap = BitmapFactory.decodeStream(new FileInputStream(f), null, options);
} catch (Exception e) {
e.printStackTrace();
}
return bitmap;
}
@Override
public int getItemCount() {
return prepBackendModals.size();
}
@Override
public int getItemViewType(int position) {
return position;
}
public class AddNewViewHolder extends RecyclerView.ViewHolder {
LinearLayout lluploadImglayout, lllabelvalue, ll_parent_label_value;
RelativeLayout rlcrossbtn;
ImageView uploadImg, tvcrossimg;
TextView day, hours, mins, labelNametxt;
CheckBox labelcheckbox;
public AddNewViewHolder(View itemview) {
super(itemview);
day = itemview.findViewById(R.id.tv_text_day);
hours = itemview.findViewById(R.id.tv_text_hour);
mins = itemview.findViewById(R.id.tv_text_mins);
lluploadImglayout = itemview.findViewById(R.id.ll_upload_img_layout);
uploadImg = itemview.findViewById(R.id.upload_img);
labelNametxt = itemview.findViewById(R.id.label_name_txt);
labelcheckbox = itemview.findViewById(R.id.label_check_box);
rlcrossbtn = itemview.findViewById(R.id.rl_cross_btn);
tvcrossimg = itemview.findViewById(R.id.tv_cross_img);
lllabelvalue = itemview.findViewById(R.id.ll_label_value);
ll_parent_label_value = itemview.findViewById(R.id.ll_parent_label_value);
}
}
}