Skip to content

Commit

Permalink
When both adding and removing a feed before the next sync, remove the…
Browse files Browse the repository at this point in the history
… other action (#6404)
  • Loading branch information
ByteHamster committed Apr 2, 2023
1 parent b706ab9 commit 0388471
Showing 1 changed file with 28 additions and 10 deletions.
Expand Up @@ -94,13 +94,15 @@ protected void clearQueue() {

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();
Expand All @@ -109,17 +111,33 @@ protected void enqueueFeedAdded(String downloadUrl) {

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, "[]");
Expand Down

0 comments on commit 0388471

Please sign in to comment.