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.
This commit is contained in:
Peter Serwylo 2013-12-13 03:24:38 +11:00
parent 135ec1f0ff
commit 6bbb939e46
5 changed files with 65 additions and 37 deletions

View File

@ -75,7 +75,7 @@
<string name="download_server">Getting application from</string>
<string name="repo_add_url">Repository address</string>
<string name="repo_add_fingerprint">fingerprint (optional)</string>
<string name="repo_add_fingerprint">Fingerprint (optional)</string>
<string name="repo_exists">This repo already exists!</string>
<string name="repo_exists_add_fingerprint">This repo is already setup, this will add new key information.</string>
<string name="repo_exists_enable">This repo is already setup, confirm that you want to re-enable it.</string>

View File

@ -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() {

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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) {