Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.quantumbadger.redreader.fragments.AccountListDialog;
import org.quantumbadger.redreader.fragments.ChangelogDialog;

import java.util.HashSet;
import java.util.Set;

public final class FeatureFlagHandler {
Expand Down Expand Up @@ -59,6 +60,7 @@ private enum FeatureFlag {
DEFAULT_PREF_VIDEO_PLAYBACK_CONTROLS("defaultPrefVideoPlaybackControls"),
DEFAULT_PREF_CUSTOM_TABS("defaultPrefCustomTabs"),
CROSSPOST_ORIGIN_MENU_ITEM("crosspostOriginMenuItem"),
COLLAPSE_THREAD_COMMENT_MENU_ITEM("collapseThreadCommentMenuItem"),
MAIN_MENU_RANDOM_REMOVED("mainMenuRandomRemoved");

@NonNull private final String id;
Expand Down Expand Up @@ -273,6 +275,28 @@ public static void handleUpgrade(@NonNull final Context context) {
.apply();
}

if(getAndSetFeatureFlag(prefs, FeatureFlag.COLLAPSE_THREAD_COMMENT_MENU_ITEM)
== FeatureFlagStatus.UPGRADE_NEEDED) {

Log.i(TAG, "Upgrading, add collapse thread to comment action menu.");

final Set<String> existingCommentActionMenuItems = new HashSet<>(
getStringSet(
R.string.pref_menus_comment_context_items_key,
R.array.pref_menus_comment_context_items_return,
context,
prefs));

existingCommentActionMenuItems.add("collapse_thread");

prefs.edit()
.putStringSet(
context.getString(
R.string.pref_menus_comment_context_items_key),
existingCommentActionMenuItems)
.apply();
}

if(getAndSetFeatureFlag(prefs, FeatureFlag.POST_TITLE_TAP_ACTION_FEATURE)
== FeatureFlagStatus.UPGRADE_NEEDED) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,7 @@ public enum CommentFlingAction {
COPY_URL,
USER_PROFILE,
COLLAPSE,
COLLAPSE_THREAD,
ACTION_MENU,
PROPERTIES,
BACK,
Expand All @@ -1143,7 +1144,7 @@ public static CommentFlingAction pref_behaviour_fling_comment_right() {
}

public enum CommentAction {
COLLAPSE, ACTION_MENU, NOTHING
COLLAPSE, COLLAPSE_THREAD, ACTION_MENU, NOTHING
}

public static CommentAction pref_behaviour_actions_comment_tap() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
import org.quantumbadger.redreader.views.liststatus.ErrorView;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.UUID;
Expand Down Expand Up @@ -195,6 +196,8 @@ public CommentListingFragment(
R.layout.floating_toolbar,
mOverlayFrame,
false);
mFloatingToolbar.setImportantForAccessibility(
View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);

if (PrefsUtility.pref_appearance_left_handed()) {
final FrameLayout.LayoutParams toolBarParams =
Expand Down Expand Up @@ -343,9 +346,82 @@ public void handleCommentVisibilityToggle(final RedditCommentView view) {
nowCollapsed
? R.string.accessibility_announcement_comment_collapsed
: R.string.accessibility_announcement_comment_expanded);

if(nowCollapsed && position != RecyclerView.NO_POSITION) {
focusNextComment(position);
}
}
}

public void handleThreadCollapse(final RedditCommentView view) {

final RedditChangeDataManager changeDataManager
= RedditChangeDataManager.getInstance(mUser);

RedditCommentListItem item = view.getComment();

if(!item.isComment()) {
return;
}

final HashSet<RedditCommentListItem> ancestors = new HashSet<>();

for(RedditCommentListItem ancestor = item;
ancestor != null;
ancestor = ancestor.getParent()) {
ancestors.add(ancestor);
}

final int initialItemCount = mCommentListingManager.getAdapter().getItemCount();
int threadPosition = -1;

for(int position = 0; position < initialItemCount; position++) {
final GroupedRecyclerViewAdapter.Item candidate
= mCommentListingManager.getItemAtPosition(position);

if(ancestors.contains(candidate)) {
item = (RedditCommentListItem)candidate;
threadPosition = position;
break;
}
}

if(threadPosition < 0) {
return;
}

if(item.asComment().isCollapsed(changeDataManager)) {
changeDataManager.markHidden(
TimestampUTC.now(),
item.asComment().getIdAndType(),
false);

mCommentListingManager.updateHiddenStatus();
return;
}

changeDataManager.markHidden(
TimestampUTC.now(),
item.asComment().getIdAndType(),
true);

mCommentListingManager.updateHiddenStatus();

final LinearLayoutManager layoutManager
= (LinearLayoutManager)mRecyclerView.getLayoutManager();
final int itemCount = layoutManager.getItemCount();

for(int position = threadPosition + 1; position < itemCount; position++) {
if(isTopLevelComment(position)) {
jumpToPosition(threadPosition, position);
return;
}
}

// Keep focus on a visible row when the invoking descendant disappears.
jumpToPosition(threadPosition);
}

@Override
public View getListingView() {
return mListingView;
Expand Down Expand Up @@ -406,6 +482,10 @@ public void onCommentClicked(final RedditCommentView view) {
handleCommentVisibilityToggle(view);
break;

case COLLAPSE_THREAD:
handleThreadCollapse(view);
break;

case ACTION_MENU: {
final RedditCommentListItem item = view.getComment();
if(item != null && item.isComment()) {
Expand Down Expand Up @@ -444,6 +524,10 @@ public void onCommentLongClicked(final RedditCommentView view) {
handleCommentVisibilityToggle(view);
break;

case COLLAPSE_THREAD:
handleThreadCollapse(view);
break;

case NOTHING:
break;
}
Expand Down Expand Up @@ -774,6 +858,27 @@ private void jumpToNextParent(final int startingPosition) {
}
}

private void focusNextComment(final int startingPosition) {
final LinearLayoutManager layoutManager
= (LinearLayoutManager)mRecyclerView.getLayoutManager();

for(
int pos = startingPosition + 1;
pos < layoutManager.getItemCount();
pos++
) {
final GroupedRecyclerViewAdapter.Item item
= mCommentListingManager.getItemAtPosition(pos);

if(item instanceof RedditCommentListItem
&& ((RedditCommentListItem)item).isComment()) {
mParentJumpCount++;
setAccessibilityFocusAfterLayout(pos, true);
return;
}
}
}

private boolean isTopLevelComment(final int position) {
final GroupedRecyclerViewAdapter.Item item
= mCommentListingManager.getItemAtPosition(position);
Expand All @@ -784,12 +889,19 @@ private boolean isTopLevelComment(final int position) {
}

private void jumpToPosition(final int position) {
jumpToPosition(position, position);
}

private void jumpToPosition(
final int scrollPosition,
final int focusPosition) {

final LinearLayoutManager layoutManager
= (LinearLayoutManager)mRecyclerView.getLayoutManager();

mParentJumpCount++;
layoutManager.scrollToPositionWithOffset(position, 0);
setAccessibilityFocusAfterLayout(position, true);
layoutManager.scrollToPositionWithOffset(scrollPosition, 0);
setAccessibilityFocusAfterLayout(focusPosition, true);
}

@SuppressLint("AccessibilityFocus")
Expand All @@ -807,13 +919,18 @@ private void setAccessibilityFocusAfterLayout(

final RecyclerView.ViewHolder holder
= mRecyclerView.findViewHolderForAdapterPosition(position);
final LinearLayoutManager layoutManager
= (LinearLayoutManager)mRecyclerView.getLayoutManager();

if(holder != null) {
if(holder != null
&& position >= layoutManager.findFirstVisibleItemPosition()
&& position <= layoutManager.findLastVisibleItemPosition()) {
holder.itemView.performAccessibilityAction(
AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS,
null);

} else if(allowRetry && mRecyclerView.hasPendingAdapterUpdates()) {
} else if(allowRetry && position >= 0 && position < layoutManager.getItemCount()) {
layoutManager.scrollToPosition(position);
setAccessibilityFocusAfterLayout(position, false);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public enum RedditCommentAction {
USER_PROFILE,
COMMENT_LINKS,
COLLAPSE,
COLLAPSE_THREAD,
EDIT,
DELETE,
EXTERNAL,
Expand Down Expand Up @@ -236,12 +237,28 @@ public static void showActionMenu(
}

if(itemPref.contains(RedditCommentAction.COLLAPSE) && commentListingFragment != null) {
final int titleRes = comment.isCollapsed(changeDataManager)
? R.string.action_expand_comment
: R.string.action_collapse;

menu.add(new RCVMenuItem(
activity,
R.string.action_collapse,
titleRes,
RedditCommentAction.COLLAPSE));
}

if(itemPref.contains(RedditCommentAction.COLLAPSE_THREAD)
&& commentListingFragment != null
&& commentView != null
&& !(commentView.getComment().getIndent() == 0
&& comment.isCollapsed(changeDataManager))) {

menu.add(new RCVMenuItem(
activity,
R.string.action_collapse_thread,
RedditCommentAction.COLLAPSE_THREAD));
}

if(itemPref.contains(RedditCommentAction.SHARE)) {
menu.add(new RCVMenuItem(
activity,
Expand Down Expand Up @@ -508,6 +525,11 @@ public static void onActionMenuItemSelected(
break;
}

case COLLAPSE_THREAD: {
commentListingFragment.handleThreadCollapse(commentView);
break;
}

case USER_PROFILE:
LinkHandler.onLinkClicked(
activity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,28 @@ private ActionDescriptionPair chooseFlingAction(final PrefsUtility.CommentFlingA
return null;
}

if(mComment.asComment().isCollapsed(mChangeDataManager)) {
return new ActionDescriptionPair(
RedditAPICommentAction.RedditCommentAction.COLLAPSE,
R.string.action_expand_comment);
}

return new ActionDescriptionPair(
RedditAPICommentAction.RedditCommentAction.COLLAPSE,
R.string.action_collapse);

case COLLAPSE_THREAD:

if(mFragment == null
|| (mComment.getIndent() == 0
&& mComment.asComment().isCollapsed(mChangeDataManager))) {
return null;
}

return new ActionDescriptionPair(
RedditAPICommentAction.RedditCommentAction.COLLAPSE_THREAD,
R.string.action_collapse_thread);

case ACTION_MENU:

if(mFragment == null) {
Expand Down Expand Up @@ -497,15 +515,10 @@ private void setupAccessibilityActions() {
}

addAccessibilityActionFromDescriptionPair(
chooseFlingAction(PrefsUtility.CommentFlingAction.COLLAPSE));
chooseFlingAction(PrefsUtility.CommentFlingAction.COLLAPSE));

mAccessibilityActionManager.addAction(R.string.button_next_comment_parent, () -> {
mFragment.onNextParent();
});

mAccessibilityActionManager.addAction(R.string.button_prev_comment_parent, () -> {
mFragment.onPreviousParent();
});
addAccessibilityActionFromDescriptionPair(
chooseFlingAction(PrefsUtility.CommentFlingAction.COLLAPSE_THREAD));

if (isAuthenticated) {
addAccessibilityActionFromDescriptionPair(
Expand Down Expand Up @@ -565,7 +578,18 @@ private Integer getAccessibilityHintForActionPref(
@NonNull final PrefsUtility.CommentAction pref) {
switch (pref) {
case COLLAPSE:
if(mComment.asComment().isCollapsed(mChangeDataManager)) {
return R.string.action_expand_comment;
}

return R.string.action_collapse;
case COLLAPSE_THREAD:
if(mComment.getIndent() == 0
&& mComment.asComment().isCollapsed(mChangeDataManager)) {
return R.string.action_expand_comment;
}

return R.string.action_collapse_thread;
case ACTION_MENU:
return R.string.action_actionmenu;
}
Expand Down
Loading
Loading