aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2021-09-22 13:02:31 +0000
committerAlex Ning <chineseperson5@gmail.com>2021-09-22 13:02:31 +0000
commit5f4ecbbe881fcfda3e7c4ec69efbbc7d546fedca (patch)
treece4dba3da368c42dd6be97e70faf3317fa22e08b /app/src/main/java/ml
parentcc9952525b96c56c61f43477fbbcfa881694adec (diff)
downloadinfinity-for-reddit-5f4ecbbe881fcfda3e7c4ec69efbbc7d546fedca.tar
infinity-for-reddit-5f4ecbbe881fcfda3e7c4ec69efbbc7d546fedca.tar.gz
infinity-for-reddit-5f4ecbbe881fcfda3e7c4ec69efbbc7d546fedca.tar.bz2
infinity-for-reddit-5f4ecbbe881fcfda3e7c4ec69efbbc7d546fedca.tar.lz
infinity-for-reddit-5f4ecbbe881fcfda3e7c4ec69efbbc7d546fedca.tar.xz
infinity-for-reddit-5f4ecbbe881fcfda3e7c4ec69efbbc7d546fedca.tar.zst
infinity-for-reddit-5f4ecbbe881fcfda3e7c4ec69efbbc7d546fedca.zip
Fix posts not marked as read in ViewPostDetailActivity if swipe between posts is enabled.
Diffstat (limited to 'app/src/main/java/ml')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java17
3 files changed, 21 insertions, 8 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java
index 21d40979..ae3538b1 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java
@@ -314,14 +314,6 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
if (savedInstanceState == null) {
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);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
index 299505ec..9eac7f5f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
@@ -18,6 +18,7 @@ import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.util.DisplayMetrics;
+import android.util.Log;
import android.view.HapticFeedbackConstants;
import android.view.KeyEvent;
import android.view.LayoutInflater;
@@ -1578,6 +1579,9 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
post.setSpoiler(event.post.isSpoiler());
post.setFlair(event.post.getFlair());
post.setSaved(event.post.isSaved());
+ if (event.post.isRead()) {
+ post.markAsRead(true);
+ }
mAdapter.notifyItemChanged(event.positionInList);
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java
index 2b79125d..0fb79a49 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java
@@ -106,6 +106,7 @@ import ml.docilealligator.infinityforreddit.post.FetchRemovedPost;
import ml.docilealligator.infinityforreddit.post.HidePost;
import ml.docilealligator.infinityforreddit.post.ParsePost;
import ml.docilealligator.infinityforreddit.post.Post;
+import ml.docilealligator.infinityforreddit.readpost.InsertReadPost;
import ml.docilealligator.infinityforreddit.subreddit.FetchSubredditData;
import ml.docilealligator.infinityforreddit.subreddit.SubredditData;
import ml.docilealligator.infinityforreddit.utils.APIUtils;
@@ -170,6 +171,9 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
@Named("post_details")
SharedPreferences mPostDetailsSharedPreferences;
@Inject
+ @Named("post_history")
+ SharedPreferences mPostHistorySharedPreferences;
+ @Inject
CustomThemeWrapper mCustomThemeWrapper;
@Inject
ExoCreator mExoCreator;
@@ -219,6 +223,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
private boolean mSwipeUpToHideFab;
private boolean mExpandChildren;
private boolean mSeparatePostAndComments = false;
+ private boolean mMarkPostsAsRead;
private int mWindowWidth;
private ConcatAdapter mConcatAdapter;
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);
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);
+ mMarkPostsAsRead = mPostHistorySharedPreferences.getBoolean(mAccountName + SharedPreferencesUtils.MARK_POSTS_AS_READ_BASE, false);
if (savedInstanceState == null) {
mRespectSubredditRecommendedSortType = mSharedPreferences.getBoolean(SharedPreferencesUtils.RESPECT_SUBREDDIT_RECOMMENDED_COMMENT_SORT_TYPE, false);
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
public void onResume() {
super.onResume();
if (mRecyclerView != null) {
mRecyclerView.onWindowVisibilityChanged(View.VISIBLE);
}
+ tryMarkingPostAsRead();
}
@Override
@@ -1173,6 +1188,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
@Override
public void onParsePostSuccess(Post post) {
mPost = post;
+ tryMarkingPostAsRead();
setupMenu();
@@ -1758,6 +1774,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
@Override
public void fetchSuccess(Post post) {
mPost = post;
+ tryMarkingPostAsRead();
if (mPostAdapter != null) {
mPostAdapter.updatePost(post);
}