From be42cc0c7176c056a5b1b7c2b0d16ad6e9850312 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Thu, 25 Jul 2019 00:38:00 +0200 Subject: [PATCH 1/6] Refactored mobile updates setting --- .../antennapod/adapter/AdapterUtils.java | 2 +- .../adapter/AllEpisodesRecycleAdapter.java | 2 +- .../adapter/QueueRecyclerAdapter.java | 2 +- .../actionbutton/DownloadActionButton.java | 2 +- .../actionbutton/MobileDownloadHelper.java | 12 +++- .../antennapod/fragment/ItemFragment.java | 14 +++- .../AutoDownloadPreferencesFragment.java | 1 - .../preferences/PreferenceUpgrader.java | 22 +++++- .../main/res/xml/preferences_autodownload.xml | 5 -- app/src/main/res/xml/preferences_network.xml | 4 +- .../core/preferences/UserPreferences.java | 67 +++++++++++++++---- .../antennapod/core/util/FeedUpdateUtils.java | 2 +- .../antennapod/core/util/NetworkUtils.java | 22 ++++-- .../core/util/download/AutoUpdateManager.java | 2 +- core/src/main/res/values/arrays.xml | 12 ++-- core/src/main/res/values/strings.xml | 12 ++-- 16 files changed, 140 insertions(+), 43 deletions(-) diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/AdapterUtils.java b/app/src/main/java/de/danoeh/antennapod/adapter/AdapterUtils.java index 5c58d00f2..315b3a173 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/AdapterUtils.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/AdapterUtils.java @@ -49,7 +49,7 @@ class AdapterUtils { } else if (!media.isDownloaded()) { if (media.getSize() > 0) { txtvPos.setText(Converter.byteToString(media.getSize())); - } else if(NetworkUtils.isDownloadAllowed() && !media.checkedOnSizeButUnknown()) { + } else if(NetworkUtils.isEpisodeHeadDownloadAllowed() && !media.checkedOnSizeButUnknown()) { txtvPos.setText("{fa-spinner}"); Iconify.addIcons(txtvPos); NetworkUtils.getFeedMediaSizeObservable(media) diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java index 7aa9f8f21..2eff33339 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java @@ -130,7 +130,7 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter 0) { holder.txtvDuration.setText(Converter.byteToString(media.getSize())); - } else if(NetworkUtils.isDownloadAllowed() && !media.checkedOnSizeButUnknown()) { + } else if(NetworkUtils.isEpisodeHeadDownloadAllowed() && !media.checkedOnSizeButUnknown()) { holder.txtvDuration.setText("{fa-spinner}"); Iconify.addIcons(holder.txtvDuration); NetworkUtils.getFeedMediaSizeObservable(media) diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/QueueRecyclerAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/QueueRecyclerAdapter.java index d9d54ac15..382abfb32 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/QueueRecyclerAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/QueueRecyclerAdapter.java @@ -252,7 +252,7 @@ public class QueueRecyclerAdapter extends RecyclerView.Adapter 0) { progressLeft.setText(Converter.byteToString(media.getSize())); - } else if(NetworkUtils.isDownloadAllowed() && !media.checkedOnSizeButUnknown()) { + } else if(NetworkUtils.isEpisodeHeadDownloadAllowed() && !media.checkedOnSizeButUnknown()) { progressLeft.setText("{fa-spinner}"); Iconify.addIcons(progressLeft); NetworkUtils.getFeedMediaSizeObservable(media) diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/DownloadActionButton.java b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/DownloadActionButton.java index 202a41161..c1559528e 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/DownloadActionButton.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/DownloadActionButton.java @@ -43,7 +43,7 @@ class DownloadActionButton extends ItemActionButton { return; } - if (NetworkUtils.isDownloadAllowed() || MobileDownloadHelper.userAllowedMobileDownloads()) { + if (NetworkUtils.isEpisodeDownloadAllowed() || MobileDownloadHelper.userAllowedMobileDownloads()) { downloadEpisode(context); } else if (MobileDownloadHelper.userChoseAddToQueue() && !isInQueue) { addEpisodeToQueue(context); diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/MobileDownloadHelper.java b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/MobileDownloadHelper.java index f8d2a139e..0d2498b60 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/MobileDownloadHelper.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/MobileDownloadHelper.java @@ -13,7 +13,7 @@ import de.danoeh.antennapod.core.storage.DBTasks; import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.storage.DownloadRequestException; -class MobileDownloadHelper { +public class MobileDownloadHelper { private static long addToQueueTimestamp; private static long allowMobileDownloadTimestamp; private static final int TEN_MINUTES_IN_MILLIS = 10 * 60 * 1000; @@ -41,6 +41,16 @@ class MobileDownloadHelper { builder.show(); } + public static void confirmMobileStreaming(final Context context, MaterialDialog.SingleButtonCallback onAllowed) { + MaterialDialog.Builder builder = new MaterialDialog.Builder(context) + .title(R.string.confirm_mobile_streaming_dialog_title) + .content(R.string.confirm_mobile_streaming_dialog_message) + .positiveText(R.string.yes) + .onPositive(onAllowed) + .negativeText(R.string.no); + builder.show(); + } + private static void addToQueue(Context context, FeedItem item) { addToQueueTimestamp = System.currentTimeMillis(); DBWriter.addQueueItem(context, item); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java index 432ada44e..e43d78ecc 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java @@ -35,6 +35,7 @@ import com.bumptech.glide.request.RequestOptions; import com.joanzapata.iconify.Iconify; import com.joanzapata.iconify.widget.IconButton; +import de.danoeh.antennapod.adapter.actionbutton.MobileDownloadHelper; import org.apache.commons.lang3.ArrayUtils; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; @@ -248,9 +249,16 @@ public class ItemFragment extends Fragment implements OnSwipeGesture { if (item.hasMedia()) { FeedMedia media = item.getMedia(); - if (!media.isDownloaded()) { - DBTasks.playMedia(getActivity(), media, true, true, true); - ((MainActivity) getActivity()).dismissChildFragment(); + if (!media.isDownloaded()) { // Stream + if (NetworkUtils.isStreamingAllowed()) { + DBTasks.playMedia(getActivity(), media, true, true, true); + ((MainActivity) getActivity()).dismissChildFragment(); + } else { + MobileDownloadHelper.confirmMobileStreaming(getContext(), (dialog, which) -> { + DBTasks.playMedia(getActivity(), media, true, true, true); + ((MainActivity) getActivity()).dismissChildFragment(); + }); + } } else { DBWriter.deleteFeedMediaOfItem(getActivity(), media.getId()); } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/AutoDownloadPreferencesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/AutoDownloadPreferencesFragment.java index bfd94b9a2..6cba798ba 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/AutoDownloadPreferencesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/AutoDownloadPreferencesFragment.java @@ -66,7 +66,6 @@ public class AutoDownloadPreferencesFragment extends PreferenceFragmentCompat { findPreference(UserPreferences.PREF_ENABLE_AUTODL_ON_BATTERY).setEnabled(autoDownload); findPreference(UserPreferences.PREF_ENABLE_AUTODL_WIFI_FILTER).setEnabled(autoDownload); findPreference(UserPreferences.PREF_EPISODE_CLEANUP).setEnabled(autoDownload); - findPreference(UserPreferences.PREF_ENABLE_AUTODL_ON_MOBILE).setEnabled(autoDownload); setSelectedNetworksEnabled(autoDownload && UserPreferences.isEnableAutodownloadWifiFilter()); } diff --git a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceUpgrader.java b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceUpgrader.java index 5866f8715..751b6789a 100644 --- a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceUpgrader.java +++ b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceUpgrader.java @@ -2,11 +2,14 @@ package de.danoeh.antennapod.preferences; import android.content.Context; import android.content.SharedPreferences; +import android.preference.MultiSelectListPreference; import android.preference.PreferenceManager; import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.util.gui.NotificationUtils; +import java.util.HashSet; + public class PreferenceUpgrader { private static final String PREF_CONFIGURED_VERSION = "configuredVersion"; private static final String PREF_NAME = "PreferenceUpgrader"; @@ -37,7 +40,7 @@ public class PreferenceUpgrader { } if (oldVersion < 1070197) { if (prefs.getBoolean("prefMobileUpdate", false)) { - prefs.edit().putString(UserPreferences.PREF_MOBILE_UPDATE, "everything").apply(); + prefs.edit().putString("prefMobileUpdateAllowed", "everything").apply(); } } if (oldVersion < 1070300) { @@ -47,6 +50,23 @@ public class PreferenceUpgrader { prefs.edit().putString(UserPreferences.PREF_MEDIA_PLAYER, UserPreferences.PREF_MEDIA_PLAYER_EXOPLAYER).apply(); } + + if (prefs.getBoolean("prefEnableAutoDownloadOnMobile", false)) { + UserPreferences.setAllowMobileAutoDownload(true); + } + switch (prefs.getString("prefMobileUpdateAllowed", "images")) { + case "everything": + UserPreferences.setAllowMobileFeedRefresh(true); + UserPreferences.setAllowMobileEpisodeDownload(true); + UserPreferences.setAllowMobileImages(true); + break; + case "images": + UserPreferences.setAllowMobileImages(true); + break; + case "nothing": + UserPreferences.setAllowMobileImages(false); + break; + } } } } diff --git a/app/src/main/res/xml/preferences_autodownload.xml b/app/src/main/res/xml/preferences_autodownload.xml index 0f3d5d024..a4967c839 100644 --- a/app/src/main/res/xml/preferences_autodownload.xml +++ b/app/src/main/res/xml/preferences_autodownload.xml @@ -30,11 +30,6 @@ android:title="@string/pref_automatic_download_on_battery_title" android:summary="@string/pref_automatic_download_on_battery_sum" android:defaultValue="true"/> - - defaultValue = new HashSet<>(); + defaultValue.add("images"); + Set allowed = prefs.getStringSet(PREF_MOBILE_UPDATE, defaultValue); + return allowed.contains(type); } - public static boolean isAllowMobileUpdate() { - return getMobileUpdatesEnabled().equals("everything"); + public static boolean isAllowMobileFeedRefresh() { + return isAllowMobileFor("feed_refresh"); + } + + public static boolean isAllowMobileEpisodeDownload() { + return isAllowMobileFor("episode_download"); + } + + public static boolean isAllowMobileAutoDownload() { + return isAllowMobileFor("auto_download"); + } + + public static boolean isAllowMobileStreaming() { + return isAllowMobileFor("streaming"); } public static boolean isAllowMobileImages() { - return isAllowMobileUpdate() || getMobileUpdatesEnabled().equals("images"); + return isAllowMobileFor("images"); + } + + private static void setAllowMobileFor(String type, boolean allow) { + HashSet defaultValue = new HashSet<>(); + defaultValue.add("images"); + Set allowed = prefs.getStringSet(PREF_MOBILE_UPDATE, defaultValue); + if (allow) { + allowed.remove(type); + } else { + allowed.add(type); + } + prefs.edit().putStringSet(PREF_MOBILE_UPDATE, allowed).apply(); + } + + public static void setAllowMobileFeedRefresh(boolean allow) { + setAllowMobileFor("feed_refresh", allow); + } + + public static void setAllowMobileEpisodeDownload(boolean allow) { + setAllowMobileFor("episode_download", allow); + } + + public static void setAllowMobileAutoDownload(boolean allow) { + setAllowMobileFor("auto_download", allow); + } + + public static void setAllowMobileStreaming(boolean allow) { + setAllowMobileFor("streaming", allow); + } + + public static void setAllowMobileImages(boolean allow) { + setAllowMobileFor("images", allow); } public static int getParallelDownloads() { @@ -420,11 +468,6 @@ public class UserPreferences { return prefs.getBoolean(PREF_ENABLE_AUTODL_WIFI_FILTER, false); } - public static boolean isEnableAutodownloadOnMobile() { - return prefs.getBoolean(PREF_ENABLE_AUTODL_ON_MOBILE, false); - } - - public static int getImageCacheSize() { String cacheSizeString = prefs.getString(PREF_IMAGE_CACHE_SIZE, IMAGE_CACHE_DEFAULT_VALUE); int cacheSizeInt = Integer.parseInt(cacheSizeString); diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/FeedUpdateUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/FeedUpdateUtils.java index a0195975f..b425687ae 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/FeedUpdateUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/FeedUpdateUtils.java @@ -24,7 +24,7 @@ public class FeedUpdateUtils { with().pollInterval(1, TimeUnit.SECONDS) .await() .atMost(10, TimeUnit.SECONDS) - .until(() -> NetworkUtils.networkAvailable() && NetworkUtils.isDownloadAllowed()); + .until(() -> NetworkUtils.networkAvailable() && NetworkUtils.isFeedRefreshAllowed()); DBTasks.refreshAllFeeds(context, null, callback); } catch (ConditionTimeoutException ignore) { Log.d(TAG, "Blocking automatic update: no wifi available / no mobile updates allowed"); diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/NetworkUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/NetworkUtils.java index d9431bc5d..ca48c9bc9 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/NetworkUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/NetworkUtils.java @@ -74,7 +74,7 @@ public class NetworkUtils { return true; } } else { - if (!UserPreferences.isEnableAutodownloadOnMobile()) { + if (!UserPreferences.isAllowMobileAutoDownload()) { Log.d(TAG, "Auto Download not enabled on Mobile"); return false; } @@ -95,14 +95,28 @@ public class NetworkUtils { return info != null && info.isConnected(); } - public static boolean isDownloadAllowed() { - return UserPreferences.isAllowMobileUpdate() || !NetworkUtils.isNetworkMetered(); + public static boolean isEpisodeDownloadAllowed() { + return UserPreferences.isAllowMobileEpisodeDownload() || !NetworkUtils.isNetworkMetered(); + } + + public static boolean isEpisodeHeadDownloadAllowed() { + // It is not an image but it is a similarly tiny request + // that is probably not even considered a download by most users + return isImageAllowed(); } public static boolean isImageAllowed() { return UserPreferences.isAllowMobileImages() || !NetworkUtils.isNetworkMetered(); } + public static boolean isStreamingAllowed() { + return UserPreferences.isAllowMobileStreaming() || !NetworkUtils.isNetworkMetered(); + } + + public static boolean isFeedRefreshAllowed() { + return UserPreferences.isAllowMobileFeedRefresh() || !NetworkUtils.isNetworkMetered(); + } + private static boolean isNetworkMetered() { ConnectivityManager connManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); @@ -123,7 +137,7 @@ public class NetworkUtils { public static Single getFeedMediaSizeObservable(FeedMedia media) { return Single.create((SingleOnSubscribe) emitter -> { - if (!NetworkUtils.isDownloadAllowed()) { + if (!NetworkUtils.isEpisodeHeadDownloadAllowed()) { emitter.onSuccess(0L); return; } diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/download/AutoUpdateManager.java b/core/src/main/java/de/danoeh/antennapod/core/util/download/AutoUpdateManager.java index e5aaa2db0..412b150fa 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/download/AutoUpdateManager.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/download/AutoUpdateManager.java @@ -67,7 +67,7 @@ public class AutoUpdateManager { private static Constraints getConstraints() { Constraints.Builder constraints = new Constraints.Builder(); - if (UserPreferences.isAllowMobileUpdate()) { + if (UserPreferences.isAllowMobileFeedRefresh()) { constraints.setRequiredNetworkType(NetworkType.CONNECTED); } else { constraints.setRequiredNetworkType(NetworkType.UNMETERED); diff --git a/core/src/main/res/values/arrays.xml b/core/src/main/res/values/arrays.xml index 39d1c0a94..d5f1c30b1 100644 --- a/core/src/main/res/values/arrays.xml +++ b/core/src/main/res/values/arrays.xml @@ -62,15 +62,19 @@ - @string/pref_mobileUpdate_nothing + @string/pref_mobileUpdate_refresh + @string/pref_mobileUpdate_episode_download + @string/pref_mobileUpdate_auto_download + @string/pref_mobileUpdate_streaming @string/pref_mobileUpdate_images - @string/pref_mobileUpdate_everything - nothing + feed_refresh + episode_download + auto_download + streaming images - everything diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 6025dc888..82a56cf88 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -265,6 +265,8 @@ Confirm Mobile Download Downloading over mobile data connection is disabled in the settings.\n\nYou can choose to either only add the episode to the queue or you can allow downloading temporarily.\n\nYour choice will be remembered for 10 minutes. Downloading over mobile data connection is disabled in the settings.\n\nDo you want to allow downloading temporarily?\n\nYour choice will be remembered for 10 minutes. + Confirm Mobile streaming + Streaming over mobile data connection is disabled in the settings. Do you want to stream anyway? Enqueue Allow temporarily @@ -386,10 +388,12 @@ Headphones Reconnect Bluetooth Reconnect Mobile Updates - Allow updates and manual episode downloads over the mobile data connection - Nothing - Images only - Everything + Select what should be allowed over the mobile data connection + Feed refresh + Cover images + Auto download + Episode download + Streaming Refreshing User Interface Select Theme From be8e7c32f138bab841d3b040dad0c85ee54875ac Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Thu, 25 Jul 2019 01:08:16 +0200 Subject: [PATCH 2/6] Display notification when trying to stream --- .../actionbutton/MobileDownloadHelper.java | 12 +----- .../antennapod/fragment/ItemFragment.java | 12 +----- .../preferences/PreferenceUpgrader.java | 3 -- app/src/main/res/xml/preferences_network.xml | 2 +- .../service/playback/PlaybackService.java | 37 +++++++++++++++++-- core/src/main/res/values/arrays.xml | 4 ++ core/src/main/res/values/strings.xml | 4 +- 7 files changed, 44 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/MobileDownloadHelper.java b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/MobileDownloadHelper.java index 0d2498b60..f8d2a139e 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/MobileDownloadHelper.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/MobileDownloadHelper.java @@ -13,7 +13,7 @@ import de.danoeh.antennapod.core.storage.DBTasks; import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.storage.DownloadRequestException; -public class MobileDownloadHelper { +class MobileDownloadHelper { private static long addToQueueTimestamp; private static long allowMobileDownloadTimestamp; private static final int TEN_MINUTES_IN_MILLIS = 10 * 60 * 1000; @@ -41,16 +41,6 @@ public class MobileDownloadHelper { builder.show(); } - public static void confirmMobileStreaming(final Context context, MaterialDialog.SingleButtonCallback onAllowed) { - MaterialDialog.Builder builder = new MaterialDialog.Builder(context) - .title(R.string.confirm_mobile_streaming_dialog_title) - .content(R.string.confirm_mobile_streaming_dialog_message) - .positiveText(R.string.yes) - .onPositive(onAllowed) - .negativeText(R.string.no); - builder.show(); - } - private static void addToQueue(Context context, FeedItem item) { addToQueueTimestamp = System.currentTimeMillis(); DBWriter.addQueueItem(context, item); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java index e43d78ecc..1196401f2 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java @@ -35,7 +35,6 @@ import com.bumptech.glide.request.RequestOptions; import com.joanzapata.iconify.Iconify; import com.joanzapata.iconify.widget.IconButton; -import de.danoeh.antennapod.adapter.actionbutton.MobileDownloadHelper; import org.apache.commons.lang3.ArrayUtils; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; @@ -250,15 +249,8 @@ public class ItemFragment extends Fragment implements OnSwipeGesture { if (item.hasMedia()) { FeedMedia media = item.getMedia(); if (!media.isDownloaded()) { // Stream - if (NetworkUtils.isStreamingAllowed()) { - DBTasks.playMedia(getActivity(), media, true, true, true); - ((MainActivity) getActivity()).dismissChildFragment(); - } else { - MobileDownloadHelper.confirmMobileStreaming(getContext(), (dialog, which) -> { - DBTasks.playMedia(getActivity(), media, true, true, true); - ((MainActivity) getActivity()).dismissChildFragment(); - }); - } + DBTasks.playMedia(getActivity(), media, true, true, true); + ((MainActivity) getActivity()).dismissChildFragment(); } else { DBWriter.deleteFeedMediaOfItem(getActivity(), media.getId()); } diff --git a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceUpgrader.java b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceUpgrader.java index 751b6789a..e56703598 100644 --- a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceUpgrader.java +++ b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceUpgrader.java @@ -2,14 +2,11 @@ package de.danoeh.antennapod.preferences; import android.content.Context; import android.content.SharedPreferences; -import android.preference.MultiSelectListPreference; import android.preference.PreferenceManager; import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.util.gui.NotificationUtils; -import java.util.HashSet; - public class PreferenceUpgrader { private static final String PREF_CONFIGURED_VERSION = "configuredVersion"; private static final String PREF_NAME = "PreferenceUpgrader"; diff --git a/app/src/main/res/xml/preferences_network.xml b/app/src/main/res/xml/preferences_network.xml index e418323a9..9d1ce28c6 100644 --- a/app/src/main/res/xml/preferences_network.xml +++ b/app/src/main/res/xml/preferences_network.xml @@ -17,7 +17,7 @@ = android.os.Build.VERSION_CODES.O) { + pendingIntent = PendingIntent.getForegroundService(this, 0, intent, 0); + } else { + pendingIntent = PendingIntent.getService(this, 0, intent, 0); + } + + NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NotificationUtils.CHANNEL_ID_USER_ACTION) + .setSmallIcon(R.drawable.stat_notify_sync_error) + .setContentTitle(getString(R.string.confirm_mobile_streaming_notification_title)) + .setContentText(getString(R.string.confirm_mobile_streaming_notification_message)) + .setStyle(new NotificationCompat.BigTextStyle() + .bigText(getString(R.string.confirm_mobile_streaming_notification_message))) + .setPriority(NotificationCompat.PRIORITY_DEFAULT) + .setContentIntent(pendingIntent) + .setAutoCancel(true); + NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); + notificationManager.notify(NOTIFICATION_ID_STREAMING, builder.build()); + } + /** * Handles media button events * return: keycode was handled diff --git a/core/src/main/res/values/arrays.xml b/core/src/main/res/values/arrays.xml index d5f1c30b1..49ebb7416 100644 --- a/core/src/main/res/values/arrays.xml +++ b/core/src/main/res/values/arrays.xml @@ -77,6 +77,10 @@ images + + images + + @string/episode_cleanup_queue_removal 0 diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 82a56cf88..a6ba0740e 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -265,8 +265,8 @@ Confirm Mobile Download Downloading over mobile data connection is disabled in the settings.\n\nYou can choose to either only add the episode to the queue or you can allow downloading temporarily.\n\nYour choice will be remembered for 10 minutes. Downloading over mobile data connection is disabled in the settings.\n\nDo you want to allow downloading temporarily?\n\nYour choice will be remembered for 10 minutes. - Confirm Mobile streaming - Streaming over mobile data connection is disabled in the settings. Do you want to stream anyway? + Confirm Mobile streaming + Streaming over mobile data connection is disabled in the settings. Tap to stream anyway. Enqueue Allow temporarily From 1651b95f774a61333a5d020cc8925c139d38e48e Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Thu, 25 Jul 2019 13:53:54 +0200 Subject: [PATCH 3/6] Displaying notification when playback switches to streamed episode --- .../core/service/playback/PlaybackService.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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 6707d10f4..bc8725432 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 @@ -73,6 +73,7 @@ import de.danoeh.antennapod.core.util.QueueAccess; import de.danoeh.antennapod.core.util.gui.NotificationUtils; import de.danoeh.antennapod.core.util.playback.ExternalMedia; import de.danoeh.antennapod.core.util.playback.Playable; +import de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter; import org.greenrobot.eventbus.EventBus; /** @@ -853,7 +854,22 @@ public class PlaybackService extends MediaBrowserServiceCompat { Log.e(TAG, "Error handling the queue in order to retrieve the next item", e); return null; } - return (nextItem != null) ? nextItem.getMedia() : null; + + if (nextItem == null || nextItem.getMedia() == null) { + return null; + } + + if (!nextItem.getMedia().localFileAvailable() && !NetworkUtils.isStreamingAllowed()) { + displayStreamingNotAllowedNotification( + new PlaybackServiceStarter(this, nextItem.getMedia()) + .prepareImmediately(true) + .startWhenPrepared(true) + .shouldStream(true) + .getIntent()); + stopService(); + return null; + } + return nextItem.getMedia(); } From de13f9b5644d4d8bd51683e845bfebd433d1f9c1 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Thu, 25 Jul 2019 14:01:24 +0200 Subject: [PATCH 4/6] Updating pendingIntent --- .../antennapod/core/service/playback/PlaybackService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 bc8725432..4da764d5a 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 @@ -501,9 +501,9 @@ public class PlaybackService extends MediaBrowserServiceCompat { intent.putExtra(EXTRA_ALLOW_STREAM_THIS_TIME, true); PendingIntent pendingIntent; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { - pendingIntent = PendingIntent.getForegroundService(this, 0, intent, 0); + pendingIntent = PendingIntent.getForegroundService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); } else { - pendingIntent = PendingIntent.getService(this, 0, intent, 0); + pendingIntent = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); } NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NotificationUtils.CHANNEL_ID_USER_ACTION) From d2084608a67bdd9359e8ec1dcea92acc30f577e6 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Sat, 10 Aug 2019 17:20:26 +0200 Subject: [PATCH 5/6] Fixed reappearing notification --- .../antennapod/core/service/playback/PlaybackService.java | 2 ++ 1 file changed, 2 insertions(+) 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 4da764d5a..2f1bc4207 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 @@ -483,6 +483,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { } if (stream && !NetworkUtils.isStreamingAllowed() && !allowStreamThisTime) { displayStreamingNotAllowedNotification(intent); + writePlaybackPreferencesNoMediaPlaying(); stopService(); return Service.START_NOT_STICKY; } @@ -866,6 +867,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { .startWhenPrepared(true) .shouldStream(true) .getIntent()); + writePlaybackPreferencesNoMediaPlaying(); stopService(); return null; } From 6f7ec2011f1f962642ef0e3a0780f98646e4e4ea Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Sat, 10 Aug 2019 17:23:31 +0200 Subject: [PATCH 6/6] Cleanup --- .../main/java/de/danoeh/antennapod/fragment/ItemFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java index 1196401f2..432ada44e 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java @@ -248,7 +248,7 @@ public class ItemFragment extends Fragment implements OnSwipeGesture { if (item.hasMedia()) { FeedMedia media = item.getMedia(); - if (!media.isDownloaded()) { // Stream + if (!media.isDownloaded()) { DBTasks.playMedia(getActivity(), media, true, true, true); ((MainActivity) getActivity()).dismissChildFragment(); } else {