aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml/docilealligator
diff options
context:
space:
mode:
authorHermes Junior <ohermesjunior@gmail.com>2020-06-21 15:39:41 +0000
committerOHermesJunior <ohermesjunior@gmail.com>2020-06-21 15:39:41 +0000
commit3a88cacdde3b70e1ace6746bbad72fbeaf9d1ced (patch)
tree8508edf96eafcbe710a90e48416f80f2dad47b7e /app/src/main/java/ml/docilealligator
parented679e835d4a0f1c50f2f517e6afd43de09da058 (diff)
downloadinfinity-for-reddit-3a88cacdde3b70e1ace6746bbad72fbeaf9d1ced.tar
infinity-for-reddit-3a88cacdde3b70e1ace6746bbad72fbeaf9d1ced.tar.gz
infinity-for-reddit-3a88cacdde3b70e1ace6746bbad72fbeaf9d1ced.tar.bz2
infinity-for-reddit-3a88cacdde3b70e1ace6746bbad72fbeaf9d1ced.tar.lz
infinity-for-reddit-3a88cacdde3b70e1ace6746bbad72fbeaf9d1ced.tar.xz
infinity-for-reddit-3a88cacdde3b70e1ace6746bbad72fbeaf9d1ced.tar.zst
infinity-for-reddit-3a88cacdde3b70e1ace6746bbad72fbeaf9d1ced.zip
Improve removed thing not found detection.
Diffstat (limited to 'app/src/main/java/ml/docilealligator')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/FetchRemovedComment.java26
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/FetchRemovedPost.java32
2 files changed, 33 insertions, 25 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRemovedComment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRemovedComment.java
index 6e18e927..d012342e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRemovedComment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRemovedComment.java
@@ -37,19 +37,19 @@ public class FetchRemovedComment {
});
}
- private static CommentData parseRemovedComment(JSONObject comment, CommentData commentData) throws JSONException {
- String id = comment.getString(JSONUtils.ID_KEY);
- if (id.equals(commentData.getId())) {
- String author = comment.getString(JSONUtils.AUTHOR_KEY);
- String commentMarkdown = "";
- if (!comment.isNull(JSONUtils.BODY_KEY)) {
- commentMarkdown = Utils.modifyMarkdown(comment.getString(JSONUtils.BODY_KEY).trim());
- }
-
- commentData.setAuthor(author);
- commentData.setCommentMarkdown(commentMarkdown);
- commentData.setCommentRawText(commentMarkdown);
- return commentData;
+ private static CommentData parseRemovedComment(JSONObject result, CommentData comment) throws JSONException {
+ String id = result.getString(JSONUtils.ID_KEY);
+ String author = result.getString(JSONUtils.AUTHOR_KEY);
+ String body = Utils.modifyMarkdown(result.optString(JSONUtils.BODY_KEY).trim());
+
+ if ( id.equals(comment.getId()) &&
+ (!author.equals(comment.getAuthor()) ||
+ !body.equals(comment.getCommentRawText()))
+ ) {
+ comment.setAuthor(author);
+ comment.setCommentMarkdown(body);
+ comment.setCommentRawText(body);
+ return comment;
} else {
return null;
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRemovedPost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRemovedPost.java
index 2a8076a9..646dfe19 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRemovedPost.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRemovedPost.java
@@ -40,26 +40,29 @@ public class FetchRemovedPost {
});
}
- private static Post parseRemovedPost(JSONObject postJson, Post post) throws JSONException {
- String id = postJson.getString(JSONUtils.ID_KEY);
- if (id.equals(post.getId())) {
- String author = postJson.getString(JSONUtils.AUTHOR_KEY);
- String title = postJson.getString(JSONUtils.TITLE_KEY);
- String postContent = Utils.modifyMarkdown(postJson.getString(JSONUtils.SELFTEXT_KEY).trim());
-
+ private static Post parseRemovedPost(JSONObject result, Post post) throws JSONException {
+ String id = result.getString(JSONUtils.ID_KEY);
+ String author = result.getString(JSONUtils.AUTHOR_KEY);
+ String title = result.getString(JSONUtils.TITLE_KEY);
+ String body = Utils.modifyMarkdown(result.getString(JSONUtils.SELFTEXT_KEY).trim());
+
+ if ( id.equals(post.getId()) &&
+ (!author.equals(post.getAuthor()) ||
+ foundSelfText(post.getSelfText(), body))
+ ) {
post.setAuthor(author);
post.setTitle(title);
- post.setSelfText(postContent);
+ post.setSelfText(body);
post.setSelfTextPlain("");
post.setSelfTextPlainTrimmed("");
- String url = postJson.optString(JSONUtils.URL_KEY);
+ String url = result.optString(JSONUtils.URL_KEY);
if (url.endsWith("gif") || url.endsWith("mp4")) {
post.setVideoUrl(url);
post.setVideoDownloadUrl(url);
} else if (post.getPostType() == Post.VIDEO_TYPE || post.getPostType() == Post.GIF_TYPE) {
- JSONObject redditVideoObject = postJson.getJSONObject("secure_media").getJSONObject(JSONUtils.REDDIT_VIDEO_KEY);
+ JSONObject redditVideoObject = result.getJSONObject("secure_media").getJSONObject(JSONUtils.REDDIT_VIDEO_KEY);
String videoUrl = Html.fromHtml(redditVideoObject.getString(JSONUtils.HLS_URL_KEY)).toString();
String videoDownloadUrl = redditVideoObject.getString(JSONUtils.FALLBACK_URL_KEY);
@@ -81,8 +84,8 @@ public class FetchRemovedPost {
}
}
- if (!postJson.isNull("thumbnail")) {
- post.setThumbnailPreviewUrl(postJson.getString("thumbnail"));
+ if (!result.isNull("thumbnail")) {
+ post.setThumbnailPreviewUrl(result.getString("thumbnail"));
}
return post;
@@ -91,6 +94,11 @@ public class FetchRemovedPost {
}
}
+ private static boolean foundSelfText(String oldText, String newText) {
+ return !(newText.equals("[deleted]") || newText.equals("[removed]")) &&
+ !newText.equals(oldText);
+ }
+
public interface FetchRemovedPostListener {
void fetchSuccess(Post post);