Skip to content

Commit

Permalink
Making more fail safe getting the last selected item from results lists
Browse files Browse the repository at this point in the history
  • Loading branch information
votaguz authored and gubatron committed Mar 23, 2016
1 parent 9965eda commit 167eb5b
Showing 1 changed file with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ protected List<SoundcloudSearchResult> doInBackground() {
return results;
}



private static class OnStartDownloadsClickListener implements View.OnClickListener {
private final WeakReference<Context> ctxRef;
private WeakReference<AbstractConfirmListDialog> dlgRef;
Expand All @@ -143,21 +141,19 @@ public void setDialog(AbstractConfirmListDialog dlg) {
public void onClick(View v) {
if (Ref.alive(ctxRef) && Ref.alive(dlgRef)) {
AbstractConfirmListDialog dlg = dlgRef.get();
List<SoundcloudSearchResult> results = dlg.getList();
List<SoundcloudSearchResult> results = dlg.getList(); // for no selection case.

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
// if (results == null || results.isEmpty()) { dlg.displayErrorNotice(ERROR_CODE); return; }

} else if (dlg.getSelectionMode() == AbstractConfirmListDialog.SelectionMode.SINGLE_SELECTION) {
SoundcloudSearchResult selected = results.get(dlg.getLastSelected());
if (selected == null) {
// MIGHT DO: dlg.displayErrorNotice(ERROR_CODE);
return;
}
results = new ArrayList<>();
results.add(selected);
// 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; }
}

startDownloads(ctxRef.get(), results);
dlg.dismiss();
}
Expand Down

0 comments on commit 167eb5b

Please sign in to comment.