Refactoring

pull/171/head
M66B 5 years ago
parent 3846a52733
commit 3427d5787f

@ -429,148 +429,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
if (!BuildConfig.DEBUG && !accessibility)
return;
view.setAccessibilityDelegate(new View.AccessibilityDelegate() {
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(host, info);
TupleMessageEx message = getMessage();
if (message == null)
return;
boolean expanded = properties.getValue("expanded", message.id);
List<String> result = new ArrayList<>();
vwColor.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
if (selectionTracker != null && selectionTracker.isSelected(message.id))
result.add(context.getString(R.string.title_accessibility_selected));
if (message.count == 1)
result.add(context.getString(message.unseen > 0 ? R.string.title_accessibility_unseen : R.string.title_accessibility_seen));
else if (message.unseen == message.count)
result.add(context.getResources().getQuantityString(
R.plurals.title_accessibility_all_of_unseen, message.count, message.count));
else if (message.unseen == 0)
result.add(context.getResources().getQuantityString(
R.plurals.title_accessibility_all_of_seen, message.count, message.count));
else
result.add(context.getResources().getQuantityString(
R.plurals.title_accessibility_count_of_unseen, message.unseen, message.unseen, message.count));
if (ibExpander.getVisibility() == View.VISIBLE) {
result.add(context.getString(expanded ? R.string.title_accessibility_expanded : R.string.title_accessibility_collapsed));
info.addAction(new AccessibilityNodeInfo.AccessibilityAction(R.id.ibExpander,
context.getString(expanded ? R.string.title_accessibility_collapse : R.string.title_accessibility_expand)));
}
ibExpander.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
if (ibAvatar.getVisibility() == View.VISIBLE && ibAvatar.isEnabled())
info.addAction(new AccessibilityNodeInfo.AccessibilityAction(R.id.ibAvatar,
context.getString(R.string.title_accessibility_view_contact)));
ibAvatar.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
if (message.drafts > 0)
result.add(context.getString(R.string.title_legend_draft));
if (message.ui_answered)
result.add(context.getString(R.string.title_accessibility_answered));
if (ibFlagged.getVisibility() == View.VISIBLE && ibFlagged.isEnabled()) {
int flagged = (message.count - message.unflagged);
if (flagged > 0)
result.add(context.getString(R.string.title_accessibility_flagged));
info.addAction(new AccessibilityNodeInfo.AccessibilityAction(R.id.ibFlagged,
context.getString(flagged > 0 ? R.string.title_unflag : R.string.title_flag)));
}
ibFlagged.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
if (EntityMessage.PRIORITIY_HIGH.equals(message.priority))
result.add(context.getString(R.string.title_legend_priority));
if (EntityMessage.PRIORITIY_LOW.equals(message.priority))
result.add(context.getString(R.string.title_legend_priority_low));
if (message.attachments > 0)
result.add(context.getString(R.string.title_legend_attachment));
// For a11y purpose report addresses first in case of incoming message
boolean outgoing = isOutgoing(message);
if (!outgoing || message.count > 1)
result.add(tvFrom.getText().toString());
else
result.add(message.subject); // Don't want to ellipsize for a11y
result.add(tvTime.getText().toString());
if (outgoing && message.count == 1)
result.add(tvFrom.getText().toString());
else
result.add(message.subject);
if (message.encrypted > 0)
result.add(context.getString(R.string.title_legend_encrypted));
if (message.signed > 0)
result.add(context.getString(R.string.title_legend_signed));
if (ibAuth.getVisibility() == View.VISIBLE) {
result.add(context.getString(R.string.title_legend_auth));
info.addAction(new AccessibilityNodeInfo.AccessibilityAction(R.id.ibAuth,
context.getString(R.string.title_accessibility_show_authentication_result)));
}
ibAuth.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
if (ibSnoozed.getVisibility() == View.VISIBLE) {
result.add(context.getString(R.string.title_legend_snoozed));
info.addAction(new AccessibilityNodeInfo.AccessibilityAction(R.id.ibSnoozed,
context.getString(R.string.title_accessibility_show_snooze_time)));
}
ibSnoozed.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
if (tvFolder.getVisibility() == View.VISIBLE)
result.add(tvFolder.getText().toString());
if (tvSize.getVisibility() == View.VISIBLE)
result.add(tvSize.getText().toString());
if (tvError.getVisibility() == View.VISIBLE)
result.add(tvError.getText().toString());
if (tvPreview.getVisibility() == View.VISIBLE)
result.add(tvPreview.getText().toString());
if (ibHelp.getVisibility() == View.VISIBLE)
info.addAction(new AccessibilityNodeInfo.AccessibilityAction(R.id.ibHelp,
context.getString(R.string.title_accessibility_view_help)));
ibHelp.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
info.setContentDescription(TextUtils.join(", ", result));
}
@Override
public boolean performAccessibilityAction(View host, int action, Bundle args) {
TupleMessageEx message = getMessage();
if (message == null)
return false;
switch (action) {
case R.id.ibExpander:
onToggleMessage(message);
return true;
case R.id.ibAvatar:
onViewContact(message);
return true;
case R.id.ibFlagged:
onToggleFlag(message);
return true;
case R.id.ibAuth:
onShowAuth(message);
return true;
case R.id.ibSnoozed:
onShowSnoozed(message);
return true;
case R.id.ibHelp:
onHelp(message);
return true;
default:
return super.performAccessibilityAction(host, action, args);
}
}
});
}
private void ensureExpanded() {
@ -762,6 +620,10 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}
});
}
if (accessibility)
header.setAccessibilityDelegate(accessibilityDelegateHeader);
}
private void unwire() {
@ -804,6 +666,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
btnCalendarMaybe.setOnClickListener(null);
ibCalendar.setOnClickListener(null);
}
if (accessibility)
header.setAccessibilityDelegate(null);
}
private void clear() {
@ -3814,6 +3679,148 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
Long getKey() {
return getKeyAtPosition(getAdapterPosition());
}
private View.AccessibilityDelegate accessibilityDelegateHeader = new View.AccessibilityDelegate() {
@Override
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(host, info);
TupleMessageEx message = getMessage();
if (message == null)
return;
boolean expanded = properties.getValue("expanded", message.id);
List<String> result = new ArrayList<>();
vwColor.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
if (selectionTracker != null && selectionTracker.isSelected(message.id))
result.add(context.getString(R.string.title_accessibility_selected));
if (message.count == 1)
result.add(context.getString(message.unseen > 0 ? R.string.title_accessibility_unseen : R.string.title_accessibility_seen));
else if (message.unseen == message.count)
result.add(context.getResources().getQuantityString(
R.plurals.title_accessibility_all_of_unseen, message.count, message.count));
else if (message.unseen == 0)
result.add(context.getResources().getQuantityString(
R.plurals.title_accessibility_all_of_seen, message.count, message.count));
else
result.add(context.getResources().getQuantityString(
R.plurals.title_accessibility_count_of_unseen, message.unseen, message.unseen, message.count));
if (ibExpander.getVisibility() == View.VISIBLE) {
result.add(context.getString(expanded ? R.string.title_accessibility_expanded : R.string.title_accessibility_collapsed));
info.addAction(new AccessibilityNodeInfo.AccessibilityAction(R.id.ibExpander,
context.getString(expanded ? R.string.title_accessibility_collapse : R.string.title_accessibility_expand)));
}
ibExpander.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
if (ibAvatar.getVisibility() == View.VISIBLE && ibAvatar.isEnabled())
info.addAction(new AccessibilityNodeInfo.AccessibilityAction(R.id.ibAvatar,
context.getString(R.string.title_accessibility_view_contact)));
ibAvatar.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
if (message.drafts > 0)
result.add(context.getString(R.string.title_legend_draft));
if (message.ui_answered)
result.add(context.getString(R.string.title_accessibility_answered));
if (ibFlagged.getVisibility() == View.VISIBLE && ibFlagged.isEnabled()) {
int flagged = (message.count - message.unflagged);
if (flagged > 0)
result.add(context.getString(R.string.title_accessibility_flagged));
info.addAction(new AccessibilityNodeInfo.AccessibilityAction(R.id.ibFlagged,
context.getString(flagged > 0 ? R.string.title_unflag : R.string.title_flag)));
}
ibFlagged.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
if (EntityMessage.PRIORITIY_HIGH.equals(message.priority))
result.add(context.getString(R.string.title_legend_priority));
if (EntityMessage.PRIORITIY_LOW.equals(message.priority))
result.add(context.getString(R.string.title_legend_priority_low));
if (message.attachments > 0)
result.add(context.getString(R.string.title_legend_attachment));
// For a11y purpose report addresses first in case of incoming message
boolean outgoing = isOutgoing(message);
if (!outgoing || message.count > 1)
result.add(tvFrom.getText().toString());
else
result.add(message.subject); // Don't want to ellipsize for a11y
result.add(tvTime.getText().toString());
if (outgoing && message.count == 1)
result.add(tvFrom.getText().toString());
else
result.add(message.subject);
if (message.encrypted > 0)
result.add(context.getString(R.string.title_legend_encrypted));
if (message.signed > 0)
result.add(context.getString(R.string.title_legend_signed));
if (ibAuth.getVisibility() == View.VISIBLE) {
result.add(context.getString(R.string.title_legend_auth));
info.addAction(new AccessibilityNodeInfo.AccessibilityAction(R.id.ibAuth,
context.getString(R.string.title_accessibility_show_authentication_result)));
}
ibAuth.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
if (ibSnoozed.getVisibility() == View.VISIBLE) {
result.add(context.getString(R.string.title_legend_snoozed));
info.addAction(new AccessibilityNodeInfo.AccessibilityAction(R.id.ibSnoozed,
context.getString(R.string.title_accessibility_show_snooze_time)));
}
ibSnoozed.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
if (tvFolder.getVisibility() == View.VISIBLE)
result.add(tvFolder.getText().toString());
if (tvSize.getVisibility() == View.VISIBLE)
result.add(tvSize.getText().toString());
if (tvError.getVisibility() == View.VISIBLE)
result.add(tvError.getText().toString());
if (tvPreview.getVisibility() == View.VISIBLE)
result.add(tvPreview.getText().toString());
if (ibHelp.getVisibility() == View.VISIBLE)
info.addAction(new AccessibilityNodeInfo.AccessibilityAction(R.id.ibHelp,
context.getString(R.string.title_accessibility_view_help)));
ibHelp.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
info.setContentDescription(TextUtils.join(", ", result));
}
@Override
public boolean performAccessibilityAction(View host, int action, Bundle args) {
TupleMessageEx message = getMessage();
if (message == null)
return false;
switch (action) {
case R.id.ibExpander:
onToggleMessage(message);
return true;
case R.id.ibAvatar:
onViewContact(message);
return true;
case R.id.ibFlagged:
onToggleFlag(message);
return true;
case R.id.ibAuth:
onShowAuth(message);
return true;
case R.id.ibSnoozed:
onShowSnoozed(message);
return true;
case R.id.ibHelp:
onHelp(message);
return true;
default:
return super.performAccessibilityAction(host, action, args);
}
}
};
}
AdapterMessage(Fragment parentFragment,

Loading…
Cancel
Save