Fix post filter usage not retain after saving the post filter again.

This commit is contained in:
Alex Ning 2021-04-06 22:48:36 +08:00
parent 68d8aaf61d
commit 98a66a8bb7
4 changed files with 12 additions and 2 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);
}
});

View File

@ -5,5 +5,5 @@
android:viewportHeight="24">
<path
android:pathData="M12,5.69l5,4.5V18h-2v-6H9v6H7v-7.81l5,-4.5M12,3L2,12h3v8h6v-6h2v6h6v-8h3L12,3z"
android:fillColor="#000000"/>
android:fillColor="#FFFFFF"/>
</vector>