添加规则订阅功能

pull/525/head
gedoor 4 years ago
parent 7dd28530f7
commit 774a0f3056
  1. 11
      app/src/main/java/io/legado/app/data/entities/RuleSub.kt
  2. 19
      app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubActivity.kt
  3. 16
      app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubAdapter.kt
  4. 2
      app/src/main/res/layout/activity_rule_sub.xml
  5. 22
      app/src/main/res/layout/dialog_rule_sub_edit.xml
  6. 0
      app/src/main/res/layout/item_rule_sub.xml
  7. 10
      app/src/main/res/values-zh-rHK/arrays.xml
  8. 2
      app/src/main/res/values-zh-rHK/strings.xml
  9. 9
      app/src/main/res/values-zh-rTW/arrays.xml
  10. 2
      app/src/main/res/values-zh-rTW/strings.xml
  11. 9
      app/src/main/res/values-zh/arrays.xml
  12. 2
      app/src/main/res/values-zh/strings.xml
  13. 9
      app/src/main/res/values/arrays.xml
  14. 2
      app/src/main/res/values/strings.xml

@ -13,13 +13,4 @@ data class RuleSub(
var customOrder: Int = 0,
var autoUpdate: Boolean = false,
var update: Long = System.currentTimeMillis()
) {
fun setType(type: Type) {
this.type = type.ordinal
}
enum class Type {
BookSource, RssSource, ReplaceRule
}
}
)

@ -11,7 +11,7 @@ import io.legado.app.R
import io.legado.app.base.BaseActivity
import io.legado.app.data.entities.RuleSub
import io.legado.app.databinding.ActivityRuleSubBinding
import io.legado.app.databinding.DialogSourceSubEditBinding
import io.legado.app.databinding.DialogRuleSubEditBinding
import io.legado.app.lib.dialogs.alert
import io.legado.app.ui.association.ImportBookSourceActivity
import io.legado.app.ui.association.ImportRssSourceActivity
@ -20,6 +20,9 @@ import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch
import org.jetbrains.anko.startActivity
/**
* 规则订阅界面
*/
class RuleSubActivity : BaseActivity<ActivityRuleSubBinding>(),
RuleSubAdapter.Callback {
@ -69,7 +72,7 @@ class RuleSubActivity : BaseActivity<ActivityRuleSubBinding>(),
override fun openSubscription(ruleSub: RuleSub) {
when (ruleSub.type) {
RuleSub.Type.RssSource.ordinal -> {
1 -> {
startActivity<ImportRssSourceActivity>("source" to ruleSub.url)
}
else -> {
@ -80,20 +83,14 @@ class RuleSubActivity : BaseActivity<ActivityRuleSubBinding>(),
override fun editSubscription(ruleSub: RuleSub) {
alert(R.string.rule_subscription) {
val alertBinding = DialogSourceSubEditBinding.inflate(layoutInflater).apply {
when (ruleSub.type) {
RuleSub.Type.RssSource.ordinal -> rgType.check(R.id.rb_rss_source)
else -> rgType.check(R.id.rb_book_source)
}
val alertBinding = DialogRuleSubEditBinding.inflate(layoutInflater).apply {
spType.setSelection(ruleSub.type)
etName.setText(ruleSub.name)
etUrl.setText(ruleSub.url)
}
customView = alertBinding.root
okButton {
when (alertBinding.rgType.checkedRadioButtonId) {
R.id.rb_rss_source -> ruleSub.setType(RuleSub.Type.RssSource)
else -> ruleSub.setType(RuleSub.Type.BookSource)
}
ruleSub.type = alertBinding.spType.selectedItemPosition
ruleSub.name = alertBinding.etName.text?.toString() ?: ""
ruleSub.url = alertBinding.etUrl.text?.toString() ?: ""
launch(IO) {

@ -9,27 +9,29 @@ 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.RuleSub
import io.legado.app.databinding.ItemSourceSubBinding
import io.legado.app.databinding.ItemRuleSubBinding
import io.legado.app.ui.widget.recycler.ItemTouchCallback
import org.jetbrains.anko.sdk27.listeners.onClick
import java.util.*
class RuleSubAdapter(context: Context, val callBack: Callback) :
SimpleRecyclerAdapter<RuleSub, ItemSourceSubBinding>(context),
SimpleRecyclerAdapter<RuleSub, ItemRuleSubBinding>(context),
ItemTouchCallback.Callback {
private val typeArray = context.resources.getStringArray(R.array.rule_type)
override fun convert(
holder: ItemViewHolder,
binding: ItemSourceSubBinding,
binding: ItemRuleSubBinding,
item: RuleSub,
payloads: MutableList<Any>
) {
binding.tvType.text = RuleSub.Type.values()[item.type].name
binding.tvType.text = typeArray[item.type]
binding.tvName.text = item.name
binding.tvUrl.text = item.url
}
override fun registerListener(holder: ItemViewHolder, binding: ItemSourceSubBinding) {
override fun registerListener(holder: ItemViewHolder, binding: ItemRuleSubBinding) {
binding.root.onClick {
callBack.openSubscription(getItem(holder.layoutPosition)!!)
}
@ -54,8 +56,8 @@ class RuleSubAdapter(context: Context, val callBack: Callback) :
popupMenu.show()
}
override fun getViewBinding(parent: ViewGroup): ItemSourceSubBinding {
return ItemSourceSubBinding.inflate(inflater, parent, false)
override fun getViewBinding(parent: ViewGroup): ItemRuleSubBinding {
return ItemRuleSubBinding.inflate(inflater, parent, false)
}
override fun onMove(srcPosition: Int, targetPosition: Int): Boolean {

@ -21,7 +21,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/item_source_sub" />
tools:listitem="@layout/item_rule_sub" />
<TextView
android:id="@+id/tv_empty_msg"

@ -3,28 +3,30 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:padding="16dp">
<RadioGroup
android:id="@+id/rg_type"
android:layout_width="wrap_content"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<io.legado.app.lib.theme.view.ATERadioButton
android:id="@+id/rb_book_source"
<io.legado.app.ui.widget.text.AccentTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/book_source" />
android:text="@string/book_type"
android:padding="3dp"
tools:ignore="RtlHardcoded" />
<io.legado.app.lib.theme.view.ATERadioButton
android:id="@+id/rb_rss_source"
<androidx.appcompat.widget.AppCompatSpinner
android:id="@+id/sp_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rss_source" />
android:entries="@array/rule_type"
app:theme="@style/Spinner" />
</RadioGroup>
</LinearLayout>
<io.legado.app.ui.widget.text.TextInputLayout
android:id="@+id/til_name"

@ -1,6 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="book_type">
<item>文本</item>
<item>音頻</item>
</string-array>
<string-array name="theme_mode">
<item>跟隨系統</item>
<item>亮色主題</item>
@ -60,4 +65,9 @@
<item>英文</item>
</string-array>
<string-array name="rule_type">
<item>書源</item>
<item>訂閲源</item>
</string-array>
</resources>

@ -592,8 +592,6 @@
<string name="change_cover_source">封面換源</string>
<string name="select_local_image">選擇本地圖片</string>
<string name="book_type">類型: </string>
<string name="book_type_text">文本</string>
<string name="book_type_audio">音頻</string>
<string name="to_backstage">後台</string>
<string name="importing">正在導入</string>
<string name="exporting">正在導出</string>

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="book_type">
<item>@string/book_type_text</item>
<item>@string/book_type_audio</item>
<item>文字</item>
<item>音訊</item>
</string-array>
<string-array name="indent">
@ -101,4 +101,9 @@
<item>英文</item>
</string-array>
<string-array name="rule_type">
<item>書源</item>
<item>訂閲源</item>
</string-array>
</resources>

@ -594,8 +594,6 @@
<string name="change_cover_source">封面換源</string>
<string name="select_local_image">選擇本機圖片</string>
<string name="book_type">類型:</string>
<string name="book_type_text">文字</string>
<string name="book_type_audio">音訊</string>
<string name="to_backstage">後台</string>
<string name="importing">正在匯入</string>
<string name="exporting">正在匯出</string>

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="book_type">
<item>@string/book_type_text</item>
<item>@string/book_type_audio</item>
<item>文本</item>
<item>音频</item>
</string-array>
<string-array name="indent">
@ -101,4 +101,9 @@
<item>英文</item>
</string-array>
<string-array name="rule_type">
<item>书源</item>
<item>订阅源</item>
</string-array>
</resources>

@ -602,8 +602,6 @@
<string name="change_cover_source">封面换源</string>
<string name="select_local_image">选择本地图片</string>
<string name="book_type">类型:</string>
<string name="book_type_text">文本</string>
<string name="book_type_audio">音频</string>
<string name="to_backstage">后台</string>
<string name="importing">正在导入</string>
<string name="exporting">正在导出</string>

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="book_type">
<item>@string/book_type_text</item>
<item>@string/book_type_audio</item>
<item>Text</item>
<item>Audio</item>
</string-array>
<string-array name="indent">
@ -101,4 +101,9 @@
<item>English</item>
</string-array>
<string-array name="rule_type">
<item>BookSource</item>
<item>RssSource</item>
</string-array>
</resources>

@ -603,8 +603,6 @@
<string name="change_cover_source">Change origin</string>
<string name="select_local_image">Local image</string>
<string name="book_type">Type:</string>
<string name="book_type_text">Text</string>
<string name="book_type_audio">Audio</string>
<string name="to_backstage">Background</string>
<string name="importing">Importing</string>
<string name="exporting">Exporting</string>

Loading…
Cancel
Save