pull/1814/head
kunfei 3 years ago
parent 4fa4be52f7
commit b2af3e18bd
  1. 52
      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<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)
}
}

Loading…
Cancel
Save