优化播放历史列表样式:固定宽度卡片、横向滚动、添加封面图
This commit is contained in:
@@ -287,24 +287,96 @@ class SearchFragment : Fragment() {
|
||||
playHistoryList.visibility = View.VISIBLE
|
||||
|
||||
for (item in list) {
|
||||
val chip = Button(requireContext()).apply {
|
||||
// 显示视频名称和剧集名称
|
||||
text = if (item.episodeName != null) {
|
||||
"${item.title} - ${item.episodeName}"
|
||||
} else {
|
||||
item.title
|
||||
// 创建外层容器,固定宽度
|
||||
val container = android.widget.LinearLayout(requireContext()).apply {
|
||||
orientation = android.widget.LinearLayout.VERTICAL
|
||||
setPadding(12, 12, 12, 12)
|
||||
layoutParams = android.widget.LinearLayout.LayoutParams(
|
||||
200, // 固定宽度 200dp
|
||||
android.widget.LinearLayout.LayoutParams.WRAP_CONTENT
|
||||
).apply {
|
||||
marginEnd = 16
|
||||
}
|
||||
setTextColor(ContextCompat.getColor(requireContext(), R.color.text_primary))
|
||||
setBackgroundResource(R.drawable.history_chip_selector)
|
||||
textSize = 14f
|
||||
setPadding(24, 12, 24, 12)
|
||||
isFocusable = true
|
||||
isFocusableInTouchMode = true
|
||||
setOnClickListener {
|
||||
openPlayerFromHistory(item)
|
||||
background = android.graphics.drawable.GradientDrawable().apply {
|
||||
setColor(android.graphics.Color.parseColor("#2D2D2D"))
|
||||
cornerRadius = 12f
|
||||
setStroke(2, android.graphics.Color.parseColor("#3D3D3D"))
|
||||
}
|
||||
}
|
||||
playHistoryList.addView(chip)
|
||||
|
||||
// 创建封面图片区域
|
||||
val coverView = android.widget.ImageView(requireContext()).apply {
|
||||
layoutParams = android.widget.LinearLayout.LayoutParams(
|
||||
android.widget.LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
100 // 固定高度 100dp
|
||||
).apply {
|
||||
bottomMargin = 8
|
||||
}
|
||||
scaleType = android.widget.ImageView.ScaleType.CENTER_CROP
|
||||
setBackgroundColor(android.graphics.Color.parseColor("#1E1E1E"))
|
||||
// 加载封面图
|
||||
if (!item.coverUrl.isNullOrEmpty()) {
|
||||
com.bumptech.glide.Glide.with(this)
|
||||
.load(item.coverUrl)
|
||||
.placeholder(android.R.color.darker_gray)
|
||||
.error(android.R.color.darker_gray)
|
||||
.into(this)
|
||||
}
|
||||
}
|
||||
|
||||
// 创建文字显示区域
|
||||
val titleText = TextView(requireContext()).apply {
|
||||
text = item.title
|
||||
setTextColor(ContextCompat.getColor(requireContext(), R.color.text_primary))
|
||||
textSize = 13f
|
||||
setPadding(4, 4, 4, 2)
|
||||
maxLines = 1
|
||||
ellipsize = android.text.TextUtils.TruncateAt.END
|
||||
}
|
||||
|
||||
// 创建剧集文字显示
|
||||
val episodeText = TextView(requireContext()).apply {
|
||||
text = item.episodeName ?: ""
|
||||
setTextColor(ContextCompat.getColor(requireContext(), R.color.text_secondary))
|
||||
textSize = 11f
|
||||
setPadding(4, 2, 4, 4)
|
||||
maxLines = 1
|
||||
ellipsize = android.text.TextUtils.TruncateAt.END
|
||||
visibility = if (item.episodeName.isNullOrEmpty()) View.GONE else View.VISIBLE
|
||||
}
|
||||
|
||||
// 添加到容器
|
||||
container.addView(coverView)
|
||||
container.addView(titleText)
|
||||
container.addView(episodeText)
|
||||
|
||||
// 设置点击事件
|
||||
container.setOnClickListener {
|
||||
openPlayerFromHistory(item)
|
||||
}
|
||||
|
||||
// 设置焦点效果
|
||||
container.isFocusable = true
|
||||
container.isFocusableInTouchMode = true
|
||||
container.setOnFocusChangeListener { v, hasFocus ->
|
||||
if (hasFocus) {
|
||||
v.background = android.graphics.drawable.GradientDrawable().apply {
|
||||
setColor(android.graphics.Color.parseColor("#3D3D3D"))
|
||||
cornerRadius = 12f
|
||||
setStroke(3, android.graphics.Color.parseColor("#1A73E8"))
|
||||
}
|
||||
v.animate().scaleX(1.05f).scaleY(1.05f).setDuration(150).start()
|
||||
} else {
|
||||
v.background = android.graphics.drawable.GradientDrawable().apply {
|
||||
setColor(android.graphics.Color.parseColor("#2D2D2D"))
|
||||
cornerRadius = 12f
|
||||
setStroke(2, android.graphics.Color.parseColor("#3D3D3D"))
|
||||
}
|
||||
v.animate().scaleX(1.0f).scaleY(1.0f).setDuration(150).start()
|
||||
}
|
||||
}
|
||||
|
||||
playHistoryList.addView(container)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user