From ade207b2d6802c96268e1bc24e33382bc1de66bf Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 29 Aug 2022 22:26:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../changesource/ChangeBookSourceAdapter.kt | 6 ++-- .../changesource/ChangeBookSourceViewModel.kt | 28 ++++++++----------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceAdapter.kt index e94f8671b..8859584f0 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceAdapter.kt @@ -1,7 +1,6 @@ package io.legado.app.ui.book.changesource import android.content.Context -import android.graphics.Color import android.os.Bundle import android.view.View import android.view.ViewGroup @@ -14,7 +13,10 @@ import io.legado.app.base.adapter.DiffRecyclerAdapter import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.data.entities.SearchBook import io.legado.app.databinding.ItemChangeSourceBinding -import io.legado.app.utils.* +import io.legado.app.utils.getCompatColor +import io.legado.app.utils.gone +import io.legado.app.utils.invisible +import io.legado.app.utils.visible import splitties.init.appCtx import splitties.views.onLongClick diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceViewModel.kt index a886df99e..ed4ba5443 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceViewModel.kt @@ -83,27 +83,23 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a searchCallback = null } }.map { - searchBooks.sortedWith(object : Comparator { - override fun compare(o1: SearchBook, o2: SearchBook): Int { - val o1bs = SourceConfig.getBookScore(o1.origin, o1.name, o1.author) - val o2bs = SourceConfig.getBookScore(o2.origin, o2.name, o2.author) - if (o1bs - o2bs > 0) { - return -1 - } else if (o1bs - o2bs < 0) { - return 1 - } else { + searchBooks.sortedWith { o1, o2 -> + val o1bs = SourceConfig.getBookScore(o1.origin, o1.name, o1.author) + val o2bs = SourceConfig.getBookScore(o2.origin, o2.name, o2.author) + when { + o1bs - o2bs > 0 -> -1 + o1bs - o2bs < 0 -> 1 + else -> { val o1ss = SourceConfig.getSourceScore(o1.origin) val o2ss = SourceConfig.getSourceScore(o2.origin) - if (o1ss - o2ss > 0) { - return -1 - } else if (o1ss - o2ss < 0) { - return 1 - } else { - return o1.originOrder - o2.originOrder + when { + o1ss - o2ss > 0 -> -1 + o1ss - o2ss < 0 -> 1 + else -> o1.originOrder - o2.originOrder } } } - }) + } }.flowOn(IO) @Volatile