mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
Address code review feedback
- Reuse LinkAccessibilityDelegate instance instead of creating new one each time - Add detailed comment explaining the magic number for action IDs - Improves performance by avoiding unnecessary object allocations Co-authored-by: adbenitez <24558636+adbenitez@users.noreply.github.com>
This commit is contained in:
@@ -126,6 +126,7 @@ public class ConversationItem extends BaseConversationItem
|
||||
private Stub<VcardView> vcardViewStub;
|
||||
private Stub<CallItemView> callViewStub;
|
||||
private @Nullable EventListener eventListener;
|
||||
private @Nullable LinkAccessibilityDelegate linkAccessibilityDelegate;
|
||||
|
||||
private int measureCalls;
|
||||
|
||||
@@ -432,7 +433,10 @@ public class ConversationItem extends BaseConversationItem
|
||||
|
||||
// Set accessibility delegate for TalkBack to expose links as custom actions
|
||||
if (Util.isTouchExplorationEnabled(context) && batchSelected.isEmpty()) {
|
||||
bodyText.setAccessibilityDelegate(new LinkAccessibilityDelegate(context));
|
||||
if (linkAccessibilityDelegate == null) {
|
||||
linkAccessibilityDelegate = new LinkAccessibilityDelegate(context);
|
||||
}
|
||||
bodyText.setAccessibilityDelegate(linkAccessibilityDelegate);
|
||||
} else {
|
||||
bodyText.setAccessibilityDelegate(null);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,10 @@ import java.util.Map;
|
||||
*/
|
||||
public class LinkAccessibilityDelegate extends View.AccessibilityDelegate {
|
||||
|
||||
// Base ID for custom link actions (using a high number to avoid conflicts)
|
||||
// Base ID for custom link actions. Using a high number (0x00FF0000, which is 16,711,680 in decimal)
|
||||
// to avoid conflicts with Android's standard accessibility action IDs, which are typically small integers
|
||||
// (e.g., ACTION_CLICK = 16, ACTION_LONG_CLICK = 32, etc.) or specific bit flags.
|
||||
// This range is safe for custom actions as per Android accessibility guidelines.
|
||||
private static final int LINK_ACTION_BASE_ID = 0x00FF0000;
|
||||
|
||||
// Map to store span references for each action ID
|
||||
|
||||
Reference in New Issue
Block a user