Merge pull request #1288 from tuskyapp/poll-description

Minimal screen reader support for polls
This commit is contained in:
Konrad Pozniak 2019-05-30 21:53:56 +02:00 committed by GitHub
commit 9a90594fae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 61 additions and 83 deletions

View file

@ -129,7 +129,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
contentWarningButton = itemView.findViewById(R.id.status_content_warning_button); contentWarningButton = itemView.findViewById(R.id.status_content_warning_button);
avatarInset = itemView.findViewById(R.id.status_avatar_inset); avatarInset = itemView.findViewById(R.id.status_avatar_inset);
pollResults = new TextView[] { pollResults = new TextView[]{
itemView.findViewById(R.id.status_poll_option_result_0), itemView.findViewById(R.id.status_poll_option_result_0),
itemView.findViewById(R.id.status_poll_option_result_1), itemView.findViewById(R.id.status_poll_option_result_1),
itemView.findViewById(R.id.status_poll_option_result_2), itemView.findViewById(R.id.status_poll_option_result_2),
@ -704,7 +704,8 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
getMediaDescription(context, status), getMediaDescription(context, status),
getVisibilityDescription(context, status.getVisibility()), getVisibilityDescription(context, status.getVisibility()),
getFavsText(context, status.getFavouritesCount()), getFavsText(context, status.getFavouritesCount()),
getReblogsText(context, status.getReblogsCount()) getReblogsText(context, status.getReblogsCount()),
getPollDescription(context, status)
); );
itemView.setContentDescription(description); itemView.setContentDescription(description);
} }
@ -753,7 +754,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
} }
private CharSequence getVisibilityDescription(Context context, Status.Visibility visibility) { private CharSequence getVisibilityDescription(Context context, Status.Visibility visibility) {
if(visibility == null) { if (visibility == null) {
return ""; return "";
} }
int resource; int resource;
@ -776,6 +777,30 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
return context.getString(resource); return context.getString(resource);
} }
private CharSequence getPollDescription(Context context,
@NonNull StatusViewData.Concrete status) {
Poll poll = status.getPoll();
if (poll == null) {
return "";
} else {
CharSequence[] args = new CharSequence[5];
List<PollOption> options = poll.getOptions();
for (int i = 0; i < args.length; i++) {
if (i < options.size()) {
int percent = options.get(i).getPercent(poll.getVotesCount());
args[i] = HtmlUtils.fromHtml(context.getString(
R.string.poll_option_format,
percent,
options.get(i).getTitle()));
} else {
args[i] = "";
}
}
args[4] = getPollInfoText(System.currentTimeMillis(), poll, context);
return context.getString(R.string.description_poll, args);
}
}
protected CharSequence getFavsText(Context context, int count) { protected CharSequence getFavsText(Context context, int count) {
if (count > 0) { if (count > 0) {
String countString = numberFormat.format(count); String countString = numberFormat.format(count);
@ -795,14 +820,14 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
} }
protected void setupPoll(Poll poll, List<Emoji> emojis, StatusActionListener listener) { protected void setupPoll(Poll poll, List<Emoji> emojis, StatusActionListener listener) {
if(poll == null) { if (poll == null) {
for(TextView pollResult: pollResults) { for (TextView pollResult : pollResults) {
pollResult.setVisibility(View.GONE); pollResult.setVisibility(View.GONE);
} }
pollDescription.setVisibility(View.GONE); pollDescription.setVisibility(View.GONE);
pollRadioGroup.setVisibility(View.GONE); pollRadioGroup.setVisibility(View.GONE);
for(CheckBox checkBox: pollCheckboxOptions) { for (CheckBox checkBox : pollCheckboxOptions) {
checkBox.setVisibility(View.GONE); checkBox.setVisibility(View.GONE);
} }
@ -814,7 +839,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
Context context = pollDescription.getContext(); Context context = pollDescription.getContext();
if(expired || poll.getVoted()) { if (expired || poll.getVoted()) {
// no voting possible // no voting possible
setupPollResult(poll, emojis); setupPollResult(poll, emojis);
} else { } else {
@ -823,16 +848,18 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
} }
pollDescription.setVisibility(View.VISIBLE); pollDescription.setVisibility(View.VISIBLE);
pollDescription.setText(getPollInfoText(timestamp, poll, context));
}
}
private CharSequence getPollInfoText(long timestamp, Poll poll, Context context) {
String votes = numberFormat.format(poll.getVotesCount()); String votes = numberFormat.format(poll.getVotesCount());
String votesText = context.getResources().getQuantityString(R.plurals.poll_info_votes, poll.getVotesCount(), votes); String votesText = context.getResources().getQuantityString(R.plurals.poll_info_votes, poll.getVotesCount(), votes);
CharSequence pollDurationInfo; CharSequence pollDurationInfo;
if(expired) { if (poll.getExpired()) {
pollDurationInfo = context.getString(R.string.poll_info_closed); pollDurationInfo = context.getString(R.string.poll_info_closed);
} else { } else {
if(useAbsoluteTime) { if (useAbsoluteTime) {
pollDurationInfo = context.getString(R.string.poll_info_time_absolute, getAbsoluteTime(poll.getExpiresAt())); pollDurationInfo = context.getString(R.string.poll_info_time_absolute, getAbsoluteTime(poll.getExpiresAt()));
} else { } else {
String pollDuration = DateUtils.formatPollDuration(pollDescription.getContext(), poll.getExpiresAt().getTime(), timestamp); String pollDuration = DateUtils.formatPollDuration(pollDescription.getContext(), poll.getExpiresAt().getTime(), timestamp);
@ -840,12 +867,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
} }
} }
String pollInfo = pollDescription.getContext().getString(R.string.poll_info_format, votesText, pollDurationInfo); return pollDescription.getContext().getString(R.string.poll_info_format, votesText, pollDurationInfo);
pollDescription.setText(pollInfo);
}
} }
private void setupPollResult(Poll poll, List<Emoji> emojis) { private void setupPollResult(Poll poll, List<Emoji> emojis) {

View file

@ -482,7 +482,6 @@
<string name="pin_action">Fixar</string> <string name="pin_action">Fixar</string>
<string name="description_status_reblogged">Respost</string> <string name="description_status_reblogged">Respost</string>
<string name="description_status"> .<!-- Nom públic, advertència\?, contingut\?, data relativa, respost per\?, respost\?, favorits\?, nom usuari, mèdia\?; visibilitat, número de favorits\?, número de respostes\?--> %1$s; %2$s; %3$s, %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s </string>
<string name="compose_preview_image_description">Accions per a la imatge %s</string> <string name="compose_preview_image_description">Accions per a la imatge %s</string>

View file

@ -374,9 +374,6 @@
</string> </string>
<string name="description_visiblity_direct"> Přímý <string name="description_visiblity_direct"> Přímý
</string> </string>
<string name="description_status"> <!-- Zobrazované jméno, varování?, obsah?, relativní datum, znovusdíleno kým?, znovusdíleno?, oblíbeno?, uživatelské jméno, média?; viditelnost, počet oblíbení?, počet boostů?-->
%1$s; %2$s; %3$s, %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s
</string>
<string name="hint_list_name">Název seznamu</string> <string name="hint_list_name">Název seznamu</string>
<string name="edit_hashtag_title">Upravit hashtag</string> <string name="edit_hashtag_title">Upravit hashtag</string>
<string name="edit_hashtag_hint">Hashtag bez #</string> <string name="edit_hashtag_hint">Hashtag bez #</string>

View file

@ -366,9 +366,7 @@
<string name="description_visiblity_private"> Sekvantoj <string name="description_visiblity_private"> Sekvantoj
</string> </string>
<string name="description_visiblity_direct"> Rekta </string> <string name="description_visiblity_direct"> Rekta </string>
<string name="description_status"> <!-- Display name, cw?, content?, relative date, reposted by?, reposted?, favorited?, username, media?; visibility, fav number?, reblog number?-->
%1$s; %2$s; %3$s, %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s
</string>
<string name="hint_list_name">Nomo de la listo</string> <string name="hint_list_name">Nomo de la listo</string>
<string name="action_delete_and_redraft">Forigi kaj reskribi</string> <string name="action_delete_and_redraft">Forigi kaj reskribi</string>
<string name="dialog_redraft_toot_warning">Ĉu forigi kaj reskribi ĉi-tiun mesaĝon\?</string> <string name="dialog_redraft_toot_warning">Ĉu forigi kaj reskribi ĉi-tiun mesaĝon\?</string>

View file

@ -424,7 +424,6 @@
<string name="action_open_reblogger">Abrir autor del impulso</string> <string name="action_open_reblogger">Abrir autor del impulso</string>
<string name="action_open_reblogged_by">Mostrar impulsos</string> <string name="action_open_reblogged_by">Mostrar impulsos</string>
<string name="description_status"> <!-- Display name, cw\?, content\?, relative date, reposted by\?, reposted\?, favorited\?, username, media\?; visibility, fav number\?, reblog number\?--> %1$s; %2$s; %3$s, %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s </string>
<string name="poll_option_format"> <!-- 15% vote for this! --> &lt;b&gt;%1$d%%&lt;/b&gt; %2$s</string> <string name="poll_option_format"> <!-- 15% vote for this! --> &lt;b&gt;%1$d%%&lt;/b&gt; %2$s</string>

View file

@ -372,9 +372,6 @@
</string> </string>
<string name="description_visiblity_direct"> Direct <string name="description_visiblity_direct"> Direct
</string> </string>
<string name="description_status"> <!-- Nom public, avertissement?, contenu?, date relative, reblogué par?, reblogué?, mis en favoris?, username, media?; visibilité, nombre de fav?, nombre de reblogs?-->
%1$s; %2$s; %3$s, %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s
</string>
<string name="hint_list_name">Nom de la liste</string> <string name="hint_list_name">Nom de la liste</string>
<string name="edit_hashtag_title">Modifier les hashtags</string> <string name="edit_hashtag_title">Modifier les hashtags</string>
<string name="edit_hashtag_hint">Hastags sans #</string> <string name="edit_hashtag_hint">Hastags sans #</string>

View file

@ -366,9 +366,6 @@
</string> </string>
<string name="description_visiblity_direct"> Diretti <string name="description_visiblity_direct"> Diretti
</string> </string>
<string name="description_status"> <!-- Nome visualizzato, cw?, contenuto?, data relativa, ripostato da?, ripostato?, apprezzato?, nome utente, media?; visibilità, numero di mi piace?, numero di riblog?-->
%1$s; %2$s; %3$s, %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s
</string>
<string name="hint_list_name">Nome della lista</string> <string name="hint_list_name">Nome della lista</string>
<string name="download_media">Scarica media</string> <string name="download_media">Scarica media</string>
<string name="downloading_media">Scaricando media</string> <string name="downloading_media">Scaricando media</string>

View file

@ -346,9 +346,6 @@
</string> </string>
<string name="description_visiblity_direct"> Direct <string name="description_visiblity_direct"> Direct
</string> </string>
<string name="description_status"> <!-- Display name, cw?, content?, relative date, reposted by?, reposted?, favorited?, username, media?; visibility, fav number?, reblog number?-->
%1$s; %2$s; %3$s, %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s
</string>
<string name="download_media">Media downloaden</string> <string name="download_media">Media downloaden</string>
<string name="downloading_media">Media aan het downloaden</string> <string name="downloading_media">Media aan het downloaden</string>

View file

@ -218,9 +218,6 @@
<string name="pref_title_http_proxy_server">Serveradresse</string> <string name="pref_title_http_proxy_server">Serveradresse</string>
<string name="pref_title_http_proxy_port">Serverport</string> <string name="pref_title_http_proxy_port">Serverport</string>
<string name="description_status"> <!-- Display name, cw\?, content\?, relative date, reposted by\?, reposted\?, favorited\?, username, media\?; visibility, fav number\?, reblog number\?--> %1$s; %2$s; %3$s, %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s </string>
<string name="pref_default_media_sensitivity">Marker alltid media som sensitivt</string> <string name="pref_default_media_sensitivity">Marker alltid media som sensitivt</string>
<string name="pref_publishing">Publisering (synkronisert med server)</string> <string name="pref_publishing">Publisering (synkronisert med server)</string>
<string name="pref_failed_to_sync">Synkronisering av innstillinger feilet</string> <string name="pref_failed_to_sync">Synkronisering av innstillinger feilet</string>

View file

@ -373,7 +373,6 @@
<string name="description_visiblity_unlisted">Pas listat</string> <string name="description_visiblity_unlisted">Pas listat</string>
<string name="description_visiblity_private">Seguidors</string> <string name="description_visiblity_private">Seguidors</string>
<string name="description_visiblity_direct">Dirècte</string> <string name="description_visiblity_direct">Dirècte</string>
<string name="description_status"> <!-- Nom dafichatge, cw\?, contengut\?, data relativa, repartejat per\?, repartajat\?, aimat\?, nom dutilizaire, mèdia\?; visibilitat, nombre de fav\?, nombre de partatge\?--> %1$s; %2$s; %3$s, %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s </string>
<string name="hint_list_name">Nom de la lista</string> <string name="hint_list_name">Nom de la lista</string>

View file

@ -386,7 +386,6 @@
<string name="description_status_favourited">Favoritado</string> <string name="description_status_favourited">Favoritado</string>
<string name="description_visiblity_unlisted">Não-listado</string> <string name="description_visiblity_unlisted">Não-listado</string>
<string name="description_visiblity_direct">Direta</string> <string name="description_visiblity_direct">Direta</string>
<string name="description_status"> <!-- Display name, cw\?, content\?, relative date, reposted by\?, reposted\?, favorited\?, username, media\?; visibility, fav number\?, reblog number\?--> %1$s; %2$s; %3$s, %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s </string>
<string name="hint_list_name">Nome da lista</string> <string name="hint_list_name">Nome da lista</string>

View file

@ -465,10 +465,6 @@
<string name="description_visiblity_direct"> <string name="description_visiblity_direct">
Для упомянутых Для упомянутых
</string> </string>
<string name="description_status">
<!-- Display name, cw?, content?, relative date, reposted by?, reposted?, favorited?, username, media?; visibility, fav number?, reblog number?-->
%1$s; %2$s; %3$s, %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s
</string>
<string name="hint_list_name">Название списка</string> <string name="hint_list_name">Название списка</string>

View file

@ -394,7 +394,6 @@
<string name="description_visiblity_unlisted">Ni prikazano</string> <string name="description_visiblity_unlisted">Ni prikazano</string>
<string name="description_visiblity_private">Sledilci</string> <string name="description_visiblity_private">Sledilci</string>
<string name="description_visiblity_direct">Neposredno</string> <string name="description_visiblity_direct">Neposredno</string>
<string name="description_status"> <!-- Display name, cw\?, content\?, relative date, reposted by\?, reposted\?, favorited\?, username, media\?; visibility, fav number\?, reblog number\?-->%1$s; %2$s; %3$s, %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s </string>
<string name="hint_list_name">Ime seznama</string> <string name="hint_list_name">Ime seznama</string>

View file

@ -366,9 +366,6 @@
</string> </string>
<string name="description_visiblity_direct"> Direkt <string name="description_visiblity_direct"> Direkt
</string> </string>
<string name="description_status"> <!-- Display name, cw?, content?, relative date, reposted by?, reposted?, favorited?, username, media?; visibility, fav number?, reblog number?-->
%1$s; %2$s; %3$s, %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s
</string>
<string name="hint_list_name">Listnamn</string> <string name="hint_list_name">Listnamn</string>
<string name="download_media">Ladda ned media</string> <string name="download_media">Ladda ned media</string>
<string name="downloading_media">Laddar ned media</string> <string name="downloading_media">Laddar ned media</string>

View file

@ -447,10 +447,6 @@
<string name="description_visiblity_direct"> <string name="description_visiblity_direct">
私信 私信
</string> </string>
<string name="description_status">
<!-- Display name, cw?, content?, relative date, reposted by?, reposted?, favorited?, username, media?; visibility, fav number?, reblog number?-->
%1$s; %2$s; %3$s, %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s
</string>
<string name="hint_list_name">列表名</string> <string name="hint_list_name">列表名</string>

View file

@ -447,10 +447,6 @@
<string name="description_visiblity_direct"> <string name="description_visiblity_direct">
私信 私信
</string> </string>
<string name="description_status">
<!-- Display name, cw?, content?, relative date, reposted by?, reposted?, favorited?, username, media?; visibility, fav number?, reblog number?-->
%1$s; %2$s; %3$s, %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s
</string>
<string name="hint_list_name">列表名</string> <string name="hint_list_name">列表名</string>

View file

@ -447,10 +447,6 @@
<string name="description_visiblity_direct"> <string name="description_visiblity_direct">
私信 私信
</string> </string>
<string name="description_status">
<!-- Display name, cw?, content?, relative date, reposted by?, reposted?, favorited?, username, media?; visibility, fav number?, reblog number?-->
%1$s; %2$s; %3$s, %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s
</string>
<string name="hint_list_name">列表名</string> <string name="hint_list_name">列表名</string>

View file

@ -447,10 +447,6 @@
<string name="description_visiblity_direct"> <string name="description_visiblity_direct">
私信 私信
</string> </string>
<string name="description_status">
<!-- Display name, cw?, content?, relative date, reposted by?, reposted?, favorited?, username, media?; visibility, fav number?, reblog number?-->
%1$s; %2$s; %3$s, %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s
</string>
<string name="hint_list_name">列表名</string> <string name="hint_list_name">列表名</string>

View file

@ -447,10 +447,6 @@
<string name="description_visiblity_direct"> <string name="description_visiblity_direct">
私信 私信
</string> </string>
<string name="description_status">
<!-- Display name, cw?, content?, relative date, reposted by?, reposted?, favorited?, username, media?; visibility, fav number?, reblog number?-->
%1$s; %2$s; %3$s, %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s
</string>
<string name="hint_list_name">列表名</string> <string name="hint_list_name">列表名</string>

View file

@ -99,4 +99,10 @@
<item>ja</item> <item>ja</item>
</string-array> </string-array>
<string name="description_status" translatable="false">
<!-- Display name, cw?, content?, poll? relative date, reposted by?, reposted?, favorited?, username, media?; visibility, fav number?, reblog number?-->
%1$s; %2$s; %3$s, %13$s %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s
</string>
</resources> </resources>

View file

@ -450,9 +450,8 @@
<string name="description_visiblity_direct"> <string name="description_visiblity_direct">
Direct Direct
</string> </string>
<string name="description_status"> <string name="description_poll">
<!-- Display name, cw?, content?, relative date, reposted by?, reposted?, favorited?, username, media?; visibility, fav number?, reblog number?--> Poll with choices: %s, %s, %s, %s; %s
%1$s; %2$s; %3$s, %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s
</string> </string>
<string name="hint_list_name">List name</string> <string name="hint_list_name">List name</string>