Merge pull request #1242 from heckler01/develop

Make Text Readable On Download Notification 

looks good. thanks!
This commit is contained in:
Tom Hennen 2015-10-08 01:48:48 -04:00
commit 57b8ced16e
1 changed files with 30 additions and 49 deletions

View File

@ -130,7 +130,6 @@ public class DownloadService extends Service {
private NotificationCompat.Builder notificationCompatBuilder; private NotificationCompat.Builder notificationCompatBuilder;
private Notification.BigTextStyle notificationBuilder;
private int NOTIFICATION_ID = 2; private int NOTIFICATION_ID = 2;
private int REPORT_ID = 3; private int REPORT_ID = 3;
@ -322,23 +321,16 @@ public class DownloadService extends Service {
DBTasks.autodownloadUndownloadedItems(getApplicationContext()); DBTasks.autodownloadUndownloadedItems(getApplicationContext());
} }
@SuppressLint("NewApi")
private void setupNotificationBuilders() { private void setupNotificationBuilders() {
Bitmap icon = BitmapFactory.decodeResource(getResources(), Bitmap icon = BitmapFactory.decodeResource(getResources(),
R.drawable.stat_notify_sync); R.drawable.stat_notify_sync);
if (android.os.Build.VERSION.SDK_INT >= 16) {
notificationBuilder = new Notification.BigTextStyle(
new Notification.Builder(this).setOngoing(true)
.setContentIntent(ClientConfig.downloadServiceCallbacks.getNotificationContentIntent(this)).setLargeIcon(icon)
.setSmallIcon(R.drawable.stat_notify_sync)
);
} else {
notificationCompatBuilder = new NotificationCompat.Builder(this) notificationCompatBuilder = new NotificationCompat.Builder(this)
.setOngoing(true).setContentIntent(ClientConfig.downloadServiceCallbacks.getNotificationContentIntent(this)) .setOngoing(true)
.setContentIntent(ClientConfig.downloadServiceCallbacks.getNotificationContentIntent(this))
.setLargeIcon(icon) .setLargeIcon(icon)
.setSmallIcon(R.drawable.stat_notify_sync); .setSmallIcon(R.drawable.stat_notify_sync);
}
Log.d(TAG, "Notification set up"); Log.d(TAG, "Notification set up");
} }
@ -346,58 +338,47 @@ public class DownloadService extends Service {
* Updates the contents of the service's notifications. Should be called * Updates the contents of the service's notifications. Should be called
* before setupNotificationBuilders. * before setupNotificationBuilders.
*/ */
@SuppressLint("NewApi")
private Notification updateNotifications() { private Notification updateNotifications() {
String contentTitle = getString(R.string.download_notification_title); String contentTitle = getString(R.string.download_notification_title);
int numDownloads = requester.getNumberOfDownloads(); int numDownloads = requester.getNumberOfDownloads();
String downloadsLeft; String downloadsLeft;
if (numDownloads > 0) { if (numDownloads > 0) {
downloadsLeft = requester.getNumberOfDownloads() downloadsLeft = requester.getNumberOfDownloads() + getString(R.string.downloads_left);
+ getString(R.string.downloads_left);
} else { } else {
downloadsLeft = getString(R.string.downloads_processing); downloadsLeft = getString(R.string.downloads_processing);
} }
if (android.os.Build.VERSION.SDK_INT >= 16) { if (notificationCompatBuilder != null) {
if (notificationBuilder != null) { StringBuilder bigText = new StringBuilder("");
for (int i = 0; i < downloads.size(); i++) {
StringBuilder bigText = new StringBuilder(""); Downloader downloader = downloads.get(i);
for (int i = 0; i < downloads.size(); i++) { final DownloadRequest request = downloader
Downloader downloader = downloads.get(i); .getDownloadRequest();
final DownloadRequest request = downloader if (request.getFeedfileType() == Feed.FEEDFILETYPE_FEED) {
.getDownloadRequest(); if (request.getTitle() != null) {
if (request.getFeedfileType() == Feed.FEEDFILETYPE_FEED) { if (i > 0) {
if (request.getTitle() != null) { bigText.append("\n");
if (i > 0) {
bigText.append("\n");
}
bigText.append("\u2022 " + request.getTitle());
}
} else if (request.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
if (request.getTitle() != null) {
if (i > 0) {
bigText.append("\n");
}
bigText.append("\u2022 " + request.getTitle()
+ " (" + request.getProgressPercent()
+ "%)");
} }
bigText.append("\u2022 " + request.getTitle());
} }
} else if (request.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
if (request.getTitle() != null) {
if (i > 0) {
bigText.append("\n");
}
bigText.append("\u2022 " + request.getTitle()
+ " (" + request.getProgressPercent()
+ "%)");
}
}
}
notificationBuilder.setSummaryText(downloadsLeft);
notificationBuilder.setBigContentTitle(contentTitle);
if (bigText != null) {
notificationBuilder.bigText(bigText.toString());
}
return notificationBuilder.build();
} }
} else { notificationCompatBuilder.setContentTitle(contentTitle);
if (notificationCompatBuilder != null) { notificationCompatBuilder.setContentText(downloadsLeft);
notificationCompatBuilder.setContentTitle(contentTitle); if (bigText != null) {
notificationCompatBuilder.setContentText(downloadsLeft); notificationCompatBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(bigText.toString()));
return notificationCompatBuilder.build();
} }
return notificationCompatBuilder.build();
} }
return null; return null;
} }