parent
1225af46a4
commit
8a57fe3b28
@ -0,0 +1,16 @@ |
|||||||
|
package io.legado.app.ui.rss.article |
||||||
|
|
||||||
|
import android.content.Context |
||||||
|
import androidx.viewbinding.ViewBinding |
||||||
|
import io.legado.app.base.adapter.SimpleRecyclerAdapter |
||||||
|
import io.legado.app.data.entities.RssArticle |
||||||
|
|
||||||
|
|
||||||
|
abstract class BaseRssArticlesAdapter<VB : ViewBinding>(context: Context, val callBack: CallBack) : |
||||||
|
SimpleRecyclerAdapter<RssArticle, VB>(context) { |
||||||
|
|
||||||
|
interface CallBack { |
||||||
|
val isGridLayout: Boolean |
||||||
|
fun readRss(rssArticle: RssArticle) |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,80 @@ |
|||||||
|
package io.legado.app.ui.rss.article |
||||||
|
|
||||||
|
import android.content.Context |
||||||
|
import android.graphics.drawable.Drawable |
||||||
|
import com.bumptech.glide.load.DataSource |
||||||
|
import com.bumptech.glide.load.engine.GlideException |
||||||
|
import com.bumptech.glide.request.RequestListener |
||||||
|
import com.bumptech.glide.request.target.Target |
||||||
|
import io.legado.app.R |
||||||
|
import io.legado.app.base.adapter.ItemViewHolder |
||||||
|
import io.legado.app.data.entities.RssArticle |
||||||
|
import io.legado.app.databinding.ItemRssArticle1Binding |
||||||
|
import io.legado.app.help.ImageLoader |
||||||
|
import io.legado.app.utils.gone |
||||||
|
import io.legado.app.utils.visible |
||||||
|
import org.jetbrains.anko.sdk27.listeners.onClick |
||||||
|
import org.jetbrains.anko.textColorResource |
||||||
|
|
||||||
|
class RssArticlesAdapter1(context: Context, callBack: CallBack) : |
||||||
|
BaseRssArticlesAdapter<ItemRssArticle1Binding>(context, callBack) { |
||||||
|
|
||||||
|
override fun convert( |
||||||
|
holder: ItemViewHolder, |
||||||
|
binding: ItemRssArticle1Binding, |
||||||
|
item: RssArticle, |
||||||
|
payloads: MutableList<Any> |
||||||
|
) { |
||||||
|
with(binding) { |
||||||
|
tvTitle.text = item.title |
||||||
|
tvPubDate.text = item.pubDate |
||||||
|
if (item.image.isNullOrBlank() && !callBack.isGridLayout) { |
||||||
|
imageView.gone() |
||||||
|
} else { |
||||||
|
ImageLoader.load(context, item.image).apply { |
||||||
|
if (callBack.isGridLayout) { |
||||||
|
placeholder(R.drawable.image_rss_article) |
||||||
|
} else { |
||||||
|
addListener(object : RequestListener<Drawable> { |
||||||
|
override fun onLoadFailed( |
||||||
|
e: GlideException?, |
||||||
|
model: Any?, |
||||||
|
target: Target<Drawable>?, |
||||||
|
isFirstResource: Boolean |
||||||
|
): Boolean { |
||||||
|
imageView.gone() |
||||||
|
return false |
||||||
|
} |
||||||
|
|
||||||
|
override fun onResourceReady( |
||||||
|
resource: Drawable?, |
||||||
|
model: Any?, |
||||||
|
target: Target<Drawable>?, |
||||||
|
dataSource: DataSource?, |
||||||
|
isFirstResource: Boolean |
||||||
|
): Boolean { |
||||||
|
imageView.visible() |
||||||
|
return false |
||||||
|
} |
||||||
|
|
||||||
|
}) |
||||||
|
} |
||||||
|
}.into(imageView) |
||||||
|
} |
||||||
|
if (item.read) { |
||||||
|
tvTitle.textColorResource = R.color.tv_text_summary |
||||||
|
} else { |
||||||
|
tvTitle.textColorResource = R.color.primaryText |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun registerListener(holder: ItemViewHolder, binding: ItemRssArticle1Binding) { |
||||||
|
holder.itemView.onClick { |
||||||
|
getItem(holder.layoutPosition)?.let { |
||||||
|
callBack.readRss(it) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,80 @@ |
|||||||
|
package io.legado.app.ui.rss.article |
||||||
|
|
||||||
|
import android.content.Context |
||||||
|
import android.graphics.drawable.Drawable |
||||||
|
import com.bumptech.glide.load.DataSource |
||||||
|
import com.bumptech.glide.load.engine.GlideException |
||||||
|
import com.bumptech.glide.request.RequestListener |
||||||
|
import com.bumptech.glide.request.target.Target |
||||||
|
import io.legado.app.R |
||||||
|
import io.legado.app.base.adapter.ItemViewHolder |
||||||
|
import io.legado.app.data.entities.RssArticle |
||||||
|
import io.legado.app.databinding.ItemRssArticle2Binding |
||||||
|
import io.legado.app.help.ImageLoader |
||||||
|
import io.legado.app.utils.gone |
||||||
|
import io.legado.app.utils.visible |
||||||
|
import org.jetbrains.anko.sdk27.listeners.onClick |
||||||
|
import org.jetbrains.anko.textColorResource |
||||||
|
|
||||||
|
class RssArticlesAdapter2(context: Context, callBack: CallBack) : |
||||||
|
BaseRssArticlesAdapter<ItemRssArticle2Binding>(context, callBack) { |
||||||
|
|
||||||
|
override fun convert( |
||||||
|
holder: ItemViewHolder, |
||||||
|
binding: ItemRssArticle2Binding, |
||||||
|
item: RssArticle, |
||||||
|
payloads: MutableList<Any> |
||||||
|
) { |
||||||
|
with(binding) { |
||||||
|
tvTitle.text = item.title |
||||||
|
tvPubDate.text = item.pubDate |
||||||
|
if (item.image.isNullOrBlank() && !callBack.isGridLayout) { |
||||||
|
imageView.gone() |
||||||
|
} else { |
||||||
|
ImageLoader.load(context, item.image).apply { |
||||||
|
if (callBack.isGridLayout) { |
||||||
|
placeholder(R.drawable.image_rss_article) |
||||||
|
} else { |
||||||
|
addListener(object : RequestListener<Drawable> { |
||||||
|
override fun onLoadFailed( |
||||||
|
e: GlideException?, |
||||||
|
model: Any?, |
||||||
|
target: Target<Drawable>?, |
||||||
|
isFirstResource: Boolean |
||||||
|
): Boolean { |
||||||
|
imageView.gone() |
||||||
|
return false |
||||||
|
} |
||||||
|
|
||||||
|
override fun onResourceReady( |
||||||
|
resource: Drawable?, |
||||||
|
model: Any?, |
||||||
|
target: Target<Drawable>?, |
||||||
|
dataSource: DataSource?, |
||||||
|
isFirstResource: Boolean |
||||||
|
): Boolean { |
||||||
|
imageView.visible() |
||||||
|
return false |
||||||
|
} |
||||||
|
|
||||||
|
}) |
||||||
|
} |
||||||
|
}.into(imageView) |
||||||
|
} |
||||||
|
if (item.read) { |
||||||
|
tvTitle.textColorResource = R.color.tv_text_summary |
||||||
|
} else { |
||||||
|
tvTitle.textColorResource = R.color.primaryText |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun registerListener(holder: ItemViewHolder, binding: ItemRssArticle2Binding) { |
||||||
|
holder.itemView.onClick { |
||||||
|
getItem(holder.layoutPosition)?.let { |
||||||
|
callBack.readRss(it) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue