mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-04 03:06:41 -04:00
Fixed: UseOrEmpty issue of detekt to simplify the conditions and use the already available extension functions
This commit is contained in:
parent
226289fbad
commit
d521acd3a6
@ -36,7 +36,7 @@ internal class JNIInitialiser @Inject constructor(context: Context, jniKiwix: JN
|
||||
if (!icuDir.exists()) {
|
||||
icuDir.mkdirs()
|
||||
}
|
||||
val icuFileNames = context.assets.list("icu") ?: emptyArray()
|
||||
val icuFileNames = context.assets.list("icu").orEmpty()
|
||||
for (icuFileName in icuFileNames) {
|
||||
val icuDataFile = File(icuDir, icuFileName)
|
||||
if (!icuDataFile.exists()) {
|
||||
|
@ -125,7 +125,7 @@ class LibkiwixBookmarks @Inject constructor(
|
||||
getBookmarksList()
|
||||
.filter { it.zimId == reader.id }
|
||||
.map(LibkiwixBookmarkItem::bookmarkUrl)
|
||||
} ?: emptyList()
|
||||
}.orEmpty()
|
||||
}
|
||||
|
||||
fun bookmarkUrlsForCurrentBook(zimId: String): Flowable<List<String>> =
|
||||
|
@ -56,13 +56,13 @@ class NewBookmarksDao @Inject constructor(val box: Box<BookmarkEntity>) : PageDa
|
||||
box.query {
|
||||
equal(
|
||||
BookmarkEntity_.zimId,
|
||||
zimFileReader?.id ?: "",
|
||||
zimFileReader?.id.orEmpty(),
|
||||
QueryBuilder.StringOrder.CASE_INSENSITIVE
|
||||
)
|
||||
.or()
|
||||
.equal(
|
||||
BookmarkEntity_.zimName,
|
||||
zimFileReader?.name ?: "",
|
||||
zimFileReader?.name.orEmpty(),
|
||||
QueryBuilder.StringOrder.CASE_INSENSITIVE
|
||||
)
|
||||
order(BookmarkEntity_.bookmarkTitle)
|
||||
@ -76,7 +76,7 @@ class NewBookmarksDao @Inject constructor(val box: Box<BookmarkEntity>) : PageDa
|
||||
box.query {
|
||||
equal(
|
||||
BookmarkEntity_.zimId,
|
||||
zimFileReader?.id ?: "",
|
||||
zimFileReader?.id.orEmpty(),
|
||||
QueryBuilder.StringOrder.CASE_INSENSITIVE
|
||||
)
|
||||
.or()
|
||||
|
@ -35,7 +35,7 @@ class NewRecentSearchDao @Inject constructor(
|
||||
box.query {
|
||||
equal(
|
||||
RecentSearchEntity_.zimId,
|
||||
zimId ?: "",
|
||||
zimId.orEmpty(),
|
||||
QueryBuilder.StringOrder.CASE_INSENSITIVE
|
||||
)
|
||||
orderDesc(RecentSearchEntity_.id)
|
||||
|
@ -90,13 +90,13 @@ data class BookOnDiskEntity(
|
||||
|
||||
class ZimSourceConverter : PropertyConverter<ZimReaderSource, String> {
|
||||
override fun convertToDatabaseValue(entityProperty: ZimReaderSource?): String =
|
||||
entityProperty?.toDatabase() ?: ""
|
||||
entityProperty?.toDatabase().orEmpty()
|
||||
|
||||
override fun convertToEntityProperty(databaseValue: String?): ZimReaderSource =
|
||||
fromDatabaseValue(databaseValue) ?: ZimReaderSource(File(""))
|
||||
}
|
||||
|
||||
class StringToFileConverter : PropertyConverter<File, String> {
|
||||
override fun convertToDatabaseValue(entityProperty: File?) = entityProperty?.path ?: ""
|
||||
override fun convertToEntityProperty(databaseValue: String?) = File(databaseValue ?: "")
|
||||
override fun convertToDatabaseValue(entityProperty: File?) = entityProperty?.path.orEmpty()
|
||||
override fun convertToEntityProperty(databaseValue: String?) = File(databaseValue.orEmpty())
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ data class HistoryRoomEntity(
|
||||
class ZimSourceRoomConverter {
|
||||
@TypeConverter
|
||||
fun convertToDatabaseValue(entityProperty: ZimReaderSource?): String =
|
||||
entityProperty?.toDatabase() ?: ""
|
||||
entityProperty?.toDatabase().orEmpty()
|
||||
|
||||
@TypeConverter
|
||||
fun convertToEntityProperty(databaseValue: String?): ZimReaderSource =
|
||||
|
@ -31,7 +31,7 @@ class BasicAuthInterceptor : Interceptor {
|
||||
val request: Request = chain.request()
|
||||
val url = request.url.toString()
|
||||
if (url.isAuthenticationUrl) {
|
||||
val userNameAndPassword = System.getenv(url.secretKey) ?: ""
|
||||
val userNameAndPassword = System.getenv(url.secretKey).orEmpty()
|
||||
val userName = userNameAndPassword.substringBefore(":", "")
|
||||
val password = userNameAndPassword.substringAfter(":", "")
|
||||
val credentials = okhttp3.Credentials.basic(userName, password)
|
||||
|
@ -43,7 +43,7 @@ data class DownloadItem(
|
||||
val eta: Seconds,
|
||||
val downloadState: DownloadState
|
||||
) {
|
||||
val readableEta: CharSequence = eta.takeIf { it.seconds > 0L }?.toHumanReadableTime() ?: ""
|
||||
val readableEta: CharSequence = eta.takeIf { it.seconds > 0L }?.toHumanReadableTime().orEmpty()
|
||||
|
||||
constructor(downloadModel: DownloadModel) : this(
|
||||
downloadModel.downloadId,
|
||||
|
@ -182,8 +182,8 @@ class AddNoteDialog : DialogFragment() {
|
||||
|
||||
private val zimNoteDirectoryName: String
|
||||
get() {
|
||||
val noteDirectoryName = getTextAfterLastSlashWithoutExtension(zimFileName ?: "")
|
||||
return (if (noteDirectoryName.isNotEmpty()) noteDirectoryName else zimFileTitle) ?: ""
|
||||
val noteDirectoryName = getTextAfterLastSlashWithoutExtension(zimFileName.orEmpty())
|
||||
return (if (noteDirectoryName.isNotEmpty()) noteDirectoryName else zimFileTitle).orEmpty()
|
||||
}
|
||||
|
||||
private fun getArticleNoteFileName(): String {
|
||||
@ -199,7 +199,7 @@ class AddNoteDialog : DialogFragment() {
|
||||
} else {
|
||||
noteFileName = getTextAfterLastSlashWithoutExtension(articleUrl)
|
||||
}
|
||||
return noteFileName.ifEmpty { articleTitle } ?: ""
|
||||
return noteFileName.ifEmpty { articleTitle }.orEmpty()
|
||||
}
|
||||
|
||||
/* From ".../Kiwix/granbluefantasy_en_all_all_nopic_2018-10.zim", returns "granbluefantasy_en_all_all_nopic_2018-10"
|
||||
|
@ -145,7 +145,7 @@ class KiwixTextToSpeech internal constructor(
|
||||
languageAvailabilityResult == LANG_MISSING_DATA ||
|
||||
languageAvailabilityResult == LANG_NOT_SUPPORTED
|
||||
|
||||
private fun getFeatures(tts: TextToSpeech?): Set<String> = tts?.voice?.features ?: setOf()
|
||||
private fun getFeatures(tts: TextToSpeech?): Set<String> = tts?.voice?.features.orEmpty()
|
||||
|
||||
private fun loadURL(webView: WebView) {
|
||||
// We use JavaScript to get the content of the page conveniently, earlier making some
|
||||
|
@ -51,7 +51,7 @@ class ZimReaderContainer @Inject constructor(private val zimFileReaderFactory: F
|
||||
|
||||
fun getRandomArticleUrl() = zimFileReader?.getRandomArticleUrl()
|
||||
fun isRedirect(url: String): Boolean = zimFileReader?.isRedirect(url) == true
|
||||
fun getRedirect(url: String): String = zimFileReader?.getRedirect(url) ?: ""
|
||||
fun getRedirect(url: String): String = zimFileReader?.getRedirect(url).orEmpty()
|
||||
fun load(url: String, requestHeaders: Map<String, String>): WebResourceResponse = runBlocking {
|
||||
return@runBlocking WebResourceResponse(
|
||||
zimFileReader?.getMimeTypeFromUrl(url),
|
||||
|
@ -51,7 +51,7 @@ object ServerUtils {
|
||||
}
|
||||
|
||||
private fun formatLocalAddress(inetAddress: InetAddress): String =
|
||||
(inetAddress.hostAddress + "\n").takeIf { inetAddress.isSiteLocalAddress } ?: ""
|
||||
(inetAddress.hostAddress + "\n").takeIf { inetAddress.isSiteLocalAddress }.orEmpty()
|
||||
|
||||
@Suppress("MagicNumber")
|
||||
fun formatIpForAndroidPie(ip: String): String {
|
||||
|
@ -89,7 +89,7 @@ class SharedPreferenceUtil @Inject constructor(val context: Context) {
|
||||
get() = sharedPreferences.getString(PREF_LANG, "") ?: Locale.ROOT.toString()
|
||||
|
||||
val prefDeviceDefaultLanguage: String
|
||||
get() = sharedPreferences.getString(PREF_DEVICE_DEFAULT_LANG, "") ?: ""
|
||||
get() = sharedPreferences.getString(PREF_DEVICE_DEFAULT_LANG, "").orEmpty()
|
||||
|
||||
val prefIsBookmarksMigrated: Boolean
|
||||
get() = sharedPreferences.getBoolean(PREF_BOOKMARKS_MIGRATED, false)
|
||||
|
@ -44,7 +44,7 @@ object StyleUtils {
|
||||
}
|
||||
|
||||
@JvmStatic fun String?.fromHtml(): Spanned {
|
||||
return (this ?: "").let {
|
||||
return (this.orEmpty()).let {
|
||||
Html.fromHtml(
|
||||
this,
|
||||
Html.FROM_HTML_MODE_LEGACY
|
||||
|
@ -25,13 +25,12 @@ import kotlin.math.pow
|
||||
@JvmInline
|
||||
value class KiloByte(private val kilobyteString: String?) {
|
||||
val humanReadable
|
||||
get() =
|
||||
kilobyteString?.toLongOrNull()?.let {
|
||||
val units = arrayOf("KB", "MB", "GB", "TB")
|
||||
val conversion = (log10(it.toDouble()) / log10(1024.0)).toInt()
|
||||
DecimalFormat("#,##0.#")
|
||||
.format(it / 1024.0.pow(conversion.toDouble())) +
|
||||
" " +
|
||||
units[conversion]
|
||||
} ?: ""
|
||||
get() = kilobyteString?.toLongOrNull()?.let {
|
||||
val units = arrayOf("KB", "MB", "GB", "TB")
|
||||
val conversion = (log10(it.toDouble()) / log10(1024.0)).toInt()
|
||||
DecimalFormat("#,##0.#")
|
||||
.format(it / 1024.0.pow(conversion.toDouble())) +
|
||||
" " +
|
||||
units[conversion]
|
||||
}.orEmpty()
|
||||
}
|
||||
|
@ -27,20 +27,19 @@ import org.kiwix.kiwixmobile.core.zim_manager.KiwixTag.TagValue.YES
|
||||
|
||||
sealed class KiwixTag {
|
||||
companion object {
|
||||
fun from(tagString: String?) =
|
||||
tagString?.split(";")
|
||||
?.map { tags ->
|
||||
val split = tags.split(":")
|
||||
val value = split.getOrNull(1)
|
||||
when (val tag = split[0]) {
|
||||
"_ftindex" -> FtIndexTag(value)
|
||||
"_pictures" -> PicturesTag(value)
|
||||
"_videos" -> VideoTag(value)
|
||||
"_details" -> DetailsTag(value)
|
||||
"_category" -> CategoryTag(value)
|
||||
else -> value?.let { ArbitraryTag(tag, it) } ?: TagOnly(tag)
|
||||
}
|
||||
} ?: emptyList()
|
||||
fun from(tagString: String?) = tagString?.split(";")
|
||||
?.map { tags ->
|
||||
val split = tags.split(":")
|
||||
val value = split.getOrNull(1)
|
||||
when (val tag = split[0]) {
|
||||
"_ftindex" -> FtIndexTag(value)
|
||||
"_pictures" -> PicturesTag(value)
|
||||
"_videos" -> VideoTag(value)
|
||||
"_details" -> DetailsTag(value)
|
||||
"_category" -> CategoryTag(value)
|
||||
else -> value?.let { ArbitraryTag(tag, it) } ?: TagOnly(tag)
|
||||
}
|
||||
}.orEmpty()
|
||||
|
||||
data class CategoryTag(val categoryValue: String?) : KiwixTag()
|
||||
data class ArbitraryTag(val tag: String, val value: String) : KiwixTag()
|
||||
|
@ -27,7 +27,7 @@ class MountPointProducer @Inject constructor() {
|
||||
.takeIf(File::exists)
|
||||
?.readLines()
|
||||
?.map { MountInfo(it.split(" ")) }
|
||||
?: emptyList()
|
||||
.orEmpty()
|
||||
}
|
||||
|
||||
data class MountInfo(val device: String, val mountPoint: String, val fileSystem: String) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user