Replace elvis operators with .orEmpty where possible

This commit is contained in:
Jobobby04
2020-11-04 22:10:13 -05:00
parent 015c610205
commit 079dd953bd
23 changed files with 59 additions and 59 deletions
@@ -48,7 +48,7 @@ class FollowsHandler(val client: OkHttpClient, val headers: Headers, val prefere
val followsPageResult = try {
MdUtil.jsonParser.decodeFromString(
FollowsPageResult.serializer(),
response.body?.string() ?: ""
response.body?.string().orEmpty()
)
} catch (e: Exception) {
XLog.e("error parsing follows", e)
@@ -79,7 +79,7 @@ class FollowsHandler(val client: OkHttpClient, val headers: Headers, val prefere
val followsPageResult = try {
MdUtil.jsonParser.decodeFromString(
FollowsPageResult.serializer(),
response.body?.string() ?: ""
response.body?.string().orEmpty()
)
} catch (e: Exception) {
XLog.e("error parsing follows", e)
@@ -20,8 +20,8 @@ fun OkHttpClient.Builder.injectPatches(sourceIdProducer: () -> Long): OkHttpClie
fun findAndApplyPatches(sourceId: Long): EHInterceptor {
// TODO make it so captcha doesnt auto open in manga eden while applying universal interceptors
return if (Injekt.get<PreferencesHelper>().eh_autoSolveCaptchas().get()) ((EH_INTERCEPTORS[sourceId] ?: emptyList()) + (EH_INTERCEPTORS[EH_UNIVERSAL_INTERCEPTOR] ?: emptyList())).merge()
else (EH_INTERCEPTORS[sourceId] ?: emptyList()).merge()
return if (Injekt.get<PreferencesHelper>().eh_autoSolveCaptchas().get()) ((EH_INTERCEPTORS[sourceId].orEmpty()) + (EH_INTERCEPTORS[EH_UNIVERSAL_INTERCEPTOR].orEmpty())).merge()
else (EH_INTERCEPTORS[sourceId].orEmpty()).merge()
}
fun List<EHInterceptor>.merge(): EHInterceptor {
@@ -83,7 +83,7 @@ class MetadataViewController : NucleusController<MetadataViewControllerBinding,
fun onNextMangaInfo(meta: RaisedSearchMetadata?) {
val context = view?.context ?: return
data = meta?.getExtraInfoPairs(context) ?: emptyList()
data = meta?.getExtraInfoPairs(context).orEmpty()
adapter?.update(data)
}
}
@@ -54,7 +54,7 @@ class PururinDescriptionAdapter(
} ?: genre?.name ?: itemView.context.getString(R.string.unknown)
}
binding.uploader.text = meta.uploaderDisp ?: meta.uploader ?: ""
binding.uploader.text = meta.uploaderDisp ?: meta.uploader.orEmpty()
binding.size.text = meta.fileSize ?: itemView.context.getString(R.string.unknown)
binding.size.bindDrawable(itemView.context, R.drawable.ic_outline_sd_card_24)
@@ -32,7 +32,7 @@ class SmartSearchController(bundle: Bundle? = null) : NucleusController<EhSmartS
return binding.root
}
override fun getTitle() = source?.name ?: ""
override fun getTitle() = source?.name.orEmpty()
override fun createPresenter() = SmartSearchPresenter(source, smartSearchConfig)
@@ -10,7 +10,7 @@ import uy.kohesive.injekt.api.get
fun Manga.isLewd(): Boolean {
val sourceName = Injekt.get<SourceManager>().get(source)?.name
val currentTags = getGenres() ?: emptyList()
val currentTags = getGenres().orEmpty()
if (source == EH_SOURCE_ID || source == EXH_SOURCE_ID || source in nHentaiSourceIds) {
return currentTags.none { tag -> isNonHentaiTag(tag) }
@@ -51,7 +51,7 @@ class LoggingRealmQuery<E : RealmModel>(val query: RealmQuery<E>) {
"\"$fieldName\" == \"$value\"" + (
casing?.let {
" CASE ${casing.name}"
} ?: ""
}.orEmpty()
)
)
}
@@ -121,7 +121,7 @@ class LoggingRealmQuery<E : RealmModel>(val query: RealmQuery<E>) {
)}] IN \"$fieldName\"" + (
casing?.let {
" CASE ${casing.name}"
} ?: ""
}.orEmpty()
)
)
}
@@ -181,7 +181,7 @@ class LoggingRealmQuery<E : RealmModel>(val query: RealmQuery<E>) {
"\"$fieldName\" != \"$value\"" + (
casing?.let {
" CASE ${casing.name}"
} ?: ""
}.orEmpty()
)
)
}
@@ -391,7 +391,7 @@ class LoggingRealmQuery<E : RealmModel>(val query: RealmQuery<E>) {
"\"$fieldName\" CONTAINS \"$value\"" + (
casing?.let {
" CASE ${casing.name}"
} ?: ""
}.orEmpty()
)
)
}
@@ -411,7 +411,7 @@ class LoggingRealmQuery<E : RealmModel>(val query: RealmQuery<E>) {
"\"$fieldName\" BEGINS WITH \"$value\"" + (
casing?.let {
" CASE ${casing.name}"
} ?: ""
}.orEmpty()
)
)
}
@@ -431,7 +431,7 @@ class LoggingRealmQuery<E : RealmModel>(val query: RealmQuery<E>) {
"\"$fieldName\" ENDS WITH \"$value\"" + (
casing?.let {
" CASE ${casing.name}"
} ?: ""
}.orEmpty()
)
)
}
@@ -451,7 +451,7 @@ class LoggingRealmQuery<E : RealmModel>(val query: RealmQuery<E>) {
"\"$fieldName\" LIKE \"$value\"" + (
casing?.let {
" CASE ${casing.name}"
} ?: ""
}.orEmpty()
)
)
}
+1 -1
View File
@@ -26,7 +26,7 @@ fun Manga.mangaType(context: Context): String {
*/
fun Manga.mangaType(): MangaType {
val sourceName = Injekt.get<SourceManager>().getOrStub(source).name
val currentTags = getGenres() ?: emptyList()
val currentTags = getGenres().orEmpty()
return if (currentTags.any { tag -> isMangaTag(tag) }) {
MangaType.TYPE_MANGA
} else if (currentTags.any { tag -> isWebtoonTag(tag) } || isWebtoonSource(sourceName)) {