Skip to content

Commit 1e43194

Browse files
Finish creating Single Selection
1 parent 1ec5dbe commit 1e43194

File tree

11 files changed

+550
-24
lines changed

11 files changed

+550
-24
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package com.drapps.selectionalertdialog;
2+
3+
import android.content.Context;
4+
import android.view.LayoutInflater;
5+
import android.view.View;
6+
import android.view.ViewGroup;
7+
import android.widget.CheckBox;
8+
9+
import java.util.ArrayList;
10+
import java.util.Arrays;
11+
import java.util.List;
12+
13+
import androidx.recyclerview.widget.RecyclerView;
14+
15+
public class MulitpleSelectionAdapter extends RecyclerView.Adapter<MulitpleSelectionAdapter.MulitpleSelectionHolder> {
16+
private List<MultiSelection> dataList;
17+
Context context;
18+
List<MultiSelection> currentField;
19+
String assetsTitle = "";
20+
21+
public class MulitpleSelectionHolder extends RecyclerView.ViewHolder {
22+
23+
public CheckBox checkBox;
24+
25+
MulitpleSelectionHolder(View view) {
26+
super(view);
27+
checkBox = view.findViewById(R.id.checkbox_dialog);
28+
29+
}
30+
}
31+
32+
33+
public MulitpleSelectionAdapter(List<MultiSelection> contentList, String title, Context context) {
34+
this.context = context;
35+
this.dataList = contentList;
36+
this.assetsTitle = title;
37+
checkExist(assetsTitle);
38+
39+
}
40+
41+
@Override
42+
public MulitpleSelectionAdapter.MulitpleSelectionHolder onCreateViewHolder(ViewGroup parent, int viewType) {
43+
View itemView = LayoutInflater.from(parent.getContext())
44+
.inflate(R.layout.layout_multi_selection, parent, false);
45+
46+
return new MulitpleSelectionAdapter.MulitpleSelectionHolder(itemView);
47+
}
48+
49+
public void onBindViewHolder(final MulitpleSelectionAdapter.MulitpleSelectionHolder holder, final int position) {
50+
holder.checkBox.setText(dataList.get(position).getTitle());
51+
52+
53+
holder.setIsRecyclable(false);
54+
holder.checkBox.setOnClickListener(new View.OnClickListener() {
55+
@Override
56+
public void onClick(View view) {
57+
58+
if (holder.checkBox.isChecked()) {
59+
dataList.get(position).setCheck(true);
60+
} else {
61+
dataList.get(position).setCheck(false);
62+
63+
}
64+
}
65+
});
66+
67+
holder.checkBox.setChecked(dataList.get(position).getCheck());
68+
69+
}
70+
71+
@Override
72+
public int getItemCount() {
73+
return dataList.size();
74+
}
75+
76+
public boolean checkExist(String dataString) {
77+
if (dataList != null && dataList.size() > 0) {
78+
for (int i = 0; i < dataList.size(); i++) {
79+
List<String> assets = new ArrayList<String>(Arrays.asList(assetsTitle.split(",")));
80+
if (assets != null && assets.size() > 0 && !assetsTitle.equals("")) {
81+
for (int j = 0; j < assets.size(); j++) {
82+
if (dataList.get(i).getTitle().equals(assets.get(j))) {
83+
dataList.get(i).setCheck(true);
84+
}
85+
}
86+
}
87+
}
88+
}
89+
90+
91+
return false;
92+
}
93+
94+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.drapps.selectionalertdialog;
2+
3+
public class MultiSelection {
4+
5+
private Boolean check = false;
6+
private String title;
7+
8+
public MultiSelection() {
9+
}
10+
11+
12+
public Boolean getCheck() {
13+
return check;
14+
}
15+
16+
public void setCheck(Boolean check) {
17+
this.check = check;
18+
}
19+
20+
public String getTitle() {
21+
return title;
22+
}
23+
24+
public void setTitle(String title) {
25+
this.title = title;
26+
}
27+
}
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
package com.drapps.selectionalertdialog;
2+
3+
import android.app.Dialog;
4+
import android.content.Context;
5+
import android.os.Bundle;
6+
7+
import java.util.ArrayList;
8+
9+
import androidx.annotation.Nullable;
10+
import androidx.appcompat.app.AppCompatActivity;
11+
12+
public class MultiSelectionDialog extends AppCompatActivity {
13+
14+
Dialog dialog;
15+
private Context context;
16+
private ArrayList<MultiSelection> list = new ArrayList<>();
17+
private ArrayList<String> temp_data_list = new ArrayList<>();
18+
private String headerTitle = "Select";
19+
private Boolean isSearchEnabled = false;
20+
SingleSelectionAdapter dialogAdapter;
21+
private String currentField = "";
22+
private int headerColor;
23+
SingleSelectionListener singleSelectionListener;
24+
25+
26+
@Override
27+
protected void onCreate(@Nullable Bundle savedInstanceState) {
28+
super.onCreate(savedInstanceState);
29+
setContentView(R.layout.single_selection_dialog);
30+
}
31+
32+
public MultiSelectionDialog(SingleSelectionListener singleSelectionListener) {
33+
this.singleSelectionListener = singleSelectionListener;
34+
}
35+
36+
public void with(Context mContext) {
37+
this.context = mContext;
38+
}
39+
40+
public void setList(ArrayList<String> dataList) {
41+
42+
temp_data_list.clear();
43+
this.temp_data_list = dataList;
44+
}
45+
46+
public void setTitle(String mTitle) {
47+
if (mTitle != null && !mTitle.equals("")) {
48+
this.headerTitle = mTitle;
49+
} else {
50+
this.headerTitle = "Select";
51+
}
52+
}
53+
54+
public void enableSearch(Boolean value) {
55+
isSearchEnabled = value;
56+
}
57+
58+
public void setColor(int color) {
59+
headerColor = color;
60+
}
61+
62+
63+
// public void show() {
64+
// //Custom pop up dialog for selecting options
65+
// try {
66+
// dialog = new Dialog(context);
67+
// final View convertView = LayoutInflater.from(context).inflate(R.layout.multi_selection_dialog, null);
68+
// dialog.setContentView(convertView);
69+
// TextView tvTitle = convertView.findViewById(R.id.tv_title);
70+
// ImageView imgDone = convertView.findViewById(R.id.img_done_multi_dialog);
71+
// final RecyclerView recyclerView = convertView.findViewById(R.id.recycler_multi_dialog);
72+
// RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(context);
73+
// recyclerView.setLayoutManager(layoutManager);
74+
// LinearLayout header = convertView.findViewById(R.id.linear_multi_dialog);
75+
// final EditText etSearch = convertView.findViewById(R.id.et_search_single_selection);
76+
// tvTitle.setText(headerTitle);
77+
//
78+
// if (headerColor != 0) {
79+
// try {
80+
// header.setBackgroundColor(headerColor);
81+
// } catch (Exception e) {
82+
// e.printStackTrace();
83+
// }
84+
// }
85+
// imgDone.setOnClickListener(new View.OnClickListener() {
86+
// @Override
87+
// public void onClick(View view) {
88+
// String getAssetsValue = "";
89+
// String assetValue = "";
90+
// if (list != null && list.size() > 0) {
91+
// for (int i = 0; i < list.size(); i++) {
92+
// if (list.get(i).getCheck()) {
93+
// getAssetsValue += list.get(i).getTitle() + ",";
94+
// assetValue = getAssetsValue.substring(0, getAssetsValue.length() - 1);
95+
// }
96+
// }
97+
// }
98+
// if (getAssetsValue.equals("")) {
99+
//
100+
//
101+
// } else {
102+
//
103+
// }
104+
// dialog.dismiss();
105+
//
106+
// }
107+
// });
108+
// recyclerView.addOnItemTouchListener(
109+
// new RecyclerItemClickListener(context, recyclerView,
110+
// new RecyclerItemClickListener.OnItemClickListener() {
111+
// @Override
112+
// public void onItemClick(View view, int position) {
113+
// dialog.dismiss();
114+
// singleSelectionListener.onDialogItemSelected(currentField, position,tag);
115+
// }
116+
//
117+
// @Override
118+
// public void onItemLongClick(View view, int position) {
119+
// dialog.dismiss();
120+
// }
121+
//
122+
// })
123+
// );
124+
//
125+
// etSearch.addTextChangedListener(new TextWatcher() {
126+
// @Override
127+
// public void beforeTextChanged(CharSequence s, int start, int count, int after) {
128+
// }
129+
//
130+
// @Override
131+
// public void onTextChanged(CharSequence s, int start, int before, int count) {
132+
//
133+
// if (etSearch.getText().toString().equals("")) {
134+
// if (list != null && list.size() > 0) {
135+
//// dialogAdapter = new SingleSelectionAdapter(list, context, currentField);
136+
// dialogAdapter.notifyDataSetChanged();
137+
// recyclerView.setAdapter(dialogAdapter);
138+
// } else {
139+
// singleSelectionListener.onDialogError("List is empty or null");
140+
// }
141+
//
142+
//
143+
// } else {
144+
//// getSearchCountryList(etSearch.getText().toString(), recyclerView);
145+
// }
146+
//
147+
//
148+
// }
149+
//
150+
//
151+
// @Override
152+
// public void afterTextChanged(Editable s) {
153+
//
154+
// }
155+
// });
156+
//
157+
// if (list != null && list.size() > 0) {
158+
//// dialogAdapter = new SingleSelectionAdapter(list, context, currentField);
159+
// recyclerView.setAdapter(dialogAdapter);
160+
// dialog.show();
161+
// } else {
162+
// Toast.makeText(context, "List is empty", Toast.LENGTH_SHORT).show();
163+
// }
164+
//
165+
// } catch (Exception e) {
166+
// e.printStackTrace();
167+
// }
168+
//
169+
// }
170+
171+
// private void getSearchCountryList(String search, RecyclerView recyclerView) {
172+
// ArrayList<String> temp_list = new ArrayList<>();
173+
// if (list != null && list.size() > 0) {
174+
// for (int i = 0; i < list.size(); i++) {
175+
// if (list.get(i).toLowerCase().contains(search.toLowerCase())) {
176+
// temp_list.add(list.get(i));
177+
//
178+
// }
179+
// }
180+
// } else {
181+
// singleSelectionListener.onError("List is empty or null");
182+
//
183+
// }
184+
//
185+
// tempCountryList.clear();
186+
// tempCountryList.addAll(temp_list);
187+
//
188+
// dialogAdapter = new RadioDialogAdapter(tempCountryList, context, currentField);
189+
// dialogAdapter.notifyDataSetChanged();
190+
// recyclerView.setAdapter(dialogAdapter);
191+
//
192+
//
193+
// }
194+
195+
196+
}

selectionalertdialog/src/main/java/com/drapps/selectionalertdialog/SingleSelectionAdapter.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.drapps.selectionalertdialog;
22

33
import android.content.Context;
4+
import android.content.res.ColorStateList;
45
import android.view.LayoutInflater;
56
import android.view.View;
67
import android.view.ViewGroup;
@@ -15,25 +16,26 @@ public class SingleSelectionAdapter extends RecyclerView.Adapter<SingleSelection
1516
private List<String> dataList = new ArrayList<>();
1617
Context context;
1718
String currentField;
19+
int color;
1820

1921
public class SingleSelectionHolder extends RecyclerView.ViewHolder {
2022

2123
public RadioButton radioButton;
22-
24+
public View line;
2325

2426
SingleSelectionHolder(View view) {
2527
super(view);
2628
radioButton = view.findViewById(R.id.radio_btn_single_selection);
27-
29+
line = view.findViewById(R.id.view_single_selection);
2830
}
2931
}
3032

3133

32-
public SingleSelectionAdapter(ArrayList<String> contentList, Context context, String currentField) {
34+
public SingleSelectionAdapter(ArrayList<String> contentList, Context context, String currentField, int radioColor) {
3335
this.context = context;
3436
this.dataList = contentList;
3537
this.currentField = currentField;
36-
38+
this.color = radioColor;
3739
}
3840

3941
@Override
@@ -45,6 +47,15 @@ public SingleSelectionHolder onCreateViewHolder(ViewGroup parent, int viewType)
4547
}
4648

4749
public void onBindViewHolder(SingleSelectionHolder holder, int position) {
50+
51+
if (color != 0) {
52+
try {
53+
holder.radioButton.setButtonTintList(ColorStateList.valueOf(color));
54+
holder.line.setBackgroundColor(color);
55+
} catch (Exception e) {
56+
57+
}
58+
}
4859
if (dataList.get(position).equals(currentField)) {
4960
holder.setIsRecyclable(false);
5061
holder.radioButton.setChecked(true);

0 commit comments

Comments
 (0)