pull/35/head^2
kunfei 5 years ago
parent 1c4672af7d
commit 2fc65b1bff
  1. 6
      app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt
  2. 8
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt
  3. 27
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt

@ -31,6 +31,9 @@ interface RssSourceDao {
@Query("update rssSources set enabled = 0 where sourceUrl in (:sourceUrls)")
fun disableSection(vararg sourceUrls: String)
@get:Query("select min(customOrder) from rssSources")
val minOrder: Int
@Query("delete from rssSources where sourceUrl in (:sourceUrls)")
fun delSection(vararg sourceUrls: String)
@ -40,6 +43,9 @@ interface RssSourceDao {
@Update
fun update(vararg rssSource: RssSource)
@Delete
fun delete(vararg rssSource: RssSource)
@Query("delete from rssSources where sourceUrl = :sourceUrl")
fun delete(sourceUrl: String)
}

@ -137,7 +137,7 @@ class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_r
}
override fun del(source: RssSource) {
viewModel.del(source)
}
override fun edit(source: RssSource) {
@ -145,15 +145,15 @@ class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_r
}
override fun update(vararg source: RssSource) {
viewModel.update(*source)
}
override fun toTop(source: RssSource) {
viewModel.topSource(source)
}
override fun upOrder() {
viewModel.upOrder()
}
}

@ -3,9 +3,36 @@ package io.legado.app.ui.rss.source.manage
import android.app.Application
import io.legado.app.App
import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.RssSource
class RssSourceViewModel(application: Application) : BaseViewModel(application) {
fun topSource(rssSource: RssSource) {
execute {
val minXh = App.db.rssSourceDao().minOrder
rssSource.customOrder = minXh - 1
App.db.rssSourceDao().insert(rssSource)
}
}
fun del(rssSource: RssSource) {
execute { App.db.rssSourceDao().delete(rssSource) }
}
fun update(vararg rssSource: RssSource) {
execute { App.db.rssSourceDao().update(*rssSource) }
}
fun upOrder() {
execute {
val sources = App.db.rssSourceDao().all
for ((index: Int, source: RssSource) in sources.withIndex()) {
source.customOrder = index + 1
}
App.db.rssSourceDao().update(*sources.toTypedArray())
}
}
fun enableSelection(ids: LinkedHashSet<String>) {
execute {
App.db.rssSourceDao().enableSection(*ids.toTypedArray())

Loading…
Cancel
Save