fix crash on old mastodon instances

main
Conny Duck 6 years ago
parent a03df86c66
commit edec387e53
  1. 4
      app/src/main/java/com/keylesspalace/tusky/AccountActivity.kt
  2. 4
      app/src/main/java/com/keylesspalace/tusky/entity/Account.kt
  3. 8
      app/src/main/java/com/keylesspalace/tusky/util/CustomEmojiHelper.java

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

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

@ -42,13 +42,13 @@ public class CustomEmojiHelper {
/** /**
* replaces emoji shortcodes in a text with EmojiSpans * replaces emoji shortcodes in a text with EmojiSpans
* @param text the text containing custom emojis * @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 * @param textView a reference to the textView the emojis will be shown in
* @return the text with the shortcodes replaced by EmojiSpans * @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); SpannableStringBuilder builder = new SpannableStringBuilder(text);
for (Emoji emoji : emojis) { for (Emoji emoji : emojis) {
@ -71,7 +71,7 @@ public class CustomEmojiHelper {
return text; 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); return emojifyText(new SpannedString(string), emojis, textView);
} }

Loading…
Cancel
Save