aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2021-04-06 14:48:36 +0000
committerAlex Ning <chineseperson5@gmail.com>2021-04-06 14:48:36 +0000
commit98a66a8bb780e083dd82a34bdff240ce132a755c (patch)
treea99e2f14bba99f4a2610614af5161edf00f45035 /app/src/main/java/ml
parent68d8aaf61d8d3f3357fdadb16a44f04acbf5ae86 (diff)
downloadinfinity-for-reddit-98a66a8bb780e083dd82a34bdff240ce132a755c.tar
infinity-for-reddit-98a66a8bb780e083dd82a34bdff240ce132a755c.tar.gz
infinity-for-reddit-98a66a8bb780e083dd82a34bdff240ce132a755c.tar.bz2
infinity-for-reddit-98a66a8bb780e083dd82a34bdff240ce132a755c.tar.lz
infinity-for-reddit-98a66a8bb780e083dd82a34bdff240ce132a755c.tar.xz
infinity-for-reddit-98a66a8bb780e083dd82a34bdff240ce132a755c.tar.zst
infinity-for-reddit-98a66a8bb780e083dd82a34bdff240ce132a755c.zip
Fix post filter usage not retain after saving the post filter again.
Diffstat (limited to 'app/src/main/java/ml')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/PostFilterUsageDao.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/SavePostFilter.java6
3 files changed, 11 insertions, 1 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java
index 96aafb97..30118395 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java
@@ -133,6 +133,7 @@ public class ParsePost {
}
if (data.has(JSONUtils.CROSSPOST_PARENT_LIST)) {
//Cross post
+ //data.getJSONArray(JSONUtils.CROSSPOST_PARENT_LIST).getJSONObject(0) out of bounds????????????
data = data.getJSONArray(JSONUtils.CROSSPOST_PARENT_LIST).getJSONObject(0);
Post crosspostParent = parseBasicData(data);
Post post = parseData(data, permalink, id, fullName, subredditName, subredditNamePrefixed,
@@ -227,7 +228,7 @@ public class ParsePost {
JSONArray thumbnailPreviews = images.getJSONArray(JSONUtils.RESOLUTIONS_KEY);
for (int i = 0; i < thumbnailPreviews.length(); i++) {
- JSONObject thumbnailPreview = images.getJSONArray(JSONUtils.RESOLUTIONS_KEY).getJSONObject(2);
+ JSONObject thumbnailPreview = images.getJSONArray(JSONUtils.RESOLUTIONS_KEY).getJSONObject(i);
String thumbnailPreviewUrl = thumbnailPreview.getString(JSONUtils.URL_KEY);
int thumbnailPreviewWidth = thumbnailPreview.getInt(JSONUtils.WIDTH_KEY);
int thumbnailPreviewHeight = thumbnailPreview.getInt(JSONUtils.HEIGHT_KEY);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/PostFilterUsageDao.java b/app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/PostFilterUsageDao.java
index a0ba8843..c94a67f7 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/PostFilterUsageDao.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/PostFilterUsageDao.java
@@ -14,6 +14,9 @@ public interface PostFilterUsageDao {
@Query("SELECT * FROM post_filter_usage WHERE name = :name")
LiveData<List<PostFilterUsage>> getAllPostFilterUsageLiveData(String name);
+ @Query("SELECT * FROM post_filter_usage WHERE name = :name")
+ List<PostFilterUsage> getAllPostFilterUsage(String name);
+
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insertPostFilterUsage(PostFilterUsage postFilterUsage);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/SavePostFilter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/SavePostFilter.java
index c7f10885..2f14ba6f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/SavePostFilter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/postfilter/SavePostFilter.java
@@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit.postfilter;
import android.os.Handler;
+import java.util.List;
import java.util.concurrent.Executor;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
@@ -19,10 +20,15 @@ public class SavePostFilter {
redditDataRoomDatabase.postFilterDao().getPostFilter(postFilter.name) != null) {
handler.post(savePostFilterListener::duplicate);
} else {
+ List<PostFilterUsage> postFilterUsages = redditDataRoomDatabase.postFilterUsageDao().getAllPostFilterUsage(originalName);
if (!originalName.equals(postFilter.name)) {
redditDataRoomDatabase.postFilterDao().deletePostFilter(originalName);
}
redditDataRoomDatabase.postFilterDao().insert(postFilter);
+ for (PostFilterUsage postFilterUsage : postFilterUsages) {
+ postFilterUsage.name = postFilter.name;
+ redditDataRoomDatabase.postFilterUsageDao().insertPostFilterUsage(postFilterUsage);
+ }
handler.post(savePostFilterListener::success);
}
});