Trying to solve #120.

This commit is contained in:
Amine Bou 2017-12-03 18:00:52 +01:00
parent baebf938ef
commit 4818a101cc
2 changed files with 12 additions and 7 deletions

View File

@ -629,9 +629,10 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
} }
recyclerView.layoutManager = mLayoutManager recyclerView.layoutManager = mLayoutManager
recyclerView.setHasFixedSize(true)
if (infiniteScroll) { if (!infiniteScroll) {
recyclerView.setHasFixedSize(true)
} else {
handleInfiniteScroll() handleInfiniteScroll()
} }

View File

@ -8,6 +8,7 @@ import android.support.v7.widget.CardView
import android.support.v7.widget.RecyclerView import android.support.v7.widget.RecyclerView
import android.text.Html import android.text.Html
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.ImageView.ScaleType import android.widget.ImageView.ScaleType
import android.widget.TextView import android.widget.TextView
@ -52,6 +53,7 @@ class ItemCardAdapter(
) : RecyclerView.Adapter<ItemCardAdapter.ViewHolder>() { ) : RecyclerView.Adapter<ItemCardAdapter.ViewHolder>() {
private val c: Context = app.baseContext private val c: Context = app.baseContext
private val generator: ColorGenerator = ColorGenerator.MATERIAL private val generator: ColorGenerator = ColorGenerator.MATERIAL
private val imageMaxHeight: Int = c.resources.getDimension(R.dimen.card_image_max_height).toInt()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val v = LayoutInflater.from(c).inflate(R.layout.card_item, parent, false) as CardView val v = LayoutInflater.from(c).inflate(R.layout.card_item, parent, false) as CardView
@ -67,10 +69,17 @@ class ItemCardAdapter(
holder.mView.sourceTitleAndDate.text = itm.sourceAndDateText() holder.mView.sourceTitleAndDate.text = itm.sourceAndDateText()
if (!fullHeightCards) {
holder.mView.itemImage.maxHeight = imageMaxHeight
holder.mView.itemImage.scaleType = ScaleType.CENTER_CROP
}
if (itm.getThumbnail(c).isEmpty()) { if (itm.getThumbnail(c).isEmpty()) {
holder.mView.itemImage.visibility = View.GONE
Glide.with(c).clear(holder.mView.itemImage) Glide.with(c).clear(holder.mView.itemImage)
holder.mView.itemImage.setImageDrawable(null) holder.mView.itemImage.setImageDrawable(null)
} else { } else {
holder.mView.itemImage.visibility = View.VISIBLE
c.bitmapCenterCrop(itm.getThumbnail(c), holder.mView.itemImage) c.bitmapCenterCrop(itm.getThumbnail(c), holder.mView.itemImage)
} }
@ -183,11 +192,6 @@ class ItemCardAdapter(
private fun handleClickListeners() { private fun handleClickListeners() {
if (!fullHeightCards) {
mView.itemImage.maxHeight = c.resources.getDimension(R.dimen.card_image_max_height).toInt()
mView.itemImage.scaleType = ScaleType.CENTER_CROP
}
mView.favButton.setOnLikeListener(object : OnLikeListener { mView.favButton.setOnLikeListener(object : OnLikeListener {
override fun liked(likeButton: LikeButton) { override fun liked(likeButton: LikeButton) {
val (id) = items[adapterPosition] val (id) = items[adapterPosition]