pull/36/head
kunfei 5 years ago
parent 0d127074c9
commit 765a012332
  1. 9
      app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt
  2. 5
      app/src/main/java/io/legado/app/data/entities/RssSource.kt
  3. 24
      app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt
  4. 7
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt
  5. 77
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt
  6. 18
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt
  7. 1
      app/src/main/res/values/strings.xml

@ -22,6 +22,15 @@ interface RssSourceDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(vararg rssSource: RssSource)
@Query("update rssSources set enabled = 1 where sourceUrl in (:sourceUrls)")
fun enableSection(vararg sourceUrls: String)
@Query("update rssSources set enabled = 0 where sourceUrl in (:sourceUrls)")
fun disableSection(vararg sourceUrls: String)
@Query("delete from rssSources where sourceUrl in (:sourceUrls)")
fun delSection(vararg sourceUrls: String)
@Update
fun update(vararg rssSource: RssSource)

@ -8,10 +8,11 @@ import kotlinx.android.parcel.Parcelize
@Parcelize
@Entity(tableName = "rssSources")
data class RssSource(
var sourceName: String = "",
@PrimaryKey
var sourceUrl: String = "",
var iconUrl: String = "",
var sourceName: String = "",
var sourceIcon: String = "",
var sourceGroup: String? = null,
var enabled: Boolean = true,
var ruleGuid: String? = null,
var ruleTitle: String? = null,

@ -112,7 +112,8 @@ class RssSourceEditActivity :
sourceEntities.apply {
add(EditEntity("sourceName", rssSource?.sourceName, R.string.rss_source_name))
add(EditEntity("sourceUrl", rssSource?.sourceUrl, R.string.rss_source_url))
add(EditEntity("iconUrl", rssSource?.iconUrl, R.string.rss_source_icon))
add(EditEntity("sourceIcon", rssSource?.sourceIcon, R.string.rss_source_icon))
add(EditEntity("sourceGroup", rssSource?.sourceGroup, R.string.rss_source_group))
add(EditEntity("ruleTitle", rssSource?.ruleTitle, R.string.rss_rule_title))
add(EditEntity("ruleAuthor", rssSource?.ruleAuthor, R.string.rss_rule_author))
add(EditEntity("ruleGuid", rssSource?.ruleGuid, R.string.rss_rule_guid))
@ -144,16 +145,17 @@ class RssSourceEditActivity :
when (it.key) {
"sourceName" -> source.sourceName = it.value ?: ""
"sourceUrl" -> source.sourceUrl = it.value ?: ""
"iconUrl" -> source.iconUrl = it.value ?: ""
"ruleTitle" -> source.ruleTitle = it.value ?: ""
"ruleAuthor" -> source.ruleAuthor = it.value ?: ""
"ruleGuid" -> source.ruleGuid = it.value ?: ""
"rulePubDate" -> source.rulePubDate = it.value ?: ""
"ruleCategories" -> source.ruleCategories = it.value ?: ""
"ruleDescription" -> source.ruleDescription = it.value ?: ""
"ruleImage" -> source.ruleImage = it.value ?: ""
"ruleContent" -> source.ruleContent = it.value ?: ""
"ruleLink" -> source.ruleLink = it.value ?: ""
"sourceIcon" -> source.sourceIcon = it.value ?: ""
"sourceGroup" -> source.sourceGroup = it.value
"ruleTitle" -> source.ruleTitle = it.value
"ruleAuthor" -> source.ruleAuthor = it.value
"ruleGuid" -> source.ruleGuid = it.value
"rulePubDate" -> source.rulePubDate = it.value
"ruleCategories" -> source.ruleCategories = it.value
"ruleDescription" -> source.ruleDescription = it.value
"ruleImage" -> source.ruleImage = it.value
"ruleContent" -> source.ruleContent = it.value
"ruleLink" -> source.ruleLink = it.value
}
}
if (source.sourceName.isBlank() || source.sourceName.isBlank()) {

@ -50,6 +50,11 @@ class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_r
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.menu_add -> startActivity<RssSourceEditActivity>()
R.id.menu_select_all -> adapter.selectAll()
R.id.menu_revert_selection -> adapter.revertSelection()
R.id.menu_enable_selection -> viewModel.enableSelection(adapter.getSelectionIds())
R.id.menu_disable_selection -> viewModel.disableSelection(adapter.getSelectionIds())
R.id.menu_del_selection -> viewModel.delSelection(adapter.getSelectionIds())
}
return super.onCompatOptionsItemSelected(item)
}
@ -103,7 +108,7 @@ class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_r
}
override fun edit(source: RssSource) {
startActivity<RssSourceEditActivity>(Pair("data", source.sourceUrl))
}
override fun update(vararg source: RssSource) {

@ -1,21 +1,94 @@
package io.legado.app.ui.rss.source.manage
import android.content.Context
import android.view.Menu
import android.widget.PopupMenu
import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.data.entities.RssSource
import io.legado.app.help.ItemTouchCallback
import io.legado.app.lib.theme.backgroundColor
import kotlinx.android.synthetic.main.item_rss_source.view.*
import org.jetbrains.anko.sdk27.listeners.onClick
class RssSourceAdapter(context: Context, val callBack: CallBack) :
SimpleRecyclerAdapter<RssSource>(context, R.layout.item_rss_source),
ItemTouchCallback.OnItemTouchCallbackListener {
private val selectedIds = linkedSetOf<String>()
fun selectAll() {
getItems().forEach {
selectedIds.add(it.sourceUrl)
}
notifyItemRangeChanged(0, itemCount, 1)
}
fun revertSelection() {
getItems().forEach {
if (selectedIds.contains(it.sourceUrl)) {
selectedIds.remove(it.sourceUrl)
} else {
selectedIds.add(it.sourceUrl)
}
}
notifyItemRangeChanged(0, itemCount, 1)
}
fun getSelectionIds(): LinkedHashSet<String> {
val selection = linkedSetOf<String>()
getItems().map {
if (selectedIds.contains(it.sourceUrl)) {
selection.add(it.sourceUrl)
}
}
return selection
}
override fun convert(holder: ItemViewHolder, item: RssSource, payloads: MutableList<Any>) {
with(holder.itemView) {
cb_source.text = item.sourceName
if (payloads.isEmpty()) {
this.setBackgroundColor(context.backgroundColor)
if (item.sourceGroup.isNullOrEmpty()) {
cb_source.text = item.sourceName
} else {
cb_source.text =
String.format("%s (%s)", item.sourceName, item.sourceGroup)
}
swt_enabled.isChecked = item.enabled
swt_enabled.onClick {
item.enabled = swt_enabled.isChecked
callBack.update(item)
}
cb_source.isChecked = selectedIds.contains(item.sourceUrl)
cb_source.setOnClickListener {
if (cb_source.isChecked) {
selectedIds.add(item.sourceUrl)
} else {
selectedIds.remove(item.sourceUrl)
}
}
iv_edit.onClick { callBack.edit(item) }
iv_menu_more.onClick {
val popupMenu = PopupMenu(context, it)
popupMenu.menu.add(Menu.NONE, R.id.menu_top, Menu.NONE, R.string.to_top)
popupMenu.menu.add(Menu.NONE, R.id.menu_del, Menu.NONE, R.string.delete)
popupMenu.setOnMenuItemClickListener { menuItem ->
when (menuItem.itemId) {
R.id.menu_top -> callBack.toTop(item)
R.id.menu_del -> callBack.del(item)
}
true
}
popupMenu.show()
}
} else {
when (payloads[0]) {
1 -> cb_source.isChecked = selectedIds.contains(item.sourceUrl)
2 -> swt_enabled.isChecked = item.enabled
}
}
}
}

@ -1,8 +1,26 @@
package io.legado.app.ui.rss.source.manage
import android.app.Application
import io.legado.app.App
import io.legado.app.base.BaseViewModel
class RssSourceViewModel(application: Application) : BaseViewModel(application) {
fun enableSelection(ids: LinkedHashSet<String>) {
execute {
App.db.rssSourceDao().enableSection(*ids.toTypedArray())
}
}
fun disableSelection(ids: LinkedHashSet<String>) {
execute {
App.db.rssSourceDao().disableSection(*ids.toTypedArray())
}
}
fun delSelection(ids: LinkedHashSet<String>) {
execute {
App.db.rssSourceDao().delSection(*ids.toTypedArray())
}
}
}

@ -379,6 +379,7 @@
<string name="rss_source_name">名称</string>
<string name="rss_source_url">url</string>
<string name="rss_source_icon">图标</string>
<string name="rss_source_group">分组</string>
<string name="rss_rule_title">标题</string>
<string name="rss_rule_author">作者</string>
<string name="rss_rule_guid">guid</string>

Loading…
Cancel
Save