添加默认图片

pull/219/head
yangyxd 5 years ago
parent 793aeb1c6d
commit b9287cf053
  1. 2
      app/src/main/assets/18PlusList.txt
  2. 17
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt
  3. 24
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesBaseAdapter.kt
  4. 63
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesGridAdapter.kt
  5. BIN
      app/src/main/res/drawable/rss_img_default.png

@ -1,2 +0,0 @@
OGN5dS5jb20=
c2cwMC54eXo=

@ -2,6 +2,8 @@ package io.legado.app.ui.rss.article
import android.content.Context
import android.graphics.drawable.Drawable
import android.widget.ImageView
import androidx.core.content.ContextCompat
import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.request.RequestListener
@ -18,15 +20,22 @@ import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.textColorResource
class RssArticlesAdapter(context: Context, layoutId: Int, val callBack: CallBack) :
class RssArticlesAdapter(context: Context, layoutId: Int, private val isGridLayout: Boolean, val callBack: CallBack) :
SimpleRecyclerAdapter<RssArticle>(context, layoutId) {
fun emptyImage(image_view: ImageView) {
if (isGridLayout)
image_view.setImageResource(R.drawable.rss_img_default)
else
image_view.gone()
}
override fun convert(holder: ItemViewHolder, item: RssArticle, payloads: MutableList<Any>) {
with(holder.itemView) {
tv_title.text = item.title
tv_pub_date.text = item.pubDate
if (item.image.isNullOrBlank()) {
image_view.gone()
emptyImage(image_view)
} else {
ImageLoader.load(context, item.image)
.addListener(object : RequestListener<Drawable> {
@ -36,8 +45,8 @@ class RssArticlesAdapter(context: Context, layoutId: Int, val callBack: CallBack
target: Target<Drawable>?,
isFirstResource: Boolean
): Boolean {
image_view.gone()
return false
emptyImage(image_view)
return true
}
override fun onResourceReady(

@ -1,24 +0,0 @@
package io.legado.app.ui.rss.article
import android.content.Context
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.data.entities.RssArticle
import org.jetbrains.anko.sdk27.listeners.onClick
abstract class RssArticlesBaseAdapter(context: Context, private val layoutId: Int, val callBack: CallBack) :
SimpleRecyclerAdapter<RssArticle>(context, layoutId) {
override fun registerListener(holder: ItemViewHolder) {
holder.itemView.onClick {
getItem(holder.layoutPosition)?.let {
callBack.readRss(it)
}
}
}
interface CallBack {
fun readRss(rssArticle: RssArticle)
}
}

@ -1,63 +0,0 @@
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.help.ImageLoader
import io.legado.app.utils.gone
import io.legado.app.utils.visible
import kotlinx.android.synthetic.main.item_rss_article.view.*
import org.jetbrains.anko.textColorResource
class RssArticlesGridAdapter(context: Context, private val layoutId: Int, callBack: CallBack) :
RssArticlesBaseAdapter(context, layoutId, callBack) {
override fun convert(holder: ItemViewHolder, item: RssArticle, payloads: MutableList<Any>) {
with(holder.itemView) {
tv_title.text = item.title
tv_pub_date.text = item.pubDate
if (item.image.isNullOrBlank()) {
image_view.gone()
} else {
ImageLoader.load(context, item.image)
.addListener(object : RequestListener<Drawable> {
override fun onLoadFailed(
e: GlideException?,
model: Any?,
target: Target<Drawable>?,
isFirstResource: Boolean
): Boolean {
image_view.gone()
return false
}
override fun onResourceReady(
resource: Drawable?,
model: Any?,
target: Target<Drawable>?,
dataSource: DataSource?,
isFirstResource: Boolean
): Boolean {
image_view.visible()
return false
}
})
.into(image_view)
}
if (item.read) {
tv_title.textColorResource = R.color.tv_text_summary
} else {
tv_title.textColorResource = R.color.tv_text_default
}
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 KiB

Loading…
Cancel
Save