Fix race condition in progress notification
This commit is contained in:
parent
4f6b563e3f
commit
18ab4ab8c6
@ -270,17 +270,20 @@ public class EpisodeDownloadWorker extends Worker {
|
|||||||
|
|
||||||
private Notification generateProgressNotification() {
|
private Notification generateProgressNotification() {
|
||||||
StringBuilder bigTextB = new StringBuilder();
|
StringBuilder bigTextB = new StringBuilder();
|
||||||
Map<String, Integer> progressCopy = new HashMap<>(notificationProgress);
|
Map<String, Integer> progressCopy;
|
||||||
|
synchronized (notificationProgress) {
|
||||||
|
progressCopy = new HashMap<>(notificationProgress);
|
||||||
|
}
|
||||||
for (Map.Entry<String, Integer> entry : progressCopy.entrySet()) {
|
for (Map.Entry<String, Integer> entry : progressCopy.entrySet()) {
|
||||||
bigTextB.append(String.format(Locale.getDefault(), "%s (%d%%)\n", entry.getKey(), entry.getValue()));
|
bigTextB.append(String.format(Locale.getDefault(), "%s (%d%%)\n", entry.getKey(), entry.getValue()));
|
||||||
}
|
}
|
||||||
String bigText = bigTextB.toString().trim();
|
String bigText = bigTextB.toString().trim();
|
||||||
String contentText;
|
String contentText;
|
||||||
if (notificationProgress.size() == 1) {
|
if (progressCopy.size() == 1) {
|
||||||
contentText = bigText;
|
contentText = bigText;
|
||||||
} else {
|
} else {
|
||||||
contentText = getApplicationContext().getResources().getQuantityString(R.plurals.downloads_left,
|
contentText = getApplicationContext().getResources().getQuantityString(R.plurals.downloads_left,
|
||||||
notificationProgress.size(), notificationProgress.size());
|
progressCopy.size(), progressCopy.size());
|
||||||
}
|
}
|
||||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext(),
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext(),
|
||||||
NotificationUtils.CHANNEL_ID_DOWNLOADING);
|
NotificationUtils.CHANNEL_ID_DOWNLOADING);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user