优化
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
package io.legado.app.data.entities
|
||||
|
||||
import android.os.Parcelable
|
||||
import android.text.TextUtils
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.Index
|
||||
import androidx.room.PrimaryKey
|
||||
import com.jayway.jsonpath.DocumentContext
|
||||
import io.legado.app.constant.AppPattern
|
||||
import io.legado.app.utils.*
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
@@ -114,6 +116,23 @@ data class RssSource(
|
||||
}
|
||||
}
|
||||
|
||||
fun addGroup(groups: String): RssSource {
|
||||
sourceGroup?.splitNotBlank(AppPattern.splitGroupRegex)?.toHashSet()?.let {
|
||||
it.addAll(groups.splitNotBlank(AppPattern.splitGroupRegex))
|
||||
sourceGroup = TextUtils.join(",", it)
|
||||
}
|
||||
if (sourceGroup.isNullOrBlank()) sourceGroup = groups
|
||||
return this
|
||||
}
|
||||
|
||||
fun removeGroup(groups: String): RssSource {
|
||||
sourceGroup?.splitNotBlank(AppPattern.splitGroupRegex)?.toHashSet()?.let {
|
||||
it.removeAll(groups.splitNotBlank(AppPattern.splitGroupRegex).toSet())
|
||||
sourceGroup = TextUtils.join(",", it)
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
fun sortUrls(): List<Pair<String, String>> = arrayListOf<Pair<String, String>>().apply {
|
||||
kotlin.runCatching {
|
||||
var a = sortUrl
|
||||
|
||||
@@ -146,6 +146,8 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
|
||||
when (item?.itemId) {
|
||||
R.id.menu_enable_selection -> viewModel.enableSelection(adapter.selection)
|
||||
R.id.menu_disable_selection -> viewModel.disableSelection(adapter.selection)
|
||||
R.id.menu_add_group -> selectionAddToGroups()
|
||||
R.id.menu_remove_group -> selectionRemoveFromGroups()
|
||||
R.id.menu_top_sel -> viewModel.topSource(*adapter.selection.toTypedArray())
|
||||
R.id.menu_bottom_sel -> viewModel.bottomSource(*adapter.selection.toTypedArray())
|
||||
R.id.menu_export_selection -> viewModel.saveToFile(adapter.selection) { file ->
|
||||
@@ -154,6 +156,7 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
|
||||
fileData = Triple("exportRssSource.json", file, "application/json")
|
||||
}
|
||||
}
|
||||
|
||||
R.id.menu_share_source -> viewModel.saveToFile(adapter.selection) {
|
||||
share(it)
|
||||
}
|
||||
@@ -213,6 +216,46 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
private fun selectionAddToGroups() {
|
||||
alert(titleResource = R.string.add_group) {
|
||||
val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply {
|
||||
editView.setHint(R.string.group_name)
|
||||
editView.setFilterValues(groups.toList())
|
||||
editView.dropDownHeight = 180.dpToPx()
|
||||
}
|
||||
customView { alertBinding.root }
|
||||
okButton {
|
||||
alertBinding.editView.text?.toString()?.let {
|
||||
if (it.isNotEmpty()) {
|
||||
viewModel.selectionAddToGroups(adapter.selection, it)
|
||||
}
|
||||
}
|
||||
}
|
||||
cancelButton()
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
private fun selectionRemoveFromGroups() {
|
||||
alert(titleResource = R.string.remove_group) {
|
||||
val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply {
|
||||
editView.setHint(R.string.group_name)
|
||||
editView.setFilterValues(groups.toList())
|
||||
editView.dropDownHeight = 180.dpToPx()
|
||||
}
|
||||
customView { alertBinding.root }
|
||||
okButton {
|
||||
alertBinding.editView.text?.toString()?.let {
|
||||
if (it.isNotEmpty()) {
|
||||
viewModel.selectionRemoveFromGroups(adapter.selection, it)
|
||||
}
|
||||
}
|
||||
}
|
||||
cancelButton()
|
||||
}
|
||||
}
|
||||
|
||||
override fun selectAll(selectAll: Boolean) {
|
||||
if (selectAll) {
|
||||
adapter.selectAll()
|
||||
|
||||
@@ -87,6 +87,24 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application)
|
||||
}
|
||||
}
|
||||
|
||||
fun selectionAddToGroups(sources: List<RssSource>, groups: String) {
|
||||
execute {
|
||||
val array = Array(sources.size) {
|
||||
sources[it].copy().addGroup(groups)
|
||||
}
|
||||
appDb.rssSourceDao.update(*array)
|
||||
}
|
||||
}
|
||||
|
||||
fun selectionRemoveFromGroups(sources: List<RssSource>, groups: String) {
|
||||
execute {
|
||||
val array = Array(sources.size) {
|
||||
sources[it].copy().removeGroup(groups)
|
||||
}
|
||||
appDb.rssSourceDao.update(*array)
|
||||
}
|
||||
}
|
||||
|
||||
fun addGroup(group: String) {
|
||||
execute {
|
||||
val sources = appDb.rssSourceDao.noGroup
|
||||
|
||||
Reference in New Issue
Block a user