From cc0be0318f1ef2f531086a3c1efbcdbd4bd41023 Mon Sep 17 00:00:00 2001 From: Nik Clayton Date: Sun, 17 Dec 2023 07:01:56 +0100 Subject: [PATCH] fix: Prevent crash if a trending tab is present (#330) Old versions of the preference value could have been serialised without the `_` in the name, so handle those specially. Fixes #329 --- .../kotlin/app/pachli/core/database/model/TabData.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/core/database/src/main/kotlin/app/pachli/core/database/model/TabData.kt b/core/database/src/main/kotlin/app/pachli/core/database/model/TabData.kt index 05be71e4b..33dcac698 100644 --- a/core/database/src/main/kotlin/app/pachli/core/database/model/TabData.kt +++ b/core/database/src/main/kotlin/app/pachli/core/database/model/TabData.kt @@ -43,8 +43,16 @@ data class TabData(val kind: TabKind, val arguments: List = emptyList()) fun from(kind: TabKind, arguments: List = emptyList()) = TabData(kind, arguments) - fun from(kind: String, arguments: List = emptyList()) = - TabData(TabKind.valueOf(kind.uppercase()), arguments) + fun from(kind: String, arguments: List = emptyList()): TabData { + // Work around for https://github.com/pachli/pachli-android/issues/329, + // as the Trending... kinds may have been serialised without the `_` + return when(kind) { + "TrendingTags" -> TabData(TabKind.TRENDING_TAGS, arguments) + "TrendingLinks" -> TabData(TabKind.TRENDING_LINKS, arguments) + "TrendingStatuses" -> TabData(TabKind.TRENDING_STATUSES, arguments) + else -> TabData(TabKind.valueOf(kind.uppercase()), arguments) + } + } } }