Changed code so it would support translations

This commit is contained in:
DMTbvr 2022-01-08 02:12:13 +01:00
parent bf3516dbe4
commit 79246ba461
5 changed files with 40 additions and 15 deletions

View File

@ -74,4 +74,5 @@
<string name="status_replied_to_format">Odpowiedź dla %s</string>
<string name="chat_our_last_message"><b>Ty</b></string>
<string name="pref_title_other">Inne</string>
<string name="status_replied_to_and_more_format">i %d więcej.</string>
</resources>

View File

@ -120,6 +120,7 @@
<string name="status_share_link">Share link to post</string>
<string name="status_boosted_format">%s repeated</string>
<string name="status_replied_to_format">Reply to %s</string>
<string name="status_replied_to_and_more_format">and %d more.</string>
<string name="title_scheduled_toot">Scheduled posts</string>
<string name="title_reblogged_by">Repeated by</string>

View File

@ -44,6 +44,7 @@ import com.keylesspalace.tusky.R;
import com.keylesspalace.tusky.entity.Account;
import com.keylesspalace.tusky.entity.Emoji;
import com.keylesspalace.tusky.entity.Notification;
import com.keylesspalace.tusky.entity.Status;
import com.keylesspalace.tusky.interfaces.AccountActionListener;
import com.keylesspalace.tusky.interfaces.LinkListener;
import com.keylesspalace.tusky.interfaces.StatusActionListener;
@ -713,11 +714,26 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
contentWarningDescriptionTextView.setText(emojifiedContentWarning);
}
private String getReplyToAccountString(Context context, Status.Mention[] mentions){
String replyToAccountString = "";
String format = context.getString(R.string.status_replied_to_and_more_format);
if(mentions != null) {
if (mentions.length > 1) {
replyToAccountString = String.format(Locale.getDefault(),"@%s "+format, mentions[0].getLocalUsername(), mentions.length - 1);
} else if (mentions.length == 1) {
replyToAccountString = String.format("@%s", mentions[0].getLocalUsername());
}
}
return replyToAccountString;
}
private void setupReplyInfo() {
if (statusViewData.getInReplyToId() != null) {
Context context = replyInfo.getContext();
String replyToAccount = statusViewData.getInReplyToAccountAcct();
replyInfo.setText(context.getString(R.string.status_replied_to_format, replyToAccount));
Status.Mention[] mentions = statusViewData.getMentions();
String replyToString = getReplyToAccountString(context, mentions);
replyInfo.setText(context.getString(R.string.status_replied_to_format, replyToAccount+replyToString));
if (!statusViewData.getParentVisible()) {
replyInfo.setPaintFlags(replyInfo.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
replyInfo.setOnClickListener(null);

View File

@ -1,6 +1,7 @@
package com.keylesspalace.tusky.adapter;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
@ -382,11 +383,26 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
}
private String getReplyToAccountString(Context context, Status.Mention[] mentions){
String replyToAccountString = "";
String format = context.getString(R.string.status_replied_to_and_more_format);
if(mentions != null) {
if (mentions.length > 1) {
replyToAccountString = String.format(Locale.getDefault(),"@%s "+format, mentions[0].getLocalUsername(), mentions.length - 1);
} else if (mentions.length == 1) {
replyToAccountString = String.format("@%s", mentions[0].getLocalUsername());
}
}
return replyToAccountString;
}
protected void setReplyInfo(StatusViewData.Concrete status, StatusActionListener listener) {
if (status.getInReplyToId() != null) {
Context context = replyInfo.getContext();
String replyToAccount = status.getInReplyToAccountAcct();
replyInfo.setText(context.getString(R.string.status_replied_to_format, replyToAccount));
Status.Mention[] mentions = status.getMentions();
String replyToString = getReplyToAccountString(context, mentions);
replyInfo.setText(context.getString(R.string.status_replied_to_format, replyToAccount+replyToString));
if (!status.getParentVisible()) {
replyInfo.setPaintFlags(replyInfo.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
replyInfo.setOnClickListener(null);

View File

@ -15,12 +15,15 @@
package com.keylesspalace.tusky.viewdata;
import android.content.res.Resources;
import android.os.Build;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import androidx.annotation.Nullable;
import androidx.core.content.res.ResourcesCompat;
import com.keylesspalace.tusky.R;
import com.keylesspalace.tusky.entity.Attachment;
import com.keylesspalace.tusky.entity.Card;
import com.keylesspalace.tusky.entity.Emoji;
@ -105,18 +108,6 @@ public abstract class StatusViewData {
private final List<EmojiReaction> emojiReactions;
private final boolean parentVisible;
private String getReplyToAccountString(){
String replyToAccountString = "";
if(this.mentions != null) {
if (this.mentions.length > 1) {
replyToAccountString = String.format(Locale.getDefault(),"@%s and %d more", this.mentions[0].getLocalUsername(), this.mentions.length - 1);
} else if (this.mentions.length == 1) {
replyToAccountString = String.format("@%s", this.mentions[0].getLocalUsername());
}
}
return replyToAccountString;
}
public Concrete(String id, Spanned content, boolean reblogged, boolean favourited, boolean bookmarked,
@Nullable String spoilerText, Status.Visibility visibility, List<Attachment> attachments,
@Nullable String rebloggedByUsername, @Nullable String rebloggedAvatar, boolean sensitive, boolean isExpanded,
@ -154,8 +145,8 @@ public abstract class StatusViewData {
this.reblogsCount = reblogsCount;
this.favouritesCount = favouritesCount;
this.inReplyToId = inReplyToId;
this.inReplyToAccountAcct = inReplyToAccountAcct;
this.mentions = mentions;
this.inReplyToAccountAcct = getReplyToAccountString();
this.senderId = senderId;
this.rebloggingEnabled = rebloggingEnabled;
this.application = application;