Updated PR according to comments

Removed unnecessary checks in while loop, and converted it to a
do...while loop.
Moved favorites export under HTML section.
Corrected indentation in resources files.
Moved to using a unified template for all HTML exports.
Removed unnecessary strings, corrected capitalization.
This commit is contained in:
malockin 2020-05-03 22:56:31 +03:00
parent 10e8f7c614
commit 1cdfd80ca1
6 changed files with 17 additions and 109 deletions

View File

@ -27,17 +27,14 @@
android:summary="@string/opml_import_summary"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/favorites">
<Preference
android:key="prefFavoritesExport"
android:title="@string/favorites_export_label"
android:summary="@string/favorites_export_summary"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/html">
<Preference
android:key="prefHtmlExport"
android:title="@string/html_export_label"
android:summary="@string/html_export_summary"/>
<Preference
android:key="prefFavoritesExport"
android:title="@string/favorites_export_label"
android:summary="@string/favorites_export_summary"/>
</PreferenceCategory>
</PreferenceScreen>

View File

@ -1,82 +0,0 @@
<?xml version='1.0' encoding='UTF-8' standalone='no' ?>
<html>
<head>
<title>AntennaPod Favorites</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
* {
font-family: 'Lato', sans-serif;
font-weight: 300;
margin: 0;
padding: 0;
box-sizing: border-box;
}
html {
background: #3498db;
text-align: center;
padding: 10px;
}
h1 {
color: #fff;
font-weight: 300;
display: inline-block;
margin-top: 40px;
margin-bottom: 20px;
vertical-align: top;
}
li {
width: 100%;
max-width: 500px;
display: block;
display: inline-flex;
padding: 10px;
}
li > div {
background: #fefefe;
padding: 10px;
display: inline-block;
width: 100%;
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
text-align: left;
}
li span {
margin-top: 10px;
display: block;
}
a {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
span a {
color: #3498db;
}
img {
width: 100px;
height: 100px;
margin-right: 10px;
}
li > div > img {
float: left;
}
li > div > p {
width: 100%;
}
body > a {
color: #ffffff;
display: inline-block;
margin-top: 10px;
clear:left;
}
</style>
</head>
<body>
<img src="https://antennapod.org/assets/img/antennapod-logo.png" />
<h1>AntennaPod Favorites</h1>
<ul>
{FAVORITES}
</ul>
<a href="https://play.google.com/store/apps/details?id=de.danoeh.antennapod" target="_blank">Get AntennaPod</a>
</body>
</html>

View File

@ -1,7 +1,7 @@
<?xml version='1.0' encoding='UTF-8' standalone='no' ?>
<html>
<head>
<title>AntennaPod Subscriptions</title>
<title>AntennaPod {TITLE}</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
* {
@ -76,7 +76,7 @@
</head>
<body>
<img src="https://antennapod.org/assets/img/antennapod-logo.png" />
<h1>AntennaPod Subscriptions</h1>
<h1>AntennaPod {TITLE}</h1>
<ul>
{FEEDS}
</ul>

View File

@ -30,9 +30,10 @@ public class FavoritesWriter implements ExportWriter {
throws IllegalArgumentException, IllegalStateException, IOException {
Log.d(TAG, "Starting to write document");
InputStream templateStream = context.getAssets().open("favorites-export-template.html");
InputStream templateStream = context.getAssets().open("html-export-template.html");
String template = IOUtils.toString(templateStream, "UTF-8");
String[] templateParts = template.split("\\{FAVORITES\\}");
template = template.replaceAll("\\{TITLE\\}", "Favorites");
String[] templateParts = template.split("\\{FEEDS\\}");
Map<Long, List<FeedItem>> favoriteByFeed = getFeedMap(getFavorites());
@ -45,7 +46,7 @@ public class FavoritesWriter implements ExportWriter {
writer.append("<li><div>");
writeFeed(writer, favorites.get(0).getFeed());
writer.append("<ul>");
writer.append("<ul style=\"text-align:left\">");
for (FeedItem item : favorites) {
writeFavoriteItem(writer, item);
}
@ -62,21 +63,13 @@ public class FavoritesWriter implements ExportWriter {
private List<FeedItem> getFavorites() {
int page = 0;
List<FeedItem> favoritesPage = DBReader.getFavoriteItemsList(page, PAGE_LIMIT);
List<FeedItem> favoritesList = new ArrayList<>();
while (!favoritesPage.isEmpty()) {
favoritesList.addAll(favoritesPage);
// save a DB call if there are no more items to fetch
if (favoritesPage.size() < PAGE_LIMIT) {
break;
}
++page;
List<FeedItem> favoritesPage;
do {
favoritesPage = DBReader.getFavoriteItemsList(page * PAGE_LIMIT, PAGE_LIMIT);
}
favoritesList.addAll(favoritesPage);
++page;
} while (!favoritesPage.isEmpty() && favoritesPage.size() == PAGE_LIMIT);
// sort in descending order
Collections.sort(favoritesList, (lhs, rhs) -> rhs.getPubDate().compareTo(lhs.getPubDate()));

View File

@ -25,6 +25,7 @@ public class HtmlWriter implements ExportWriter {
InputStream templateStream = context.getAssets().open("html-export-template.html");
String template = IOUtils.toString(templateStream, "UTF-8");
template = template.replaceAll("\\{TITLE\\}", "Subscriptions");
String[] templateParts = template.split("\\{FEEDS\\}");
writer.append(templateParts[0]);

View File

@ -576,8 +576,7 @@
<string name="import_select_file">Select file to import</string>
<string name="import_ok">Import successful.\n\nPlease press OK to restart AntennaPod</string>
<string name="import_no_downgrade">This database was exported with a newer version of AntennaPod. Your current installation does not yet know how to handle this file.</string>
<string name="favorites">Favorites</string>
<string name="favorites_export_label">Favorites Export</string>
<string name="favorites_export_label">Favorites export</string>
<string name="favorites_export_summary">Export saved favorites to file</string>
<!-- Sleep timer -->