Don't re-read database when switching categories

This commit is contained in:
Ciaran Gultnieks 2012-09-12 17:19:52 +01:00
parent a2de56e2a5
commit 2ecfb9d5a0

View File

@ -97,6 +97,9 @@ public class FDroid extends TabActivity implements OnItemClickListener,
private boolean triedEmptyUpdate; private boolean triedEmptyUpdate;
// List of apps.
private Vector<DB.App> apps = null;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -141,7 +144,7 @@ public class FDroid extends TabActivity implements OnItemClickListener,
@Override @Override
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();
populateLists(true); populateLists(true, true);
} }
@Override @Override
@ -321,7 +324,9 @@ public class FDroid extends TabActivity implements OnItemClickListener,
// Populate the lists. // Populate the lists.
// 'update' - true to update the installed status of the applications // 'update' - true to update the installed status of the applications
// by asking the system. // by asking the system.
private void populateLists(boolean update) { // 'refreshdb' - true to refresh the list from the database rather
// than using the last one we got.
private void populateLists(boolean update, boolean refreshdb) {
apps_in.clear(); apps_in.clear();
apps_av.clear(); apps_av.clear();
@ -331,15 +336,13 @@ public class FDroid extends TabActivity implements OnItemClickListener,
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
DB db; DB db;
Vector<DB.App> apps;
String cat_all, cat_whatsnew, cat_recentlyupdated; String cat_all, cat_whatsnew, cat_recentlyupdated;
try { try {
db = DB.getDB(); db = DB.getDB();
// Populate the category list with the real categories, and the // Populate the category list with the real categories, and the
// locally // locally generated meta-categories for "All", "What's New" and
// generated meta-categories for "All", "What's New" and "Recently // "Recently Updated"...
// Updated"...
cat_all = getString(R.string.category_all); cat_all = getString(R.string.category_all);
cat_whatsnew = getString(R.string.category_whatsnew); cat_whatsnew = getString(R.string.category_whatsnew);
cat_recentlyupdated = getString(R.string.category_recentlyupdated); cat_recentlyupdated = getString(R.string.category_recentlyupdated);
@ -353,7 +356,9 @@ public class FDroid extends TabActivity implements OnItemClickListener,
if (currentCategory == null) if (currentCategory == null)
currentCategory = cat_all; currentCategory = cat_all;
apps = db.getApps(null, null, update, true); if(apps == null || refreshdb || update)
apps = db.getApps(null, null, update, true);
} finally { } finally {
DB.releaseDB(); DB.releaseDB();
} }
@ -370,9 +375,6 @@ public class FDroid extends TabActivity implements OnItemClickListener,
triedEmptyUpdate = true; triedEmptyUpdate = true;
return; return;
} }
Log.d("FDroid", "Updating lists - " + apps.size() + " apps in total"
+ " (update took " + (System.currentTimeMillis() - startTime)
+ " ms)");
// Calculate the cutoff date we'll use for What's New and Recently // Calculate the cutoff date we'll use for What's New and Recently
// Updated... // Updated...
@ -424,6 +426,9 @@ public class FDroid extends TabActivity implements OnItemClickListener,
apps_up.notifyDataSetChanged(); apps_up.notifyDataSetChanged();
categories.notifyDataSetChanged(); categories.notifyDataSetChanged();
Log.d("FDroid", "Updated lists - " + apps.size() + " apps in total"
+ " (update took " + (System.currentTimeMillis() - startTime)
+ " ms)");
} }
// For receiving results from the UpdateService when we've told it to // For receiving results from the UpdateService when we've told it to
@ -439,7 +444,7 @@ public class FDroid extends TabActivity implements OnItemClickListener,
Toast.makeText(FDroid.this, resultData.getString("errmsg"), Toast.makeText(FDroid.this, resultData.getString("errmsg"),
Toast.LENGTH_LONG).show(); Toast.LENGTH_LONG).show();
} else { } else {
populateLists(true); populateLists(true, true);
} }
if (pd.isShowing()) if (pd.isShowing())
pd.dismiss(); pd.dismiss();
@ -465,7 +470,7 @@ public class FDroid extends TabActivity implements OnItemClickListener,
public void onItemSelected(AdapterView<?> parent, View view, int pos, public void onItemSelected(AdapterView<?> parent, View view, int pos,
long id) { long id) {
currentCategory = parent.getItemAtPosition(pos).toString(); currentCategory = parent.getItemAtPosition(pos).toString();
populateLists(false); populateLists(false, false);
} }
public void onNothingSelected(AdapterView<?> parent) { public void onNothingSelected(AdapterView<?> parent) {