Skip to content

Commit

Permalink
[android] Work in progress. Confirm dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
votaguz authored and gubatron committed Mar 23, 2016
1 parent 0409298 commit 954c9ce
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ protected void initComponents(Dialog dlg, Bundle savedInstanceState) {
textView.setText(dialogText);


if (selectionMode == SelectionMode.MULTIPLE_SELECTION){
if (selectionMode == SelectionMode.MULTIPLE_SELECTION) {
CheckBox checkBox = findView(dlg, R.id.dialog_confirm_list_select_all_checkbox);
checkBox.setVisibility(View.VISIBLE);
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(buttonView.isChecked()){
if (buttonView.isChecked()) {
adapter.checkAll();
} else {
adapter.clearChecked();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public void onClick(View v) {
if (Ref.alive(ctxRef) && Ref.alive(dlgRef)) {
AbstractConfirmListDialog dlg = dlgRef.get();
List<SoundcloudSearchResult> results = dlg.getList();

if (dlg.getSelectionMode() == AbstractConfirmListDialog.SelectionMode.MULTIPLE_SELECTION) {
results = new ArrayList<>(dlg.getChecked());
// TODO: If results is empty, then we should probably trigger an error message in the dialog
Expand All @@ -152,7 +153,10 @@ public void onClick(View v) {
} else if (dlg.getSelectionMode() == AbstractConfirmListDialog.SelectionMode.SINGLE_SELECTION) {
// TODO: If results is empty, then we should probably trigger an error message in the dialog
// if (results == null || results.isEmpty()) { dlg.displayErrorNotice(ERROR_CODE); return; }
} else {
//We already know have NO_SELECTION mode. Then
}

startDownloads(ctxRef.get(), results);
dlg.dismiss();
}
Expand All @@ -173,7 +177,7 @@ public static ConfirmSoundcloudDownloadDialog newInstance(String dialogTitle,
String dialogText,
List<SoundcloudSearchResult> listData) {

ConfirmSoundcloudDownloadDialog dlg = new ConfirmSoundcloudDownloadDialog(SelectionMode.MULTIPLE_SELECTION);
ConfirmSoundcloudDownloadDialog dlg = new ConfirmSoundcloudDownloadDialog(SelectionMode.SINGLE_SELECTION); //TODO: Set this back to MULTIPLE SELECTION
SoundcloudSearchResultList srList = new SoundcloudSearchResultList();
srList.listData = listData;
dlg.prepareArguments(dialogTitle, dialogText, JsonUtils.toJson(srList));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public abstract class AbstractListAdapter<T> extends BaseAdapter implements Filt
protected List<T> visualList;

protected int lastSelectedRadioButtonIndex = 0;
private final OnCheckedChangeListener radioButtonCheckedChangeListener;

public AbstractListAdapter(Context context, int viewItemId, List<T> list, Set<T> checked) {
this.context = context;
Expand All @@ -92,6 +93,8 @@ public AbstractListAdapter(Context context, int viewItemId, List<T> list, Set<T>
this.list = list.equals(Collections.emptyList()) ? new ArrayList<T>() : list;
this.checked = checked;
this.visualList = list;

this.radioButtonCheckedChangeListener = new RadioButtonOnCheckedChangeListener(this);
}

public AbstractListAdapter(Context context, int viewItemId, List<T> list) {
Expand Down Expand Up @@ -557,31 +560,28 @@ protected void publishResults(CharSequence constraint, FilterResults results) {

}

private final class RadioButtonOnCheckedChangeListener implements OnClickListener {
private final class RadioButtonOnCheckedChangeListener implements OnCheckedChangeListener {

private final AbstractListAdapter adapter;
private WeakReference<RadioButton> lastRadioButtonChecked = null;

public RadioButtonOnCheckedChangeListener(AbstractListAdapter adapter) {
this.adapter = adapter;
System.out.println("Adding checked listener");
}

@Override
public void onClick(View v) {
System.out.println("On Click Event");
if (v instanceof RadioButton) {
RadioButton radioButton = (RadioButton) v;
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (buttonView instanceof RadioButton && isChecked){
RadioButton radioButton = (RadioButton) buttonView;
RadioButtonTag tag = (RadioButtonTag) radioButton.getTag();

if (Ref.alive(lastRadioButtonChecked)) {
if(Ref.alive(lastRadioButtonChecked)){
lastRadioButtonChecked.get().setChecked(false);
Ref.free(lastRadioButtonChecked);
}

lastSelectedRadioButtonIndex = tag.position;
radioButton.setChecked(true);

Ref.free(lastRadioButtonChecked);
lastRadioButtonChecked = new WeakReference<RadioButton>(radioButton);
}
}
Expand All @@ -598,19 +598,12 @@ public RadioButtonTag(T item, int position) {
}

protected void initRadioButton(View view, RadioButtonTag tag) {
RadioButton radioButton = (RadioButton) findView(view, R.id.view_selectable_list_item_radiobutton);

RadioButton radioButton = findView(view, R.id.view_selectable_list_item_radiobutton);
if (radioButton != null) {
radioButton.setVisibility(View.VISIBLE);
radioButton.setChecked(false);
radioButton.setTag(tag);

if (!radioButton.hasOnClickListeners()) {
radioButton.setOnClickListener(new RadioButtonOnCheckedChangeListener(this));
}

radioButton.setOnCheckedChangeListener(radioButtonCheckedChangeListener);
radioButton.setChecked(tag.position == lastSelectedRadioButtonIndex);
}
}

}

0 comments on commit 954c9ce

Please sign in to comment.