优化
This commit is contained in:
@@ -14,20 +14,20 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
|
|||||||
fun topSource(vararg sources: BookSource) {
|
fun topSource(vararg sources: BookSource) {
|
||||||
execute {
|
execute {
|
||||||
val minOrder = appDb.bookSourceDao.minOrder - 1
|
val minOrder = appDb.bookSourceDao.minOrder - 1
|
||||||
sources.forEachIndexed { index, bookSource ->
|
val array = Array(sources.size) {
|
||||||
bookSource.customOrder = minOrder - index
|
sources[it].copy(customOrder = minOrder - it)
|
||||||
}
|
}
|
||||||
appDb.bookSourceDao.update(*sources)
|
appDb.bookSourceDao.update(*array)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun bottomSource(vararg sources: BookSource) {
|
fun bottomSource(vararg sources: BookSource) {
|
||||||
execute {
|
execute {
|
||||||
val maxOrder = appDb.bookSourceDao.maxOrder + 1
|
val maxOrder = appDb.bookSourceDao.maxOrder + 1
|
||||||
sources.forEachIndexed { index, bookSource ->
|
val array = Array(sources.size) {
|
||||||
bookSource.customOrder = maxOrder + index
|
sources[it].copy(customOrder = maxOrder + it)
|
||||||
}
|
}
|
||||||
appDb.bookSourceDao.update(*sources)
|
appDb.bookSourceDao.update(*array)
|
||||||
}
|
}
|
||||||