From 41b32f26ce20c531614c22533925b660342c8942 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 16 Jan 2021 19:19:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E5=85=A5=E4=B9=A6=E6=BA=90=E6=98=AF?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E5=88=86=E7=BB=84=E5=8F=AF=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/data/dao/BookSourceDao.kt | 12 ++++++------ .../app/ui/association/ImportBookSourceDialog.kt | 15 +++++++++++---- .../ui/book/source/manage/BookSourceActivity.kt | 4 ++-- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt index c2f82bf13..7a40d4cc8 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt @@ -32,18 +32,15 @@ interface BookSourceDao { @Query("select * from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' and (bookSourceGroup like :key) order by customOrder asc") fun liveGroupExplore(key: String): LiveData> - @Query("select bookSourceGroup from book_sources where trim(bookSourceGroup) <> ''") + @Query("select distinct bookSourceGroup from book_sources where trim(bookSourceGroup) <> ''") fun liveGroup(): LiveData> - @Query("select bookSourceGroup from book_sources where enabled = 1 and trim(bookSourceGroup) <> ''") + @Query("select distinct bookSourceGroup from book_sources where enabled = 1 and trim(bookSourceGroup) <> ''") fun liveGroupEnabled(): LiveData> - @Query("select bookSourceGroup from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' and trim(bookSourceGroup) <> ''") + @Query("select distinct bookSourceGroup from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' and trim(bookSourceGroup) <> ''") fun liveExploreGroup(): LiveData> - @Query("select distinct enabled from book_sources where bookSourceName like :searchKey or bookSourceGroup like :searchKey or bookSourceUrl like :searchKey") - fun searchIsEnable(searchKey: String = ""): List - @Query("select * from book_sources where enabledExplore = 1 order by customOrder asc") fun observeFind(): DataSource.Factory @@ -68,6 +65,9 @@ interface BookSourceDao { @get:Query("select * from book_sources where enabled = 1 and bookSourceType = 0 order by customOrder") val allTextEnabled: List + @get:Query("select distinct bookSourceGroup from book_sources where trim(bookSourceGroup) <> ''") + val allGroup: List + @Query("select * from book_sources where bookSourceUrl = :key") fun getBookSource(key: String): BookSource? diff --git a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt index 6aa236744..0f3e6008f 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt @@ -10,10 +10,12 @@ import android.view.View import android.view.ViewGroup import androidx.appcompat.widget.Toolbar import androidx.recyclerview.widget.LinearLayoutManager +import io.legado.app.App 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.entities.BookSource import io.legado.app.databinding.DialogEditTextBinding @@ -21,10 +23,8 @@ import io.legado.app.databinding.DialogRecyclerViewBinding import io.legado.app.databinding.ItemSourceImportBinding import io.legado.app.help.AppConfig import io.legado.app.lib.dialogs.alert -import io.legado.app.utils.getViewModelOfActivity -import io.legado.app.utils.putPrefBoolean +import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding -import io.legado.app.utils.visible import org.jetbrains.anko.sdk27.listeners.onClick /** @@ -85,7 +85,14 @@ class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList when (item.itemId) { R.id.menu_new_group -> { alert(R.string.diy_edit_source_group) { - val alertBinding = DialogEditTextBinding.inflate(layoutInflater) + val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply { + val groups = linkedSetOf() + App.db.bookSourceDao.allGroup.forEach { group -> + groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) + } + editView.setFilterValues(groups.toList()) + editView.dropDownHeight = 180.dp + } customView = alertBinding.root okButton { alertBinding.editView.text?.toString()?.let { group -> diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index b23e1a641..aa78e4a5b 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -58,7 +58,7 @@ class BookSourceActivity : VMBaseActivity>? = null - private var groups = linkedSetOf() + private val groups = linkedSetOf() private var groupMenu: SubMenu? = null private var sort = Sort.Default private var sortAscending = true @@ -249,7 +249,7 @@ class BookSourceActivity : VMBaseActivity + it.forEach { group -> groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) } upGroupMenu()