diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-09-16 15:26:56 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-09-16 15:26:56 +0000 |
commit | 50a357267985b14894e275ef515778f33b3023af (patch) | |
tree | bebd27febd1e190c936afb1289645602dce21969 | |
parent | 1d73231a82545376170868f5bafdf24381748b97 (diff) | |
download | infinity-for-reddit-50a357267985b14894e275ef515778f33b3023af.tar infinity-for-reddit-50a357267985b14894e275ef515778f33b3023af.tar.gz infinity-for-reddit-50a357267985b14894e275ef515778f33b3023af.tar.bz2 infinity-for-reddit-50a357267985b14894e275ef515778f33b3023af.tar.lz infinity-for-reddit-50a357267985b14894e275ef515778f33b3023af.tar.xz infinity-for-reddit-50a357267985b14894e275ef515778f33b3023af.tar.zst infinity-for-reddit-50a357267985b14894e275ef515778f33b3023af.zip |
No need to pass a HashSet to hide read posts.
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java | 4 | ||||
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java | 23 |
2 files changed, 14 insertions, 13 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java index 768d3672..307bbd52 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java @@ -49,6 +49,7 @@ import androidx.transition.TransitionManager; import com.bumptech.glide.Glide; import com.bumptech.glide.RequestManager; +import com.google.common.collect.Lists; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; @@ -871,6 +872,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean(accountName + SharedPreferencesUtils.NSFW_BASE, false); } this.readPosts = readPostList; + currentlyReadPostIds.addAll(Lists.transform(readPosts, ReadPost::getId)); initializeAndBindPostViewModel(accessToken); } }); @@ -1494,7 +1496,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { mAdapter.prepareToHideReadPosts(); refreshAdapter(); }*/ - mPostViewModel.setCurrentlyReadPostIds(currentlyReadPostIds); + mPostViewModel.hideReadPosts(); } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java index 09cfc0f5..4f9a3890 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java @@ -17,7 +17,6 @@ import androidx.paging.PagingData; import androidx.paging.PagingDataTransforms; import androidx.paging.PagingLiveData; -import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.concurrent.Executor; @@ -42,7 +41,7 @@ public class PostViewModel extends ViewModel { private PostFilter postFilter; private String userWhere; private List<ReadPost> readPostList; - private MutableLiveData<Set<String>> currentlyReadPostIdsLiveData = new MutableLiveData<>(); + private MutableLiveData<Boolean> currentlyReadPostIdsLiveData = new MutableLiveData<>(); private LiveData<PagingData<Post>> posts; private LiveData<PagingData<Post>> postsWithReadPostsHidden; @@ -85,9 +84,9 @@ public class PostViewModel extends ViewModel { posts, postPagingData -> PagingDataTransforms.filter( postPagingData, executor, - post -> !currentlyReadPostIds.contains(post.getId())))), ViewModelKt.getViewModelScope(this)); + post -> !post.isRead() || !currentlyReadPostIdsLiveData.getValue()))), ViewModelKt.getViewModelScope(this)); - currentlyReadPostIdsLiveData.setValue(new HashSet<>()); + currentlyReadPostIdsLiveData.setValue(false); } public PostViewModel(Executor executor, Retrofit retrofit, String accessToken, String accountName, @@ -126,9 +125,9 @@ public class PostViewModel extends ViewModel { posts, postPagingData -> PagingDataTransforms.filter( postPagingData, executor, - post -> !currentlyReadPostIds.contains(post.getId())))), ViewModelKt.getViewModelScope(this)); + post -> !post.isRead() || !currentlyReadPostIdsLiveData.getValue()))), ViewModelKt.getViewModelScope(this)); - currentlyReadPostIdsLiveData.setValue(new HashSet<>()); + currentlyReadPostIdsLiveData.setValue(false); } public PostViewModel(Executor executor, Retrofit retrofit, String accessToken, String accountName, @@ -169,9 +168,9 @@ public class PostViewModel extends ViewModel { posts, postPagingData -> PagingDataTransforms.filter( postPagingData, executor, - post -> !currentlyReadPostIds.contains(post.getId())))), ViewModelKt.getViewModelScope(this)); + post -> !post.isRead() || !currentlyReadPostIdsLiveData.getValue()))), ViewModelKt.getViewModelScope(this)); - currentlyReadPostIdsLiveData.setValue(new HashSet<>()); + currentlyReadPostIdsLiveData.setValue(false); } public PostViewModel(Executor executor, Retrofit retrofit, String accessToken, String accountName, @@ -212,17 +211,17 @@ public class PostViewModel extends ViewModel { posts, postPagingData -> PagingDataTransforms.filter( postPagingData, executor, - post -> !currentlyReadPostIds.contains(post.getId())))), ViewModelKt.getViewModelScope(this)); + post -> !post.isRead() || !currentlyReadPostIdsLiveData.getValue()))), ViewModelKt.getViewModelScope(this)); - currentlyReadPostIdsLiveData.setValue(new HashSet<>()); + currentlyReadPostIdsLiveData.setValue(false); } public LiveData<PagingData<Post>> getPosts() { return postsWithReadPostsHidden; } - public void setCurrentlyReadPostIds(Set<String> currentlyReadPostIds) { - currentlyReadPostIdsLiveData.setValue(currentlyReadPostIds); + public void hideReadPosts() { + currentlyReadPostIdsLiveData.setValue(true); } public PostPagingSource returnPagingSoruce() { |