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
This commit is contained in:
Levi Bard 2019-10-11 17:35:22 +02:00 committed by Konrad Pozniak
parent a5cccb2056
commit a308b4c139
29 changed files with 28 additions and 54 deletions

View file

@ -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<PollViewHolder>() {
@ -71,10 +72,7 @@ class PollAdapter: RecyclerView.Adapter<PollViewHolder>() {
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

View file

@ -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] = "";
}

View file

@ -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();

View file

@ -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

View file

@ -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(

View file

@ -440,7 +440,6 @@
<string name="poll_info_time_relative">%s বাকি</string>
<string name="poll_info_time_absolute">%s এ শেষ হবে</string>
<string name="poll_info_closed">বন্ধ</string>
<string name="poll_option_format"> <!-- ১৫% এতে ভোট দিয়েছে! --> &lt;b&gt;%1$d%%&lt;/b&gt; %2$s</string>
<string name="poll_vote">ভোট</string>

View file

@ -465,7 +465,6 @@
</plurals>
<string name="description_status_cw">Advertència: %s</string>
<string name="poll_option_format"> <!-- 15% vota aquesta acció! --> &lt;b&gt;%1$d%%&lt;/b&gt; %2$s</string>
<string name="title_statuses_pinned">Toot fixat</string>
<string name="unpin_action">Toot no fixat</string>

View file

@ -392,7 +392,6 @@
<string name="poll_info_time_relative">zbývá %s</string>
<string name="poll_info_time_absolute">končí v %s</string>
<string name="poll_info_closed">uzavřena</string>
<string name="poll_option_format"> <!-- 15% vote for this! --> &lt;b&gt;%1$d%%&lt;/b&gt; %2$s</string>
<string name="poll_vote">Hlasovat</string>

View file

@ -376,7 +376,6 @@
<string name="poll_info_time_relative">%s verbleibend</string>
<string name="poll_info_time_absolute">endet um %s</string>
<string name="poll_info_closed">Geschlossen</string>
<string name="poll_option_format"> &lt;b&gt;%1$d%%&lt;/b&gt; %2$s</string>
<string name="poll_vote">Abstimmen</string>

View file

@ -391,7 +391,6 @@
<string name="poll_info_time_relative">%s restas</string>
<string name="poll_info_time_absolute">finiĝos je %s</string>
<string name="poll_info_closed">finiĝita</string>
<string name="poll_option_format"> <!-- 15% vote for this! --> &lt;b&gt;%1$d%%&lt;/b&gt; %2$s</string>
<string name="poll_vote">Voĉdoni</string>

View file

@ -416,8 +416,6 @@
<string name="action_open_reblogger">Abrir autor del impulso</string>
<string name="action_open_reblogged_by">Mostrar impulsos</string>
<string name="poll_option_format"> <!-- 15% vote for this! --> &lt;b&gt;%1$d%%&lt;/b&gt; %2$s</string>
<string name="title_domain_mutes">Dominios ocultos</string>
<string name="action_view_domain_mutes">Dominios ocultos</string>
<string name="action_mute_domain">Silenciar %s</string>

View file

@ -421,7 +421,6 @@
<string name="compose_preview_image_description">Actions pour limage %s</string>
<string name="poll_info_format"> <!-- 15 votes • 1 heure restante --> %1$s • %2$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_ended_voted">Un sondage auquel vous avez participé vient de se terminer</string>

View file

@ -413,7 +413,6 @@
<string name="poll_info_time_relative">%s maradt</string>
<string name="poll_info_time_absolute">vége %s</string>
<string name="poll_info_closed">véget ért</string>
<string name="poll_option_format"> <!-- 15% erre szavazott! --> &lt;b&gt;%1$d%%&lt;/b&gt; %2$s</string>
<string name="poll_vote">Szavazás</string>

View file

@ -450,7 +450,6 @@
<string name="poll_info_time_relative">%s 남음</string>
<string name="poll_info_time_absolute">%s에 종료</string>
<string name="poll_info_closed">마감됨</string>
<string name="poll_option_format"> <!-- 15% 가 투표했습니다 --> <b>%1$d%%</b> %2$s</string>
<string name="poll_vote">투표</string>

View file

@ -390,7 +390,6 @@
<string name="poll_info_time_relative">%s over</string>
<string name="poll_info_time_absolute">eindigt op %s</string>
<string name="poll_info_closed">gesloten</string>
<string name="poll_option_format"> <!-- 15% vote for this! --> &lt;b&gt;%1$d%%&lt;/b&gt; %2$s</string>
<string name="poll_vote">Stemmen</string>

View file

@ -410,7 +410,6 @@
<string name="poll_info_time_relative">%s igjen</string>
<string name="poll_info_time_absolute">avsluttes %s</string>
<string name="poll_info_closed">stengt</string>
<string name="poll_option_format"> <!-- 15% vote for this! --> &lt;b&gt;%1$d%%&lt;/b&gt; %2$s</string>
<string name="poll_vote">Stem</string>

View file

@ -405,7 +405,6 @@
<string name="poll_info_format"> <!-- 15 votes • 1 hour left --> %1$s • %2$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_ended_voted">Un sondatge ont avètz votat es acabat</string>
<string name="poll_ended_created">Un sondatge quavètz creat es acabat</string>

View file

@ -424,7 +424,6 @@
<string name="poll_info_time_relative">Zostało %s</string>
<string name="poll_info_time_absolute">kończy się %s</string>
<string name="poll_info_closed">zakończone</string>
<string name="poll_option_format"> <!-- 15% na to głosuje! --> &lt;b&gt;%1$d%%&lt;/b&gt; %2$s</string>
<string name="poll_vote">Głosuj</string>

View file

@ -400,7 +400,6 @@
<string name="poll_info_time_relative">%s restando</string>
<string name="poll_info_time_absolute">termina em %s</string>
<string name="poll_info_closed">Terminou</string>
<string name="poll_option_format"> <!-- 15% vote for this! --> &lt;b&gt;%1$d%%&lt;/b&gt; %2$s</string>
<string name="poll_vote">Votar</string>

View file

@ -482,9 +482,6 @@
<string name="poll_info_time_relative">%s</string>
<string name="poll_info_time_absolute">завершится %s</string>
<string name="poll_info_closed">завершён</string>
<string name="poll_option_format">
<!-- 15% vote for this! -->
&lt;b&gt;%1$d%%&lt;/b&gt; %2$s</string>
<string name="poll_vote">Голосовать</string>

View file

@ -417,7 +417,6 @@
<string name="poll_info_time_relative">še %s</string>
<string name="poll_info_time_absolute">se konča ob %s</string>
<string name="poll_info_closed">zaprto</string>
<string name="poll_option_format"> <!-- 15% vote for this! --> &lt;b&gt;%1$d%%&lt;/b&gt; %2$s</string>
<string name="poll_vote">Glasovanje</string>

View file

@ -388,7 +388,6 @@
<string name="poll_info_time_relative">%s kvar</string>
<string name="poll_info_time_absolute">avslutas %s</string>
<string name="poll_info_closed">stängd</string>
<string name="poll_option_format"> <!-- 15% röstar på detta! --> &lt;b&gt;%1$d%%&lt;/b&gt; %2$s</string>
<string name="poll_vote">Rösta</string>

View file

@ -459,9 +459,6 @@
<string name="poll_info_time_relative">剩余 %s</string>
<string name="poll_info_time_absolute">%s 结束</string>
<string name="poll_info_closed">已结束</string>
<string name="poll_option_format">
<!-- 15% vote for this! -->
&lt;b&gt;%1$d%%&lt;/b&gt; %2$s</string>
<string name="poll_vote">投票</string>

View file

@ -454,10 +454,7 @@
<string name="poll_info_time_relative">剩餘 %s</string>
<string name="poll_info_time_absolute">%s 結束</string>
<string name="poll_info_closed">已結束</string>
<string name="poll_option_format">
<!-- 15% vote for this! -->
&lt;b>%1$d%%&lt;/b> %2$s</string>
<string name="poll_vote">投票</string>
<string name="poll_ended_voted">你參與的投票已結束</string>

View file

@ -454,10 +454,7 @@
<string name="poll_info_time_relative">剩餘 %s</string>
<string name="poll_info_time_absolute">%s 結束</string>
<string name="poll_info_closed">已結束</string>
<string name="poll_option_format">
<!-- 15% vote for this! -->
&lt;b>%1$d%%&lt;/b> %2$s</string>
<string name="poll_vote">投票</string>
<string name="poll_ended_voted">你參與的投票已結束</string>

View file

@ -459,9 +459,6 @@
<string name="poll_info_time_relative">剩余 %s</string>
<string name="poll_info_time_absolute">%s 结束</string>
<string name="poll_info_closed">已结束</string>
<string name="poll_option_format">
<!-- 15% vote for this! -->
&lt;b>%1$d%%&lt;/b> %2$s</string>
<string name="poll_vote">投票</string>

View file

@ -453,10 +453,7 @@
<string name="poll_info_time_relative">剩餘 %s</string>
<string name="poll_info_time_absolute">%s 結束</string>
<string name="poll_info_closed">已結束</string>
<string name="poll_option_format">
<!-- 15% vote for this! -->
&lt;b&gt;%1$d%%&lt;/b&gt; %2$s</string>
<string name="poll_vote">投票</string>
<string name="poll_ended_voted">你參與的投票已結束</string>

View file

@ -138,5 +138,5 @@
<item>604800</item>
</integer-array>
<string name="poll_percent_format"><!-- 15% --> &lt;b>%1$d%%&lt;/b></string>
</resources>

View file

@ -484,8 +484,6 @@
<string name="poll_info_time_relative">%s left</string>
<string name="poll_info_time_absolute">ends at %s</string>
<string name="poll_info_closed">closed</string>
<string name="poll_option_format">
<!-- 15% vote for this! --> &lt;b>%1$d%%&lt;/b> %2$s</string>
<string name="poll_vote">Vote</string>