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. 42
      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") @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> 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") @Query("select * from book_sources where enabledExplore = 1 order by customOrder asc")
fun observeFind(): DataSource.Factory<Int, BookSource> fun observeFind(): DataSource.Factory<Int, BookSource>
@ -78,7 +63,7 @@ interface BookSourceDao {
fun update(vararg bookSource: BookSource) fun update(vararg bookSource: BookSource)
@Delete @Delete
fun delete(bookSource: BookSource) fun delete(vararg bookSource: BookSource)
@Query("delete from book_sources where bookSourceUrl = :key") @Query("delete from book_sources where bookSourceUrl = :key")
fun delete(key: String) fun delete(key: String)

@ -47,6 +47,18 @@ data class BookSource(
var ruleToc: String? = null, // 目录页规则 var ruleToc: String? = null, // 目录页规则
var ruleContent: String? = null // 正文页规则 var ruleContent: String? = null // 正文页规则
) : Parcelable, JsExtensions { ) : 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 @Ignore
@IgnoredOnParcel @IgnoredOnParcel
private var searchRuleV: SearchRule? = null private var searchRuleV: SearchRule? = null

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

@ -80,20 +80,18 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
when (item.itemId) { when (item.itemId) {
R.id.menu_add_book_source -> startActivity<BookSourceEditActivity>() R.id.menu_add_book_source -> startActivity<BookSourceEditActivity>()
R.id.menu_import_source_qr -> startActivityForResult<QrCodeActivity>(qrRequestCode) R.id.menu_import_source_qr -> startActivityForResult<QrCodeActivity>(qrRequestCode)
R.id.menu_group_manage -> GroupManageDialog().show( R.id.menu_group_manage ->
supportFragmentManager, GroupManageDialog().show(supportFragmentManager, "groupManage")
"groupManage"
)
R.id.menu_import_source_local -> selectFileSys() R.id.menu_import_source_local -> selectFileSys()
R.id.menu_select_all -> adapter.selectAll() R.id.menu_select_all -> adapter.selectAll()
R.id.menu_revert_selection -> adapter.revertSelection() R.id.menu_revert_selection -> adapter.revertSelection()
R.id.menu_enable_selection -> viewModel.enableSelection(adapter.getSelectionIds()) R.id.menu_enable_selection -> viewModel.enableSelection(adapter.getSelection())
R.id.menu_disable_selection -> viewModel.disableSelection(adapter.getSelectionIds()) R.id.menu_disable_selection -> viewModel.disableSelection(adapter.getSelection())
R.id.menu_enable_explore -> viewModel.enableSelectExplore(adapter.getSelectionIds()) R.id.menu_enable_explore -> viewModel.enableSelectExplore(adapter.getSelection())
R.id.menu_disable_explore -> viewModel.disableSelectExplore(adapter.getSelectionIds()) R.id.menu_disable_explore -> viewModel.disableSelectExplore(adapter.getSelection())
R.id.menu_del_selection -> viewModel.delSelection(adapter.getSelectionIds()) R.id.menu_del_selection -> viewModel.delSelection(adapter.getSelection())
R.id.menu_export_selection -> viewModel.exportSelection(adapter.getSelectionIds()) R.id.menu_export_selection -> viewModel.exportSelection(adapter.getSelection())
R.id.menu_check_source -> CheckSource.start(this, ArrayList(adapter.getSelectionIds())) R.id.menu_check_source -> CheckSource.start(this, adapter.getSelection())
R.id.menu_import_source_onLine -> showImportDialog() R.id.menu_import_source_onLine -> showImportDialog()
} }
if (item.groupId == R.id.source_group) { 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), SimpleRecyclerAdapter<BookSource>(context, R.layout.item_book_source),
OnItemTouchCallbackListener { OnItemTouchCallbackListener {
private val selectedIds = linkedSetOf<String>() private val selected = linkedSetOf<BookSource>()
fun selectAll() { fun selectAll() {
getItems().forEach { getItems().forEach {
selectedIds.add(it.bookSourceUrl) selected.add(it)
} }
notifyItemRangeChanged(0, itemCount, 1) notifyItemRangeChanged(0, itemCount, 1)
} }
fun revertSelection() { fun revertSelection() {
getItems().forEach { getItems().forEach {
if (selectedIds.contains(it.bookSourceUrl)) { if (selected.contains(it)) {
selectedIds.remove(it.bookSourceUrl) selected.remove(it)
} else { } else {
selectedIds.add(it.bookSourceUrl) selected.add(it)
} }
} }
notifyItemRangeChanged(0, itemCount, 1) notifyItemRangeChanged(0, itemCount, 1)
} }
fun getSelectionIds(): LinkedHashSet<String> { fun getSelection(): LinkedHashSet<BookSource> {
val selection = linkedSetOf<String>() val selection = linkedSetOf<BookSource>()
getItems().map { getItems().map {
if (selectedIds.contains(it.bookSourceUrl)) { if (selected.contains(it)) {
selection.add(it.bookSourceUrl) selection.add(it)
} }
} }
return selection return selection
@ -81,12 +81,12 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
item.enabled = swt_enabled.isChecked item.enabled = swt_enabled.isChecked
callBack.update(item) callBack.update(item)
} }
cb_book_source.isChecked = selectedIds.contains(item.bookSourceUrl) cb_book_source.isChecked = selected.contains(item)
cb_book_source.setOnClickListener { cb_book_source.setOnClickListener {
if (cb_book_source.isChecked) { if (cb_book_source.isChecked) {
selectedIds.add(item.bookSourceUrl) selected.add(item)
} else { } else {
selectedIds.remove(item.bookSourceUrl) selected.remove(item)
} }
} }
iv_edit.onClick { callBack.edit(item) } iv_edit.onClick { callBack.edit(item) }
@ -105,7 +105,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
} }
} else { } else {
when (payloads[0]) { 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 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 { execute {
ids.forEach { sources.forEach {
App.db.bookSourceDao().enableSection(it) it.enabled = true
} }
App.db.bookSourceDao().update(*sources.toTypedArray())
} }
} }
fun disableSelection(ids: LinkedHashSet<String>) { fun disableSelection(sources: LinkedHashSet<BookSource>) {
execute { execute {
ids.forEach { sources.forEach {
App.db.bookSourceDao().disableSection(it) it.enabled = false
} }
App.db.bookSourceDao().update(*sources.toTypedArray())
} }
} }
fun enableSelectExplore(ids: LinkedHashSet<String>) { fun enableSelectExplore(sources: LinkedHashSet<BookSource>) {
execute { execute {
ids.forEach { sources.forEach {
App.db.bookSourceDao().enableSectionExplore(it) it.enabledExplore = true
} }
App.db.bookSourceDao().update(*sources.toTypedArray())
} }
} }
fun disableSelectExplore(ids: LinkedHashSet<String>) { fun disableSelectExplore(sources: LinkedHashSet<BookSource>) {
execute { execute {
ids.forEach { sources.forEach {
App.db.bookSourceDao().disableSectionExplore(it) it.enabledExplore = false
} }
App.db.bookSourceDao().update(*sources.toTypedArray())
} }
} }
fun delSelection(ids: LinkedHashSet<String>) { fun delSelection(sources: LinkedHashSet<BookSource>) {
execute { execute {
ids.forEach { App.db.bookSourceDao().delete(*sources.toTypedArray())
App.db.bookSourceDao().delSection(it)
}
} }
} }
fun exportSelection(ids: LinkedHashSet<String>) { fun exportSelection(sources: LinkedHashSet<BookSource>) {
execute { execute {
ids.map { val json = GSON.toJson(sources)
App.db.bookSourceDao().getBookSource(it)
}.let {
val json = GSON.toJson(it)
val file = val file =
FileUtils.createFileIfNotExist(Backup.exportPath + File.separator + "exportBookSource.json") FileUtils.createFileIfNotExist(Backup.exportPath + File.separator + "exportBookSource.json")
file.writeText(json) file.writeText(json)
}
}.onSuccess { }.onSuccess {
context.toast("成功导出至\n${Backup.exportPath}") context.toast("成功导出至\n${Backup.exportPath}")
}.onError { }.onError {

Loading…
Cancel
Save