From e44f8b67a77172c5d3a77674c308ee6e05ea452b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Mon, 22 Jul 2013 14:59:22 +0200 Subject: [PATCH] Disabling repos now clears their apks as well The current method is quite ugly, mainly because enabling and disabling repos uses SQL and the list item click function does not tell us whether a repo is being enabled or disabled. For now it works, but there's room for improvement. --- src/org/fdroid/fdroid/DB.java | 7 ++-- src/org/fdroid/fdroid/ManageRepo.java | 51 ++++++++++++++++++++++++--- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/src/org/fdroid/fdroid/DB.java b/src/org/fdroid/fdroid/DB.java index 7e26c25ec..97eacce97 100644 --- a/src/org/fdroid/fdroid/DB.java +++ b/src/org/fdroid/fdroid/DB.java @@ -1326,7 +1326,8 @@ public class DB { db.insert(TABLE_REPO, null, values); } - public void removeRepos(List addresses) { + public void doDisableRepos(List addresses, boolean remove) { + if (addresses.isEmpty()) return; db.beginTransaction(); try { for (String address : addresses) { @@ -1348,7 +1349,9 @@ public class DB { c.close(); } } - db.delete(TABLE_REPO, "address = ?", new String[] { address }); + if (remove) + db.delete(TABLE_REPO, "address = ?", + new String[] { address }); } List apps = getAppsBasic(true); for (App app : apps) { diff --git a/src/org/fdroid/fdroid/ManageRepo.java b/src/org/fdroid/fdroid/ManageRepo.java index 1274bd58c..f8cd95e17 100644 --- a/src/org/fdroid/fdroid/ManageRepo.java +++ b/src/org/fdroid/fdroid/ManageRepo.java @@ -56,6 +56,24 @@ public class ManageRepo extends ListActivity { private List repos; + private static List reposToDisable; + private static List reposToRemove; + + public void disableRepo(String address) { + if (reposToDisable.contains(address)) return; + reposToDisable.add(address); + } + + public void removeRepo(String address) { + if (reposToRemove.contains(address)) return; + reposToRemove.add(address); + } + + public void removeRepos(List addresses) { + for (String address : addresses) + removeRepo(address); + } + @Override protected void onCreate(Bundle savedInstanceState) { @@ -68,7 +86,7 @@ public class ManageRepo extends ListActivity { TextView tv_lastCheck = (TextView)findViewById(R.id.lastUpdateCheck); long lastUpdate = prefs.getLong("lastUpdateCheck", 0); String s_lastUpdateCheck = ""; - if(lastUpdate == 0) { + if (lastUpdate == 0) { s_lastUpdateCheck = getString(R.string.never); } else { Date d = new Date(lastUpdate); @@ -76,6 +94,9 @@ public class ManageRepo extends ListActivity { " " + DateFormat.getTimeFormat(this).format(d); } tv_lastCheck.setText(getString(R.string.last_update_check,s_lastUpdateCheck)); + + reposToRemove = new ArrayList(); + reposToDisable = new ArrayList(); } @Override @@ -138,7 +159,10 @@ public class ManageRepo extends ListActivity { super.onListItemClick(l, v, position, id); try { DB db = DB.getDB(); - db.changeServerStatus(repos.get(position).address); + String address = repos.get(position).address; + db.changeServerStatus(address); + // TODO: Disabling and re-enabling a repo will delete its apks too. + disableRepo(address); } finally { DB.releaseDB(); } @@ -228,8 +252,7 @@ public class ManageRepo extends ListActivity { int whichButton) { try { DB db = DB.getDB(); - db.removeRepos(rem_lst); - ((FDroidApp) getApplication()).invalidateAllApps(); + removeRepos(rem_lst); } finally { DB.releaseDB(); } @@ -253,6 +276,26 @@ public class ManageRepo extends ListActivity { @Override public void finish() { + if (!reposToRemove.isEmpty()) { + try { + DB db = DB.getDB(); + db.doDisableRepos(reposToRemove, true); + } finally { + DB.releaseDB(); + } + ((FDroidApp) getApplication()).invalidateAllApps(); + } + + if (!reposToDisable.isEmpty()) { + try { + DB db = DB.getDB(); + db.doDisableRepos(reposToDisable, false); + } finally { + DB.releaseDB(); + } + ((FDroidApp) getApplication()).invalidateAllApps(); + } + Intent ret = new Intent(); if (changed) ret.putExtra("update", true);