summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorByteHamster <ByteHamster@users.noreply.github.com>2023-10-29 16:10:38 +0100
committerGitHub <noreply@github.com>2023-10-29 16:10:38 +0100
commit4931734d94a30d4b9b83c13a7869fc84bbf22a11 (patch)
tree2c5ca755f771abda555b3ca12523ffda96639354 /core/src
parent8a011badd3253dde83769ec9dc3be3129528e4b7 (diff)
downloadAntennaPod-4931734d94a30d4b9b83c13a7869fc84bbf22a11.zip
Allow hiding notification permission nag (#6730)
- Support showing most error messages as a snackbar - Ask for notification permission when enabling episode notifications - Clarify what we use notifications for
Diffstat (limited to 'core/src')
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/download/EpisodeDownloadWorker.java21
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java6
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/sync/SyncService.java12
3 files changed, 24 insertions, 15 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/EpisodeDownloadWorker.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/EpisodeDownloadWorker.java
index 62956894c..dcce26042 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/service/download/EpisodeDownloadWorker.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/EpisodeDownloadWorker.java
@@ -129,11 +129,7 @@ public class EpisodeDownloadWorker extends Worker {
downloader.call();
} catch (Exception e) {
DBWriter.addDownloadStatus(downloader.getResult());
- if (EventBus.getDefault().hasSubscriberForEvent(MessageEvent.class)) {
- sendMessage(request.getTitle(), false);
- } else {
- sendErrorNotification();
- }
+ sendErrorNotification(request.getTitle());
FileUtils.deleteQuietly(new File(downloader.getDownloadRequest().getDestination()));
return Result.failure();
}
@@ -176,11 +172,7 @@ public class EpisodeDownloadWorker extends Worker {
|| status.getReason() == DownloadError.ERROR_UNAUTHORIZED
|| status.getReason() == DownloadError.ERROR_IO_BLOCKED) {
// Fail fast, these are probably unrecoverable
- if (EventBus.getDefault().hasSubscriberForEvent(MessageEvent.class)) {
- sendMessage(request.getTitle(), false);
- } else {
- sendErrorNotification();
- }
+ sendErrorNotification(request.getTitle());
FileUtils.deleteQuietly(new File(downloader.getDownloadRequest().getDestination()));
return Result.failure();
}
@@ -193,7 +185,7 @@ public class EpisodeDownloadWorker extends Worker {
private Result retry3times() {
if (isLastRunAttempt()) {
- sendErrorNotification();
+ sendErrorNotification(downloader.getDownloadRequest().getTitle());
return Result.failure();
} else {
return Result.retry();
@@ -227,7 +219,12 @@ public class EpisodeDownloadWorker extends Worker {
PendingIntent.FLAG_UPDATE_CURRENT | (Build.VERSION.SDK_INT >= 23 ? PendingIntent.FLAG_IMMUTABLE : 0));
}
- private void sendErrorNotification() {
+ private void sendErrorNotification(String title) {
+ if (EventBus.getDefault().hasSubscriberForEvent(MessageEvent.class)) {
+ sendMessage(title, false);
+ return;
+ }
+
NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext(),
NotificationUtils.CHANNEL_ID_DOWNLOAD_ERROR);
builder.setTicker(getApplicationContext().getString(R.string.download_report_title))
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java
index c82d6f975..77ac2bccc 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java
@@ -562,6 +562,12 @@ public class PlaybackService extends MediaBrowserServiceCompat {
@SuppressLint("LaunchActivityFromNotification")
private void displayStreamingNotAllowedNotification(Intent originalIntent) {
+ if (EventBus.getDefault().hasSubscriberForEvent(MessageEvent.class)) {
+ EventBus.getDefault().post(new MessageEvent(
+ getString(R.string.confirm_mobile_streaming_notification_message)));
+ return;
+ }
+
Intent intentAllowThisTime = new Intent(originalIntent);
intentAllowThisTime.setAction(PlaybackServiceInterface.EXTRA_ALLOW_STREAM_THIS_TIME);
intentAllowThisTime.putExtra(PlaybackServiceInterface.EXTRA_ALLOW_STREAM_THIS_TIME, true);
diff --git a/core/src/main/java/de/danoeh/antennapod/core/sync/SyncService.java b/core/src/main/java/de/danoeh/antennapod/core/sync/SyncService.java
index 7fe0c5e46..dc6b7ff80 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/sync/SyncService.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/sync/SyncService.java
@@ -22,6 +22,7 @@ import androidx.work.WorkerParameters;
import de.danoeh.antennapod.core.util.download.FeedUpdateManager;
import de.danoeh.antennapod.event.FeedUpdateRunningEvent;
+import de.danoeh.antennapod.event.MessageEvent;
import de.danoeh.antennapod.model.feed.FeedItemFilter;
import de.danoeh.antennapod.model.feed.SortOrder;
import org.apache.commons.lang3.StringUtils;
@@ -298,13 +299,18 @@ public class SyncService extends Worker {
}
private void updateErrorNotification(Exception exception) {
+ Log.d(TAG, "Posting sync error notification");
+ final String description = getApplicationContext().getString(R.string.gpodnetsync_error_descr)
+ + exception.getMessage();
+
if (!UserPreferences.gpodnetNotificationsEnabled()) {
Log.d(TAG, "Skipping sync error notification because of user setting");
return;
}
- Log.d(TAG, "Posting sync error notification");
- final String description = getApplicationContext().getString(R.string.gpodnetsync_error_descr)
- + exception.getMessage();
+ if (EventBus.getDefault().hasSubscriberForEvent(MessageEvent.class)) {
+ EventBus.getDefault().post(new MessageEvent(description));
+ return;
+ }
Intent intent = getApplicationContext().getPackageManager().getLaunchIntentForPackage(
getApplicationContext().getPackageName());