Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

Prevent Slide blanking existing toolbox configs #3362

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

import com.afollestad.materialdialogs.MaterialDialog;

import net.dean.jraw.http.NetworkException;

import me.ccrama.redditslide.R;
import me.ccrama.redditslide.SettingValues;
import me.ccrama.redditslide.Toolbox.Toolbox;
Expand Down Expand Up @@ -242,9 +244,15 @@ private static class AsyncRefreshToolboxTask extends AsyncTask<Void, Void, Void>
@Override
protected Void doInBackground(Void... voids) {
for (String sub : UserSubscriptions.modOf) {
Toolbox.downloadToolboxConfig(sub);
try {
Toolbox.downloadToolboxConfig(sub);
} catch (NetworkException ignored) {
}
publishProgress();
Toolbox.downloadUsernotes(sub);
try {
Toolbox.downloadUsernotes(sub);
} catch (NetworkException ignored) {
}
publishProgress();
}
return null;
Expand Down
14 changes: 12 additions & 2 deletions app/src/main/java/me/ccrama/redditslide/Toolbox/Toolbox.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ public static void downloadUsernotes(String subreddit) {
} catch (NetworkException | JsonParseException e) {
if (e instanceof JsonParseException) {
notes.remove(subreddit);
} else if (e instanceof NetworkException && ((NetworkException) e).getResponse().getStatusCode() != 404) {
throw e;
}
cache.edit().putLong(subreddit + "_usernotes_timestamp", System.currentTimeMillis())
.putBoolean(subreddit + "_usernotes_exists", false).apply();
Expand Down Expand Up @@ -230,6 +232,8 @@ public static void downloadToolboxConfig(String subreddit) {
} catch (NetworkException | JsonParseException e) {
if (e instanceof JsonParseException) {
toolboxConfigs.remove(subreddit);
} else if (e instanceof NetworkException && ((NetworkException) e).getResponse().getStatusCode() != 404) {
throw e;
}
cache.edit().putLong(subreddit + "_config_timestamp", System.currentTimeMillis())
.putBoolean(subreddit + "_config_exists", false).apply();
Expand Down Expand Up @@ -261,15 +265,21 @@ public static void uploadUsernotes(String subreddit, String editReason) {
private static class AsyncLoadUsernotes extends AsyncTask<String, Void, Void> {
@Override
protected Void doInBackground(String... subreddit) {
downloadUsernotes(subreddit[0]);
try {
downloadUsernotes(subreddit[0]);
} catch (NetworkException ignored) {
}
return null;
}
}

private static class AsyncLoadToolboxConfig extends AsyncTask<String, Void, Void> {
@Override
protected Void doInBackground(String... subreddit) {
downloadToolboxConfig(subreddit[0]);
try {
downloadToolboxConfig(subreddit[0]);
} catch (NetworkException ignored) {
}
return null;
}
}
Expand Down
12 changes: 10 additions & 2 deletions app/src/main/java/me/ccrama/redditslide/Toolbox/ToolboxUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,11 @@ public static class AsyncAddUsernoteTask extends AsyncTask<String, Void, Boolean
protected Boolean doInBackground(String... strings) {
String reason;

Toolbox.downloadUsernotes(strings[0]);
try {
Toolbox.downloadUsernotes(strings[0]);
} catch (NetworkException e) {
return false;
}
if (Toolbox.getUsernotes(strings[0]) == null) {
Toolbox.createUsernotes(strings[0]);
reason = "create usernotes config";
Expand Down Expand Up @@ -791,7 +795,11 @@ public static class AsyncRemoveUsernoteTask extends AsyncTask<String, Void, Bool

@Override
protected Boolean doInBackground(String... strings) {
Toolbox.downloadUsernotes(strings[0]);
try {
Toolbox.downloadUsernotes(strings[0]);
} catch (NetworkException e) {
return false;
}
Toolbox.getUsernotes(strings[0]).removeNote(strings[1], note);
try {
Toolbox.uploadUsernotes(strings[0], "delete note " + note.getTime() + " on user " + strings[1]);
Expand Down