Fix post not updating in PostFragment after voting it in ViewPostDetailFragment.

This commit is contained in:
Alex Ning 2021-04-20 23:58:46 +08:00
parent 83dd21450f
commit 9ad6d705e6
4 changed files with 24 additions and 23 deletions

View File

@ -113,7 +113,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
private String mAccessToken;
private String mAccountName;
private long postFragmentId;
private int postListPosition = -1;
private int postListPosition;
private int orientation;
private boolean mVolumeKeysNavigateComments;
private boolean isNsfwSubreddit;
@ -172,6 +172,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
EventBus.getDefault().post(new NeedForPostListFromPostFragmentEvent(postFragmentId));
}
postListPosition = getIntent().getIntExtra(EXTRA_POST_LIST_POSITION, -1);
isNsfwSubreddit = getIntent().getBooleanExtra(EXTRA_IS_NSFW_SUBREDDIT, false);
fragmentManager = getSupportFragmentManager();
@ -519,7 +520,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
bundle.putString(ViewPostDetailFragment.EXTRA_POST_ID, getIntent().getStringExtra(EXTRA_POST_ID));
} else {
bundle.putParcelable(ViewPostDetailFragment.EXTRA_POST_DATA, post);
bundle.putInt(ViewPostDetailFragment.EXTRA_POST_LIST_POSITION, position);
bundle.putInt(ViewPostDetailFragment.EXTRA_POST_LIST_POSITION, postListPosition);
}
bundle.putString(ViewPostDetailFragment.EXTRA_SINGLE_COMMENT_ID, getIntent().getStringExtra(EXTRA_SINGLE_COMMENT_ID));
bundle.putString(ViewPostDetailFragment.EXTRA_MESSAGE_FULLNAME, getIntent().getStringExtra(EXTRA_MESSAGE_FULLNAME));

View File

@ -90,7 +90,7 @@ import ml.docilealligator.infinityforreddit.asynctasks.LoadUserData;
import ml.docilealligator.infinityforreddit.bottomsheetfragments.ShareLinkBottomSheetFragment;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.customviews.AspectRatioGifImageView;
import ml.docilealligator.infinityforreddit.events.PostUpdateEventToDetailActivity;
import ml.docilealligator.infinityforreddit.events.PostUpdateEventToPostDetailFragment;
import ml.docilealligator.infinityforreddit.fragments.PostFragment;
import ml.docilealligator.infinityforreddit.post.Post;
import ml.docilealligator.infinityforreddit.post.PostDataSource;
@ -2393,7 +2393,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
}
}
EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post));
EventBus.getDefault().post(new PostUpdateEventToPostDetailFragment(post));
}
@Override
@ -2409,7 +2409,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
scoreTextView.setTextColor(previousScoreTextViewColor);
}
EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post));
EventBus.getDefault().post(new PostUpdateEventToPostDetailFragment(post));
}
}, post.getFullName(), newVoteType, getBindingAdapterPosition());
}
@ -2489,7 +2489,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
}
}
EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post));
EventBus.getDefault().post(new PostUpdateEventToPostDetailFragment(post));
}
@Override
@ -2505,7 +2505,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
scoreTextView.setTextColor(previousScoreTextViewColor);
}
EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post));
EventBus.getDefault().post(new PostUpdateEventToPostDetailFragment(post));
}
}, post.getFullName(), newVoteType, getBindingAdapterPosition());
}
@ -2534,7 +2534,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
}
Toast.makeText(mActivity, R.string.post_unsaved_success, Toast.LENGTH_SHORT).show();
EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post));
EventBus.getDefault().post(new PostUpdateEventToPostDetailFragment(post));
}
@Override
@ -2544,7 +2544,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
}
Toast.makeText(mActivity, R.string.post_unsaved_failed, Toast.LENGTH_SHORT).show();
EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post));
EventBus.getDefault().post(new PostUpdateEventToPostDetailFragment(post));
}
});
} else {
@ -2558,7 +2558,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
}
Toast.makeText(mActivity, R.string.post_saved_success, Toast.LENGTH_SHORT).show();
EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post));
EventBus.getDefault().post(new PostUpdateEventToPostDetailFragment(post));
}
@Override
@ -2568,7 +2568,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
}
Toast.makeText(mActivity, R.string.post_saved_failed, Toast.LENGTH_SHORT).show();
EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post));
EventBus.getDefault().post(new PostUpdateEventToPostDetailFragment(post));
}
});
}
@ -3371,7 +3371,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
}
}
EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post));
EventBus.getDefault().post(new PostUpdateEventToPostDetailFragment(post));
}
@Override
@ -3387,7 +3387,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
scoreTextView.setTextColor(previousScoreTextViewColor);
}
EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post));
EventBus.getDefault().post(new PostUpdateEventToPostDetailFragment(post));
}
}, post.getFullName(), newVoteType, getBindingAdapterPosition());
}
@ -3468,7 +3468,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
}
}
EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post));
EventBus.getDefault().post(new PostUpdateEventToPostDetailFragment(post));
}
@Override
@ -3484,7 +3484,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
scoreTextView.setTextColor(previousScoreTextViewColor);
}
EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post));
EventBus.getDefault().post(new PostUpdateEventToPostDetailFragment(post));
}
}, post.getFullName(), newVoteType, getBindingAdapterPosition());
}
@ -3513,7 +3513,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
}
Toast.makeText(mActivity, R.string.post_unsaved_success, Toast.LENGTH_SHORT).show();
EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post));
EventBus.getDefault().post(new PostUpdateEventToPostDetailFragment(post));
}
@Override
@ -3523,7 +3523,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
}
Toast.makeText(mActivity, R.string.post_unsaved_failed, Toast.LENGTH_SHORT).show();
EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post));
EventBus.getDefault().post(new PostUpdateEventToPostDetailFragment(post));
}
});
} else {
@ -3537,7 +3537,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
}
Toast.makeText(mActivity, R.string.post_saved_success, Toast.LENGTH_SHORT).show();
EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post));
EventBus.getDefault().post(new PostUpdateEventToPostDetailFragment(post));
}
@Override
@ -3547,7 +3547,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
}
Toast.makeText(mActivity, R.string.post_saved_failed, Toast.LENGTH_SHORT).show();
EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post));
EventBus.getDefault().post(new PostUpdateEventToPostDetailFragment(post));
}
});
}

View File

@ -2,10 +2,10 @@ package ml.docilealligator.infinityforreddit.events;
import ml.docilealligator.infinityforreddit.post.Post;
public class PostUpdateEventToDetailActivity {
public class PostUpdateEventToPostDetailFragment {
public final Post post;
public PostUpdateEventToDetailActivity(Post post) {
public PostUpdateEventToPostDetailFragment(Post post) {
this.post = post;
}
}

View File

@ -89,7 +89,7 @@ import ml.docilealligator.infinityforreddit.events.ChangeNSFWBlurEvent;
import ml.docilealligator.infinityforreddit.events.ChangeNetworkStatusEvent;
import ml.docilealligator.infinityforreddit.events.ChangeSpoilerBlurEvent;
import ml.docilealligator.infinityforreddit.events.FlairSelectedEvent;
import ml.docilealligator.infinityforreddit.events.PostUpdateEventToDetailActivity;
import ml.docilealligator.infinityforreddit.events.PostUpdateEventToPostDetailFragment;
import ml.docilealligator.infinityforreddit.events.PostUpdateEventToPostList;
import ml.docilealligator.infinityforreddit.message.ReadMessage;
import ml.docilealligator.infinityforreddit.post.FetchPost;
@ -1682,7 +1682,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
}
@Subscribe
public void onPostUpdateEvent(PostUpdateEventToDetailActivity event) {
public void onPostUpdateEvent(PostUpdateEventToPostDetailFragment event) {
if (mPost.getId().equals(event.post.getId())) {
mPost.setVoteType(event.post.getVoteType());
mPost.setSaved(event.post.isSaved());