|
| 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 | +} |
0 commit comments