-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
wangpeng
committed
Jun 13, 2021
1 parent
7c7421d
commit 51ab772
Showing
15 changed files
with
168 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 13 additions & 9 deletions
22
app/src/main/java/com/github/iielse/imageviewer/demo/business/TestDataViewHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,42 @@ | ||
package com.github.iielse.imageviewer.demo.business | ||
|
||
import android.view.View | ||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import android.widget.ImageView | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.bumptech.glide.Glide | ||
import com.github.iielse.imageviewer.demo.core.AdapterCallback | ||
import com.github.iielse.imageviewer.demo.core.ITEM_CLICKED | ||
import com.github.iielse.imageviewer.demo.data.MyData | ||
import kotlinx.android.extensions.LayoutContainer | ||
import kotlinx.android.synthetic.main.item_image.* | ||
import kotlinx.android.synthetic.main.item_image.view.* | ||
import com.github.iielse.imageviewer.demo.databinding.ItemImageBinding | ||
|
||
class TestDataViewHolder(override val containerView: View, private val listener: AdapterCallback) : RecyclerView.ViewHolder(containerView), LayoutContainer { | ||
class TestDataViewHolder( | ||
parent: ViewGroup, | ||
callback: AdapterCallback, | ||
val binding: ItemImageBinding = | ||
ItemImageBinding.inflate(LayoutInflater.from(parent.context), parent, false) | ||
) : RecyclerView.ViewHolder(binding.root) { | ||
init { | ||
// 初始化点击回调 | ||
itemView.setOnClickListener { | ||
(it.tag as? MyData?)?.let { listener.invoke(ITEM_CLICKED, it) } | ||
(it.tag as? MyData?)?.let { callback.invoke(ITEM_CLICKED, it) } | ||
} | ||
} | ||
|
||
fun bind(item: MyData, pos: Int) { | ||
itemView.tag = item | ||
|
||
posTxt.text = when { | ||
binding.posTxt.text = when { | ||
item.subsampling -> "$pos subsampling" | ||
item.url.endsWith(".gif") -> "$pos gif" | ||
item.url.endsWith(".mp4") -> "$pos video" | ||
else -> pos.toString() | ||
} | ||
|
||
// 测试 fitXY 的过渡动画效果 | ||
itemView.imageView.scaleType = if (pos == 19) ImageView.ScaleType.FIT_XY else ImageView.ScaleType.CENTER_CROP | ||
binding.imageView.scaleType = if (pos == 19) ImageView.ScaleType.FIT_XY else ImageView.ScaleType.CENTER_CROP | ||
|
||
Glide.with(imageView).load(item.url).into(imageView) | ||
Glide.with(binding.imageView).load(item.url).into(binding.imageView) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.