添加源地址订阅功能

pull/517/head
gedoor 4 years ago
parent fa1f69ce57
commit e7a2ab958d
  1. 9
      app/src/main/java/io/legado/app/ui/rss/subscription/SourceSubActivity.kt
  2. 13
      app/src/main/java/io/legado/app/ui/rss/subscription/SourceSubAdapter.kt
  3. 4
      app/src/main/res/layout/item_source_sub.xml

@ -12,7 +12,8 @@ import io.legado.app.databinding.ActivitySourceSubBinding
import io.legado.app.databinding.DialogSourceSubEditBinding import io.legado.app.databinding.DialogSourceSubEditBinding
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
class SourceSubActivity : BaseActivity<ActivitySourceSubBinding>() { class SourceSubActivity : BaseActivity<ActivitySourceSubBinding>(),
SourceSubAdapter.Callback {
private lateinit var adapter: SourceSubAdapter private lateinit var adapter: SourceSubAdapter
private var liveData: LiveData<List<SourceSub>>? = null private var liveData: LiveData<List<SourceSub>>? = null
@ -39,7 +40,7 @@ class SourceSubActivity : BaseActivity<ActivitySourceSubBinding>() {
} }
private fun initView() { private fun initView() {
adapter = SourceSubAdapter(this) adapter = SourceSubAdapter(this, this)
binding.recyclerView.adapter = adapter binding.recyclerView.adapter = adapter
} }
@ -51,7 +52,7 @@ class SourceSubActivity : BaseActivity<ActivitySourceSubBinding>() {
} }
} }
private fun editSubscription(sourceSub: SourceSub) { override fun editSubscription(sourceSub: SourceSub) {
alert(R.string.source_subscription) { alert(R.string.source_subscription) {
val alertBinding = DialogSourceSubEditBinding.inflate(layoutInflater).apply { val alertBinding = DialogSourceSubEditBinding.inflate(layoutInflater).apply {
when (sourceSub.type) { when (sourceSub.type) {
@ -75,5 +76,7 @@ class SourceSubActivity : BaseActivity<ActivitySourceSubBinding>() {
}.show() }.show()
} }
override fun delSubscription(sourceSub: SourceSub) {
}
} }

@ -6,8 +6,9 @@ import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.data.entities.SourceSub import io.legado.app.data.entities.SourceSub
import io.legado.app.databinding.ItemSourceSubBinding import io.legado.app.databinding.ItemSourceSubBinding
import org.jetbrains.anko.sdk27.listeners.onClick
class SourceSubAdapter(context: Context) : class SourceSubAdapter(context: Context, val callBack: Callback) :
SimpleRecyclerAdapter<SourceSub, ItemSourceSubBinding>(context) { SimpleRecyclerAdapter<SourceSub, ItemSourceSubBinding>(context) {
@ -17,16 +18,24 @@ class SourceSubAdapter(context: Context) :
item: SourceSub, item: SourceSub,
payloads: MutableList<Any> payloads: MutableList<Any>
) { ) {
binding.tvType.text = SourceSub.Type.values()[item.type].name
binding.tvName.text = item.name binding.tvName.text = item.name
binding.tvUrl.text = item.url binding.tvUrl.text = item.url
} }
override fun registerListener(holder: ItemViewHolder, binding: ItemSourceSubBinding) { override fun registerListener(holder: ItemViewHolder, binding: ItemSourceSubBinding) {
binding.ivEdit.onClick {
callBack.editSubscription(getItem(holder.layoutPosition)!!)
}
} }
override fun getViewBinding(parent: ViewGroup): ItemSourceSubBinding { override fun getViewBinding(parent: ViewGroup): ItemSourceSubBinding {
return ItemSourceSubBinding.inflate(inflater, parent, false) return ItemSourceSubBinding.inflate(inflater, parent, false)
} }
interface Callback {
fun editSubscription(sourceSub: SourceSub)
fun delSubscription(sourceSub: SourceSub)
}
} }

@ -15,6 +15,7 @@
android:textColor="@color/primaryText" android:textColor="@color/primaryText"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@id/iv_edit"
tools:text="name" /> tools:text="name" />
<io.legado.app.ui.widget.text.AccentBgTextView <io.legado.app.ui.widget.text.AccentBgTextView
@ -35,11 +36,12 @@
android:padding="3dp" android:padding="3dp"
android:textSize="12sp" android:textSize="12sp"
android:textColor="@color/secondaryText" android:textColor="@color/secondaryText"
android:ellipsize="middle"
app:layout_constraintTop_toBottomOf="@+id/tv_name" app:layout_constraintTop_toBottomOf="@+id/tv_name"
app:layout_constraintLeft_toRightOf="@+id/tv_type" app:layout_constraintLeft_toRightOf="@+id/tv_type"
app:layout_constraintRight_toLeftOf="@+id/iv_edit"
tools:text="url" /> tools:text="url" />
<androidx.appcompat.widget.AppCompatImageView <androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_edit" android:id="@+id/iv_edit"
android:layout_width="36dp" android:layout_width="36dp"

Loading…
Cancel
Save