Simplify download notification title

This commit is contained in:
ByteHamster 2022-03-17 00:12:29 +01:00
parent 3b47deb705
commit 33e9e57d6e
2 changed files with 28 additions and 3 deletions

View File

@ -52,18 +52,41 @@ public class DownloadServiceNotification {
return null; return null;
} }
String contentTitle = context.getString(R.string.download_notification_title); String contentTitle;
String downloadsLeft = (downloads.size() > 0) if (typeIsOnly(downloads, Feed.FEEDFILETYPE_FEED)) {
contentTitle = context.getString(R.string.download_notification_title_feeds);
} else if (typeIsOnly(downloads, FeedMedia.FEEDFILETYPE_FEEDMEDIA)) {
contentTitle = context.getString(R.string.download_notification_title_episodes);
} else {
contentTitle = context.getString(R.string.download_notification_title);
}
String contentText = (downloads.size() > 0)
? context.getResources().getQuantityString(R.plurals.downloads_left, downloads.size(), downloads.size()) ? context.getResources().getQuantityString(R.plurals.downloads_left, downloads.size(), downloads.size())
: context.getString(R.string.completing); : context.getString(R.string.completing);
String bigText = compileNotificationString(downloads); String bigText = compileNotificationString(downloads);
if (!bigText.contains("\n")) {
contentText = bigText;
}
notificationCompatBuilder.setContentTitle(contentTitle); notificationCompatBuilder.setContentTitle(contentTitle);
notificationCompatBuilder.setContentText(downloadsLeft); notificationCompatBuilder.setContentText(contentText);
notificationCompatBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(bigText)); notificationCompatBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(bigText));
return notificationCompatBuilder.build(); return notificationCompatBuilder.build();
} }
private boolean typeIsOnly(List<Downloader> downloads, int feedFileType) {
for (Downloader downloader : downloads) {
if (downloader.cancelled) {
continue;
}
DownloadRequest request = downloader.getDownloadRequest();
if (request.getFeedfileType() != feedFileType) {
return false;
}
}
return true;
}
private static String compileNotificationString(List<Downloader> downloads) { private static String compileNotificationString(List<Downloader> downloads) {
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < downloads.size(); i++) { for (int i = 0; i < downloads.size(); i++) {

View File

@ -279,6 +279,8 @@
</plurals> </plurals>
<string name="completing">Completing…</string> <string name="completing">Completing…</string>
<string name="download_notification_title">Downloading podcast data</string> <string name="download_notification_title">Downloading podcast data</string>
<string name="download_notification_title_feeds">Refreshing podcasts</string>
<string name="download_notification_title_episodes">Downloading episodes</string>
<string name="download_log_title_unknown">Unknown Title</string> <string name="download_log_title_unknown">Unknown Title</string>
<string name="download_type_feed">Feed</string> <string name="download_type_feed">Feed</string>
<string name="download_type_media">Media file</string> <string name="download_type_media">Media file</string>