Skip to content

Commit

Permalink
[android] more on select all logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
gubatron committed Mar 23, 2016
1 parent 94d0be6 commit 89acc39
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public abstract class AbstractConfirmListDialog<T extends SearchResult> extends
*/

Logger LOGGER = Logger.getLogger(AbstractConfirmListDialog.class);
private CompoundButton.OnCheckedChangeListener selectAllCheckboxOnCheckedChangeListener;

public enum SelectionMode {
NO_SELECTION,
Expand Down Expand Up @@ -129,36 +130,12 @@ protected void initComponents(Dialog dlg, Bundle savedInstanceState) {
TextView confirmTextView = findView(dlg, R.id.dialog_confirm_list_text);
confirmTextView.setText(dialogText);

CheckBox selectAllCheckbox = findView(dlg, R.id.dialog_confirm_list_select_all_checkbox);
selectAllCheckbox.setVisibility(selectionMode == SelectionMode.MULTIPLE_SELECTION ? View.VISIBLE : View.GONE);
initListViewAndAdapter(bundle);
initSelectAllCheckbox();
initButtonListeners();
}

if (selectionMode == SelectionMode.MULTIPLE_SELECTION) {
selectAllCheckbox.setVisibility(View.VISIBLE);
updateSelectedCount();
selectAllCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (buttonView.isChecked()) {
adapter.checkAll();
} else {
adapter.clearChecked();
}
updateSelectedCount();
}
});
}
ListView listView = findView(dlg, R.id.dialog_confirm_list_list);
String listDataString = bundle.getString("listData");
List<T> listData = deserializeData(listDataString);
if (adapter != null) {
adapter.addList(listData);
} else {
adapter = new ConfirmListDialogDefaultAdapter<>(getActivity(),
listData,
selectionMode);
adapter.setOnItemCheckedListener(this);
}
listView.setAdapter(adapter);
private void initButtonListeners() {
final Dialog dialog = dlg;
Button noButton = findView(dialog, R.id.dialog_confirm_list_button_no);
noButton.setOnClickListener(new OnClickListener() {
Expand All @@ -175,11 +152,52 @@ public void onClick(View v) {
}
onYesListener = createOnYesListener(this);
if (onYesListener != null) {
Button yesButton = findView(dialog, R.id.dialog_confirm_list_button_yes);
yesButton.setOnClickListener(onYesListener);
Button yesButton = findView(dialog, R.id.dialog_confirm_list_button_yes);
yesButton.setOnClickListener(onYesListener);
}
}

private void initSelectAllCheckbox() {
selectAllCheckboxOnCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (buttonView.isChecked()) {
adapter.checkAll();
} else {
adapter.clearChecked();
}
updateSelectedCount();
}
};

CheckBox selectAllCheckbox = findView(dlg, R.id.dialog_confirm_list_select_all_checkbox);
selectAllCheckbox.setVisibility(selectionMode == SelectionMode.MULTIPLE_SELECTION ? View.VISIBLE : View.GONE);
if (selectionMode == SelectionMode.MULTIPLE_SELECTION) {
selectAllCheckbox.setVisibility(View.VISIBLE);
selectAllCheckbox.setOnCheckedChangeListener(selectAllCheckboxOnCheckedChangeListener);
}
}


private void initListViewAndAdapter(Bundle bundle) {
ListView listView = findView(dlg, R.id.dialog_confirm_list_list);
String listDataString = bundle.getString("listData");
List<T> listData = deserializeData(listDataString);
if (adapter != null) {
adapter.addList(listData);
} else {
adapter = new ConfirmListDialogDefaultAdapter<>(getActivity(),
listData,
selectionMode);

if (selectionMode == SelectionMode.MULTIPLE_SELECTION) {
updateSelectedCount();
}

adapter.setOnItemCheckedListener(this);
}
listView.setAdapter(adapter);
}

public void setOnYesListener(OnClickListener listener) {
onYesListener = listener;
}
Expand Down Expand Up @@ -250,6 +268,11 @@ public void updateSelectedCount() {
selectedCountTextView.setText(selected + " " + getString(R.string.selected));
selectedCountTextView.setVisibility(selected > 0 ? View.VISIBLE : View.GONE);
}

final CheckBox selectAllCheckbox = findView(dlg, R.id.dialog_confirm_list_select_all_checkbox);
selectAllCheckbox.setOnCheckedChangeListener(null);
selectAllCheckbox.setChecked(selected == adapter.getTotalCount());
selectAllCheckbox.setOnCheckedChangeListener(selectAllCheckboxOnCheckedChangeListener);
}

// AbstractListAdapter.OnItemCheckedListener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ public View getView(int position, View view, ViewGroup parent) {
}

try {

initTouchFeedback(view, item);
if(selectionMode == SelectionMode.MULTIPLE_SELECTION) {
initCheckBox(view, item);
Expand Down

0 comments on commit 89acc39

Please sign in to comment.