When both adding and removing a feed before the next sync, remove the other action (#6404)

This commit is contained in:
ByteHamster 2023-04-02 10:37:41 +02:00 committed by GitHub
parent b706ab9776
commit 038847177e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -94,13 +94,15 @@ public class SynchronizationQueueStorage {
protected void enqueueFeedAdded(String downloadUrl) { protected void enqueueFeedAdded(String downloadUrl) {
SharedPreferences sharedPreferences = getSharedPreferences(); SharedPreferences sharedPreferences = getSharedPreferences();
String json = sharedPreferences
.getString(QUEUED_FEEDS_ADDED, "[]");
try { try {
JSONArray queue = new JSONArray(json); JSONArray addedQueue = new JSONArray(sharedPreferences.getString(QUEUED_FEEDS_ADDED, "[]"));
queue.put(downloadUrl); addedQueue.put(downloadUrl);
sharedPreferences JSONArray removedQueue = new JSONArray(sharedPreferences.getString(QUEUED_FEEDS_REMOVED, "[]"));
.edit().putString(QUEUED_FEEDS_ADDED, queue.toString()).apply(); removedQueue.remove(indexOf(downloadUrl, removedQueue));
sharedPreferences.edit()
.putString(QUEUED_FEEDS_ADDED, addedQueue.toString())
.putString(QUEUED_FEEDS_REMOVED, removedQueue.toString())
.apply();
} catch (JSONException jsonException) { } catch (JSONException jsonException) {
jsonException.printStackTrace(); jsonException.printStackTrace();
@ -109,17 +111,33 @@ public class SynchronizationQueueStorage {
protected void enqueueFeedRemoved(String downloadUrl) { protected void enqueueFeedRemoved(String downloadUrl) {
SharedPreferences sharedPreferences = getSharedPreferences(); SharedPreferences sharedPreferences = getSharedPreferences();
String json = sharedPreferences.getString(QUEUED_FEEDS_REMOVED, "[]");
try { try {
JSONArray queue = new JSONArray(json); JSONArray removedQueue = new JSONArray(sharedPreferences.getString(QUEUED_FEEDS_REMOVED, "[]"));
queue.put(downloadUrl); removedQueue.put(downloadUrl);
sharedPreferences.edit().putString(QUEUED_FEEDS_REMOVED, queue.toString()) 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(); .apply();
} catch (JSONException jsonException) { } catch (JSONException jsonException) {
jsonException.printStackTrace(); 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) { protected void enqueueEpisodeAction(EpisodeAction action) {
SharedPreferences sharedPreferences = getSharedPreferences(); SharedPreferences sharedPreferences = getSharedPreferences();
String json = sharedPreferences.getString(QUEUED_EPISODE_ACTIONS, "[]"); String json = sharedPreferences.getString(QUEUED_EPISODE_ACTIONS, "[]");