Skip to content

Commit e5406d7

Browse files
Report which search result is shown in a chat
Searching inside a chat shows which result is being looked at, as "3 of 27" next to the arrows that go through them. The count is drawn rather than written, so nothing reads it, and going to the next or the previous result says nothing at all. Let the count be reached by a screen reader, and have it told as soon as going through the results moves to another one.
1 parent 45ab8f4 commit e5406d7

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26849,19 +26849,37 @@ private void updateSearchButtons(int mask, int num, int count) {
2684926849
}
2685026850
}
2685126851

26852+
private int accessibilityAnnouncedSearchIndex = -1;
26853+
2685226854
private void updateSearchCountText() {
2685326855
if (searchCountText != null) {
2685426856
boolean animated = !LocaleController.isRTL;
26857+
final CharSequence text;
2685526858
if (searchLastCount < 0) {
26856-
searchCountText.setText("", animated);
26859+
text = "";
2685726860
} else if (searchLastCount == 0) {
26858-
searchCountText.setText(LocaleController.getString(R.string.NoResult), animated);
26861+
text = LocaleController.getString(R.string.NoResult);
2685926862
} else if (searchingFiltered) {
26860-
searchCountText.setText(LocaleController.formatPluralString("TaggedMessages", searchLastCount), animated);
26863+
text = LocaleController.formatPluralString("TaggedMessages", searchLastCount);
2686126864
} else if (chatMode == MODE_SEARCH || isMessagesSearchListVisible()) {
26862-
searchCountText.setText(LocaleController.formatPluralString("SearchMessagesResultCount", searchLastCount, LocaleController.formatNumber(searchLastCount, ' ')), animated);
26865+
text = LocaleController.formatPluralString("SearchMessagesResultCount", searchLastCount, LocaleController.formatNumber(searchLastCount, ' '));
2686326866
} else {
26864-
searchCountText.setText(LocaleController.formatString(R.string.Of, searchLastIndex + 1, searchLastCount), animated);
26867+
text = LocaleController.formatString(R.string.Of, searchLastIndex + 1, searchLastCount);
26868+
}
26869+
searchCountText.setText(text, animated);
26870+
// the count is drawn, so nothing reads it: give it what it shows, since the text it
26871+
// is set to only reaches it once the animation carrying it is over, and let it be
26872+
// reached by touch as well as by swiping
26873+
searchCountText.setContentDescription(text);
26874+
searchCountText.setImportantForAccessibility(TextUtils.isEmpty(text) ? View.IMPORTANT_FOR_ACCESSIBILITY_NO : View.IMPORTANT_FOR_ACCESSIBILITY_YES);
26875+
searchCountText.setFocusable(!TextUtils.isEmpty(text));
26876+
if (searchLastCount > 0 && searchLastIndex != accessibilityAnnouncedSearchIndex && AndroidUtilities.isAccessibilityScreenReaderEnabled()) {
26877+
if (accessibilityAnnouncedSearchIndex != -1) {
26878+
searchCountText.announceForAccessibility(text);
26879+
}
26880+
accessibilityAnnouncedSearchIndex = searchLastIndex;
26881+
} else if (searchLastCount <= 0) {
26882+
accessibilityAnnouncedSearchIndex = -1;
2686526883
}
2686626884
}
2686726885
}

0 commit comments

Comments
 (0)