From a74da4f96872b3049d8870667448feae4326d462 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 8 Feb 2022 17:26:18 +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 --- .../book/source/manage/BookSourceActivity.kt | 72 +++++++++---------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index 3d2620f72..6f4627d04 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -229,46 +229,46 @@ class BookSourceActivity : VMBaseActivity { appDb.bookSourceDao.flowSearch("%$searchKey%") } - } - }.onFailure { - AppLog.put("更新书源出错", it) - }.getOrNull()?.collect { data -> - val sourceList = - if (sortAscending) when (sort) { - Sort.Weight -> data.sortedBy { it.weight } - Sort.Name -> data.sortedWith { o1, o2 -> - o1.bookSourceName.cnCompare(o2.bookSourceName) - } - Sort.Url -> data.sortedBy { it.bookSourceUrl } - Sort.Update -> data.sortedByDescending { it.lastUpdateTime } - Sort.Respond -> data.sortedBy { it.respondTime } - Sort.Enable -> data.sortedWith { o1, o2 -> - var sort = -o1.enabled.compareTo(o2.enabled) - if (sort == 0) { - sort = o1.bookSourceName.cnCompare(o2.bookSourceName) + }.collect { data -> + val sourceList = + if (sortAscending) when (sort) { + Sort.Weight -> data.sortedBy { it.weight } + Sort.Name -> data.sortedWith { o1, o2 -> + o1.bookSourceName.cnCompare(o2.bookSourceName) } - sort - } - else -> data - } - else when (sort) { - Sort.Weight -> data.sortedByDescending { it.weight } - Sort.Name -> data.sortedWith { o1, o2 -> - o2.bookSourceName.cnCompare(o1.bookSourceName) + Sort.Url -> data.sortedBy { it.bookSourceUrl } + Sort.Update -> data.sortedByDescending { it.lastUpdateTime } + Sort.Respond -> data.sortedBy { it.respondTime } + Sort.Enable -> data.sortedWith { o1, o2 -> + var sort = -o1.enabled.compareTo(o2.enabled) + if (sort == 0) { + sort = o1.bookSourceName.cnCompare(o2.bookSourceName) + } + sort + } + else -> data } - Sort.Url -> data.sortedByDescending { it.bookSourceUrl } - Sort.Update -> data.sortedBy { it.lastUpdateTime } - Sort.Respond -> data.sortedByDescending { it.respondTime } - Sort.Enable -> data.sortedWith { o1, o2 -> - var sort = o1.enabled.compareTo(o2.enabled) - if (sort == 0) { - sort = o1.bookSourceName.cnCompare(o2.bookSourceName) + else when (sort) { + Sort.Weight -> data.sortedByDescending { it.weight } + Sort.Name -> data.sortedWith { o1, o2 -> + o2.bookSourceName.cnCompare(o1.bookSourceName) + } + Sort.Url -> data.sortedByDescending { it.bookSourceUrl } + Sort.Update -> data.sortedBy { it.lastUpdateTime } + Sort.Respond -> data.sortedByDescending { it.respondTime } + Sort.Enable -> data.sortedWith { o1, o2 -> + var sort = o1.enabled.compareTo(o2.enabled) + if (sort == 0) { + sort = o1.bookSourceName.cnCompare(o2.bookSourceName) + } + sort } - sort + else -> data.reversed() } - else -> data.reversed() - } - adapter.setItems(sourceList, adapter.diffItemCallback) + adapter.setItems(sourceList, adapter.diffItemCallback) + } + }.onFailure { + AppLog.put("更新书源出错", it) } } }