When both adding and removing a feed before the next sync, remove the other action (#6404)
This commit is contained in:
parent
b706ab9776
commit
038847177e
@ -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, "[]");
|
||||
|
Loading…
x
Reference in New Issue
Block a user