Permalink
Browse files

Closing some cursors that needed closing.

  • Loading branch information...
1 parent 155b357 commit 1d103193fe0b46e271f1d037d9f86fc4fde4a6ef @lucasrowe lucasrowe committed Mar 31, 2012
@@ -424,7 +424,8 @@ public int countPlayablePhrases(LinkedList<Pack> packs) {
" WHERE " + PhraseColumns.PACK_ID + " IN (" + args[0] + ")" +
" AND " + PhraseColumns.DIFFICULTY + " IN (" + args[1] + ")", null);
int count = countQuery.getCount();
-
+
+ countQuery.close();
return count;
}
@@ -452,6 +453,7 @@ public int countPlayablePhrases(Pack pack) {
" AND " + PhraseColumns.DIFFICULTY + " IN (" + args[1] + ")", null);
int count = countQuery.getCount();
+ countQuery.close();
return count;
}
@@ -491,6 +493,7 @@ public int countPacks() {
}
}
+ packQuery.close();
mDatabase.close();
return ret;
}
@@ -514,6 +517,7 @@ public Pack getPackFromDB(String packId) {
packQuery.getString(3), null, packQuery.getInt(4), packQuery.getInt(5), true);
}
packQuery.close();
+ mDatabase.close();
return pack;
}
@@ -564,6 +568,7 @@ public void digestPackFromServer(Pack pack) throws IOException, URISyntaxExcepti
}
CardJSONIterator cardItr = PackClient.getInstance().getCardsForPack(pack);
digestPackInternal(mDatabase, pack, cardItr);
+ mDatabase.close();
}
/**
@@ -600,14 +605,17 @@ private static void digestPackInternal(SQLiteDatabase db, Pack pack, CardJSONIte
*/
public static long upsertPhrase(Card phrase, int packId, SQLiteDatabase db) {
Log.d(TAG, "upsertPhrase(" + phrase + ")");
+ long ret;
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);
- if (res.getCount() == 1) {
- return updatePhrase(phrase, packId, db);
+ if (cursor.getCount() == 1) {
+ ret = updatePhrase(phrase, packId, db);
} else {
- return insertPhrase(phrase, packId, db);
+ ret = insertPhrase(phrase, packId, db);
}
+ cursor.close();
+ return ret;
}
/**
@@ -46,7 +46,7 @@
*/
private static final String URL_BASE = "http://siramix.com/phrasecraze/packs/";
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";
/**
@@ -83,17 +83,17 @@ public static PackClient getInstance() {
}
/**
- * 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
* @throws IOException if the request to the server fails
* @throws URISyntaxException if the uri is malformed
* @throws JSONException if the JSON is invalid
*/
- public LinkedList<Pack> getSocialPacks() throws IOException, URISyntaxException, JSONException {
- Log.d(TAG, "getSocialPacks");
+ public LinkedList<Pack> getFreePacks() throws IOException, URISyntaxException, JSONException {
+ Log.d(TAG, "getFreePacks");
StringBuilder in = null;
LinkedList<Pack> ret = null;
- in = doHTTPGet(URL_BASE+SOCIAL_LIST_URL);
+ in = doHTTPGet(URL_BASE+FREE_LIST_URL);
ret = PackParser.parsePacks(in);
return ret;
}
@@ -56,6 +56,7 @@
private SharedPreferences mPackPrefs;
+ // A map of request codes and their corresponding packs
private HashMap<Integer, Pack> mSocialPacks;
/**
@@ -260,19 +261,17 @@ private void refreshAllPackLayouts() {
paidPackLayout.removeAllViewsInLayout();
PackClient client = PackClient.getInstance();
- LinkedList<Pack> socialPacks;
- LinkedList<Pack> paidPacks;
- LinkedList<Pack> localPacks;
+ LinkedList<Pack> serverPacks = new LinkedList<Pack>();
+ LinkedList<Pack> localPacks = new LinkedList<Pack>();
localPacks = game.getInstalledPacks();
mSocialPacks = new HashMap<Integer, Pack>();
// First try to get the online packs, if no internet, just use local packs
try {
- socialPacks = client.getSocialPacks();
- paidPacks = client.getPayPacks();
- paidPacks.addAll(socialPacks);
+ serverPacks.addAll(client.getPayPacks());
+ serverPacks.addAll(client.getFreePacks());
populatePackLayout(localPacks, unlockedPackLayout);
- populatePackLayout(paidPacks, paidPackLayout);
+ populatePackLayout(serverPacks, paidPackLayout);
} catch (IOException e1) {
populatePackLayout(localPacks, unlockedPackLayout);
showToast(getString(R.string.toast_packpurchase_nointerneterror));
@@ -298,6 +297,7 @@ private void refreshAllPackLayouts() {
Button btn = (Button) this.findViewById(R.id.PackPurchase_Button_Next);
btn.setOnClickListener(mGameSetupListener);
}
+
/**
* Create dynamic rows of packs at runtime for pack purchase view. This will

0 comments on commit 1d10319

Please sign in to comment.