fix crash on old mastodon instances

This commit is contained in:
Conny Duck 2018-07-01 13:33:16 +02:00
parent 71f4f0ad2d
commit 0930fab72b
3 changed files with 8 additions and 8 deletions

View file

@ -325,8 +325,8 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasSupportF
.load(account.header)
.into(accountHeaderImageView)
accountFieldAdapter.fields = account.fields
accountFieldAdapter.emojis = account.emojis
accountFieldAdapter.fields = account.fields ?: emptyList()
accountFieldAdapter.emojis = account.emojis ?: emptyList()
accountFieldAdapter.notifyDataSetChanged()
if (account.moved != null) {

View file

@ -41,8 +41,8 @@ data class Account(
@SerializedName("statuses_count") val statusesCount: Int,
val source: AccountSource?,
val bot: Boolean,
val emojis: List<Emoji> = emptyList(),
val fields: List<Field> = emptyList(),
val emojis: List<Emoji>?, // nullable for backward compatibility
val fields: List<Field>?, //nullable for backward compatibility
val moved: Account? = null
) : Parcelable {

View file

@ -42,13 +42,13 @@ public class CustomEmojiHelper {
/**
* replaces emoji shortcodes in a text with EmojiSpans
* @param text the text containing custom emojis
* @param emojis a list of the custom emojis
* @param emojis a list of the custom emojis (nullable for backward compatibility with old mastodon instances)
* @param textView a reference to the textView the emojis will be shown in
* @return the text with the shortcodes replaced by EmojiSpans
*/
public static Spanned emojifyText(@NonNull Spanned text, @NonNull List<Emoji> emojis, @NonNull final TextView textView) {
public static Spanned emojifyText(@NonNull Spanned text, @Nullable List<Emoji> emojis, @NonNull final TextView textView) {
if (!emojis.isEmpty()) {
if (emojis != null && !emojis.isEmpty()) {
SpannableStringBuilder builder = new SpannableStringBuilder(text);
for (Emoji emoji : emojis) {
@ -71,7 +71,7 @@ public class CustomEmojiHelper {
return text;
}
public static Spanned emojifyString(@NonNull String string, @NonNull List<Emoji> emojis, @NonNull final TextView textView) {
public static Spanned emojifyString(@NonNull String string, @Nullable List<Emoji> emojis, @NonNull final TextView textView) {
return emojifyText(new SpannedString(string), emojis, textView);
}