From b2af3e18bd9755441a5d1b8ce38db52adfc435be Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 21 Apr 2022 15:23:22 +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/BookSourceViewModel.kt | 52 +++++++++---------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt index 68b739f20..0b9533d8f 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt @@ -14,20 +14,20 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application) fun topSource(vararg sources: BookSource) { execute { val minOrder = appDb.bookSourceDao.minOrder - 1 - sources.forEachIndexed { index, bookSource -> - bookSource.customOrder = minOrder - index + val array = Array(sources.size) { + sources[it].copy(customOrder = minOrder - it) } - appDb.bookSourceDao.update(*sources) + appDb.bookSourceDao.update(*array) } } fun bottomSource(vararg sources: BookSource) { execute { val maxOrder = appDb.bookSourceDao.maxOrder + 1 - sources.forEachIndexed { index, bookSource -> - bookSource.customOrder = maxOrder + index + val array = Array(sources.size) { + sources[it].copy(customOrder = maxOrder + it) } - appDb.bookSourceDao.update(*sources) + appDb.bookSourceDao.update(*array) } } @@ -51,59 +51,55 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application) fun enableSelection(sources: List) { execute { - val list = arrayListOf() - sources.forEach { - list.add(it.copy(enabled = true)) + val array = Array(sources.size) { + sources[it].copy(enabled = true) } - appDb.bookSourceDao.update(*list.toTypedArray()) + appDb.bookSourceDao.update(*array) } } fun disableSelection(sources: List) { execute { - val list = arrayListOf() - sources.forEach { - list.add(it.copy(enabled = false)) + val array = Array(sources.size) { + sources[it].copy(enabled = false) } - appDb.bookSourceDao.update(*list.toTypedArray()) + appDb.bookSourceDao.update(*array) } } fun enableSelectExplore(sources: List) { execute { - val list = arrayListOf() - sources.forEach { - list.add(it.copy(enabledExplore = true)) + val array = Array(sources.size) { + sources[it].copy(enabledExplore = true) } - appDb.bookSourceDao.update(*list.toTypedArray()) + appDb.bookSourceDao.update(*array) } } fun disableSelectExplore(sources: List) { execute { - val list = arrayListOf() - sources.forEach { - list.add(it.copy(enabledExplore = false)) + val array = Array(sources.size) { + sources[it].copy(enabledExplore = false) } - appDb.bookSourceDao.update(*list.toTypedArray()) + appDb.bookSourceDao.update(*array) } } fun selectionAddToGroups(sources: List, groups: String) { execute { - sources.forEach { source -> - source.addGroup(groups) + val array = Array(sources.size) { + sources[it].copy().addGroup(groups) } - appDb.bookSourceDao.update(*sources.toTypedArray()) + appDb.bookSourceDao.update(*array) } } fun selectionRemoveFromGroups(sources: List, groups: String) { execute { - sources.forEach { source -> - source.removeGroup(groups) + val array = Array(sources.size) { + sources[it].copy().removeGroup(groups) } - appDb.bookSourceDao.update(*sources.toTypedArray()) + appDb.bookSourceDao.update(*array) } }