From a308b4c139399623d1e2bdf7f2b101f36427cf90 Mon Sep 17 00:00:00 2001 From: Levi Bard Date: Fri, 11 Oct 2019 17:35:22 +0200 Subject: [PATCH] Don't interpret html inside poll options. (#1527) * Don't interpret html inside poll options. Closes #1362 * Update translations * Mark poll_percent_format as untranslatable --- .../com/keylesspalace/tusky/adapter/PollAdapter.kt | 6 ++---- .../tusky/adapter/StatusBaseViewHolder.java | 7 +++---- .../keylesspalace/tusky/util/NotificationHelper.java | 8 +++++--- .../com/keylesspalace/tusky/util/StatusViewHelper.kt | 5 +++-- .../com/keylesspalace/tusky/viewdata/PollViewData.kt | 11 +++++++++++ app/src/main/res/values-bn-rIN/strings.xml | 1 - app/src/main/res/values-ca/strings.xml | 1 - app/src/main/res/values-cs/strings.xml | 1 - app/src/main/res/values-de/strings.xml | 1 - app/src/main/res/values-eo/strings.xml | 1 - app/src/main/res/values-es/strings.xml | 2 -- app/src/main/res/values-fr/strings.xml | 1 - app/src/main/res/values-hu/strings.xml | 1 - app/src/main/res/values-ko/strings.xml | 1 - app/src/main/res/values-nl/strings.xml | 1 - app/src/main/res/values-no-rNB/strings.xml | 1 - app/src/main/res/values-oc/strings.xml | 1 - app/src/main/res/values-pl/strings.xml | 1 - app/src/main/res/values-pt-rBR/strings.xml | 1 - app/src/main/res/values-ru/strings.xml | 3 --- app/src/main/res/values-sl/strings.xml | 1 - app/src/main/res/values-sv/strings.xml | 1 - app/src/main/res/values-zh-rCN/strings.xml | 3 --- app/src/main/res/values-zh-rHK/strings.xml | 5 +---- app/src/main/res/values-zh-rMO/strings.xml | 5 +---- app/src/main/res/values-zh-rSG/strings.xml | 3 --- app/src/main/res/values-zh-rTW/strings.xml | 5 +---- app/src/main/res/values/donottranslate.xml | 2 +- app/src/main/res/values/strings.xml | 2 -- 29 files changed, 28 insertions(+), 54 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/PollAdapter.kt b/app/src/main/java/com/keylesspalace/tusky/adapter/PollAdapter.kt index adfc681f8..0adc0c371 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/PollAdapter.kt +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/PollAdapter.kt @@ -29,6 +29,7 @@ import com.keylesspalace.tusky.util.CustomEmojiHelper import com.keylesspalace.tusky.util.HtmlUtils import com.keylesspalace.tusky.util.visible import com.keylesspalace.tusky.viewdata.PollOptionViewData +import com.keylesspalace.tusky.viewdata.buildDescription import com.keylesspalace.tusky.viewdata.calculatePercent class PollAdapter: RecyclerView.Adapter() { @@ -71,10 +72,7 @@ class PollAdapter: RecyclerView.Adapter() { when(mode) { RESULT -> { val percent = calculatePercent(option.votesCount, voteCount) - - val pollOptionText = holder.resultTextView.context.getString(R.string.poll_option_format, percent, option.title) - - val emojifiedPollOptionText = CustomEmojiHelper.emojifyText(HtmlUtils.fromHtml(pollOptionText), emojis, holder.resultTextView) + val emojifiedPollOptionText = CustomEmojiHelper.emojifyText(buildDescription(option.title, percent, holder.resultTextView.context), emojis, holder.resultTextView) holder.resultTextView.text = EmojiCompat.get().process(emojifiedPollOptionText) val level = percent * 100 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 5a082cfe1..1d9789758 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java @@ -52,6 +52,8 @@ import at.connyduck.sparkbutton.SparkButton; import at.connyduck.sparkbutton.SparkEventListener; import kotlin.collections.CollectionsKt; +import static com.keylesspalace.tusky.viewdata.PollViewDataKt.buildDescription; + public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { public static class Key { public static final String KEY_CREATED = "created"; @@ -775,10 +777,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { for (int i = 0; i < args.length; i++) { if (i < options.size()) { int percent = PollViewDataKt.calculatePercent(options.get(i).getVotesCount(), poll.getVotesCount()); - args[i] = HtmlUtils.fromHtml(context.getString( - R.string.poll_option_format, - percent, - options.get(i).getTitle())); + args[i] = buildDescription(options.get(i).getTitle(), percent, context); } else { args[i] = ""; } diff --git a/app/src/main/java/com/keylesspalace/tusky/util/NotificationHelper.java b/app/src/main/java/com/keylesspalace/tusky/util/NotificationHelper.java index 805079a7a..39f19c30a 100644 --- a/app/src/main/java/com/keylesspalace/tusky/util/NotificationHelper.java +++ b/app/src/main/java/com/keylesspalace/tusky/util/NotificationHelper.java @@ -69,6 +69,8 @@ import java.util.concurrent.ExecutionException; import io.reactivex.Single; import io.reactivex.schedulers.Schedulers; +import static com.keylesspalace.tusky.viewdata.PollViewDataKt.buildDescription; + public class NotificationHelper { private static int notificationId = 0; @@ -627,9 +629,9 @@ public class NotificationHelper { builder.append('\n'); Poll poll = notification.getStatus().getPoll(); for(PollOption option: poll.getOptions()) { - int percent = PollViewDataKt.calculatePercent(option.getVotesCount(), poll.getVotesCount()); - CharSequence optionText = HtmlUtils.fromHtml(context.getString(R.string.poll_option_format, percent, option.getTitle())); - builder.append(optionText); + builder.append(buildDescription(option.getTitle(), + PollViewDataKt.calculatePercent(option.getVotesCount(), poll.getVotesCount()), + context)); builder.append('\n'); } return builder.toString(); diff --git a/app/src/main/java/com/keylesspalace/tusky/util/StatusViewHelper.kt b/app/src/main/java/com/keylesspalace/tusky/util/StatusViewHelper.kt index fc0b7c9d2..85e89802a 100644 --- a/app/src/main/java/com/keylesspalace/tusky/util/StatusViewHelper.kt +++ b/app/src/main/java/com/keylesspalace/tusky/util/StatusViewHelper.kt @@ -30,6 +30,7 @@ import com.keylesspalace.tusky.entity.Emoji import com.keylesspalace.tusky.entity.Status import com.keylesspalace.tusky.view.MediaPreviewImageView import com.keylesspalace.tusky.viewdata.PollViewData +import com.keylesspalace.tusky.viewdata.buildDescription import com.keylesspalace.tusky.viewdata.calculatePercent import java.text.NumberFormat import java.text.SimpleDateFormat @@ -283,8 +284,8 @@ class StatusViewHelper(private val itemView: View) { if (i < options.size) { val percent = calculatePercent(options[i].votesCount, poll.votesCount) - val pollOptionText = pollResults[i].context.getString(R.string.poll_option_format, percent, options[i].title) - pollResults[i].text = CustomEmojiHelper.emojifyText(HtmlUtils.fromHtml(pollOptionText), emojis, pollResults[i]) + val pollOptionText = buildDescription(options[i].title, percent, pollResults[i].context) + pollResults[i].text = CustomEmojiHelper.emojifyText(pollOptionText, emojis, pollResults[i]) pollResults[i].visibility = View.VISIBLE val level = percent * 100 diff --git a/app/src/main/java/com/keylesspalace/tusky/viewdata/PollViewData.kt b/app/src/main/java/com/keylesspalace/tusky/viewdata/PollViewData.kt index 3b893f8b0..dff0c9f60 100644 --- a/app/src/main/java/com/keylesspalace/tusky/viewdata/PollViewData.kt +++ b/app/src/main/java/com/keylesspalace/tusky/viewdata/PollViewData.kt @@ -15,8 +15,13 @@ package com.keylesspalace.tusky.viewdata +import android.content.Context +import android.text.SpannableStringBuilder +import android.text.Spanned +import com.keylesspalace.tusky.R import com.keylesspalace.tusky.entity.Poll import com.keylesspalace.tusky.entity.PollOption +import com.keylesspalace.tusky.util.HtmlUtils import java.util.* import kotlin.math.roundToInt @@ -44,6 +49,12 @@ fun calculatePercent(fraction: Int, total: Int): Int { } } +fun buildDescription(title: String, percent: Int, context: Context): Spanned { + return SpannableStringBuilder(HtmlUtils.fromHtml(context.getString(R.string.poll_percent_format, percent))) + .append(" ") + .append(title) +} + fun Poll?.toViewData(): PollViewData? { if (this == null) return null return PollViewData( diff --git a/app/src/main/res/values-bn-rIN/strings.xml b/app/src/main/res/values-bn-rIN/strings.xml index e5d857a13..734bb0066 100644 --- a/app/src/main/res/values-bn-rIN/strings.xml +++ b/app/src/main/res/values-bn-rIN/strings.xml @@ -440,7 +440,6 @@ %s বাকি %s এ শেষ হবে বন্ধ - <b>%1$d%%</b> %2$s ভোট diff --git a/app/src/main/res/values-ca/strings.xml b/app/src/main/res/values-ca/strings.xml index da6720c72..970feda81 100644 --- a/app/src/main/res/values-ca/strings.xml +++ b/app/src/main/res/values-ca/strings.xml @@ -465,7 +465,6 @@ Advertència: %s - <b>%1$d%%</b> %2$s Toot fixat Toot no fixat diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index d909a3c26..b504e9e29 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -392,7 +392,6 @@ zbývá %s končí v %s uzavřena - <b>%1$d%%</b> %2$s Hlasovat diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 94f753748..10bc414be 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -376,7 +376,6 @@ %s verbleibend endet um %s Geschlossen - <b>%1$d%%</b> %2$s Abstimmen diff --git a/app/src/main/res/values-eo/strings.xml b/app/src/main/res/values-eo/strings.xml index d62aa4286..8583ba322 100644 --- a/app/src/main/res/values-eo/strings.xml +++ b/app/src/main/res/values-eo/strings.xml @@ -391,7 +391,6 @@ %s restas finiĝos je %s finiĝita - <b>%1$d%%</b> %2$s Voĉdoni diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 8f36f190e..d6f9a9b9e 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -416,8 +416,6 @@ Abrir autor del impulso Mostrar impulsos - <b>%1$d%%</b> %2$s - Dominios ocultos Dominios ocultos Silenciar %s diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 757a94744..5ad03675f 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -421,7 +421,6 @@ Actions pour l’image %s %1$s • %2$s - <b>%1$d%%</b> %2$s Un sondage auquel vous avez participé vient de se terminer diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index de72540d7..ff4828cb8 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -413,7 +413,6 @@ %s maradt vége %s véget ért - <b>%1$d%%</b> %2$s Szavazás diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index 05caa435b..8c3d6ded3 100644 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -450,7 +450,6 @@ %s 남음 %s에 종료 마감됨 - %1$d%% %2$s 투표 diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index c1dd409df..0d3c744e7 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -390,7 +390,6 @@ %s over eindigt op %s gesloten - <b>%1$d%%</b> %2$s Stemmen diff --git a/app/src/main/res/values-no-rNB/strings.xml b/app/src/main/res/values-no-rNB/strings.xml index b7fbaed13..d148b1d7b 100644 --- a/app/src/main/res/values-no-rNB/strings.xml +++ b/app/src/main/res/values-no-rNB/strings.xml @@ -410,7 +410,6 @@ %s igjen avsluttes %s stengt - <b>%1$d%%</b> %2$s Stem diff --git a/app/src/main/res/values-oc/strings.xml b/app/src/main/res/values-oc/strings.xml index 292b8ec5d..fa8238a53 100644 --- a/app/src/main/res/values-oc/strings.xml +++ b/app/src/main/res/values-oc/strings.xml @@ -405,7 +405,6 @@ %1$s • %2$s - <b>%1$d%%</b> %2$s Un sondatge ont avètz votat es acabat Un sondatge qu’avètz creat es acabat diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index eb23d2e7f..b92f1f1cc 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -424,7 +424,6 @@ Zostało %s kończy się %s zakończone - <b>%1$d%%</b> %2$s Głosuj diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 5f47f0703..8fa93a55a 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -400,7 +400,6 @@ %s restando termina em %s Terminou - <b>%1$d%%</b> %2$s Votar diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 896ebd5d3..04abce13e 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -482,9 +482,6 @@ %s завершится %s завершён - - - <b>%1$d%%</b> %2$s Голосовать diff --git a/app/src/main/res/values-sl/strings.xml b/app/src/main/res/values-sl/strings.xml index 5429d458b..81781eed0 100644 --- a/app/src/main/res/values-sl/strings.xml +++ b/app/src/main/res/values-sl/strings.xml @@ -417,7 +417,6 @@ še %s se konča ob %s zaprto - <b>%1$d%%</b> %2$s Glasovanje diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index 7bc6c2ee2..54cf81b63 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -388,7 +388,6 @@ %s kvar avslutas %s stängd - <b>%1$d%%</b> %2$s Rösta diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 18ff9dd99..943baa514 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -459,9 +459,6 @@ 剩余 %s %s 结束 已结束 - - - <b>%1$d%%</b> %2$s 投票 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 942e5c8c1..bd74cdc51 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -454,10 +454,7 @@ 剩餘 %s %s 結束 已結束 - - - <b>%1$d%%</b> %2$s - + 投票 你參與的投票已結束 diff --git a/app/src/main/res/values-zh-rMO/strings.xml b/app/src/main/res/values-zh-rMO/strings.xml index 942e5c8c1..bd74cdc51 100644 --- a/app/src/main/res/values-zh-rMO/strings.xml +++ b/app/src/main/res/values-zh-rMO/strings.xml @@ -454,10 +454,7 @@ 剩餘 %s %s 結束 已結束 - - - <b>%1$d%%</b> %2$s - + 投票 你參與的投票已結束 diff --git a/app/src/main/res/values-zh-rSG/strings.xml b/app/src/main/res/values-zh-rSG/strings.xml index 31d3ce773..c022514b1 100644 --- a/app/src/main/res/values-zh-rSG/strings.xml +++ b/app/src/main/res/values-zh-rSG/strings.xml @@ -459,9 +459,6 @@ 剩余 %s %s 结束 已结束 - - - <b>%1$d%%</b> %2$s 投票 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 81c9263ea..bc4684c38 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -453,10 +453,7 @@ 剩餘 %s %s 結束 已結束 - - - <b>%1$d%%</b> %2$s - + 投票 你參與的投票已結束 diff --git a/app/src/main/res/values/donottranslate.xml b/app/src/main/res/values/donottranslate.xml index 103aeffd9..aca83f892 100644 --- a/app/src/main/res/values/donottranslate.xml +++ b/app/src/main/res/values/donottranslate.xml @@ -138,5 +138,5 @@ 604800 - + <b>%1$d%%</b> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f71993680..a1f78a520 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -484,8 +484,6 @@ %s left ends at %s closed - - <b>%1$d%%</b> %2$s Vote