From 381cf86bf08a2f0d3ddae871bae1016f088466c4 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 25 Aug 2019 09:21:43 +0800 Subject: [PATCH] up --- .../io/legado/app/ui/main/rss/RssAdapter.kt | 37 ++++++++++++++++++- .../io/legado/app/ui/main/rss/RssFragment.kt | 2 +- app/src/main/res/layout/item_rss.xml | 7 ++++ 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 app/src/main/res/layout/item_rss.xml diff --git a/app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt b/app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt index cbce98ce0..882e4f738 100644 --- a/app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt @@ -1,13 +1,48 @@ package io.legado.app.ui.main.rss +import android.view.LayoutInflater import android.view.View +import android.view.ViewGroup +import androidx.paging.PagedListAdapter +import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.RecyclerView +import io.legado.app.R +import io.legado.app.data.entities.RssSource -class RssAdapter { +class RssAdapter : PagedListAdapter(DIFF_CALLBACK) { + companion object { + @JvmField + val DIFF_CALLBACK = object : DiffUtil.ItemCallback() { + override fun areItemsTheSame(oldItem: RssSource, newItem: RssSource): Boolean = + oldItem.sourceUrl == newItem.sourceUrl + + override fun areContentsTheSame(oldItem: RssSource, newItem: RssSource): Boolean = + oldItem.sourceName == newItem.sourceName + } + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder { + return MyViewHolder( + LayoutInflater.from(parent.context).inflate( + R.layout.item_rss, + parent, + false + ) + ) + } + + override fun onBindViewHolder(holder: MyViewHolder, position: Int) { + getItem(position)?.let { + holder.onBind(it) + } + } class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) { + fun onBind(rssSource: RssSource) { + + } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt index e00c9d00e..7603f03ea 100644 --- a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt @@ -28,7 +28,7 @@ class RssFragment : BaseFragment(R.layout.fragment_rss) { ATH.applyEdgeEffectColor(recycler_view) adapter = RssAdapter() recycler_view.layoutManager = GridLayoutManager(requireContext(), 4) - + recycler_view.adapter = adapter } private fun initData() { diff --git a/app/src/main/res/layout/item_rss.xml b/app/src/main/res/layout/item_rss.xml new file mode 100644 index 000000000..d829e291c --- /dev/null +++ b/app/src/main/res/layout/item_rss.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file