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