Skip to content

Commit 4a9b0a6

Browse files
New option in CommentMoreBottomSheetFragment: Jump to Top-Level Comment. Fix the color of @drawable/ic_keyboard_double_arrow_up_day_night_24dp. Fix issues in CommentsRecyclerViewAdapter.getNextParentCommentPosition and CommentsRecyclerViewAdapter.getPreviousParentCommentPosition.
1 parent 23614c2 commit 4a9b0a6

File tree

7 files changed

+61
-4
lines changed

7 files changed

+61
-4
lines changed

app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,15 @@ public void fetchMorePosts(boolean changePage) {
737737
}
738738
}
739739

740+
public void scrollToTopLevelComment(int position) {
741+
if (mSectionsPagerAdapter != null) {
742+
ViewPostDetailFragment fragment = mSectionsPagerAdapter.getCurrentFragment();
743+
if (fragment != null) {
744+
fragment.scrollToTopLevelComment(position);
745+
}
746+
}
747+
}
748+
740749
@Subscribe
741750
public void onAccountSwitchEvent(SwitchAccountEvent event) {
742751
if (!getClass().getName().equals(event.excludeActivityClassName)) {

app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,7 @@ public int getNextParentCommentPosition(int currentPosition) {
11421142
if (mIsSingleCommentThreadMode) {
11431143
for (int i = currentPosition + 1; i - 1 < mVisibleComments.size() && i - 1 >= 0; i++) {
11441144
if (mVisibleComments.get(i - 1).getDepth() == 0) {
1145-
return i;
1145+
return i + 1;
11461146
}
11471147
}
11481148
} else {
@@ -1161,7 +1161,7 @@ public int getPreviousParentCommentPosition(int currentPosition) {
11611161
if (mIsSingleCommentThreadMode) {
11621162
for (int i = currentPosition - 1; i - 1 >= 0; i--) {
11631163
if (mVisibleComments.get(i - 1).getDepth() == 0) {
1164-
return i;
1164+
return i + 1;
11651165
}
11661166
}
11671167
} else {

app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CommentMoreBottomSheetFragment.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,21 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
197197
Intent intent = new Intent(activity, CommentFilterPreferenceActivity.class);
198198
intent.putExtra(CommentFilterPreferenceActivity.EXTRA_COMMENT, comment);
199199
activity.startActivity(intent);
200+
201+
dismiss();
200202
});
201203

204+
if (comment.getDepth() > 0 && activity instanceof ViewPostDetailActivity) {
205+
binding.jumpToTopLevelCommentCommentMoreBottomSheetFragment.setVisibility(View.VISIBLE);
206+
binding.jumpToTopLevelCommentCommentMoreBottomSheetFragment.setOnClickListener(view -> {
207+
if (activity instanceof ViewPostDetailActivity) {
208+
((ViewPostDetailActivity) activity).scrollToTopLevelComment(bundle.getInt(EXTRA_POSITION));
209+
}
210+
211+
dismiss();
212+
});
213+
}
214+
202215
if (activity.typeface != null) {
203216
Utils.setFontToAllTextViews(binding.getRoot(), activity.typeface);
204217
}

app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,6 +1861,20 @@ public void scrollToPreviousParentComment() {
18611861
}
18621862
}
18631863

1864+
public void scrollToTopLevelComment(int position) {
1865+
RecyclerView chooseYourView = mCommentsRecyclerView == null ? binding.postDetailRecyclerViewViewPostDetailFragment : mCommentsRecyclerView;
1866+
if (mCommentsAdapter != null && chooseYourView != null) {
1867+
int viewPosition = mCommentsRecyclerView == null ? (!isSingleCommentThreadMode ? position + 1 : position + 2) : (!isSingleCommentThreadMode ? position : position + 1);
1868+
int previousParentPosition = mCommentsAdapter.getPreviousParentCommentPosition(viewPosition);
1869+
if (previousParentPosition < 0) {
1870+
return;
1871+
}
1872+
mSmoothScroller.setTargetPosition(mCommentsRecyclerView == null && !isSingleCommentThreadMode ? previousParentPosition + 1 : previousParentPosition);
1873+
mIsSmoothScrolling = true;
1874+
chooseYourView.getLayoutManager().startSmoothScroll(mSmoothScroller);
1875+
}
1876+
}
1877+
18641878
public void delayTransition() {
18651879
TransitionManager.beginDelayedTransition((mCommentsRecyclerView == null ? binding.postDetailRecyclerViewViewPostDetailFragment : mCommentsRecyclerView), new AutoTransition());
18661880
}

app/src/main/res/drawable/ic_keyboard_double_arrow_up_day_night_24dp.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
android:width="24dp"
33
android:height="24dp"
44
android:viewportWidth="24"
5-
android:viewportHeight="24"
6-
android:tint="?attr/colorControlNormal">
5+
android:viewportHeight="24">
76
<path
87
android:fillColor="@android:color/black"
98
android:pathData="M6,17.59l1.41,1.41l4.59,-4.58l4.59,4.58l1.41,-1.41l-6,-6z"/>

app/src/main/res/layout/fragment_comment_more_bottom_sheet.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,26 @@
200200
android:visibility="gone"
201201
app:drawableStartCompat="@drawable/ic_notifications_day_night_24dp" />
202202

203+
<TextView
204+
android:id="@+id/jump_to_top_level_comment_comment_more_bottom_sheet_fragment"
205+
android:layout_width="match_parent"
206+
android:layout_height="wrap_content"
207+
android:background="?attr/selectableItemBackground"
208+
android:clickable="true"
209+
android:drawablePadding="48dp"
210+
android:focusable="true"
211+
android:gravity="center_vertical"
212+
android:paddingStart="32dp"
213+
android:paddingTop="16dp"
214+
android:paddingEnd="32dp"
215+
android:paddingBottom="16dp"
216+
android:text="@string/jump_to_top_level_comment"
217+
android:textColor="?attr/primaryTextColor"
218+
android:textSize="?attr/font_default"
219+
android:fontFamily="?attr/font_family"
220+
android:visibility="gone"
221+
app:drawableStartCompat="@drawable/ic_keyboard_double_arrow_up_day_night_24dp" />
222+
203223
</LinearLayout>
204224

205225
</androidx.core.widget.NestedScrollView>

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,4 +1536,6 @@
15361536
<string name="proxy_http">HTTP</string>
15371537
<string name="proxy_socks">SOCKS</string>
15381538
<string name="proxy_direct">Direct</string>
1539+
1540+
<string name="jump_to_top_level_comment">Jump to Top-Level Comment</string>
15391541
</resources>

0 commit comments

Comments
 (0)