Cleanup
This commit is contained in:
parent
c0e1ca1185
commit
f5b6fc5b54
@ -41,7 +41,6 @@ import exh.metadata.metadata.EHentaiSearchMetadata.Companion.TAG_TYPE_WEAK
|
||||
import exh.metadata.metadata.base.RaisedSearchMetadata.Companion.TAG_TYPE_VIRTUAL
|
||||
import exh.metadata.metadata.base.RaisedSearchMetadata.Companion.toGenreString
|
||||
import exh.metadata.metadata.base.RaisedTag
|
||||
import exh.metadata.nullIfBlank
|
||||
import exh.metadata.parseHumanReadableByteCount
|
||||
import exh.ui.login.LoginController
|
||||
import exh.ui.metadata.adapters.EHentaiDescriptionAdapter
|
||||
@ -49,6 +48,7 @@ import exh.util.UriFilter
|
||||
import exh.util.UriGroup
|
||||
import exh.util.asObservableWithAsyncStacktrace
|
||||
import exh.util.ignore
|
||||
import exh.util.nullIfBlank
|
||||
import exh.util.trimOrNull
|
||||
import exh.util.urlImportFetchSearchManga
|
||||
import java.net.URLEncoder
|
||||
|
@ -44,10 +44,10 @@ import exh.favorites.FavoritesIntroDialog
|
||||
import exh.favorites.LocalFavoritesStorage
|
||||
import exh.metadata.metadata.EHentaiSearchMetadata
|
||||
import exh.metadata.metadata.base.getFlatMetadataForManga
|
||||
import exh.metadata.nullIfBlank
|
||||
import exh.uconfig.WarnConfigureDialogController
|
||||
import exh.ui.login.LoginController
|
||||
import exh.util.await
|
||||
import exh.util.nullIfBlank
|
||||
import exh.util.trans
|
||||
import humanize.Humanize
|
||||
import java.util.Date
|
||||
|
@ -2,6 +2,8 @@ package exh.metadata
|
||||
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Locale
|
||||
import kotlin.math.ln
|
||||
import kotlin.math.pow
|
||||
|
||||
/**
|
||||
* Metadata utils
|
||||
@ -9,9 +11,9 @@ import java.util.Locale
|
||||
fun humanReadableByteCount(bytes: Long, si: Boolean): String {
|
||||
val unit = if (si) 1000 else 1024
|
||||
if (bytes < unit) return "$bytes B"
|
||||
val exp = (Math.log(bytes.toDouble()) / Math.log(unit.toDouble())).toInt()
|
||||
val exp = (ln(bytes.toDouble()) / ln(unit.toDouble())).toInt()
|
||||
val pre = (if (si) "kMGTPE" else "KMGTPE")[exp - 1] + if (si) "" else "i"
|
||||
return String.format("%.1f %sB", bytes / Math.pow(unit.toDouble(), exp.toDouble()), pre)
|
||||
return String.format("%.1f %sB", bytes / unit.toDouble().pow(exp.toDouble()), pre)
|
||||
}
|
||||
|
||||
private const val KB_FACTOR: Long = 1000
|
||||
@ -35,12 +37,6 @@ fun parseHumanReadableByteCount(arg0: String): Double? {
|
||||
return null
|
||||
}
|
||||
|
||||
fun String?.nullIfBlank(): String? = if (isNullOrBlank()) {
|
||||
null
|
||||
} else {
|
||||
this
|
||||
}
|
||||
|
||||
fun <K, V> Set<Map.Entry<K, V>>.forEach(action: (K, V) -> Unit) {
|
||||
forEach { action(it.key, it.value) }
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
|
||||
import exh.GalleryAddEvent
|
||||
import exh.GalleryAdder
|
||||
import exh.metadata.nullIfBlank
|
||||
import exh.util.trimOrNull
|
||||
import kotlin.concurrent.thread
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
@ -42,7 +42,7 @@ class BatchAddPresenter : BasePresenter<BatchAddController>() {
|
||||
galleries
|
||||
}
|
||||
val splitGalleries = testedGalleries.split("\n").mapNotNull {
|
||||
it.trim().nullIfBlank()
|
||||
it.trimOrNull()
|
||||
}
|
||||
|
||||
progressRelay.call(0)
|
||||
|
@ -12,3 +12,9 @@ fun String.trimOrNull(): String? {
|
||||
val trimmed = trim()
|
||||
return if (trimmed.isBlank()) null else trimmed
|
||||
}
|
||||
|
||||
fun String?.nullIfBlank(): String? = if (isNullOrBlank()) {
|
||||
null
|
||||
} else {
|
||||
this
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user