pull/2274/head
kunfei 2 years ago
parent cacfcbdb1b
commit 1ba3d30785
  1. 33
      app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt
  2. 6
      app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt
  3. 30
      app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt
  4. 1
      app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditAdapter.kt
  5. 16
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  6. 17
      app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt
  7. 1
      app/src/main/res/values/ids.xml

@ -1,8 +1,12 @@
package io.legado.app.data.dao
import androidx.room.*
import io.legado.app.constant.AppPattern
import io.legado.app.data.entities.BookSource
import io.legado.app.utils.cnCompare
import io.legado.app.utils.splitNotBlank
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
@Dao
interface BookSourceDao {
@ -82,7 +86,7 @@ interface BookSourceDao {
fun flowGroupExplore(key: String): Flow<List<BookSource>>
@Query("select distinct bookSourceGroup from book_sources where trim(bookSourceGroup) <> ''")
fun flowGroup(): Flow<List<String>>
fun flowGroupsUnDeal(): Flow<List<String>>
@Query("select distinct bookSourceGroup from book_sources where enabled = 1 and trim(bookSourceGroup) <> ''")
fun flowGroupEnabled(): Flow<List<String>>
@ -127,8 +131,8 @@ interface BookSourceDao {
@get:Query("select * from book_sources where enabled = 1 and bookSourceType = 0 order by customOrder")
val allTextEnabled: List<BookSource>
@get:Query("select distinct bookSourceGroup from book_sources where trim(bookSourceGroup) <> ''")
val allGroup: List<String>
@Query("select distinct bookSourceGroup from book_sources where trim(bookSourceGroup) <> ''")
fun getAllGroupsUnDeal(): List<String>
@Query("select * from book_sources where bookSourceUrl = :key")
fun getBookSource(key: String): BookSource?
@ -153,4 +157,27 @@ interface BookSourceDao {
@get:Query("select max(customOrder) from book_sources")
val maxOrder: Int
fun dealGroups(list: List<String>): List<String> {
val groups = linkedSetOf<String>()
list.forEach {
it.splitNotBlank(AppPattern.splitGroupRegex).forEach { group ->
groups.add(group)
}
}
return groups.sortedWith { o1, o2 ->
o1.cnCompare(o2)
}
}
val allGroups: List<String>
get() {
return dealGroups(getAllGroupsUnDeal())
}
fun flowGroups(): Flow<List<String>> {
return flowGroupsUnDeal().map { list ->
dealGroups(list)
}
}
}

@ -14,7 +14,6 @@ import io.legado.app.R
import io.legado.app.base.BaseDialogFragment
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.constant.AppPattern
import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb
import io.legado.app.data.entities.BookSource
@ -158,10 +157,7 @@ class ImportBookSourceDialog() : BaseDialogFragment(R.layout.dialog_recycler_vie
private fun alertCustomGroup(item: MenuItem) {
alert(R.string.diy_edit_source_group) {
val alertBinding = DialogCustomGroupBinding.inflate(layoutInflater).apply {
val groups = linkedSetOf<String>()
appDb.bookSourceDao.allGroup.forEach { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
}
val groups = appDb.bookSourceDao.allGroups
textInputLayout.setHint(R.string.group_name)
editView.setFilterValues(groups.toList())
editView.dropDownHeight = 180.dpToPx()

@ -12,12 +12,14 @@ import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel
import io.legado.app.R
import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.BookType
import io.legado.app.data.appDb
import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.rule.*
import io.legado.app.databinding.ActivityBookSourceEditBinding
import io.legado.app.help.config.LocalConfig
import io.legado.app.lib.dialogs.SelectItem
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.selector
import io.legado.app.lib.theme.accentColor
import io.legado.app.lib.theme.backgroundColor
import io.legado.app.lib.theme.primaryColor
@ -30,6 +32,9 @@ import io.legado.app.ui.widget.dialog.UrlOptionDialog
import io.legado.app.ui.widget.keyboard.KeyboardToolPop
import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
class BookSourceEditActivity :
VMBaseActivity<ActivityBookSourceEditBinding, BookSourceEditViewModel>(false),
@ -484,21 +489,38 @@ class BookSourceEditActivity :
return true
}
private fun alertGroups() {
launch {
val groups = withContext(IO) {
appDb.bookSourceDao.allGroups
}
selector(groups) { _, s, _ ->
sendText(s)
}
}
}
override fun helpActions(): List<SelectItem<String>> {
return arrayListOf(
val helpActions = arrayListOf(
SelectItem("插入URL参数", "urlOption"),
SelectItem("书源教程", "ruleHelp"),
SelectItem("js教程", "jsHelp"),
SelectItem("正则教程", "regexHelp"),
SelectItem("选择文件", "selectFile"),
)
val view = window.decorView.findFocus()
if (view is EditText && view.getTag(R.id.tag) == "bookSourceGroup") {
helpActions.add(
SelectItem("插入分组", "addGroup")
)
}
return helpActions
}
override fun onHelpActionSelect(action: String) {
when (action) {
"urlOption" -> UrlOptionDialog(this) {
sendText(it)
}.show()
"addGroup" -> alertGroups()
"urlOption" -> UrlOptionDialog(this) { sendText(it) }.show()
"ruleHelp" -> showHelp("ruleHelp")
"jsHelp" -> showHelp("jsHelp")
"regexHelp" -> showHelp("regexHelp")

@ -42,6 +42,7 @@ class BookSourceEditAdapter : RecyclerView.Adapter<BookSourceEditAdapter.MyViewH
class MyViewHolder(val binding: ItemSourceEditBinding) : RecyclerView.ViewHolder(binding.root) {
fun bind(editEntity: EditEntity) = binding.run {
editText.setTag(R.id.tag, editEntity.key)
if (editText.getTag(R.id.tag1) == null) {
val listener = object : View.OnAttachStateChangeListener {
override fun onViewAttachedToWindow(v: View) {

@ -15,7 +15,6 @@ import com.google.android.material.snackbar.Snackbar
import io.legado.app.R
import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.AppLog
import io.legado.app.constant.AppPattern
import io.legado.app.constant.EventBus
import io.legado.app.data.appDb
import io.legado.app.data.entities.BookSource
@ -306,16 +305,9 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
private fun initLiveDataGroup() {
launch {
val noGroupName = getString(R.string.no_group)
appDb.bookSourceDao.flowGroup().conflate().collect {
appDb.bookSourceDao.flowGroups().conflate().collect {
groups.clear()
it.forEach { groupStr ->
groupStr.splitNotBlank(AppPattern.splitGroupRegex).forEach { group ->
if (group != noGroupName) {
groups.add(group)
}
}
}
groups.addAll(it)
upGroupMenu()
}
}
@ -453,9 +445,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
private fun upGroupMenu() = groupMenu?.let { menu ->
menu.removeGroup(R.id.source_group)
groups.sortedWith { o1, o2 ->
o1.cnCompare(o2)
}.map {
groups.forEach {
menu.add(R.id.source_group, Menu.NONE, Menu.NONE, it)
}
}

@ -13,7 +13,6 @@ import io.legado.app.R
import io.legado.app.base.BaseDialogFragment
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.constant.AppPattern
import io.legado.app.data.appDb
import io.legado.app.databinding.DialogEditTextBinding
import io.legado.app.databinding.DialogRecyclerViewBinding
@ -22,7 +21,9 @@ import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.backgroundColor
import io.legado.app.lib.theme.primaryColor
import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.*
import io.legado.app.utils.applyTint
import io.legado.app.utils.requestInputMethod
import io.legado.app.utils.setLayout
import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.launch
@ -54,16 +55,8 @@ class GroupManageDialog : BaseDialogFragment(R.layout.dialog_recycler_view),
private fun initData() {
launch {
appDb.bookSourceDao.flowGroup().collect {
val groups = linkedSetOf<String>()
it.map { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
}
adapter.setItems(
groups.sortedWith { o1, o2 ->
o1.cnCompare(o2)
}
)
appDb.bookSourceDao.flowGroups().collect {
adapter.setItems(it)
}
}
}

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="tag" type="id" />
<item name="tag1" type="id" />
<item name="tag2" type="id" />

Loading…
Cancel
Save