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
main
Levi Bard 5 years ago committed by Konrad Pozniak
parent 9afe1d3f4b
commit 5ce9a416b9
  1. 6
      app/src/main/java/com/keylesspalace/tusky/adapter/PollAdapter.kt
  2. 7
      app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java
  3. 8
      app/src/main/java/com/keylesspalace/tusky/util/NotificationHelper.java
  4. 5
      app/src/main/java/com/keylesspalace/tusky/util/StatusViewHelper.kt
  5. 11
      app/src/main/java/com/keylesspalace/tusky/viewdata/PollViewData.kt
  6. 1
      app/src/main/res/values-bn-rIN/strings.xml
  7. 1
      app/src/main/res/values-ca/strings.xml
  8. 1
      app/src/main/res/values-cs/strings.xml
  9. 1
      app/src/main/res/values-de/strings.xml
  10. 1
      app/src/main/res/values-eo/strings.xml
  11. 2
      app/src/main/res/values-es/strings.xml
  12. 1
      app/src/main/res/values-fr/strings.xml
  13. 1
      app/src/main/res/values-hu/strings.xml
  14. 1
      app/src/main/res/values-ko/strings.xml
  15. 1
      app/src/main/res/values-nl/strings.xml
  16. 1
      app/src/main/res/values-no-rNB/strings.xml
  17. 1
      app/src/main/res/values-oc/strings.xml
  18. 1
      app/src/main/res/values-pl/strings.xml
  19. 1
      app/src/main/res/values-pt-rBR/strings.xml
  20. 3
      app/src/main/res/values-ru/strings.xml
  21. 1
      app/src/main/res/values-sl/strings.xml
  22. 1
      app/src/main/res/values-sv/strings.xml
  23. 3
      app/src/main/res/values-zh-rCN/strings.xml
  24. 5
      app/src/main/res/values-zh-rHK/strings.xml
  25. 5
      app/src/main/res/values-zh-rMO/strings.xml
  26. 3
      app/src/main/res/values-zh-rSG/strings.xml
  27. 5
      app/src/main/res/values-zh-rTW/strings.xml
  28. 2
      app/src/main/res/values/donottranslate.xml
  29. 2
      app/src/main/res/values/strings.xml

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

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

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

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

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

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

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

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

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

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

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

@ -421,7 +421,6 @@
<string name="compose_preview_image_description">Actions pour l’image %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>

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

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

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

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

@ -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 qu’avètz creat es acabat</string>

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

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

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

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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save