pull/32/head
kunfei 5 years ago
parent ac0fc7a16e
commit 1a94dbd14e
  1. 3
      app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt
  2. 24
      app/src/main/java/io/legado/app/ui/booksource/BookSourceViewModel.kt

@ -26,6 +26,9 @@ interface BookSourceDao {
@Query("select * from book_sources where enabledExplore = 1 order by customOrder asc")
fun observeFind(): DataSource.Factory<Int, BookSource>
@Query("select * from book_sources where bookSourceGroup like '%' || :group || '%'")
fun getByGroup(group: String): List<BookSource>
@get:Query("select * from book_sources order by customOrder asc")
val all: List<BookSource>

@ -1,9 +1,11 @@
package io.legado.app.ui.booksource
import android.app.Application
import android.text.TextUtils
import io.legado.app.App
import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.BookSource
import io.legado.app.utils.splitNotBlank
class BookSourceViewModel(application: Application) : BaseViewModel(application) {
@ -26,13 +28,31 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
fun upGroup(oldGroup: String, newGroup: String?) {
execute {
val sources = App.db.bookSourceDao().getByGroup(oldGroup)
sources.map { source ->
source.bookSourceGroup?.splitNotBlank(",")?.toHashSet()?.let {
it.remove(oldGroup)
if (!newGroup.isNullOrEmpty())
it.add(newGroup)
source.bookSourceGroup = TextUtils.join(",", it)
}
}
App.db.bookSourceDao().update(*sources.toTypedArray())
}
}
fun delGroup(group: String) {
execute {
execute {
val sources = App.db.bookSourceDao().getByGroup(group)
sources.map { source ->
source.bookSourceGroup?.splitNotBlank(",")?.toHashSet()?.let {
it.remove(group)
source.bookSourceGroup = TextUtils.join(",", it)
}
}
App.db.bookSourceDao().update(*sources.toTypedArray())
}
}
}
}
Loading…
Cancel
Save