From df45c0cd96446ae796c3b656634ffba8d66ca916 Mon Sep 17 00:00:00 2001 From: Nik Clayton Date: Sat, 9 Dec 2023 22:30:31 +0100 Subject: [PATCH] fix: Prevent crash showing profile if account has null `createdAt` field --- .../pachli/components/account/AccountActivity.kt | 14 ++++++++------ .../app/pachli/core/network/model/Account.kt | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/app/pachli/components/account/AccountActivity.kt b/app/src/main/java/app/pachli/components/account/AccountActivity.kt index 544d53307..ff409e740 100644 --- a/app/src/main/java/app/pachli/components/account/AccountActivity.kt +++ b/app/src/main/java/app/pachli/components/account/AccountActivity.kt @@ -503,13 +503,15 @@ class AccountActivity : private fun updateAccountJoinedDate() { loadedAccount?.let { account -> try { - binding.accountDateJoined.text = resources.getString( - R.string.account_date_joined, - SimpleDateFormat("MMMM, yyyy", Locale.getDefault()).format(account.createdAt), - ) - binding.accountDateJoined.visibility = View.VISIBLE + account.createdAt?.let { createdAt -> + binding.accountDateJoined.text = resources.getString( + R.string.account_date_joined, + SimpleDateFormat("MMMM, yyyy", Locale.getDefault()).format(createdAt), + ) + binding.accountDateJoined.show() + } ?: binding.accountDateJoined.hide() } catch (e: ParseException) { - binding.accountDateJoined.visibility = View.GONE + binding.accountDateJoined.hide() } } } diff --git a/core/network/src/main/kotlin/app/pachli/core/network/model/Account.kt b/core/network/src/main/kotlin/app/pachli/core/network/model/Account.kt index 63a7d0628..11e7a56ba 100644 --- a/core/network/src/main/kotlin/app/pachli/core/network/model/Account.kt +++ b/core/network/src/main/kotlin/app/pachli/core/network/model/Account.kt @@ -23,8 +23,8 @@ data class Account( val id: String, @SerializedName("username") val localUsername: String, @SerializedName("acct") val username: String, - @SerializedName("display_name") val displayName: String?, // should never be null per Api definition, but some servers break the contract - @SerializedName("created_at") val createdAt: Date, + @SerializedName("display_name") val displayName: String?, // should never be null per API definition, but some servers break the contract + @SerializedName("created_at") val createdAt: Date?, // should never be null per API definition, but some servers break the contract val note: String, val url: String, val avatar: String,