diff --git a/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt index 001877246..deaa45726 100644 --- a/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt @@ -37,9 +37,12 @@ interface RssSourceDao { @Query("SELECT * FROM rssSources where enabled = 1 and sourceGroup like :searchKey order by customOrder") fun liveEnabledByGroup(searchKey: String): LiveData> - @Query("select sourceGroup from rssSources where trim(sourceGroup) <> ''") + @Query("select distinct sourceGroup from rssSources where trim(sourceGroup) <> ''") fun liveGroup(): LiveData> + @get:Query("select distinct sourceGroup from rssSources where trim(sourceGroup) <> ''") + val allGroup: List + @get:Query("select min(customOrder) from rssSources") val minOrder: Int diff --git a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt index 41bda67fd..5ad9aeee7 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.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.RssSource 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 ImportRssSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListe 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.rssSourceDao.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 ->