aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java23
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() {