pull/32/head
kunfei 5 years ago
parent 0d8b9be12d
commit 381cf86bf0
  1. 37
      app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt
  2. 2
      app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt
  3. 7
      app/src/main/res/layout/item_rss.xml

@ -1,13 +1,48 @@
package io.legado.app.ui.main.rss package io.legado.app.ui.main.rss
import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup
import androidx.paging.PagedListAdapter
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import io.legado.app.R
import io.legado.app.data.entities.RssSource
class RssAdapter { class RssAdapter : PagedListAdapter<RssSource, RssAdapter.MyViewHolder>(DIFF_CALLBACK) {
companion object {
@JvmField
val DIFF_CALLBACK = object : DiffUtil.ItemCallback<RssSource>() {
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) { class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
fun onBind(rssSource: RssSource) {
}
} }
} }

@ -28,7 +28,7 @@ class RssFragment : BaseFragment(R.layout.fragment_rss) {
ATH.applyEdgeEffectColor(recycler_view) ATH.applyEdgeEffectColor(recycler_view)
adapter = RssAdapter() adapter = RssAdapter()
recycler_view.layoutManager = GridLayoutManager(requireContext(), 4) recycler_view.layoutManager = GridLayoutManager(requireContext(), 4)
recycler_view.adapter = adapter
} }
private fun initData() { private fun initData() {

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>
Loading…
Cancel
Save