@@ -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 ;
0 commit comments