Fix posts not marked as read in ViewPostDetailActivity if swipe between posts is enabled.

This commit is contained in:
Alex Ning 2021-09-22 21:02:31 +08:00
parent cc9952525b
commit 5f4ecbbe88
3 changed files with 21 additions and 8 deletions

View File

@ -314,14 +314,6 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
if (savedInstanceState == null) { if (savedInstanceState == null) {
viewPager2.setCurrentItem(getIntent().getIntExtra(EXTRA_POST_LIST_POSITION, 0), false); viewPager2.setCurrentItem(getIntent().getIntExtra(EXTRA_POST_LIST_POSITION, 0), false);
} }
if (mSharedPreferences.getBoolean(mAccountName + SharedPreferencesUtils.MARK_POSTS_AS_READ_BASE, false)) {
viewPager2.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
@Override
public void onPageSelected(int position) {
//EventBus.getDefault().post(new (getClass().getName()));
}
});
}
searchPanelMaterialCardView.setOnClickListener(null); searchPanelMaterialCardView.setOnClickListener(null);

View File

@ -18,6 +18,7 @@ import android.os.Bundle;
import android.os.CountDownTimer; import android.os.CountDownTimer;
import android.os.Handler; import android.os.Handler;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log;
import android.view.HapticFeedbackConstants; import android.view.HapticFeedbackConstants;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -1578,6 +1579,9 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
post.setSpoiler(event.post.isSpoiler()); post.setSpoiler(event.post.isSpoiler());
post.setFlair(event.post.getFlair()); post.setFlair(event.post.getFlair());
post.setSaved(event.post.isSaved()); post.setSaved(event.post.isSaved());
if (event.post.isRead()) {
post.markAsRead(true);
}
mAdapter.notifyItemChanged(event.positionInList); mAdapter.notifyItemChanged(event.positionInList);
} }
} }

View File

@ -106,6 +106,7 @@ import ml.docilealligator.infinityforreddit.post.FetchRemovedPost;
import ml.docilealligator.infinityforreddit.post.HidePost; import ml.docilealligator.infinityforreddit.post.HidePost;
import ml.docilealligator.infinityforreddit.post.ParsePost; import ml.docilealligator.infinityforreddit.post.ParsePost;
import ml.docilealligator.infinityforreddit.post.Post; import ml.docilealligator.infinityforreddit.post.Post;
import ml.docilealligator.infinityforreddit.readpost.InsertReadPost;
import ml.docilealligator.infinityforreddit.subreddit.FetchSubredditData; import ml.docilealligator.infinityforreddit.subreddit.FetchSubredditData;
import ml.docilealligator.infinityforreddit.subreddit.SubredditData; import ml.docilealligator.infinityforreddit.subreddit.SubredditData;
import ml.docilealligator.infinityforreddit.utils.APIUtils; import ml.docilealligator.infinityforreddit.utils.APIUtils;
@ -170,6 +171,9 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
@Named("post_details") @Named("post_details")
SharedPreferences mPostDetailsSharedPreferences; SharedPreferences mPostDetailsSharedPreferences;
@Inject @Inject
@Named("post_history")
SharedPreferences mPostHistorySharedPreferences;
@Inject
CustomThemeWrapper mCustomThemeWrapper; CustomThemeWrapper mCustomThemeWrapper;
@Inject @Inject
ExoCreator mExoCreator; ExoCreator mExoCreator;
@ -219,6 +223,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
private boolean mSwipeUpToHideFab; private boolean mSwipeUpToHideFab;
private boolean mExpandChildren; private boolean mExpandChildren;
private boolean mSeparatePostAndComments = false; private boolean mSeparatePostAndComments = false;
private boolean mMarkPostsAsRead;
private int mWindowWidth; private int mWindowWidth;
private ConcatAdapter mConcatAdapter; private ConcatAdapter mConcatAdapter;
private PostDetailRecyclerViewAdapter mPostAdapter; private PostDetailRecyclerViewAdapter mPostAdapter;
@ -292,6 +297,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
mLockFab = mSharedPreferences.getBoolean(SharedPreferencesUtils.LOCK_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON, false); mLockFab = mSharedPreferences.getBoolean(SharedPreferencesUtils.LOCK_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON, false);
mSwipeUpToHideFab = mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_UP_TO_HIDE_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON, false); mSwipeUpToHideFab = mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_UP_TO_HIDE_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON, false);
mExpandChildren = !mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_TOP_LEVEL_COMMENTS_FIRST, false); mExpandChildren = !mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_TOP_LEVEL_COMMENTS_FIRST, false);
mMarkPostsAsRead = mPostHistorySharedPreferences.getBoolean(mAccountName + SharedPreferencesUtils.MARK_POSTS_AS_READ_BASE, false);
if (savedInstanceState == null) { if (savedInstanceState == null) {
mRespectSubredditRecommendedSortType = mSharedPreferences.getBoolean(SharedPreferencesUtils.RESPECT_SUBREDDIT_RECOMMENDED_COMMENT_SORT_TYPE, false); mRespectSubredditRecommendedSortType = mSharedPreferences.getBoolean(SharedPreferencesUtils.RESPECT_SUBREDDIT_RECOMMENDED_COMMENT_SORT_TYPE, false);
viewPostDetailFragmentId = System.currentTimeMillis(); viewPostDetailFragmentId = System.currentTimeMillis();
@ -1087,12 +1093,21 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
} }
} }
private void tryMarkingPostAsRead() {
if (mMarkPostsAsRead && !mPost.isRead()) {
mPost.markAsRead(true);
InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, mAccountName, mPost.getId());
EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition));
}
}
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
if (mRecyclerView != null) { if (mRecyclerView != null) {
mRecyclerView.onWindowVisibilityChanged(View.VISIBLE); mRecyclerView.onWindowVisibilityChanged(View.VISIBLE);
} }
tryMarkingPostAsRead();
} }
@Override @Override
@ -1173,6 +1188,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
@Override @Override
public void onParsePostSuccess(Post post) { public void onParsePostSuccess(Post post) {
mPost = post; mPost = post;
tryMarkingPostAsRead();
setupMenu(); setupMenu();
@ -1758,6 +1774,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
@Override @Override
public void fetchSuccess(Post post) { public void fetchSuccess(Post post) {
mPost = post; mPost = post;
tryMarkingPostAsRead();
if (mPostAdapter != null) { if (mPostAdapter != null) {
mPostAdapter.updatePost(post); mPostAdapter.updatePost(post);
} }