From 1c982c2a01c1bba5ec4a955c9bf61cb346c752e7 Mon Sep 17 00:00:00 2001 From: AntsyLich <59261191+AntsyLich@users.noreply.github.com> Date: Tue, 22 Apr 2025 19:02:52 +0600 Subject: [PATCH] Fix crash when trying use source sort filter without a pre-selection (#2036) --- CHANGELOG.md | 1 + .../source/browse/SourceFilterDialog.kt | 30 ++++++++++--------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 377be3079..b81762ba0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co - Fix navigation issue after migrating a duplicated entry from History tab ([@cuong-tran](https://github.com/cuong-tran)) ([#1980](https://github.com/mihonapp/mihon/pull/1980)) - Fix duplicate requests in WebView due to empty reasonPhrase ([@AwkwardPeak7](https://github.com/AwkwardPeak7)) ([#2003](https://github.com/mihonapp/mihon/pull/2003)) - Fix content under source browse screen top appbar is interactable ([@AntsyLich](https://github.com/AntsyLich)) ([#2026](https://github.com/mihonapp/mihon/pull/2026)) +- Fix crash when trying use source sort filter without a pre-selection ([@AntsyLich](https://github.com/AntsyLich)) ([#2036](https://github.com/mihonapp/mihon/pull/2036)) ### Removed - Remove Okhttp networking from WebView Screen ([@AwkwardPeak7](https://github.com/AwkwardPeak7)) ([#2020](https://github.com/mihonapp/mihon/pull/2020)) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/SourceFilterDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/SourceFilterDialog.kt index 42355c504..6ff7c6087 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/SourceFilterDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/SourceFilterDialog.kt @@ -128,22 +128,24 @@ private fun FilterItem(filter: Filter<*>, onUpdate: () -> Unit) { ) { Column { filter.values.mapIndexed { index, item -> + val sortAscending = filter.state?.ascending + ?.takeIf { index == filter.state?.index } SortItem( label = item, - sortDescending = filter.state?.ascending?.not() - ?.takeIf { index == filter.state?.index }, - ) { - val ascending = if (index == filter.state?.index) { - !filter.state!!.ascending - } else { - filter.state!!.ascending - } - filter.state = Filter.Sort.Selection( - index = index, - ascending = ascending, - ) - onUpdate() - } + sortDescending = if (sortAscending != null) !sortAscending else null, + onClick = { + val ascending = if (index == filter.state?.index) { + !filter.state!!.ascending + } else { + filter.state?.ascending ?: true + } + filter.state = Filter.Sort.Selection( + index = index, + ascending = ascending, + ) + onUpdate() + }, + ) } } }