From e7a2ab958d6a739df363b78ef8ec9bcc9f10fefe Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 5 Dec 2020 13:16:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=BA=90=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=E8=AE=A2=E9=98=85=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/rss/subscription/SourceSubActivity.kt | 9 ++++++--- .../app/ui/rss/subscription/SourceSubAdapter.kt | 13 +++++++++++-- app/src/main/res/layout/item_source_sub.xml | 4 +++- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/subscription/SourceSubActivity.kt b/app/src/main/java/io/legado/app/ui/rss/subscription/SourceSubActivity.kt index 490d23491..73cab72ca 100644 --- a/app/src/main/java/io/legado/app/ui/rss/subscription/SourceSubActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/subscription/SourceSubActivity.kt @@ -12,7 +12,8 @@ import io.legado.app.databinding.ActivitySourceSubBinding import io.legado.app.databinding.DialogSourceSubEditBinding import io.legado.app.lib.dialogs.alert -class SourceSubActivity : BaseActivity() { +class SourceSubActivity : BaseActivity(), + SourceSubAdapter.Callback { private lateinit var adapter: SourceSubAdapter private var liveData: LiveData>? = null @@ -39,7 +40,7 @@ class SourceSubActivity : BaseActivity() { } private fun initView() { - adapter = SourceSubAdapter(this) + adapter = SourceSubAdapter(this, this) binding.recyclerView.adapter = adapter } @@ -51,7 +52,7 @@ class SourceSubActivity : BaseActivity() { } } - private fun editSubscription(sourceSub: SourceSub) { + override fun editSubscription(sourceSub: SourceSub) { alert(R.string.source_subscription) { val alertBinding = DialogSourceSubEditBinding.inflate(layoutInflater).apply { when (sourceSub.type) { @@ -75,5 +76,7 @@ class SourceSubActivity : BaseActivity() { }.show() } + override fun delSubscription(sourceSub: SourceSub) { + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/rss/subscription/SourceSubAdapter.kt b/app/src/main/java/io/legado/app/ui/rss/subscription/SourceSubAdapter.kt index d2b98105c..f08b443e7 100644 --- a/app/src/main/java/io/legado/app/ui/rss/subscription/SourceSubAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/rss/subscription/SourceSubAdapter.kt @@ -6,8 +6,9 @@ import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.SourceSub 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(context) { @@ -17,16 +18,24 @@ class SourceSubAdapter(context: Context) : item: SourceSub, payloads: MutableList ) { + binding.tvType.text = SourceSub.Type.values()[item.type].name binding.tvName.text = item.name binding.tvUrl.text = item.url } override fun registerListener(holder: ItemViewHolder, binding: ItemSourceSubBinding) { - + binding.ivEdit.onClick { + callBack.editSubscription(getItem(holder.layoutPosition)!!) + } } override fun getViewBinding(parent: ViewGroup): ItemSourceSubBinding { return ItemSourceSubBinding.inflate(inflater, parent, false) } + interface Callback { + fun editSubscription(sourceSub: SourceSub) + fun delSubscription(sourceSub: SourceSub) + } + } \ No newline at end of file diff --git a/app/src/main/res/layout/item_source_sub.xml b/app/src/main/res/layout/item_source_sub.xml index b64595177..6e65c171e 100644 --- a/app/src/main/res/layout/item_source_sub.xml +++ b/app/src/main/res/layout/item_source_sub.xml @@ -15,6 +15,7 @@ android:textColor="@color/primaryText" app:layout_constraintTop_toTopOf="parent" app:layout_constraintLeft_toLeftOf="parent" + app:layout_constraintRight_toLeftOf="@id/iv_edit" tools:text="name" /> -