diff options
author | ByteHamster <ByteHamster@users.noreply.github.com> | 2023-04-02 10:37:41 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-02 10:37:41 +0200 |
commit | 038847177e33d82669ff61dd730589fb58adbed4 (patch) | |
tree | 523b1a87a61830f9c942c7d7f1d54534d1972657 /core/src/main/java | |
parent | b706ab97767935929e1545cf7423836a0bbaa654 (diff) | |
download | AntennaPod-038847177e33d82669ff61dd730589fb58adbed4.zip |
When both adding and removing a feed before the next sync, remove the other action (#6404)
Diffstat (limited to 'core/src/main/java')
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/sync/queue/SynchronizationQueueStorage.java | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/sync/queue/SynchronizationQueueStorage.java b/core/src/main/java/de/danoeh/antennapod/core/sync/queue/SynchronizationQueueStorage.java index 5c6d58fe3..e1e373953 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/sync/queue/SynchronizationQueueStorage.java +++ b/core/src/main/java/de/danoeh/antennapod/core/sync/queue/SynchronizationQueueStorage.java @@ -94,13 +94,15 @@ public class SynchronizationQueueStorage { protected void enqueueFeedAdded(String downloadUrl) { SharedPreferences sharedPreferences = getSharedPreferences(); - String json = sharedPreferences - .getString(QUEUED_FEEDS_ADDED, "[]"); try { - JSONArray queue = new JSONArray(json); - queue.put(downloadUrl); - sharedPreferences - .edit().putString(QUEUED_FEEDS_ADDED, queue.toString()).apply(); + JSONArray addedQueue = new JSONArray(sharedPreferences.getString(QUEUED_FEEDS_ADDED, "[]")); + addedQueue.put(downloadUrl); + JSONArray removedQueue = new JSONArray(sharedPreferences.getString(QUEUED_FEEDS_REMOVED, "[]")); + removedQueue.remove(indexOf(downloadUrl, removedQueue)); + sharedPreferences.edit() + .putString(QUEUED_FEEDS_ADDED, addedQueue.toString()) + .putString(QUEUED_FEEDS_REMOVED, removedQueue.toString()) + .apply(); } catch (JSONException jsonException) { jsonException.printStackTrace(); @@ -109,17 +111,33 @@ public class SynchronizationQueueStorage { protected void enqueueFeedRemoved(String downloadUrl) { SharedPreferences sharedPreferences = getSharedPreferences(); - String json = sharedPreferences.getString(QUEUED_FEEDS_REMOVED, "[]"); try { - JSONArray queue = new JSONArray(json); - queue.put(downloadUrl); - sharedPreferences.edit().putString(QUEUED_FEEDS_REMOVED, queue.toString()) + JSONArray removedQueue = new JSONArray(sharedPreferences.getString(QUEUED_FEEDS_REMOVED, "[]")); + removedQueue.put(downloadUrl); + JSONArray addedQueue = new JSONArray(sharedPreferences.getString(QUEUED_FEEDS_ADDED, "[]")); + addedQueue.remove(indexOf(downloadUrl, addedQueue)); + sharedPreferences.edit() + .putString(QUEUED_FEEDS_ADDED, addedQueue.toString()) + .putString(QUEUED_FEEDS_REMOVED, removedQueue.toString()) .apply(); } catch (JSONException jsonException) { jsonException.printStackTrace(); } } + private int indexOf(String string, JSONArray array) { + try { + for (int i = 0; i < array.length(); i++) { + if (array.getString(i).equals(string)) { + return i; + } + } + } catch (JSONException jsonException) { + jsonException.printStackTrace(); + } + return -1; + } + protected void enqueueEpisodeAction(EpisodeAction action) { SharedPreferences sharedPreferences = getSharedPreferences(); String json = sharedPreferences.getString(QUEUED_EPISODE_ACTIONS, "[]"); |