feat: 优化代码

pull/238/head
gedoor 5 years ago
parent 95f8b57716
commit ae75aff5af
  1. 13
      app/src/main/java/io/legado/app/data/entities/BookSource.kt
  2. 3
      app/src/main/java/io/legado/app/service/help/CheckSource.kt
  3. 5
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt

@ -1,6 +1,7 @@
package io.legado.app.data.entities
import android.os.Parcelable
import android.text.TextUtils
import androidx.room.*
import io.legado.app.App
import io.legado.app.constant.AppConst
@ -8,10 +9,7 @@ import io.legado.app.constant.AppConst.userAgent
import io.legado.app.constant.BookType
import io.legado.app.data.entities.rule.*
import io.legado.app.help.JsExtensions
import io.legado.app.utils.ACache
import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonObject
import io.legado.app.utils.getPrefString
import io.legado.app.utils.*
import kotlinx.android.parcel.Parcelize
import java.util.*
import javax.script.SimpleBindings
@ -105,6 +103,13 @@ data class BookSource(
}
}
fun removeGroup(group: String) {
bookSourceGroup?.splitNotBlank(",")?.toHashSet()?.let {
it.remove(group)
bookSourceGroup = TextUtils.join(",", it)
}
}
fun getExploreKinds(): ArrayList<ExploreKind>? {
val exploreKinds = arrayListOf<ExploreKind>()
exploreUrl?.let {

@ -53,6 +53,9 @@ class CheckSource(val source: BookSource) {
.onError(Dispatchers.IO) {
source.addGroup("失效")
App.db.bookSourceDao().update(source)
}.onSuccess(Dispatchers.IO) {
source.removeGroup("失效")
App.db.bookSourceDao().update(source)
}.onFinally(Dispatchers.IO) {
onNext(source.bookSourceUrl)
}

@ -158,10 +158,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
execute {
val sources = App.db.bookSourceDao().getByGroup(group)
sources.map { source ->
source.bookSourceGroup?.splitNotBlank(",")?.toHashSet()?.let {
it.remove(group)
source.bookSourceGroup = TextUtils.join(",", it)
}
source.removeGroup(group)
}
App.db.bookSourceDao().update(*sources.toTypedArray())
}

Loading…
Cancel
Save