pull/90/head^2
kunfei 5 years ago
parent 9c7e5d9a27
commit 07ca45d5ae
  1. 17
      app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt
  2. 12
      app/src/main/java/io/legado/app/data/entities/BookSource.kt
  3. 9
      app/src/main/java/io/legado/app/service/help/CheckSource.kt
  4. 20
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  5. 26
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt
  6. 48
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt

@ -29,21 +29,6 @@ interface BookSourceDao {
@Query("select distinct enabled from book_sources where bookSourceName like :searchKey or bookSourceGroup like :searchKey or bookSourceUrl like :searchKey")
fun searchIsEnable(searchKey: String = ""): List<Boolean>
@Query("update book_sources set enabled = 1 where bookSourceUrl = :sourceUrl")
fun enableSection(sourceUrl: String)
@Query("update book_sources set enabled = 0 where bookSourceUrl = :sourceUrl")
fun disableSection(sourceUrl: String)
@Query("update book_sources set enabledExplore = 1 where bookSourceUrl = :sourceUrl")
fun enableSectionExplore(sourceUrl: String)
@Query("update book_sources set enabledExplore = 0 where bookSourceUrl = :sourceUrl")
fun disableSectionExplore(sourceUrl: String)
@Query("delete from book_sources where bookSourceUrl = :sourceUrl")
fun delSection(sourceUrl: String)
@Query("select * from book_sources where enabledExplore = 1 order by customOrder asc")
fun observeFind(): DataSource.Factory<Int, BookSource>
@ -78,7 +63,7 @@ interface BookSourceDao {
fun update(vararg bookSource: BookSource)
@Delete
fun delete(bookSource: BookSource)
fun delete(vararg bookSource: BookSource)
@Query("delete from book_sources where bookSourceUrl = :key")
fun delete(key: String)

@ -47,6 +47,18 @@ data class BookSource(
var ruleToc: String? = null, // 目录页规则
var ruleContent: String? = null // 正文页规则
) : Parcelable, JsExtensions {
override fun hashCode(): Int {
return bookSourceUrl.hashCode()
}
override fun equals(other: Any?): Boolean {
if (other is BookSource) {
return other.bookSourceUrl == bookSourceUrl
}
return false
}
@Ignore
@IgnoredOnParcel
private var searchRuleV: SearchRule? = null

@ -4,16 +4,21 @@ import android.content.Context
import android.content.Intent
import io.legado.app.R
import io.legado.app.constant.IntentAction
import io.legado.app.data.entities.BookSource
import io.legado.app.service.CheckSourceService
import org.jetbrains.anko.toast
object CheckSource {
fun start(context: Context, selectedIds: ArrayList<String>) {
if (selectedIds.isEmpty()) {
fun start(context: Context, sources: LinkedHashSet<BookSource>) {
if (sources.isEmpty()) {
context.toast(R.string.non_select)
return
}
val selectedIds: ArrayList<String> = arrayListOf()
sources.map {
selectedIds.add(it.bookSourceUrl)
}
Intent(context, CheckSourceService::class.java).let {
it.action = IntentAction.start
it.putExtra("selectIds", selectedIds)

@ -80,20 +80,18 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
when (item.itemId) {
R.id.menu_add_book_source -> startActivity<BookSourceEditActivity>()
R.id.menu_import_source_qr -> startActivityForResult<QrCodeActivity>(qrRequestCode)
R.id.menu_group_manage -> GroupManageDialog().show(
supportFragmentManager,
"groupManage"
)
R.id.menu_group_manage ->
GroupManageDialog().show(supportFragmentManager, "groupManage")
R.id.menu_import_source_local -> selectFileSys()
R.id.menu_select_all -> adapter.selectAll()
R.id.menu_revert_selection -> adapter.revertSelection()
R.id.menu_enable_selection -> viewModel.enableSelection(adapter.getSelectionIds())
R.id.menu_disable_selection -> viewModel.disableSelection(adapter.getSelectionIds())
R.id.menu_enable_explore -> viewModel.enableSelectExplore(adapter.getSelectionIds())
R.id.menu_disable_explore -> viewModel.disableSelectExplore(adapter.getSelectionIds())
R.id.menu_del_selection -> viewModel.delSelection(adapter.getSelectionIds())
R.id.menu_export_selection -> viewModel.exportSelection(adapter.getSelectionIds())
R.id.menu_check_source -> CheckSource.start(this, ArrayList(adapter.getSelectionIds()))
R.id.menu_enable_selection -> viewModel.enableSelection(adapter.getSelection())
R.id.menu_disable_selection -> viewModel.disableSelection(adapter.getSelection())
R.id.menu_enable_explore -> viewModel.enableSelectExplore(adapter.getSelection())
R.id.menu_disable_explore -> viewModel.disableSelectExplore(adapter.getSelection())
R.id.menu_del_selection -> viewModel.delSelection(adapter.getSelection())
R.id.menu_export_selection -> viewModel.exportSelection(adapter.getSelection())
R.id.menu_check_source -> CheckSource.start(this, adapter.getSelection())
R.id.menu_import_source_onLine -> showImportDialog()
}
if (item.groupId == R.id.source_group) {

@ -16,31 +16,31 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
SimpleRecyclerAdapter<BookSource>(context, R.layout.item_book_source),
OnItemTouchCallbackListener {
private val selectedIds = linkedSetOf<String>()
private val selected = linkedSetOf<BookSource>()
fun selectAll() {
getItems().forEach {
selectedIds.add(it.bookSourceUrl)
selected.add(it)
}
notifyItemRangeChanged(0, itemCount, 1)
}
fun revertSelection() {
getItems().forEach {
if (selectedIds.contains(it.bookSourceUrl)) {
selectedIds.remove(it.bookSourceUrl)
if (selected.contains(it)) {
selected.remove(it)
} else {
selectedIds.add(it.bookSourceUrl)
selected.add(it)
}
}
notifyItemRangeChanged(0, itemCount, 1)
}
fun getSelectionIds(): LinkedHashSet<String> {
val selection = linkedSetOf<String>()
fun getSelection(): LinkedHashSet<BookSource> {
val selection = linkedSetOf<BookSource>()
getItems().map {
if (selectedIds.contains(it.bookSourceUrl)) {
selection.add(it.bookSourceUrl)
if (selected.contains(it)) {
selection.add(it)
}
}
return selection
@ -81,12 +81,12 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
item.enabled = swt_enabled.isChecked
callBack.update(item)
}
cb_book_source.isChecked = selectedIds.contains(item.bookSourceUrl)
cb_book_source.isChecked = selected.contains(item)
cb_book_source.setOnClickListener {
if (cb_book_source.isChecked) {
selectedIds.add(item.bookSourceUrl)
selected.add(item)
} else {
selectedIds.remove(item.bookSourceUrl)
selected.remove(item)
}
}
iv_edit.onClick { callBack.edit(item) }
@ -105,7 +105,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
}
} else {
when (payloads[0]) {
1 -> cb_book_source.isChecked = selectedIds.contains(item.bookSourceUrl)
1 -> cb_book_source.isChecked = selected.contains(item)
2 -> swt_enabled.isChecked = item.enabled
}
}

@ -43,56 +43,54 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
}
}
fun enableSelection(ids: LinkedHashSet<String>) {
fun enableSelection(sources: LinkedHashSet<BookSource>) {
execute {
ids.forEach {
App.db.bookSourceDao().enableSection(it)
sources.forEach {
it.enabled = true
}
App.db.bookSourceDao().update(*sources.toTypedArray())
}
}
fun disableSelection(ids: LinkedHashSet<String>) {
fun disableSelection(sources: LinkedHashSet<BookSource>) {
execute {
ids.forEach {
App.db.bookSourceDao().disableSection(it)
sources.forEach {
it.enabled = false
}
App.db.bookSourceDao().update(*sources.toTypedArray())
}
}
fun enableSelectExplore(ids: LinkedHashSet<String>) {
fun enableSelectExplore(sources: LinkedHashSet<BookSource>) {
execute {
ids.forEach {
App.db.bookSourceDao().enableSectionExplore(it)
sources.forEach {
it.enabledExplore = true
}
App.db.bookSourceDao().update(*sources.toTypedArray())
}
}
fun disableSelectExplore(ids: LinkedHashSet<String>) {
fun disableSelectExplore(sources: LinkedHashSet<BookSource>) {
execute {
ids.forEach {
App.db.bookSourceDao().disableSectionExplore(it)
sources.forEach {
it.enabledExplore = false
}
App.db.bookSourceDao().update(*sources.toTypedArray())
}
}
fun delSelection(ids: LinkedHashSet<String>) {
fun delSelection(sources: LinkedHashSet<BookSource>) {
execute {
ids.forEach {
App.db.bookSourceDao().delSection(it)
}
App.db.bookSourceDao().delete(*sources.toTypedArray())
}
}
fun exportSelection(ids: LinkedHashSet<String>) {
fun exportSelection(sources: LinkedHashSet<BookSource>) {
execute {
ids.map {
App.db.bookSourceDao().getBookSource(it)
}.let {
val json = GSON.toJson(it)
val file =
FileUtils.createFileIfNotExist(Backup.exportPath + File.separator + "exportBookSource.json")
file.writeText(json)
}
val json = GSON.toJson(sources)
val file =
FileUtils.createFileIfNotExist(Backup.exportPath + File.separator + "exportBookSource.json")
file.writeText(json)
}.onSuccess {
context.toast("成功导出至\n${Backup.exportPath}")
}.onError {

Loading…
Cancel
Save