From 7811e498676938a036b058f3f4078597b37818e1 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 5 Dec 2020 11:20:53 +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/src/main/AndroidManifest.xml | 2 +- .../io/legado/app/data/entities/SourceSub.kt | 16 +++++- ...ceSubscription.kt => SourceSubActivity.kt} | 17 +++++- .../ui/rss/subscription/SourceSubAdapter.kt | 32 +++++++++++ app/src/main/res/layout/item_source_sub.xml | 57 +++++++++++++++++++ 5 files changed, 117 insertions(+), 7 deletions(-) rename app/src/main/java/io/legado/app/ui/rss/subscription/{SourceSubscription.kt => SourceSubActivity.kt} (64%) create mode 100644 app/src/main/java/io/legado/app/ui/rss/subscription/SourceSubAdapter.kt create mode 100644 app/src/main/res/layout/item_source_sub.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d455a6eb4..91e0795d8 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -173,7 +173,7 @@ android:launchMode="singleTask" /> () { +class SourceSubscriptionActivity : BaseActivity() { + + private lateinit var adapter: SourceSubAdapter + private var liveData: LiveData>? = null override fun getViewBinding(): ActivitySourceSubBinding { return ActivitySourceSubBinding.inflate(layoutInflater) @@ -31,11 +37,16 @@ class SourceSubscription : BaseActivity() { } private fun initView() { - binding.recyclerView + adapter = SourceSubAdapter(this) + binding.recyclerView.adapter = adapter } private fun initData() { - + liveData?.removeObservers(this) + liveData = App.db.sourceSubDao().observeAll() + liveData?.observe(this) { + adapter.setItems(it) + } } private fun editSubscription() { 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 new file mode 100644 index 000000000..d2b98105c --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/rss/subscription/SourceSubAdapter.kt @@ -0,0 +1,32 @@ +package io.legado.app.ui.rss.subscription + +import android.content.Context +import android.view.ViewGroup +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 + +class SourceSubAdapter(context: Context) : + SimpleRecyclerAdapter(context) { + + + override fun convert( + holder: ItemViewHolder, + binding: ItemSourceSubBinding, + item: SourceSub, + payloads: MutableList + ) { + binding.tvName.text = item.name + binding.tvUrl.text = item.url + } + + override fun registerListener(holder: ItemViewHolder, binding: ItemSourceSubBinding) { + + } + + override fun getViewBinding(parent: ViewGroup): ItemSourceSubBinding { + return ItemSourceSubBinding.inflate(inflater, parent, false) + } + +} \ 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 new file mode 100644 index 000000000..e131f32fc --- /dev/null +++ b/app/src/main/res/layout/item_source_sub.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + \ No newline at end of file