Skip to content

Commit 05824bf

Browse files
New toolbar options in ViewPostDetailActivity: Next Top-Level Comment and Previous Top-Level Comment.
1 parent bf74b20 commit 05824bf

File tree

3 files changed

+50
-26
lines changed

3 files changed

+50
-26
lines changed

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

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -250,24 +250,10 @@ protected void onCreate(Bundle savedInstanceState) {
250250
mVolumeKeysNavigateComments = mSharedPreferences.getBoolean(SharedPreferencesUtils.VOLUME_KEYS_NAVIGATE_COMMENTS, false);
251251

252252
binding.fabViewPostDetailActivity.setOnClickListener(view -> {
253-
if (mSectionsPagerAdapter != null) {
254-
ViewPostDetailFragment fragment = mSectionsPagerAdapter.getCurrentFragment();
255-
if (fragment != null) {
256-
fragment.scrollToNextParentComment();
257-
}
258-
}
253+
scrollToNextParentComment();
259254
});
260255

261-
binding.fabViewPostDetailActivity.setOnLongClickListener(view -> {
262-
if (mSectionsPagerAdapter != null) {
263-
ViewPostDetailFragment fragment = mSectionsPagerAdapter.getCurrentFragment();
264-
if (fragment != null) {
265-
fragment.scrollToPreviousParentComment();
266-
return true;
267-
}
268-
}
269-
return false;
270-
});
256+
binding.fabViewPostDetailActivity.setOnLongClickListener(view -> scrollToPreviousParentComment());
271257

272258
if (accountName.equals(Account.ANONYMOUS_ACCOUNT) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
273259
binding.searchTextInputEditTextViewPostDetailActivity.setImeOptions(binding.searchTextInputEditTextViewPostDetailActivity.getImeOptions() | EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING);
@@ -318,6 +304,27 @@ public void showSnackBar(int resId) {
318304
Snackbar.make(binding.getRoot(), resId, Snackbar.LENGTH_SHORT).show();
319305
}
320306

307+
public void scrollToNextParentComment() {
308+
if (mSectionsPagerAdapter != null) {
309+
ViewPostDetailFragment fragment = mSectionsPagerAdapter.getCurrentFragment();
310+
if (fragment != null) {
311+
fragment.scrollToNextParentComment();
312+
}
313+
}
314+
}
315+
316+
public boolean scrollToPreviousParentComment() {
317+
if (mSectionsPagerAdapter != null) {
318+
ViewPostDetailFragment fragment = mSectionsPagerAdapter.getCurrentFragment();
319+
if (fragment != null) {
320+
fragment.scrollToPreviousParentComment();
321+
return true;
322+
}
323+
}
324+
325+
return false;
326+
}
327+
321328
@Override
322329
public SharedPreferences getDefaultSharedPreferences() {
323330
return mSharedPreferences;
@@ -792,6 +799,12 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
792799
} else if (item.getItemId() == R.id.action_reset_fab_position_view_post_detail_activity) {
793800
binding.fabViewPostDetailActivity.resetCoordinates();
794801
return true;
802+
} else if (item.getItemId() == R.id.action_next_parent_comment_view_post_detail_activity) {
803+
scrollToNextParentComment();
804+
return true;
805+
} else if (item.getItemId() == R.id.action_previous_parent_comment_view_post_detail_activity) {
806+
scrollToPreviousParentComment();
807+
return true;
795808
}
796809
return false;
797810
}
@@ -858,16 +871,13 @@ protected void onDestroy() {
858871
@Override
859872
public boolean onKeyDown(int keyCode, KeyEvent event) {
860873
if (mVolumeKeysNavigateComments) {
861-
ViewPostDetailFragment fragment = mSectionsPagerAdapter.getCurrentFragment();
862-
if (fragment != null) {
863-
switch (keyCode) {
864-
case KeyEvent.KEYCODE_VOLUME_UP:
865-
fragment.scrollToPreviousParentComment();
866-
return true;
867-
case KeyEvent.KEYCODE_VOLUME_DOWN:
868-
fragment.scrollToNextParentComment();
869-
return true;
870-
}
874+
switch (keyCode) {
875+
case KeyEvent.KEYCODE_VOLUME_UP:
876+
scrollToPreviousParentComment();
877+
return true;
878+
case KeyEvent.KEYCODE_VOLUME_DOWN:
879+
scrollToNextParentComment();
880+
return true;
871881
}
872882
}
873883
return super.onKeyDown(keyCode, event);

app/src/main/res/menu/view_post_detail_activity.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,16 @@
66
android:orderInCategory="100"
77
android:title="@string/action_reset_fab_position"
88
app:showAsAction="never" />
9+
10+
<item
11+
android:id="@+id/action_next_parent_comment_view_post_detail_activity"
12+
android:orderInCategory="101"
13+
android:title="@string/action_next_parent_comment"
14+
app:showAsAction="never" />
15+
16+
<item
17+
android:id="@+id/action_previous_parent_comment_view_post_detail_activity"
18+
android:orderInCategory="102"
19+
android:title="@string/action_previous_parent_comment"
20+
app:showAsAction="never" />
921
</menu>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@
101101
<string name="action_reset_fab_position">Reset FAB position</string>
102102
<string name="action_download_all_gallery_media">Download All Gallery Media</string>
103103
<string name="action_download_all_imgur_album_media">Download All Imgur Album Media</string>
104+
<string name="action_next_parent_comment">Next Top-Level Comment</string>
105+
<string name="action_previous_parent_comment">Previous Top-Level Comment</string>
104106

105107
<string name="parse_json_response_error">Error occurred when parsing the JSON response</string>
106108
<string name="retrieve_token_error">Error Retrieving the token</string>

0 commit comments

Comments
 (0)