Skip to content

Commit 09f7844

Browse files
Added Positive and NegativeButton
1 parent 6e07ef6 commit 09f7844

File tree

3 files changed

+130
-10
lines changed

3 files changed

+130
-10
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.

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

Lines changed: 92 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ public class MultiSelectionDialog extends AppCompatActivity {
5151
private ArrayList<MultiSelection> temp_data_list = new ArrayList<>();
5252
private String headerTitle = "Select";
5353
MulitpleSelectionAdapter dialogAdapter;
54-
private String currentField = "", currentValue = "", currentPosition = "", tag = "", hintText = "Search here";
55-
private int headerColor, textColor;
54+
private String currentField = "", currentValue = "", currentPosition = "", tag = "", hintText = "Search here", positiveText = "", negativeText = "";
55+
private int headerColor, textColor, positiveTextColor, negativeTextColor;
5656
MultiSelectionListener multiSelectionListener;
57-
57+
private boolean doneVisibility;
5858

5959
@Override
6060
protected void onCreate(@Nullable Bundle savedInstanceState) {
@@ -81,6 +81,11 @@ private MultiSelectionDialog(Builder builder) {
8181
headerColor = builder.headerColor;
8282
textColor = builder.textColor;
8383
multiSelectionListener = builder.multiSelectionListener;
84+
negativeTextColor = builder.negativeColor;
85+
positiveTextColor = builder.positiveColor;
86+
positiveText = builder.positiveText;
87+
negativeText = builder.negativeText;
88+
doneVisibility = builder.doneVisibility;
8489
Log.d("TAG--", headerTitle);
8590
}
8691

@@ -100,15 +105,38 @@ public void show() {
100105
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(context);
101106
recyclerView.setLayoutManager(layoutManager);
102107
LinearLayout header = convertView.findViewById(R.id.linear_multi_dialog);
108+
LinearLayout linearBtn = convertView.findViewById(R.id.linear_btn_multi_dialog);
109+
TextView tvPositive = convertView.findViewById(R.id.tv_positive_multi_dialog);
110+
TextView tvNegative = convertView.findViewById(R.id.tv_negative_multi_dialog);
103111
tvTitle.setText(headerTitle);
104-
112+
tvPositive.setText(positiveText);
113+
tvNegative.setText(negativeText);
114+
if (doneVisibility) {
115+
imgDone.setVisibility(View.VISIBLE);
116+
} else {
117+
imgDone.setVisibility(View.GONE);
118+
}
105119
if (headerColor != 0) {
106120
try {
107121
header.setBackgroundColor(headerColor);
108122
} catch (Exception e) {
109123
e.printStackTrace();
110124
}
111125
}
126+
if (positiveTextColor != 0) {
127+
try {
128+
tvPositive.setBackgroundColor(positiveTextColor);
129+
} catch (Exception e) {
130+
e.printStackTrace();
131+
}
132+
}
133+
if (negativeTextColor != 0) {
134+
try {
135+
tvPositive.setBackgroundColor(negativeTextColor);
136+
} catch (Exception e) {
137+
e.printStackTrace();
138+
}
139+
}
112140

113141
recyclerView.addOnItemTouchListener(
114142
new RecyclerItemClickListener(context, recyclerView,
@@ -153,15 +181,52 @@ public void onClick(View view) {
153181

154182
}
155183
});
184+
tvPositive.setOnClickListener(new View.OnClickListener() {
185+
@Override
186+
public void onClick(View view) {
187+
String getAssetsValue = "";
188+
String assetValue = "";
189+
ArrayList<String> temp_string_list = new ArrayList<>();
190+
if (multiList != null && multiList.size() > 0) {
191+
for (int i = 0; i < multiList.size(); i++) {
192+
if (multiList.get(i).getCheck()) {
193+
temp_string_list.add(multiList.get(i).getTitle());
194+
getAssetsValue += multiList.get(i).getTitle() + ",";
195+
assetValue = getAssetsValue.substring(0, getAssetsValue.length() - 1);
196+
}
197+
}
198+
if (multiSelectionListener != null) {
199+
multiSelectionListener.onMultiDialogItemsSelected(assetValue, tag, temp_string_list);
200+
}
201+
} else {
202+
if (multiSelectionListener != null) {
203+
multiSelectionListener.onMultiDialogError("List is null or empty", tag);
204+
}
205+
}
206+
207+
dialog.dismiss();
208+
209+
}
210+
});
211+
tvNegative.setOnClickListener(new View.OnClickListener() {
212+
@Override
213+
public void onClick(View v) {
214+
if (dialog.isShowing()) {
215+
dialog.dismiss();
216+
}
217+
}
218+
});
156219

157220
if (list != null && list.size() > 0) {
158221
dialogAdapter = new MulitpleSelectionAdapter(multiSelectionListener, multiList, currentField, tag, context, headerColor, textColor);
159222
recyclerView.setAdapter(dialogAdapter);
160223
dialog.show();
161-
} else { if (multiSelectionListener!=null){
224+
} else {
225+
if (multiSelectionListener != null) {
162226

163-
multiSelectionListener.onMultiDialogError("List is null or empty", tag);
164-
}}
227+
multiSelectionListener.onMultiDialogError("List is null or empty", tag);
228+
}
229+
}
165230

166231
dialog.show();
167232
} catch (Exception e) {
@@ -180,9 +245,10 @@ public static class Builder {
180245
private Context context;
181246
private ArrayList<String> list = new ArrayList<>();
182247
private String headerTitle = "Select";
183-
private String currentField = "", tag = "", hintText = "Search here";
184-
private int headerColor, textColor;
248+
private String currentField = "", tag = "", hintText = "Search here", positiveText = "", negativeText = "";
249+
private int headerColor, textColor, positiveColor, negativeColor;
185250
MultiSelectionListener multiSelectionListener;
251+
private boolean doneVisibility = true;
186252

187253
public Builder(Context ctx, String tag) {
188254
this.context = ctx;
@@ -214,11 +280,28 @@ public Builder setColor(int color) {
214280
return this;
215281
}
216282

283+
public Builder setPositiveButton(String text, int color) {
284+
positiveColor = color;
285+
positiveText = text;
286+
return this;
287+
}
288+
289+
public Builder setNegativeButton(String text, int color) {
290+
negativeColor = color;
291+
negativeText = text;
292+
return this;
293+
}
294+
217295
public Builder setListener(MultiSelectionListener listener) {
218296
multiSelectionListener = listener;
219297
return this;
220298
}
221299

300+
public Builder setDoneVisibility(boolean visible) {
301+
doneVisibility = visible;
302+
return this;
303+
}
304+
222305

223306
public Builder setSelectedField(String selectedField) {
224307
currentField = selectedField;

selectionalertdialog/src/main/res/layout/multi_selection_dialog.xml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
34
android:layout_width="match_parent"
45
android:layout_height="match_parent">
56

@@ -40,4 +41,40 @@
4041
android:layout_height="wrap_content"
4142
android:layout_below="@id/linear_multi_dialog"
4243
android:layout_marginTop="10dp" />
44+
45+
<LinearLayout
46+
android:id="@+id/linear_btn_multi_dialog"
47+
android:layout_width="match_parent"
48+
android:layout_height="wrap_content"
49+
android:layout_below="@id/recycler_multi_dialog"
50+
android:layout_marginTop="10dp"
51+
android:orientation="horizontal"
52+
android:weightSum="2">
53+
54+
<TextView
55+
android:id="@+id/tv_negative_multi_dialog"
56+
android:layout_width="wrap_content"
57+
android:layout_height="wrap_content"
58+
android:layout_gravity="start"
59+
android:layout_marginLeft="10dp"
60+
android:layout_weight="1"
61+
android:maxLines="1"
62+
android:textSize="18sp"
63+
android:textStyle="bold"
64+
tools:text="Cancel" />
65+
66+
<TextView
67+
android:id="@+id/tv_positive_multi_dialog"
68+
android:layout_width="wrap_content"
69+
android:layout_height="wrap_content"
70+
android:layout_gravity="end"
71+
android:layout_marginRight="10dp"
72+
android:layout_weight="1"
73+
android:gravity="end"
74+
android:textSize="18sp"
75+
android:textStyle="bold"
76+
tools:text="OK" />
77+
78+
79+
</LinearLayout>
4380
</RelativeLayout>

0 commit comments

Comments
 (0)