From 6bbb939e467094bcd150245ffb8b09e652749ce9 Mon Sep 17 00:00:00 2001 From: Peter Serwylo Date: Fri, 13 Dec 2013 03:24:38 +1100 Subject: [PATCH] Refresh UI more appropriately. When the repository is updated, it will check if the "name" or "description" have been modified (or learnt for the first time) and if so, update the DB and UI. --- res/values/strings.xml | 2 +- src/org/fdroid/fdroid/ManageRepo.java | 9 +- src/org/fdroid/fdroid/RepoXMLHandler.java | 84 ++++++++++++------- src/org/fdroid/fdroid/views/RepoAdapter.java | 2 - .../views/fragments/RepoDetailsFragment.java | 5 +- 5 files changed, 65 insertions(+), 37 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index daabe25af..5ea16fd1b 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -75,7 +75,7 @@ Getting application from Repository address - fingerprint (optional) + Fingerprint (optional) This repo already exists! This repo is already setup, this will add new key information. This repo is already setup, confirm that you want to re-enable it. diff --git a/src/org/fdroid/fdroid/ManageRepo.java b/src/org/fdroid/fdroid/ManageRepo.java index 7b6c593a7..63412360a 100644 --- a/src/org/fdroid/fdroid/ManageRepo.java +++ b/src/org/fdroid/fdroid/ManageRepo.java @@ -261,7 +261,14 @@ public class ManageRepo extends ListActivity { } private void updateRepos() { - UpdateService.updateNow(this); + UpdateService.updateNow(this).setListener(new ProgressListener() { + @Override + public void onProgress(Event event) { + // No need to prompt to update any more, we just did it! + changed = false; + refreshList(); + } + }); } private void showAddRepo() { diff --git a/src/org/fdroid/fdroid/RepoXMLHandler.java b/src/org/fdroid/fdroid/RepoXMLHandler.java index 29648f7c9..1cb4b1b33 100644 --- a/src/org/fdroid/fdroid/RepoXMLHandler.java +++ b/src/org/fdroid/fdroid/RepoXMLHandler.java @@ -61,9 +61,9 @@ public class RepoXMLHandler extends DefaultHandler { private DB.Apk curapk = null; private StringBuilder curchars = new StringBuilder(); - // After processing the XML, this will be null if the index didn't specify + // After processing the XML, this will be -1 if the index didn't specify // a maximum age - otherwise it will be the value specified. - private String maxage; + private int maxage = -1; // After processing the XML, this will be null if the index specified a // public key - otherwise a public key. This is used for TOFU where an @@ -247,6 +247,8 @@ public class RepoXMLHandler extends DefaultHandler { } else if (curel.equals("requirements")) { curapp.requirements = DB.CommaSeparatedList.make(str); } + } else if (curel.equals("description")) { + description = str; } } @@ -264,7 +266,13 @@ public class RepoXMLHandler extends DefaultHandler { String pk = attributes.getValue("", "pubkey"); if (pk != null) pubkey = pk; - maxage = attributes.getValue("", "maxage"); + String maxAgeAttr = attributes.getValue("", "maxage"); + if (maxAgeAttr != null) { + try { + maxage = Integer.parseInt(maxAgeAttr); + } catch (NumberFormatException nfe) {} + } + String nm = attributes.getValue("", "name"); if (nm != null) name = nm; @@ -453,35 +461,7 @@ public class RepoXMLHandler extends DefaultHandler { InputSource is = new InputSource(r); xr.parse(is); - - if (handler.pubkey != null && repo.pubkey == null) { - // We read an unsigned index, but that indicates that - // a signed version is now available... - Log.d("FDroid", - "Public key found - switching to signed repo for future updates"); - repo.pubkey = handler.pubkey; - try { - DB db = DB.getDB(); - db.updateRepoByAddress(repo); - } finally { - DB.releaseDB(); - } - } - - if (handler.maxage != null) { - int maxage = Integer.parseInt(handler.maxage); - if (maxage != repo.maxage) { - Log.d("FDroid", - "Repo specified a new maximum age - updated"); - repo.maxage = maxage; - try { - DB db = DB.getDB(); - db.updateRepoByAddress(repo); - } finally { - DB.releaseDB(); - } - } - } + handler.updateRepoDetails(repo); } else if (code == 304) { // The index is unchanged since we last read it. We just mark @@ -514,6 +494,46 @@ public class RepoXMLHandler extends DefaultHandler { return null; } + public void updateRepoDetails(DB.Repo repo) { + + boolean repoChanged = false; + + if (pubkey != null && repo.pubkey == null) { + // We read an unsigned index, but that indicates that + // a signed version is now available... + Log.d("FDroid", + "Public key found - switching to signed repo for future updates"); + repo.pubkey = pubkey; + repoChanged = true; + } + + if (maxage != -1 && maxage != repo.maxage) { + Log.d("FDroid", + "Repo specified a new maximum age - updated"); + repo.maxage = maxage; + repoChanged = true; + } + + if (description != null && !description.equals(repo.description)) { + repo.description = description; + repoChanged = true; + } + + if (name != null && !name.equals(repo.name)) { + repo.name = name; + repoChanged = true; + } + + if (repoChanged) { + try { + DB db = DB.getDB(); + db.updateRepoByAddress(repo); + } finally { + DB.releaseDB(); + } + } + } + public void setTotalAppCount(int totalAppCount) { this.totalAppCount = totalAppCount; } diff --git a/src/org/fdroid/fdroid/views/RepoAdapter.java b/src/org/fdroid/fdroid/views/RepoAdapter.java index 891fce3cd..71c9f73dd 100644 --- a/src/org/fdroid/fdroid/views/RepoAdapter.java +++ b/src/org/fdroid/fdroid/views/RepoAdapter.java @@ -83,10 +83,8 @@ public class RepoAdapter extends BaseAdapter { // height of each list item varies. View signedView = view.findViewById(R.id.repo_unsigned); if (repository.isSigned()) { - nameViewLayout.addRule(RelativeLayout.CENTER_VERTICAL); signedView.setVisibility(View.INVISIBLE); } else { - nameViewLayout.addRule(RelativeLayout.ALIGN_PARENT_TOP); signedView.setVisibility(View.VISIBLE); } diff --git a/src/org/fdroid/fdroid/views/fragments/RepoDetailsFragment.java b/src/org/fdroid/fdroid/views/fragments/RepoDetailsFragment.java index 704a8c9d9..84c3d347b 100644 --- a/src/org/fdroid/fdroid/views/fragments/RepoDetailsFragment.java +++ b/src/org/fdroid/fdroid/views/fragments/RepoDetailsFragment.java @@ -199,7 +199,9 @@ public class RepoDetailsFragment extends Fragment { description.setVisibility(View.VISIBLE); } - description.setText(repo.description); + String descriptionText = repo.description == null + ? "" : repo.description.replaceAll("\n", " "); + description.setText(descriptionText); } @@ -208,6 +210,7 @@ public class RepoDetailsFragment extends Fragment { * list can be updated. We will perform the update ourselves though. */ private void performUpdate() { + repo.enable((FDroidApp)getActivity().getApplication()); UpdateService.updateNow(getActivity()).setListener(new ProgressListener() { @Override public void onProgress(Event event) {