mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -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<BookSource>) {
|
||||
execute {
|
||||
val list = arrayListOf<BookSource>()
|
||||
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<BookSource>) {
|
||||
execute {
|
||||
val list = arrayListOf<BookSource>()
|
||||
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<BookSource>) {
|
||||
execute {
|
||||
val list = arrayListOf<BookSource>()
|
||||
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<BookSource>) {
|
||||
execute {
|
||||
val list = arrayListOf<BookSource>()
|
||||
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<BookSource>, 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<BookSource>, 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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user