mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-30 21:07:11 +01:00
No need to pass a HashSet to hide read posts.
This commit is contained in:
parent
1d73231a82
commit
50a3572679
@ -49,6 +49,7 @@ import androidx.transition.TransitionManager;
|
|||||||
|
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
import com.bumptech.glide.RequestManager;
|
import com.bumptech.glide.RequestManager;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import org.greenrobot.eventbus.EventBus;
|
import org.greenrobot.eventbus.EventBus;
|
||||||
import org.greenrobot.eventbus.Subscribe;
|
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);
|
postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean(accountName + SharedPreferencesUtils.NSFW_BASE, false);
|
||||||
}
|
}
|
||||||
this.readPosts = readPostList;
|
this.readPosts = readPostList;
|
||||||
|
currentlyReadPostIds.addAll(Lists.transform(readPosts, ReadPost::getId));
|
||||||
initializeAndBindPostViewModel(accessToken);
|
initializeAndBindPostViewModel(accessToken);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -1494,7 +1496,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
mAdapter.prepareToHideReadPosts();
|
mAdapter.prepareToHideReadPosts();
|
||||||
refreshAdapter();
|
refreshAdapter();
|
||||||
}*/
|
}*/
|
||||||
mPostViewModel.setCurrentlyReadPostIds(currentlyReadPostIds);
|
mPostViewModel.hideReadPosts();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -17,7 +17,6 @@ import androidx.paging.PagingData;
|
|||||||
import androidx.paging.PagingDataTransforms;
|
import androidx.paging.PagingDataTransforms;
|
||||||
import androidx.paging.PagingLiveData;
|
import androidx.paging.PagingLiveData;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
@ -42,7 +41,7 @@ public class PostViewModel extends ViewModel {
|
|||||||
private PostFilter postFilter;
|
private PostFilter postFilter;
|
||||||
private String userWhere;
|
private String userWhere;
|
||||||
private List<ReadPost> readPostList;
|
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>> posts;
|
||||||
private LiveData<PagingData<Post>> postsWithReadPostsHidden;
|
private LiveData<PagingData<Post>> postsWithReadPostsHidden;
|
||||||
@ -85,9 +84,9 @@ public class PostViewModel extends ViewModel {
|
|||||||
posts,
|
posts,
|
||||||
postPagingData -> PagingDataTransforms.filter(
|
postPagingData -> PagingDataTransforms.filter(
|
||||||
postPagingData, executor,
|
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,
|
public PostViewModel(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||||
@ -126,9 +125,9 @@ public class PostViewModel extends ViewModel {
|
|||||||
posts,
|
posts,
|
||||||
postPagingData -> PagingDataTransforms.filter(
|
postPagingData -> PagingDataTransforms.filter(
|
||||||
postPagingData, executor,
|
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,
|
public PostViewModel(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||||
@ -169,9 +168,9 @@ public class PostViewModel extends ViewModel {
|
|||||||
posts,
|
posts,
|
||||||
postPagingData -> PagingDataTransforms.filter(
|
postPagingData -> PagingDataTransforms.filter(
|
||||||
postPagingData, executor,
|
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,
|
public PostViewModel(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||||
@ -212,17 +211,17 @@ public class PostViewModel extends ViewModel {
|
|||||||
posts,
|
posts,
|
||||||
postPagingData -> PagingDataTransforms.filter(
|
postPagingData -> PagingDataTransforms.filter(
|
||||||
postPagingData, executor,
|
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() {
|
public LiveData<PagingData<Post>> getPosts() {
|
||||||
return postsWithReadPostsHidden;
|
return postsWithReadPostsHidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCurrentlyReadPostIds(Set<String> currentlyReadPostIds) {
|
public void hideReadPosts() {
|
||||||
currentlyReadPostIdsLiveData.setValue(currentlyReadPostIds);
|
currentlyReadPostIdsLiveData.setValue(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PostPagingSource returnPagingSoruce() {
|
public PostPagingSource returnPagingSoruce() {
|
||||||
|
Loading…
Reference in New Issue
Block a user