From 3f613dc56f981209828a63108e048a6492029107 Mon Sep 17 00:00:00 2001 From: charlag Date: Sun, 26 May 2019 15:56:26 +0200 Subject: [PATCH] Minimal screen reader support for polls --- .../tusky/adapter/StatusBaseViewHolder.java | 82 ++++++++++++------- app/src/main/res/values-ca/strings.xml | 1 - app/src/main/res/values-cs/strings.xml | 3 - app/src/main/res/values-eo/strings.xml | 4 +- app/src/main/res/values-es/strings.xml | 1 - app/src/main/res/values-fr/strings.xml | 3 - app/src/main/res/values-it/strings.xml | 3 - app/src/main/res/values-nl/strings.xml | 3 - app/src/main/res/values-no-rNB/strings.xml | 3 - app/src/main/res/values-oc/strings.xml | 1 - app/src/main/res/values-pt-rBR/strings.xml | 1 - app/src/main/res/values-ru/strings.xml | 4 - app/src/main/res/values-sl/strings.xml | 1 - app/src/main/res/values-sv/strings.xml | 3 - app/src/main/res/values-zh-rCN/strings.xml | 4 - app/src/main/res/values-zh-rHK/strings.xml | 4 - app/src/main/res/values-zh-rMO/strings.xml | 4 - app/src/main/res/values-zh-rSG/strings.xml | 4 - app/src/main/res/values-zh-rTW/strings.xml | 4 - app/src/main/res/values/donottranslate.xml | 6 ++ app/src/main/res/values/strings.xml | 5 +- 21 files changed, 61 insertions(+), 83 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java index 3c0c44fdb..00f33683b 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java @@ -129,7 +129,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { contentWarningButton = itemView.findViewById(R.id.status_content_warning_button); 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_1), itemView.findViewById(R.id.status_poll_option_result_2), @@ -704,7 +704,8 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { getMediaDescription(context, status), getVisibilityDescription(context, status.getVisibility()), getFavsText(context, status.getFavouritesCount()), - getReblogsText(context, status.getReblogsCount()) + getReblogsText(context, status.getReblogsCount()), + getPollDescription(context, status) ); itemView.setContentDescription(description); } @@ -753,7 +754,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { } private CharSequence getVisibilityDescription(Context context, Status.Visibility visibility) { - if(visibility == null) { + if (visibility == null) { return ""; } int resource; @@ -776,6 +777,30 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { 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 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) { if (count > 0) { String countString = numberFormat.format(count); @@ -795,14 +820,14 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { } protected void setupPoll(Poll poll, List emojis, StatusActionListener listener) { - if(poll == null) { - for(TextView pollResult: pollResults) { + if (poll == null) { + for (TextView pollResult : pollResults) { pollResult.setVisibility(View.GONE); } pollDescription.setVisibility(View.GONE); pollRadioGroup.setVisibility(View.GONE); - for(CheckBox checkBox: pollCheckboxOptions) { + for (CheckBox checkBox : pollCheckboxOptions) { checkBox.setVisibility(View.GONE); } @@ -814,40 +839,37 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { Context context = pollDescription.getContext(); - if(expired || poll.getVoted()) { + if (expired || poll.getVoted()) { // no voting possible - setupPollResult(poll, emojis); + setupPollResult(poll, emojis); } else { // voting possible setupPollVoting(poll, emojis, listener); } pollDescription.setVisibility(View.VISIBLE); - - String votes = numberFormat.format(poll.getVotesCount()); - String votesText = context.getResources().getQuantityString(R.plurals.poll_info_votes, poll.getVotesCount(), votes); - - - CharSequence pollDurationInfo; - if(expired) { - pollDurationInfo = context.getString(R.string.poll_info_closed); - } else { - if(useAbsoluteTime) { - pollDurationInfo = context.getString(R.string.poll_info_time_absolute, getAbsoluteTime(poll.getExpiresAt())); - } else { - String pollDuration = DateUtils.formatPollDuration(pollDescription.getContext(), poll.getExpiresAt().getTime(), timestamp); - pollDurationInfo = context.getString(R.string.poll_info_time_relative, pollDuration); - } - } - - String pollInfo = pollDescription.getContext().getString(R.string.poll_info_format, votesText, pollDurationInfo); - - pollDescription.setText(pollInfo); - - + pollDescription.setText(getPollInfoText(timestamp, poll, context)); } } + private CharSequence getPollInfoText(long timestamp, Poll poll, Context context) { + String votes = numberFormat.format(poll.getVotesCount()); + String votesText = context.getResources().getQuantityString(R.plurals.poll_info_votes, poll.getVotesCount(), votes); + CharSequence pollDurationInfo; + if (poll.getExpired()) { + pollDurationInfo = context.getString(R.string.poll_info_closed); + } else { + if (useAbsoluteTime) { + pollDurationInfo = context.getString(R.string.poll_info_time_absolute, getAbsoluteTime(poll.getExpiresAt())); + } else { + String pollDuration = DateUtils.formatPollDuration(pollDescription.getContext(), poll.getExpiresAt().getTime(), timestamp); + pollDurationInfo = context.getString(R.string.poll_info_time_relative, pollDuration); + } + } + + return pollDescription.getContext().getString(R.string.poll_info_format, votesText, pollDurationInfo); + } + private void setupPollResult(Poll poll, List emojis) { List options = poll.getOptions(); diff --git a/app/src/main/res/values-ca/strings.xml b/app/src/main/res/values-ca/strings.xml index 226c108ac..46d277818 100644 --- a/app/src/main/res/values-ca/strings.xml +++ b/app/src/main/res/values-ca/strings.xml @@ -482,7 +482,6 @@ Fixar Respost - . %1$s; %2$s; %3$s, %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s Accions per a la imatge %s diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index c8e23cabd..1743e64ac 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -374,9 +374,6 @@ Přímý - - %1$s; %2$s; %3$s, %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s - Název seznamu Upravit hashtag Hashtag bez # diff --git a/app/src/main/res/values-eo/strings.xml b/app/src/main/res/values-eo/strings.xml index 0edbc711e..19fbb5924 100644 --- a/app/src/main/res/values-eo/strings.xml +++ b/app/src/main/res/values-eo/strings.xml @@ -366,8 +366,6 @@ Sekvantoj Rekta - - %1$s; %2$s; %3$s, %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s - + Nomo de la listo diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 8254531e6..53286dd03 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -424,7 +424,6 @@ Abrir autor del impulso Mostrar impulsos - %1$s; %2$s; %3$s, %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s <b>%1$d%%</b> %2$s diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 6408aea91..37693617a 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -372,9 +372,6 @@ Direct - - %1$s; %2$s; %3$s, %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s - Nom de la liste Modifier les hashtags Hastags sans # diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 3c2601d18..bf52a08d0 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -366,9 +366,6 @@ Diretti - - %1$s; %2$s; %3$s, %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s - Nome della lista Scarica media Scaricando media diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index e41485029..a7b155073 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -346,9 +346,6 @@ Direct - - %1$s; %2$s; %3$s, %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s - Media downloaden Media aan het downloaden diff --git a/app/src/main/res/values-no-rNB/strings.xml b/app/src/main/res/values-no-rNB/strings.xml index 93424fcc1..ac31fc5bd 100644 --- a/app/src/main/res/values-no-rNB/strings.xml +++ b/app/src/main/res/values-no-rNB/strings.xml @@ -218,9 +218,6 @@ Serveradresse Serverport - - %1$s; %2$s; %3$s, %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s - Marker alltid media som sensitivt Publisering (synkronisert med server) Synkronisering av innstillinger feilet diff --git a/app/src/main/res/values-oc/strings.xml b/app/src/main/res/values-oc/strings.xml index 7ef930a80..f9a62e365 100644 --- a/app/src/main/res/values-oc/strings.xml +++ b/app/src/main/res/values-oc/strings.xml @@ -373,7 +373,6 @@ Pas listat Seguidors Dirècte - %1$s; %2$s; %3$s, %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s Nom de la lista diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index d8d593005..cbcc83892 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -386,7 +386,6 @@ Favoritado Não-listado Direta - %1$s; %2$s; %3$s, %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s Nome da lista diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 314ed2a0d..47428b7c3 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -465,10 +465,6 @@ Для упомянутых - - - %1$s; %2$s; %3$s, %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s - Название списка diff --git a/app/src/main/res/values-sl/strings.xml b/app/src/main/res/values-sl/strings.xml index facb0b50d..e5a9cf1c3 100644 --- a/app/src/main/res/values-sl/strings.xml +++ b/app/src/main/res/values-sl/strings.xml @@ -394,7 +394,6 @@ Ni prikazano Sledilci Neposredno - %1$s; %2$s; %3$s, %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s Ime seznama diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index 19ca1e9a9..705d27a9d 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -366,9 +366,6 @@ Direkt - - %1$s; %2$s; %3$s, %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s - Listnamn Ladda ned media Laddar ned media diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index a3fcfbba1..49003ee54 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -447,10 +447,6 @@ 私信 - - - %1$s; %2$s; %3$s, %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s - 列表名 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index a9b41c87c..3cb31e533 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -447,10 +447,6 @@ 私信 - - - %1$s; %2$s; %3$s, %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s - 列表名 diff --git a/app/src/main/res/values-zh-rMO/strings.xml b/app/src/main/res/values-zh-rMO/strings.xml index a9b41c87c..3cb31e533 100644 --- a/app/src/main/res/values-zh-rMO/strings.xml +++ b/app/src/main/res/values-zh-rMO/strings.xml @@ -447,10 +447,6 @@ 私信 - - - %1$s; %2$s; %3$s, %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s - 列表名 diff --git a/app/src/main/res/values-zh-rSG/strings.xml b/app/src/main/res/values-zh-rSG/strings.xml index b9b11499f..da37814a1 100644 --- a/app/src/main/res/values-zh-rSG/strings.xml +++ b/app/src/main/res/values-zh-rSG/strings.xml @@ -447,10 +447,6 @@ 私信 - - - %1$s; %2$s; %3$s, %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s - 列表名 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index a9b41c87c..3cb31e533 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -447,10 +447,6 @@ 私信 - - - %1$s; %2$s; %3$s, %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s - 列表名 diff --git a/app/src/main/res/values/donottranslate.xml b/app/src/main/res/values/donottranslate.xml index ba0ee3d83..2aa4f90f4 100644 --- a/app/src/main/res/values/donottranslate.xml +++ b/app/src/main/res/values/donottranslate.xml @@ -99,4 +99,10 @@ ja + + + + %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 + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6aae71129..043d810c9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -450,9 +450,8 @@ Direct - - - %1$s; %2$s; %3$s, %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s + + Poll with choices: %s, %s, %s, %s; %s List name