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
This commit is contained in:
Nik Clayton 2023-12-17 07:01:56 +01:00 committed by GitHub
parent 88466373b3
commit cc0be0318f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 2 deletions

View File

@ -43,8 +43,16 @@ data class TabData(val kind: TabKind, val arguments: List<String> = emptyList())
fun from(kind: TabKind, arguments: List<String> = emptyList()) =
TabData(kind, arguments)
fun from(kind: String, arguments: List<String> = emptyList()) =
TabData(TabKind.valueOf(kind.uppercase()), arguments)
fun from(kind: String, arguments: List<String> = 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)
}
}
}
}