From 88b8eca16aac9399a727f03261026b91d910c293 Mon Sep 17 00:00:00 2001 From: Konrad Pozniak Date: Fri, 7 Feb 2020 20:23:51 +0100 Subject: [PATCH] fix crash when Account.displayName is null (#1667) --- app/src/main/java/com/keylesspalace/tusky/AccountActivity.kt | 2 +- .../tusky/components/conversation/ConversationEntity.kt | 2 +- app/src/main/java/com/keylesspalace/tusky/entity/Account.kt | 4 ++-- .../com/keylesspalace/tusky/repository/TimelineRepository.kt | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/AccountActivity.kt b/app/src/main/java/com/keylesspalace/tusky/AccountActivity.kt index d2868631..4a1caaa2 100644 --- a/app/src/main/java/com/keylesspalace/tusky/AccountActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/AccountActivity.kt @@ -458,7 +458,7 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidI loadAvatar(movedAccount.avatar, accountMovedAvatar, avatarRadius, animateAvatar) - accountMovedText.text = getString(R.string.account_moved_description, movedAccount.displayName) + accountMovedText.text = getString(R.string.account_moved_description, movedAccount.name) // this is necessary because API 19 can't handle vector compound drawables val movedIcon = ContextCompat.getDrawable(this, R.drawable.ic_briefcase)?.mutate() diff --git a/app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationEntity.kt b/app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationEntity.kt index a59df12b..7c4ed108 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationEntity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationEntity.kt @@ -166,7 +166,7 @@ fun Account.toEntity() = ConversationAccountEntity( id, username, - displayName, + displayName.orEmpty(), avatar, emojis ?: emptyList() ) diff --git a/app/src/main/java/com/keylesspalace/tusky/entity/Account.kt b/app/src/main/java/com/keylesspalace/tusky/entity/Account.kt index 71518573..62990758 100644 --- a/app/src/main/java/com/keylesspalace/tusky/entity/Account.kt +++ b/app/src/main/java/com/keylesspalace/tusky/entity/Account.kt @@ -31,7 +31,7 @@ data class Account( val id: String, @SerializedName("username") val localUsername: String, @SerializedName("acct") val username: String, - @SerializedName("display_name") val displayName: String, + @SerializedName("display_name") val displayName: String?, // should never be null per Api definition, but some servers break the contract val note: @WriteWith() Spanned, val url: String, val avatar: String, @@ -49,7 +49,7 @@ data class Account( ) : Parcelable { val name: String - get() = if (displayName.isEmpty()) { + get() = if (displayName.isNullOrEmpty()) { localUsername } else displayName diff --git a/app/src/main/java/com/keylesspalace/tusky/repository/TimelineRepository.kt b/app/src/main/java/com/keylesspalace/tusky/repository/TimelineRepository.kt index 7cdc9ac9..06c001c9 100644 --- a/app/src/main/java/com/keylesspalace/tusky/repository/TimelineRepository.kt +++ b/app/src/main/java/com/keylesspalace/tusky/repository/TimelineRepository.kt @@ -298,7 +298,7 @@ fun Account.toEntity(accountId: Long, gson: Gson): TimelineAccountEntity { timelineUserId = accountId, localUsername = localUsername, username = username, - displayName = displayName, + displayName = displayName.orEmpty(), url = url, avatar = avatar, emojis = gson.toJson(emojis),