CreateGoGrabProTabBackendAdapter.java
7.25 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
package etelligens.com.foodsafety.adapter;
import android.annotation.SuppressLint;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.gson.Gson;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import etelligens.com.foodsafety.R;
import etelligens.com.foodsafety.model.AddGoGrabLineModal;
import etelligens.com.foodsafety.model.CreateGoGrabTabModal;
import etelligens.com.foodsafety.model.GrabAndGoSubLabelsModel;
public class CreateGoGrabProTabBackendAdapter extends RecyclerView.Adapter<CreateGoGrabProTabBackendAdapter.GoGrabViewHolder> {
Context context;
private ArrayList<CreateGoGrabTabModal> goGrabTabModals;
private ArrayList<GrabAndGoSubLabelsModel> grabAndGoSubLabelsModels;
AddGoGrabLineBackendAdapter addGoGrabLineBackendAdapter;
OnItemClick onItemClick;
String nameItem;
int idItem;
//GoGrabLineAdapter goGrabLineAdapter;
ArrayList<AddGoGrabLineModal> goGrabLineModals;
public interface OnItemClick {
void sendData(String id);
void nameItem(CreateGoGrabTabModal createGoGrabTabModal, int count, int id, int pId, String name, String value, String per, int isLs,int position);
}
public CreateGoGrabProTabBackendAdapter(Context context, ArrayList<CreateGoGrabTabModal> list, OnItemClick onItemClick) {
this.context = context;
this.goGrabTabModals = list;
this.onItemClick = onItemClick;
}
View view;
@NonNull
@Override
public CreateGoGrabProTabBackendAdapter.GoGrabViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int i) {
view = LayoutInflater.from(context).inflate(R.layout.item_layout_go_grab_pro_backend, parent, false);
return new GoGrabViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull final CreateGoGrabProTabBackendAdapter.GoGrabViewHolder holder, @SuppressLint("RecyclerView") int position) {
final CreateGoGrabTabModal modal = goGrabTabModals.get(position);
grabAndGoSubLabelsModels = (ArrayList<GrabAndGoSubLabelsModel>) modal.getSub_labels();
String labelName = modal.getName();
final int pId = modal.getId();
Log.e("isHead===: ", modal.getIs_head() + "");
if (modal.getIs_head() == 1) {
holder.dailyValue_Layout.setVisibility(View.VISIBLE);
holder.addlinetxt.setVisibility(View.GONE);
} else if (modal.getIs_head() == 0) {
holder.labelnameedittxt.setText(labelName);
holder.addlinetxt.setVisibility(View.VISIBLE);
holder.dailyValue_Layout.setVisibility(View.GONE);
}
if (labelName.equalsIgnoreCase(context.getString(R.string.calories))) {
holder.addlinetxt.setVisibility(View.GONE);
}else if (labelName.equalsIgnoreCase(context.getString(R.string.sodium))){
holder.addlinetxt.setVisibility(View.GONE);
}else {
//do nothing...
}
if (labelName.equals(R.string.daily_value)) {
holder.label_name_dailyvalue.setText("%" + labelName);
} else if (modal.getIs_head() == 1) {
holder.label_name_dailyvalue.setText("");
}
if (position == goGrabTabModals.size() - 1) {
holder.addbuttontxt.setVisibility(View.VISIBLE);
}
holder.addbuttontxt.setOnClickListener(v -> onItemClick.sendData(String.valueOf(pId)));
holder.addlineRecyclerview.setHasFixedSize(true);
LinearLayoutManager layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false);
holder.addlineRecyclerview.setLayoutManager(layoutManager);
addGoGrabLineBackendAdapter = new AddGoGrabLineBackendAdapter(context, grabAndGoSubLabelsModels, new AddGoGrabLineBackendAdapter.PassData() {
@Override
public void sendData() {
}
@Override
public void nameItem(GrabAndGoSubLabelsModel grabAndGoSubLabelsModel, int count) {
int id = grabAndGoSubLabelsModel.getId();
int pId = grabAndGoSubLabelsModel.getParent_id();
String name = grabAndGoSubLabelsModel.getName();
String value = grabAndGoSubLabelsModel.getValue();
String per = grabAndGoSubLabelsModel.getPercent();
int isLs = grabAndGoSubLabelsModel.getIs_list();
onItemClick.nameItem(modal, count, id, pId, name, value, per, isLs,position);
}
});
holder.addlineRecyclerview.setAdapter(addGoGrabLineBackendAdapter);
addGoGrabLineBackendAdapter.notifyDataSetChanged();
holder.addlinetxt.setOnClickListener(view -> {
int id = grabAndGoSubLabelsModels.size() + 2;
String name = "";
addLine(id, name, pId, position);
});
}
private void addLine(int id, String name, int pId, int pos) {
System.out.println("checkkkk");
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("id", id);
jsonObject.put("name", name);
jsonObject.put("parent_id", pId);
jsonObject.put("is_list", 0);
Gson gson = new Gson();
GrabAndGoSubLabelsModel addGoGrabLineModal = gson.fromJson(String.valueOf(jsonObject), GrabAndGoSubLabelsModel.class);
goGrabTabModals.get(pos).getSub_labels().add(addGoGrabLineModal);
notifyDataSetChanged();
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public int getItemCount() {
return goGrabTabModals.size();
}
public class GoGrabViewHolder extends RecyclerView.ViewHolder {
RecyclerView addlineRecyclerview;
TextView addlinetxt, addbuttontxt, label_name_dailyvalue;
EditText labelnameedittxt, enteredittxt, enterlabelnametxt;
Button savetxt;
RelativeLayout rldialogboxlayout;
LinearLayout dailyValue_Layout, ll_lable;
public GoGrabViewHolder(View itemview) {
super(itemview);
addlineRecyclerview = itemview.findViewById(R.id.add_line_recyclerview);
addlinetxt = itemview.findViewById(R.id.add_new_tatxt);
addlinetxt.setText(R.string.add_line_txt);
labelnameedittxt = itemview.findViewById(R.id.label_name_edittxt);
addbuttontxt = itemview.findViewById(R.id.add_button_txt);
//enteredittxt = itemview.findViewById(R.id.enter_parent_id_txt);
savetxt = itemview.findViewById(R.id.savebutton);
enterlabelnametxt = itemview.findViewById(R.id.enter_label_name_txt);
rldialogboxlayout = itemview.findViewById(R.id.rl_dialog_boxlayout);
label_name_dailyvalue = itemview.findViewById(R.id.label_name_dailyvalue);
dailyValue_Layout = itemview.findViewById(R.id.dailyValue_Layout);
ll_lable = itemview.findViewById(R.id.ll_lable);
}
}
}