Don't hide read posts automatically in subreddit, user and search posts.

This commit is contained in:
Docile-Alligator 2025-09-23 17:31:11 -04:00
parent f896c974a0
commit 22db534c1d

View File

@ -51,7 +51,7 @@ public class PostViewModel extends ViewModel {
private PostFilter postFilter;
private String userWhere;
private ReadPostsListInterface readPostsList;
private final MutableLiveData<Boolean> currentlyReadPostIdsLiveData = new MutableLiveData<>();
private final MutableLiveData<Boolean> hideReadPostsValue = new MutableLiveData<>();
private final LiveData<PagingData<Post>> posts;
private final LiveData<PagingData<Post>> postsWithReadPostsHidden;
@ -91,14 +91,14 @@ public class PostViewModel extends ViewModel {
return PagingLiveData.cachedIn(PagingLiveData.getLiveData(pager), ViewModelKt.getViewModelScope(this));
});
postsWithReadPostsHidden = PagingLiveData.cachedIn(Transformations.switchMap(currentlyReadPostIdsLiveData,
postsWithReadPostsHidden = PagingLiveData.cachedIn(Transformations.switchMap(hideReadPostsValue,
currentlyReadPostIds -> Transformations.map(
posts,
postPagingData -> PagingDataTransforms.filter(
postPagingData, executor,
post -> !post.isRead() || !currentlyReadPostIdsLiveData.getValue()))), ViewModelKt.getViewModelScope(this));
post -> !post.isRead() || !hideReadPostsValue.getValue()))), ViewModelKt.getViewModelScope(this));
currentlyReadPostIdsLiveData.setValue(postHistorySharedPreferences != null
hideReadPostsValue.setValue(postHistorySharedPreferences != null
&& postHistorySharedPreferences.getBoolean((accountName.equals(Account.ANONYMOUS_ACCOUNT) ? "" : accountName) + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, false));
}
@ -132,15 +132,16 @@ public class PostViewModel extends ViewModel {
return PagingLiveData.cachedIn(PagingLiveData.getLiveData(pager), ViewModelKt.getViewModelScope(this));
});
postsWithReadPostsHidden = PagingLiveData.cachedIn(Transformations.switchMap(currentlyReadPostIdsLiveData,
postsWithReadPostsHidden = PagingLiveData.cachedIn(Transformations.switchMap(hideReadPostsValue,
currentlyReadPostIds -> Transformations.map(
posts,
postPagingData -> PagingDataTransforms.filter(
postPagingData, executor,
post -> !post.isRead() || !currentlyReadPostIdsLiveData.getValue()))), ViewModelKt.getViewModelScope(this));
post -> !post.isRead() || !hideReadPostsValue.getValue()))), ViewModelKt.getViewModelScope(this));
currentlyReadPostIdsLiveData.setValue(postHistorySharedPreferences != null
&& postHistorySharedPreferences.getBoolean((accountName.equals(Account.ANONYMOUS_ACCOUNT) ? "" : accountName) + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, false));
hideReadPostsValue.setValue(postHistorySharedPreferences != null
&& postHistorySharedPreferences.getBoolean((accountName.equals(Account.ANONYMOUS_ACCOUNT) ? "" : accountName) + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, false)
&& (postType != PostPagingSource.TYPE_SUBREDDIT || subredditName.equals("all") || subredditName.equals("popular")));
}
// PostPagingSource.TYPE_MULTI_REDDIT
@ -174,17 +175,18 @@ public class PostViewModel extends ViewModel {
return PagingLiveData.cachedIn(PagingLiveData.getLiveData(pager), ViewModelKt.getViewModelScope(this));
});
postsWithReadPostsHidden = PagingLiveData.cachedIn(Transformations.switchMap(currentlyReadPostIdsLiveData,
postsWithReadPostsHidden = PagingLiveData.cachedIn(Transformations.switchMap(hideReadPostsValue,
currentlyReadPostIds -> Transformations.map(
posts,
postPagingData -> PagingDataTransforms.filter(
postPagingData, executor,
post -> !post.isRead() || !currentlyReadPostIdsLiveData.getValue()))), ViewModelKt.getViewModelScope(this));
post -> !post.isRead() || !hideReadPostsValue.getValue()))), ViewModelKt.getViewModelScope(this));
currentlyReadPostIdsLiveData.setValue(postHistorySharedPreferences != null
hideReadPostsValue.setValue(postHistorySharedPreferences != null
&& postHistorySharedPreferences.getBoolean((accountName.equals(Account.ANONYMOUS_ACCOUNT) ? "" : accountName) + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, false));
}
// PostPagingSource.TYPE_USER
public PostViewModel(Executor executor, Retrofit retrofit, @Nullable String accessToken, @NonNull String accountName,
SharedPreferences sharedPreferences,
SharedPreferences postFeedScrolledPositionSharedPreferences,
@ -217,15 +219,16 @@ public class PostViewModel extends ViewModel {
return PagingLiveData.cachedIn(PagingLiveData.getLiveData(pager), ViewModelKt.getViewModelScope(this));
});
postsWithReadPostsHidden = PagingLiveData.cachedIn(Transformations.switchMap(currentlyReadPostIdsLiveData,
postsWithReadPostsHidden = PagingLiveData.cachedIn(Transformations.switchMap(hideReadPostsValue,
currentlyReadPostIds -> Transformations.map(
posts,
postPagingData -> PagingDataTransforms.filter(
postPagingData, executor,
post -> !post.isRead() || !currentlyReadPostIdsLiveData.getValue()))), ViewModelKt.getViewModelScope(this));
post -> !post.isRead() || !hideReadPostsValue.getValue()))), ViewModelKt.getViewModelScope(this));
currentlyReadPostIdsLiveData.setValue(postHistorySharedPreferences != null
&& postHistorySharedPreferences.getBoolean((accountName.equals(Account.ANONYMOUS_ACCOUNT) ? "" : accountName) + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, false));
hideReadPostsValue.setValue(false);
/*hideReadPostsValue.setValue(postHistorySharedPreferences != null
&& postHistorySharedPreferences.getBoolean((accountName.equals(Account.ANONYMOUS_ACCOUNT) ? "" : accountName) + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, false));*/
}
// postType == PostPagingSource.TYPE_SEARCH
@ -261,15 +264,16 @@ public class PostViewModel extends ViewModel {
return PagingLiveData.cachedIn(PagingLiveData.getLiveData(pager), ViewModelKt.getViewModelScope(this));
});
postsWithReadPostsHidden = PagingLiveData.cachedIn(Transformations.switchMap(currentlyReadPostIdsLiveData,
postsWithReadPostsHidden = PagingLiveData.cachedIn(Transformations.switchMap(hideReadPostsValue,
currentlyReadPostIds -> Transformations.map(
posts,
postPagingData -> PagingDataTransforms.filter(
postPagingData, executor,
post -> !post.isRead() || !currentlyReadPostIdsLiveData.getValue()))), ViewModelKt.getViewModelScope(this));
post -> !post.isRead() || !hideReadPostsValue.getValue()))), ViewModelKt.getViewModelScope(this));
currentlyReadPostIdsLiveData.setValue(postHistorySharedPreferences != null
&& postHistorySharedPreferences.getBoolean((accountName.equals(Account.ANONYMOUS_ACCOUNT) ? "" : accountName) + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, false));
hideReadPostsValue.setValue(false);
/*hideReadPostsValue.setValue(postHistorySharedPreferences != null
&& postHistorySharedPreferences.getBoolean((accountName.equals(Account.ANONYMOUS_ACCOUNT) ? "" : accountName) + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, false));*/
}
public LiveData<PagingData<Post>> getPosts() {
@ -277,7 +281,7 @@ public class PostViewModel extends ViewModel {
}
public void hideReadPosts() {
currentlyReadPostIdsLiveData.setValue(true);
hideReadPostsValue.setValue(true);
}
public PostPagingSource returnPagingSoruce() {