/** * Read in the wishlist from the file, and pack it into an ArrayList of CompressedWishlistInfo for * display in the ListView. This data structure stores one copy of the card itself, and a list of * set-specific attributes like set name, rarity, and price. * * @param changedCardName If the wishlist was changed by a dialog, this is the card which we * should look at for changes */ private void readAndCompressWishlist(String changedCardName) { /* Read the wishlist */ ArrayList<MtgCard> wishlist = WishlistHelpers.ReadWishlist(getActivity()); SQLiteDatabase database = DatabaseManager.getInstance(getActivity(), false).openDatabase(false); try { /* Translate the set code to tcg name, of course it's not saved */ for (MtgCard card : wishlist) { card.setName = CardDbAdapter.getSetNameFromCode(card.setCode, database); } /* Clear the wishlist, or just the card that changed */ if (changedCardName == null) { mCompressedWishlist.clear(); } else { for (CompressedWishlistInfo cwi : mCompressedWishlist) { if (cwi.mCard.name.equals(changedCardName)) { cwi.clearCompressedInfo(); } } } /* Compress the whole wishlist, or just the card that changed */ for (MtgCard card : wishlist) { if (changedCardName == null || changedCardName.equals(card.name)) { /* This works because both MtgCard's and CompressedWishlistInfo's .equals() can compare each * other */ if (!mCompressedWishlist.contains(card)) { mCompressedWishlist.add(new CompressedWishlistInfo(card)); } else { mCompressedWishlist.get(mCompressedWishlist.indexOf(card)).add(card); } /* Look up the new price */ if (mShowIndividualPrices || mShowTotalWishlistPrice) { loadPrice(card.name, card.setCode, card.number); } } } /* Check for wholly removed cards if one card was modified */ if (changedCardName != null) { for (int i = 0; i < mCompressedWishlist.size(); i++) { if (mCompressedWishlist.get(i).mInfo.size() == 0) { mCompressedWishlist.remove(i); i--; } } } /* Fill extra card data from the database, for displaying full card info */ CardDbAdapter.fillExtraWishlistData(mCompressedWishlist, database); } catch (FamiliarDbException e) { handleFamiliarDbException(false); } DatabaseManager.getInstance(getActivity(), false).closeDatabase(false); }