summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorByteHamster <ByteHamster@users.noreply.github.com>2023-07-04 22:31:47 +0200
committerGitHub <noreply@github.com>2023-07-04 22:31:47 +0200
commit6999a944bb3c1ce1547832ad15e401ff7cbbbe10 (patch)
treefe199e17b41dbcc22d5f4161d49124bdcd9d6243
parent23d4cf5632279bcc9293396d8943bf84275a9d60 (diff)
downloadAntennaPod-6999a944bb3c1ce1547832ad15e401ff7cbbbe10.zip
Fix 'allow once' for feed update on mobile networks (#6528)
-rw-r--r--app/src/main/java/de/danoeh/antennapod/adapter/DownloadLogAdapter.java4
-rw-r--r--app/src/main/java/de/danoeh/antennapod/dialog/EditUrlSettingsDialog.java4
-rw-r--r--app/src/main/java/de/danoeh/antennapod/fragment/AddFeedFragment.java3
-rw-r--r--app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java3
-rw-r--r--app/src/main/java/de/danoeh/antennapod/menuhandler/FeedMenuHandler.java3
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/FeedUpdateWorker.java8
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java9
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/util/download/FeedUpdateManager.java29
-rw-r--r--ui/i18n/src/main/res/values/strings.xml1
9 files changed, 34 insertions, 30 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/DownloadLogAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/DownloadLogAdapter.java
index 0fb6a7e7a..08d7cbefd 100644
--- a/app/src/main/java/de/danoeh/antennapod/adapter/DownloadLogAdapter.java
+++ b/app/src/main/java/de/danoeh/antennapod/adapter/DownloadLogAdapter.java
@@ -11,8 +11,8 @@ import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.adapter.actionbutton.DownloadActionButton;
import de.danoeh.antennapod.core.storage.DBReader;
-import de.danoeh.antennapod.core.storage.DBTasks;
import de.danoeh.antennapod.core.util.DownloadErrorLabel;
+import de.danoeh.antennapod.core.util.download.FeedUpdateManager;
import de.danoeh.antennapod.model.download.DownloadError;
import de.danoeh.antennapod.model.download.DownloadResult;
import de.danoeh.antennapod.model.feed.Feed;
@@ -109,7 +109,7 @@ public class DownloadLogAdapter extends BaseAdapter {
Log.e(TAG, "Could not find feed for feed id: " + status.getFeedfileId());
return;
}
- DBTasks.forceRefreshFeed(context, feed, true);
+ FeedUpdateManager.runOnce(context, feed);
});
} else if (status.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
holder.secondaryActionButton.setOnClickListener(v -> {
diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/EditUrlSettingsDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/EditUrlSettingsDialog.java
index e6ad78a89..1929b997e 100644
--- a/app/src/main/java/de/danoeh/antennapod/dialog/EditUrlSettingsDialog.java
+++ b/app/src/main/java/de/danoeh/antennapod/dialog/EditUrlSettingsDialog.java
@@ -6,8 +6,8 @@ import android.view.LayoutInflater;
import androidx.appcompat.app.AlertDialog;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import de.danoeh.antennapod.R;
-import de.danoeh.antennapod.core.storage.DBTasks;
import de.danoeh.antennapod.core.storage.DBWriter;
+import de.danoeh.antennapod.core.util.download.FeedUpdateManager;
import de.danoeh.antennapod.databinding.EditTextDialogBinding;
import de.danoeh.antennapod.model.feed.Feed;
@@ -48,7 +48,7 @@ public abstract class EditUrlSettingsDialog {
try {
DBWriter.updateFeedDownloadURL(original, updated).get();
feed.setDownload_url(updated);
- DBTasks.forceRefreshFeed(activityRef.get(), feed, false);
+ FeedUpdateManager.runOnce(activityRef.get(), feed);
} catch (ExecutionException | InterruptedException e) {
throw new RuntimeException(e);
}
diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/AddFeedFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/AddFeedFragment.java
index 864e23d7d..6a72348bc 100644
--- a/app/src/main/java/de/danoeh/antennapod/fragment/AddFeedFragment.java
+++ b/app/src/main/java/de/danoeh/antennapod/fragment/AddFeedFragment.java
@@ -27,6 +27,7 @@ import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.activity.OnlineFeedViewActivity;
import de.danoeh.antennapod.activity.OpmlImportActivity;
+import de.danoeh.antennapod.core.util.download.FeedUpdateManager;
import de.danoeh.antennapod.model.feed.Feed;
import de.danoeh.antennapod.core.storage.DBTasks;
import de.danoeh.antennapod.model.feed.SortOrder;
@@ -210,7 +211,7 @@ public class AddFeedFragment extends Fragment {
dirFeed.setItems(Collections.emptyList());
dirFeed.setSortOrder(SortOrder.EPISODE_TITLE_A_Z);
Feed fromDatabase = DBTasks.updateFeed(getContext(), dirFeed, false);
- DBTasks.forceRefreshFeed(getContext(), fromDatabase, true);
+ FeedUpdateManager.runOnce(requireContext(), fromDatabase);
return fromDatabase;
}
diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java
index 6f3aaa6a5..6b6fedd1f 100644
--- a/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java
+++ b/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java
@@ -32,7 +32,6 @@ import de.danoeh.antennapod.adapter.EpisodeItemListAdapter;
import de.danoeh.antennapod.core.feed.FeedEvent;
import de.danoeh.antennapod.core.menuhandler.MenuItemUtils;
import de.danoeh.antennapod.core.storage.DBReader;
-import de.danoeh.antennapod.core.storage.DBTasks;
import de.danoeh.antennapod.core.util.FeedItemPermutors;
import de.danoeh.antennapod.core.util.FeedItemUtil;
import de.danoeh.antennapod.core.util.download.FeedUpdateManager;
@@ -185,7 +184,7 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem
viewBinding.swipeRefresh.setDistanceToTriggerSync(getResources().getInteger(R.integer.swipe_refresh_distance));
viewBinding.swipeRefresh.setOnRefreshListener(() -> {
- DBTasks.forceRefreshFeed(requireContext(), feed, true);
+ FeedUpdateManager.runOnceOrAsk(requireContext(), feed);
new Handler(Looper.getMainLooper()).postDelayed(() -> viewBinding.swipeRefresh.setRefreshing(false),
getResources().getInteger(R.integer.swipe_to_refresh_duration_in_ms));
});
diff --git a/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedMenuHandler.java b/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedMenuHandler.java
index 9b9525133..7a9eb1bb5 100644
--- a/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedMenuHandler.java
+++ b/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedMenuHandler.java
@@ -6,7 +6,6 @@ import android.view.Menu;
import android.view.MenuItem;
import androidx.annotation.NonNull;
import de.danoeh.antennapod.R;
-import de.danoeh.antennapod.core.storage.DBTasks;
import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.util.IntentUtils;
import de.danoeh.antennapod.core.util.ShareUtils;
@@ -64,7 +63,7 @@ public class FeedMenuHandler {
public static boolean onOptionsItemClicked(final Context context, final MenuItem item, final Feed selectedFeed) {
final int itemId = item.getItemId();
if (itemId == R.id.refresh_item) {
- DBTasks.forceRefreshFeed(context, selectedFeed, true);
+ FeedUpdateManager.runOnceOrAsk(context, selectedFeed);
} else if (itemId == R.id.refresh_complete_item) {
new Thread(() -> {
selectedFeed.setNextPageLink(selectedFeed.getDownload_url());
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/FeedUpdateWorker.java b/core/src/main/java/de/danoeh/antennapod/core/service/FeedUpdateWorker.java
index b9618f201..59d9df8f5 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/service/FeedUpdateWorker.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/service/FeedUpdateWorker.java
@@ -53,9 +53,11 @@ public class FeedUpdateWorker extends Worker {
ClientConfigurator.initialize(getApplicationContext());
newEpisodesNotification.loadCountersBeforeRefresh();
- if (!NetworkUtils.networkAvailable() || !NetworkUtils.isFeedRefreshAllowed()) {
- Log.d(TAG, "Blocking automatic update: no wifi available / no mobile updates allowed");
- return Result.retry();
+ if (!getInputData().getBoolean(FeedUpdateManager.EXTRA_EVEN_ON_MOBILE, false)) {
+ if (!NetworkUtils.networkAvailable() || !NetworkUtils.isFeedRefreshAllowed()) {
+ Log.d(TAG, "Blocking automatic update: no wifi available / no mobile updates allowed");
+ return Result.retry();
+ }
}
List<Feed> toUpdate;
diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java
index e3ac7a7e1..d42f14591 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java
@@ -8,7 +8,6 @@ import androidx.annotation.VisibleForTesting;
import de.danoeh.antennapod.core.R;
import de.danoeh.antennapod.core.sync.queue.SynchronizationQueueSink;
import de.danoeh.antennapod.core.util.comparator.FeedItemPubdateComparator;
-import de.danoeh.antennapod.core.util.download.FeedUpdateManager;
import de.danoeh.antennapod.event.FeedItemEvent;
import de.danoeh.antennapod.event.FeedListUpdateEvent;
import de.danoeh.antennapod.event.MessageEvent;
@@ -92,14 +91,6 @@ public final class DBTasks {
}
}
- public static void forceRefreshFeed(Context context, Feed feed, boolean initiatedByUser) {
- forceRefreshFeed(context, feed, false, initiatedByUser);
- }
-
- private static void forceRefreshFeed(Context context, Feed feed, boolean loadAllPages, boolean initiatedByUser) {
- FeedUpdateManager.runOnce(context, feed);
- }
-
/**
* Notifies the database about a missing FeedMedia file. This method will correct the FeedMedia object's
* values in the DB and send a FeedItemEvent.
diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/download/FeedUpdateManager.java b/core/src/main/java/de/danoeh/antennapod/core/util/download/FeedUpdateManager.java
index d1a273d4e..b09e58fad 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/util/download/FeedUpdateManager.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/util/download/FeedUpdateManager.java
@@ -3,6 +3,7 @@ package de.danoeh.antennapod.core.util.download;
import android.content.Context;
import android.util.Log;
import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
import androidx.work.Constraints;
import androidx.work.Data;
import androidx.work.ExistingPeriodicWorkPolicy;
@@ -16,8 +17,10 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import de.danoeh.antennapod.core.R;
import de.danoeh.antennapod.core.service.FeedUpdateWorker;
import de.danoeh.antennapod.core.util.NetworkUtils;
+import de.danoeh.antennapod.event.MessageEvent;
import de.danoeh.antennapod.model.feed.Feed;
import de.danoeh.antennapod.storage.preferences.UserPreferences;
+import org.greenrobot.eventbus.EventBus;
import java.util.concurrent.TimeUnit;
@@ -27,6 +30,7 @@ public class FeedUpdateManager {
private static final String WORK_ID_FEED_UPDATE_MANUAL = "feedUpdateManual";
public static final String EXTRA_FEED_ID = "feed_id";
public static final String EXTRA_NEXT_PAGE = "next_page";
+ public static final String EXTRA_EVEN_ON_MOBILE = "even_on_mobile";
private static final String TAG = "AutoUpdateManager";
private FeedUpdateManager() {
@@ -62,37 +66,44 @@ public class FeedUpdateManager {
OneTimeWorkRequest.Builder workRequest = new OneTimeWorkRequest.Builder(FeedUpdateWorker.class)
.setInitialDelay(0L, TimeUnit.MILLISECONDS)
.setExpedited(OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST)
- .addTag(WORK_TAG_FEED_UPDATE);
+ .addTag(WORK_TAG_FEED_UPDATE)
+ .setConstraints(new Constraints.Builder()
+ .setRequiredNetworkType(NetworkType.CONNECTED).build());
+ Data.Builder builder = new Data.Builder();
+ builder.putBoolean(EXTRA_EVEN_ON_MOBILE, true);
if (feed != null) {
- Data.Builder builder = new Data.Builder();
builder.putLong(EXTRA_FEED_ID, feed.getId());
builder.putBoolean(EXTRA_NEXT_PAGE, nextPage);
- workRequest.setInputData(builder.build());
}
+ workRequest.setInputData(builder.build());
WorkManager.getInstance(context).enqueueUniqueWork(WORK_ID_FEED_UPDATE_MANUAL,
ExistingWorkPolicy.REPLACE, workRequest.build());
}
public static void runOnceOrAsk(@NonNull Context context) {
+ runOnceOrAsk(context, null);
+ }
+
+ public static void runOnceOrAsk(@NonNull Context context, @Nullable Feed feed) {
Log.d(TAG, "Run auto update immediately in background.");
if (!NetworkUtils.networkAvailable()) {
- Log.d(TAG, "Ignoring: No network connection.");
+ EventBus.getDefault().post(new MessageEvent(context.getString(R.string.download_error_no_connection)));
} else if (NetworkUtils.isFeedRefreshAllowed()) {
- runOnce(context);
+ runOnce(context, feed);
} else {
- confirmMobileAllFeedsRefresh(context);
+ confirmMobileRefresh(context, feed);
}
}
- private static void confirmMobileAllFeedsRefresh(final Context context) {
+ private static void confirmMobileRefresh(final Context context, @Nullable Feed feed) {
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(context)
.setTitle(R.string.feed_refresh_title)
.setMessage(R.string.confirm_mobile_feed_refresh_dialog_message)
.setPositiveButton(R.string.confirm_mobile_streaming_button_once,
- (dialog, which) -> runOnce(context))
+ (dialog, which) -> runOnce(context, feed))
.setNeutralButton(R.string.confirm_mobile_streaming_button_always, (dialog, which) -> {
UserPreferences.setAllowMobileFeedRefresh(true);
- runOnce(context);
+ runOnce(context, feed);
})
.setNegativeButton(R.string.no, null);
builder.show();
diff --git a/ui/i18n/src/main/res/values/strings.xml b/ui/i18n/src/main/res/values/strings.xml
index 8178ec220..6bdb836dd 100644
--- a/ui/i18n/src/main/res/values/strings.xml
+++ b/ui/i18n/src/main/res/values/strings.xml
@@ -275,6 +275,7 @@
<string name="download_error_unsupported_type_html">The podcast host\'s server sent a website, not a podcast.</string>
<string name="download_error_not_found">The podcast host\'s server does not know where to find the file. It may have been deleted.</string>
<string name="download_error_connection_error">Connection error</string>
+ <string name="download_error_no_connection">No network connection</string>
<string name="download_error_unknown_host">Cannot find the server. Check if the address is typed correctly and if you have a working network connection.</string>
<string name="download_error_unauthorized">Authentication error. Make sure that username and password are correct.</string>
<string name="download_error_file_type_type">File type error</string>