diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/model/Manga.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/model/Manga.kt index 2d7101042..5c5ef2883 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/model/Manga.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/model/Manga.kt @@ -48,10 +48,10 @@ fun Manga.getPreferredBranch(history: MangaHistory?): String? { if (groups.size == 1) { return groups.keys.first() } - val candidates = HashMap>(groups.size) for (locale in LocaleListCompat.getAdjustedDefault()) { val displayLanguage = locale.getDisplayLanguage(locale) val displayName = locale.getDisplayName(locale) + val candidates = HashMap>(3) for (branch in groups.keys) { if (branch != null && ( branch.contains(displayLanguage, ignoreCase = true) || @@ -61,8 +61,11 @@ fun Manga.getPreferredBranch(history: MangaHistory?): String? { candidates[branch] = groups[branch] ?: continue } } + if (candidates.isNotEmpty()) { + return candidates.maxBy { it.value.size }.key + } } - return candidates.ifEmpty { groups }.maxByOrNull { it.value.size }?.key + return groups.maxByOrNull { it.value.size }?.key } val Manga.isLocal: Boolean