parent
8130256962
commit
0bf0c340bf
@ -0,0 +1,24 @@ |
|||||||
|
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) |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,63 @@ |
|||||||
|
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 |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,8 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"> |
||||||
|
<solid android:color="@color/background" /> |
||||||
|
<stroke android:width="1dp" android:color="@color/bg_divider_line" /> |
||||||
|
<corners android:radius="1dp" /> |
||||||
|
<padding android:left="0dp" android:top="0dp" |
||||||
|
android:right="0dp" android:bottom="0dp" /> |
||||||
|
</shape> |
Loading…
Reference in new issue