Skip to content

Commit

Permalink
Closing some cursors that needed closing.
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasrowe committed Mar 31, 2012
1 parent 155b357 commit 1d10319
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
18 changes: 13 additions & 5 deletions src/com/siramix/phrasecraze/Deck.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -424,7 +424,8 @@ public int countPlayablePhrases(LinkedList<Pack> packs) {
" WHERE " + PhraseColumns.PACK_ID + " IN (" + args[0] + ")" + " WHERE " + PhraseColumns.PACK_ID + " IN (" + args[0] + ")" +
" AND " + PhraseColumns.DIFFICULTY + " IN (" + args[1] + ")", null); " AND " + PhraseColumns.DIFFICULTY + " IN (" + args[1] + ")", null);
int count = countQuery.getCount(); int count = countQuery.getCount();


countQuery.close();
return count; return count;
} }


Expand Down Expand Up @@ -452,6 +453,7 @@ public int countPlayablePhrases(Pack pack) {
" AND " + PhraseColumns.DIFFICULTY + " IN (" + args[1] + ")", null); " AND " + PhraseColumns.DIFFICULTY + " IN (" + args[1] + ")", null);
int count = countQuery.getCount(); int count = countQuery.getCount();


countQuery.close();
return count; return count;
} }


Expand Down Expand Up @@ -491,6 +493,7 @@ public LinkedList<Pack> getAllPacksFromDB() {
} }
} }


packQuery.close();
mDatabase.close(); mDatabase.close();
return ret; return ret;
} }
Expand All @@ -514,6 +517,7 @@ public Pack getPackFromDB(String packId) {
packQuery.getString(3), null, packQuery.getInt(4), packQuery.getInt(5), true); packQuery.getString(3), null, packQuery.getInt(4), packQuery.getInt(5), true);
} }
packQuery.close(); packQuery.close();
mDatabase.close();
return pack; return pack;
} }


Expand Down Expand Up @@ -564,6 +568,7 @@ public void digestPackFromServer(Pack pack) throws IOException, URISyntaxExcepti
} }
CardJSONIterator cardItr = PackClient.getInstance().getCardsForPack(pack); CardJSONIterator cardItr = PackClient.getInstance().getCardsForPack(pack);
digestPackInternal(mDatabase, pack, cardItr); digestPackInternal(mDatabase, pack, cardItr);
mDatabase.close();
} }


/** /**
Expand Down Expand Up @@ -600,14 +605,17 @@ private static void digestPackInternal(SQLiteDatabase db, Pack pack, CardJSONIte
*/ */
public static long upsertPhrase(Card phrase, int packId, SQLiteDatabase db) { public static long upsertPhrase(Card phrase, int packId, SQLiteDatabase db) {
Log.d(TAG, "upsertPhrase(" + phrase + ")"); Log.d(TAG, "upsertPhrase(" + phrase + ")");
long ret;
String[] whereArgs = new String[] { String.valueOf(phrase.getId()) }; String[] whereArgs = new String[] { String.valueOf(phrase.getId()) };
Cursor res = db.query(PhraseColumns.TABLE_NAME, PhraseColumns.COLUMNS, Cursor cursor = db.query(PhraseColumns.TABLE_NAME, PhraseColumns.COLUMNS,
PhraseColumns._ID + "= ?", whereArgs, null, null, null); PhraseColumns._ID + "= ?", whereArgs, null, null, null);
if (res.getCount() == 1) { if (cursor.getCount() == 1) {
return updatePhrase(phrase, packId, db); ret = updatePhrase(phrase, packId, db);
} else { } else {
return insertPhrase(phrase, packId, db); ret = insertPhrase(phrase, packId, db);
} }
cursor.close();
return ret;
} }


/** /**
Expand Down
10 changes: 5 additions & 5 deletions src/com/siramix/phrasecraze/PackClient.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class PackClient {
*/ */
private static final String URL_BASE = "http://siramix.com/phrasecraze/packs/"; private static final String URL_BASE = "http://siramix.com/phrasecraze/packs/";
private static final String PAY_LIST_URL = "premiumpacks.json"; private static final String PAY_LIST_URL = "premiumpacks.json";
private static final String SOCIAL_LIST_URL = "freepacks.json"; private static final String FREE_LIST_URL = "freepacks.json";
private static final String TAG = "PackClient"; private static final String TAG = "PackClient";


/** /**
Expand Down Expand Up @@ -83,17 +83,17 @@ public LinkedList<Pack> getPayPacks() throws IOException, URISyntaxException, JS
} }


/** /**
* Get all of the packs available on the server for social promotion * Get all of the packs available on the server that don't go through the market (free)
* @return a LinkedList of Packs representing the pack that is available * @return a LinkedList of Packs representing the pack that is available
* @throws IOException if the request to the server fails * @throws IOException if the request to the server fails
* @throws URISyntaxException if the uri is malformed * @throws URISyntaxException if the uri is malformed
* @throws JSONException if the JSON is invalid * @throws JSONException if the JSON is invalid
*/ */
public LinkedList<Pack> getSocialPacks() throws IOException, URISyntaxException, JSONException { public LinkedList<Pack> getFreePacks() throws IOException, URISyntaxException, JSONException {
Log.d(TAG, "getSocialPacks"); Log.d(TAG, "getFreePacks");
StringBuilder in = null; StringBuilder in = null;
LinkedList<Pack> ret = null; LinkedList<Pack> ret = null;
in = doHTTPGet(URL_BASE+SOCIAL_LIST_URL); in = doHTTPGet(URL_BASE+FREE_LIST_URL);
ret = PackParser.parsePacks(in); ret = PackParser.parsePacks(in);
return ret; return ret;
} }
Expand Down
14 changes: 7 additions & 7 deletions src/com/siramix/phrasecraze/PhrasePackPurchase.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class PhrasePackPurchase extends Activity {


private SharedPreferences mPackPrefs; private SharedPreferences mPackPrefs;


// A map of request codes and their corresponding packs
private HashMap<Integer, Pack> mSocialPacks; private HashMap<Integer, Pack> mSocialPacks;


/** /**
Expand Down Expand Up @@ -260,19 +261,17 @@ private void refreshAllPackLayouts() {
paidPackLayout.removeAllViewsInLayout(); paidPackLayout.removeAllViewsInLayout();


PackClient client = PackClient.getInstance(); PackClient client = PackClient.getInstance();
LinkedList<Pack> socialPacks; LinkedList<Pack> serverPacks = new LinkedList<Pack>();
LinkedList<Pack> paidPacks; LinkedList<Pack> localPacks = new LinkedList<Pack>();
LinkedList<Pack> localPacks;
localPacks = game.getInstalledPacks(); localPacks = game.getInstalledPacks();
mSocialPacks = new HashMap<Integer, Pack>(); mSocialPacks = new HashMap<Integer, Pack>();


// First try to get the online packs, if no internet, just use local packs // First try to get the online packs, if no internet, just use local packs
try { try {
socialPacks = client.getSocialPacks(); serverPacks.addAll(client.getPayPacks());
paidPacks = client.getPayPacks(); serverPacks.addAll(client.getFreePacks());
paidPacks.addAll(socialPacks);
populatePackLayout(localPacks, unlockedPackLayout); populatePackLayout(localPacks, unlockedPackLayout);
populatePackLayout(paidPacks, paidPackLayout); populatePackLayout(serverPacks, paidPackLayout);
} catch (IOException e1) { } catch (IOException e1) {
populatePackLayout(localPacks, unlockedPackLayout); populatePackLayout(localPacks, unlockedPackLayout);
showToast(getString(R.string.toast_packpurchase_nointerneterror)); showToast(getString(R.string.toast_packpurchase_nointerneterror));
Expand All @@ -298,6 +297,7 @@ private void refreshAllPackLayouts() {
Button btn = (Button) this.findViewById(R.id.PackPurchase_Button_Next); Button btn = (Button) this.findViewById(R.id.PackPurchase_Button_Next);
btn.setOnClickListener(mGameSetupListener); btn.setOnClickListener(mGameSetupListener);
} }



/** /**
* Create dynamic rows of packs at runtime for pack purchase view. This will * Create dynamic rows of packs at runtime for pack purchase view. This will
Expand Down

0 comments on commit 1d10319

Please sign in to comment.