From 98a66a8bb780e083dd82a34bdff240ce132a755c Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Tue, 6 Apr 2021 22:48:36 +0800 Subject: Fix post filter usage not retain after saving the post filter again. --- .../java/ml/docilealligator/infinityforreddit/post/ParsePost.java | 3 ++- .../infinityforreddit/postfilter/PostFilterUsageDao.java | 3 +++ .../infinityforreddit/postfilter/SavePostFilter.java | 6 ++++++ app/src/main/res/drawable-night/ic_home_black_24dp.xml | 2 +- 4 files changed, 12 insertions(+), 2 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> getAllPostFilterUsageLiveData(String name); + @Query("SELECT * FROM post_filter_usage WHERE name = :name") + List 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 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); } }); diff --git a/app/src/main/res/drawable-night/ic_home_black_24dp.xml b/app/src/main/res/drawable-night/ic_home_black_24dp.xml index a35f1eff..c112c91b 100644 --- a/app/src/main/res/drawable-night/ic_home_black_24dp.xml +++ b/app/src/main/res/drawable-night/ic_home_black_24dp.xml @@ -5,5 +5,5 @@ android:viewportHeight="24"> + android:fillColor="#FFFFFF"/> -- cgit v1.2.3