优化
This commit is contained in:
@@ -89,8 +89,9 @@ class MangaAdapter(private val context: Context) :
|
|||||||
binding.retry.setOnClickListener {
|
binding.retry.setOnClickListener {
|
||||||
val item = mDiffer.currentList[layoutPosition]
|
val item = mDiffer.currentList[layoutPosition]
|
||||||
if (item is MangaPage) {
|
if (item is MangaPage) {
|
||||||
|
val isLastImage = item.imageCount > 0 && item.index == item.imageCount - 1
|
||||||
loadImageWithRetry(
|
loadImageWithRetry(
|
||||||
item.mImageUrl, isHorizontal, item.imageCount == 1
|
item.mImageUrl, isHorizontal, isLastImage
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -98,7 +99,8 @@ class MangaAdapter(private val context: Context) :
|
|||||||
|
|
||||||
fun onBind(item: MangaPage) {
|
fun onBind(item: MangaPage) {
|
||||||
setImageColorFilter()
|
setImageColorFilter()
|
||||||
loadImageWithRetry(item.mImageUrl, isHorizontal, item.imageCount == 1)
|
val isLastImage = item.imageCount > 0 && item.index == item.imageCount - 1
|
||||||
|
loadImageWithRetry(item.mImageUrl, isHorizontal, isLastImage)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setImageColorFilter() {
|
fun setImageColorFilter() {
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ open class MangaVH<VB : ViewBinding>(val binding: VB, private val context: Conte
|
|||||||
protected lateinit var mFlProgress: FrameLayout
|
protected lateinit var mFlProgress: FrameLayout
|
||||||
protected var mRetry: Button? = null
|
protected var mRetry: Button? = null
|
||||||
|
|
||||||
|
private val minHeight = context.resources.displayMetrics.heightPixels * 2 / 3
|
||||||
|
|
||||||
fun initComponent(
|
fun initComponent(
|
||||||
loading: ProgressBar,
|
loading: ProgressBar,
|
||||||
image: AppCompatImageView,
|
image: AppCompatImageView,
|
||||||
@@ -49,7 +51,7 @@ open class MangaVH<VB : ViewBinding>(val binding: VB, private val context: Conte
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("CheckResult")
|
@SuppressLint("CheckResult")
|
||||||
fun loadImageWithRetry(imageUrl: String, isHorizontal: Boolean, singleImage: Boolean) {
|
fun loadImageWithRetry(imageUrl: String, isHorizontal: Boolean, isLastImage: Boolean) {
|
||||||
mFlProgress.isVisible = true
|
mFlProgress.isVisible = true
|
||||||
mLoading.isVisible = true
|
mLoading.isVisible = true
|
||||||
mRetry?.isGone = true
|
mRetry?.isGone = true
|
||||||
@@ -92,14 +94,29 @@ open class MangaVH<VB : ViewBinding>(val binding: VB, private val context: Conte
|
|||||||
mFlProgress.isGone = true
|
mFlProgress.isGone = true
|
||||||
if (!isHorizontal) {
|
if (!isHorizontal) {
|
||||||
itemView.updateLayoutParams<ViewGroup.LayoutParams> {
|
itemView.updateLayoutParams<ViewGroup.LayoutParams> {
|
||||||
height = if (singleImage) {
|
height = ViewGroup.LayoutParams.WRAP_CONTENT
|
||||||
ViewGroup.LayoutParams.MATCH_PARENT
|
|
||||||
} else {
|
|
||||||
ViewGroup.LayoutParams.WRAP_CONTENT
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
mImage.updateLayoutParams<FrameLayout.LayoutParams> {
|
mImage.updateLayoutParams<FrameLayout.LayoutParams> {
|
||||||
|
gravity = Gravity.NO_GRAVITY
|
||||||
|
}
|
||||||
|
if (isLastImage) {
|
||||||
|
mImage.updateLayoutParams<FrameLayout.LayoutParams> {
|
||||||
|
height = ViewGroup.LayoutParams.WRAP_CONTENT
|
||||||
|
}
|
||||||
|
itemView.minimumHeight = minHeight
|
||||||
|
} else {
|
||||||
|
mImage.updateLayoutParams<FrameLayout.LayoutParams> {
|
||||||
|
height = ViewGroup.LayoutParams.MATCH_PARENT
|
||||||
|
}
|
||||||
|
itemView.minimumHeight = 0
|
||||||
|
}
|
||||||
|
mImage.scaleType = ImageView.ScaleType.FIT_XY
|
||||||
|
} else {
|
||||||
|
itemView.updateLayoutParams<ViewGroup.LayoutParams> {
|
||||||
|
height = ViewGroup.LayoutParams.MATCH_PARENT
|
||||||
|
}
|
||||||
|
mImage.updateLayoutParams<FrameLayout.LayoutParams> {
|
||||||
|
height = ViewGroup.LayoutParams.MATCH_PARENT
|
||||||
gravity = Gravity.CENTER
|
gravity = Gravity.CENTER
|
||||||
}
|
}
|
||||||
mImage.scaleType = ImageView.ScaleType.FIT_CENTER
|
mImage.scaleType = ImageView.ScaleType.FIT_CENTER
|
||||||
|
|||||||
Reference in New Issue
Block a user