mirror of
https://github.com/Docile-Alligator/Infinity-For-Reddit.git
synced 2026-08-18 11:03:26 +00:00
Fix wrong posts showing when swiping between posts.
This commit is contained in:
@ -602,6 +602,10 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
|
||||
);
|
||||
}
|
||||
|
||||
public void updatePostFromEvent(Post post, int postListPosition) {
|
||||
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onAccountSwitchEvent(SwitchAccountEvent event) {
|
||||
if (!getClass().getName().equals(event.excludeActivityClassName)) {
|
||||
|
||||
@ -1381,7 +1381,9 @@ public class ViewPostDetailFragmentNew extends Fragment implements FragmentCommu
|
||||
|
||||
@Subscribe
|
||||
public void onPostUpdateEvent(PostUpdateEventToPostList event) {
|
||||
viewPostDetailFragmentViewModel.setPost(event.post);
|
||||
if (viewPostDetailFragmentViewModel.updatePostFromEvent(event.post)) {
|
||||
mActivity.updatePostFromEvent(event.post, postListPosition);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -18,7 +18,6 @@ import ml.docilealligator.infinityforreddit.post.ParsePost
|
||||
import ml.docilealligator.infinityforreddit.post.Post
|
||||
import ml.docilealligator.infinityforreddit.post.PostType
|
||||
import ml.docilealligator.infinityforreddit.postfilter.PostFilter
|
||||
import ml.docilealligator.infinityforreddit.readpost.NullReadPostsList
|
||||
import ml.docilealligator.infinityforreddit.readpost.ReadPost
|
||||
import ml.docilealligator.infinityforreddit.readpost.ReadPostType
|
||||
import ml.docilealligator.infinityforreddit.readpost.ReadPostsListInterface
|
||||
@ -55,6 +54,36 @@ class ViewPostDetailActivityViewModel(
|
||||
return posts?.getOrNull(index)
|
||||
}
|
||||
|
||||
fun updatePostFromEvent(post: Post, postListPosition: Int) {
|
||||
posts?.let {
|
||||
if (postListPosition in it.indices && it[postListPosition].id == post.id) {
|
||||
post.title = post.title
|
||||
post.selfText = post.selfText
|
||||
post.selfTextPlain = post.selfTextPlain
|
||||
post.selfTextPlainTrimmed = post.selfTextPlainTrimmed
|
||||
post.mediaMetadataMap = post.mediaMetadataMap
|
||||
post.voteType = post.voteType
|
||||
post.score = post.score
|
||||
post.nComments = post.nComments
|
||||
post.isNSFW = post.isNSFW
|
||||
post.isHidden = post.isHidden
|
||||
post.isSpoiler = post.isSpoiler
|
||||
post.flair = post.flair
|
||||
post.isSaved = post.isSaved
|
||||
post.setIsStickied(post.isStickied)
|
||||
post.isApproved = post.isApproved
|
||||
post.approvedAtUTC = post.approvedAtUTC
|
||||
post.approvedBy = post.approvedBy
|
||||
post.setRemoved(post.isRemoved, post.isSpam)
|
||||
post.setIsLocked(post.isLocked)
|
||||
post.setIsModerator(post.isModerator)
|
||||
if (post.isRead) {
|
||||
post.markAsRead()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun loadAuthorImages(comments: MutableList<Comment?>, loadIconListener: UserProfileImagesBatchLoader.LoadIconListener) {
|
||||
loader.loadAuthorImagesInComments(accessToken, comments, loadIconListener)
|
||||
}
|
||||
|
||||
@ -144,6 +144,17 @@ class ViewPostDetailFragmentViewModelNew(
|
||||
)
|
||||
}
|
||||
|
||||
fun updatePostFromEvent(post: Post): Boolean {
|
||||
if (_dataState.value.post?.id == post.id) {
|
||||
_dataState.value = _dataState.value.copy(
|
||||
post = post
|
||||
)
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
fun getPost(): Post? {
|
||||
return _dataState.value.post
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user