Skip to content

Commit

Permalink
#284 Check for empty cursors before checking for foil-ability
Browse files Browse the repository at this point in the history
  • Loading branch information
AEFeinstein committed Oct 31, 2017
1 parent b77b200 commit 0c5c208
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,14 @@ public static MtgCard makeMtgCard(
Cursor cardCursor;
if (cardSet == null) {
cardCursor = CardDbAdapter.fetchCardByName(cardName, fields, true, database);

/* Make sure at least one card was found */
if (cardCursor.getCount() == 0) {
ToastWrapper.makeText(activity, activity.getString(R.string.toast_no_card),
ToastWrapper.LENGTH_LONG).show();
DatabaseManager.getInstance(activity, false).closeDatabase(false);
return null;
}
/* If we don't specify the set, and we are trying to find a foil card, choose the
* latest foil printing. If there are no eligible printings, select the latest */
if (isFoil) {
Expand All @@ -741,12 +749,7 @@ public static MtgCard makeMtgCard(
} else {
cardCursor = CardDbAdapter.fetchCardByNameAndSet(cardName, cardSet, fields, database);
}
if (cardCursor.getCount() == 0) {
ToastWrapper.makeText(activity, activity.getString(R.string.toast_no_card),
ToastWrapper.LENGTH_LONG).show();
DatabaseManager.getInstance(activity, false).closeDatabase(false);
return null;
}

/* Don't rely on the user's given name, get it from the DB just to be sure */
card.mName = cardCursor.getString(cardCursor.getColumnIndex(CardDbAdapter.KEY_NAME));
card.setCode = cardCursor.getString(cardCursor.getColumnIndex(CardDbAdapter.KEY_SET));
Expand Down

0 comments on commit 0c5c208

Please sign in to comment.