diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt index b7c713cff..1dea94761 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt @@ -34,13 +34,9 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : val selection: List get() { - val selection = arrayListOf() - getItems().map { - if (selected.contains(it)) { - selection.add(it) - } + return getItems().filter { + selected.contains(it) } - return selection.sortedBy { it.customOrder } } val diffItemCallback: DiffUtil.ItemCallback 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 0b9533d8f..4a24f70ac 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 @@ -13,6 +13,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application) fun topSource(vararg sources: BookSource) { execute { + sources.sortBy { it.customOrder } val minOrder = appDb.bookSourceDao.minOrder - 1 val array = Array(sources.size) { sources[it].copy(customOrder = minOrder - it) @@ -23,6 +24,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application) fun bottomSource(vararg sources: BookSource) { execute { + sources.sortBy { it.customOrder } val maxOrder = appDb.bookSourceDao.maxOrder + 1 val array = Array(sources.size) { sources[it].copy(customOrder = maxOrder + it) diff --git a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleAdapter.kt b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleAdapter.kt index 26a3f2e7b..ade5e72ab 100644 --- a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleAdapter.kt @@ -25,15 +25,11 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) : private val selected = linkedSetOf() - val selection: LinkedHashSet + val selection: List get() { - val selection = linkedSetOf() - getItems().map { - if (selected.contains(it)) { - selection.add(it) - } + return getItems().filter { + selected.contains(it) } - return selection } val diffItemCallBack = object : DiffUtil.ItemCallback() { diff --git a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleViewModel.kt b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleViewModel.kt index 9f8aaa92e..5caa85656 100644 --- a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleViewModel.kt @@ -65,23 +65,21 @@ class ReplaceRuleViewModel(application: Application) : BaseViewModel(application } } - fun enableSelection(rules: LinkedHashSet) { + fun enableSelection(rules: List) { execute { - val list = arrayListOf() - rules.forEach { - list.add(it.copy(isEnabled = true)) + val array = Array(rules.size) { + rules[it].copy(isEnabled = true) } - appDb.replaceRuleDao.update(*list.toTypedArray()) + appDb.replaceRuleDao.update(*array) } } - fun disableSelection(rules: LinkedHashSet) { + fun disableSelection(rules: List) { execute { - val list = arrayListOf() - rules.forEach { - list.add(it.copy(isEnabled = false)) + val array = Array(rules.size) { + rules[it].copy(isEnabled = false) } - appDb.replaceRuleDao.update(*list.toTypedArray()) + appDb.replaceRuleDao.update(*array) } } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt index dd1480046..c1f3aa883 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt @@ -27,13 +27,9 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) : val selection: List get() { - val selection = arrayListOf() - getItems().forEach { - if (selected.contains(it)) { - selection.add(it) - } + return getItems().filter { + selected.contains(it) } - return selection.sortedBy { it.customOrder } } val diffItemCallback = object : DiffUtil.ItemCallback() { diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt index b3bb3895f..224e4db3d 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt @@ -13,21 +13,23 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application) fun topSource(vararg sources: RssSource) { execute { + sources.sortBy { it.customOrder } val minOrder = appDb.rssSourceDao.minOrder - 1 - sources.forEachIndexed { index, rssSource -> - rssSource.customOrder = minOrder - index + val array = Array(sources.size) { + sources[it].copy(customOrder = minOrder - it) } - appDb.rssSourceDao.update(*sources) + appDb.rssSourceDao.update(*array) } } fun bottomSource(vararg sources: RssSource) { execute { + sources.sortBy { it.customOrder } val maxOrder = appDb.rssSourceDao.maxOrder + 1 - sources.forEachIndexed { index, rssSource -> - rssSource.customOrder = maxOrder + index + val array = Array(sources.size) { + sources[it].copy(customOrder = maxOrder + it) } - appDb.rssSourceDao.update(*sources) + appDb.rssSourceDao.update(*array) } } @@ -51,21 +53,19 @@ class RssSourceViewModel(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.rssSourceDao.update(*list.toTypedArray()) + appDb.rssSourceDao.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.rssSourceDao.update(*list.toTypedArray()) + appDb.rssSourceDao.update(*array) } }