Merge branch 'html-with-saved-newlines' into 'master'

implement HTML with preserved newlines for app descriptions

Closes #1114

See merge request fdroid/fdroidclient!618
This commit is contained in:
Hans-Christoph Steiner 2017-12-01 19:59:40 +00:00
commit 1ef92f55cd
2 changed files with 19 additions and 2 deletions

View File

@ -203,7 +203,7 @@ public class RepoXMLHandler extends DefaultHandler {
break;
case "desc":
// New-style description.
curapp.description = str;
curapp.description = App.formatDescription(str);
break;
case "summary":
curapp.summary = str;

View File

@ -382,6 +382,16 @@ public class App extends ValueObject implements Comparable<App>, Parcelable {
initApkFromApkFile(context, this.installedApk, packageInfo, apkFile);
}
/**
* In order to format all in coming descriptions before they are written
* out to the database and used elsewhere, this is needed to intercept
* the setting of {@link App#description} to insert the format method.
*/
@JsonProperty("description")
private void setDescription(String description) { // NOPMD
this.description = formatDescription(description);
}
/**
* Parses the {@code localized} block in the incoming index metadata,
* choosing the best match in terms of locale/language while filling as
@ -499,7 +509,7 @@ public class App extends ValueObject implements Comparable<App>, Parcelable {
}
value = getLocalizedEntry(localized, localesToUse, "description");
if (!TextUtils.isEmpty(value)) {
description = value;
description = formatDescription(value);
}
featureGraphic = getLocalizedGraphicsEntry(localized, localesToUse, "featureGraphic");
@ -583,6 +593,13 @@ public class App extends ValueObject implements Comparable<App>, Parcelable {
return new String[0];
}
/**
* Returns the app description text with all newlines replaced by {@code <br>}
*/
public static String formatDescription(String description) {
return description.replace("\n", "<br>");
}
public String getFeatureGraphicUrl(Context context) {
if (TextUtils.isEmpty(featureGraphic)) {
return null;