Fixing BookUtil error

This commit is contained in:
Hritik Wadhwa 2020-03-20 03:27:28 +05:30
parent 91fc864d9f
commit 41b7abf565
2 changed files with 5 additions and 6 deletions

View File

@ -45,7 +45,7 @@ fun Book.buildSearchableText(bookUtils: BookUtils): String =
append(NetworkUtils.parseURL(CoreApp.getInstance(), url))
append("|")
if (bookUtils.localeMap.containsKey(language)) {
append(bookUtils.localeMap[language]!!.displayLanguage)
append(bookUtils.localeMap[language]?.displayLanguage)
append("|")
}
}.toString()

View File

@ -17,25 +17,24 @@
*/
package org.kiwix.kiwixmobile.core.utils
import java.util.HashMap
import java.util.Locale
/**
* Created by mhutti1 on 19/04/17.
*/
class BookUtils {
val localeMap = Locale.getISOLanguages().associateBy { Locale(it).isO3Language; Locale(it) }
val localeMap = Locale.getISOLanguages().associateBy({ Locale(it).isO3Language }, ::Locale)
// Get the language from the language codes of the parsed xml stream
@Suppress("MagicNumber")
fun getLanguage(languageCode: String?): String {
fun getLanguage(languageCode: String): String? {
return when {
languageCode == null -> ""
languageCode.length == 2 -> {
LanguageContainer(languageCode).languageName
}
languageCode.length == 3 -> {
localeMap.filter { it.value == languageCode }.keys.first().displayLanguage
localeMap[languageCode]?.displayLanguage
}
else -> {
""
@ -43,4 +42,4 @@ class BookUtils {
}
}
}
}