From eeb1cc008aa568d41a7bd14d92608e060c090c5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=99=E5=89=8D=E5=8D=AB?= <2298122580@qq.com> Date: Wed, 12 Jun 2024 16:42:27 +0800 Subject: [PATCH] =?UTF-8?q?6.7.0=E7=94=A8=E6=88=B7=E7=AB=AF=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=EF=BC=9A=E4=BF=AE=E5=A4=8D=E7=A9=BA=E6=8C=87=E9=92=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/yunbao/live/utils/Zeus.kt | 90 +++++++++++++++++++ .../yunbao/live/views/LiveRoomViewHolder.java | 20 +++-- 2 files changed, 104 insertions(+), 6 deletions(-) create mode 100644 live/src/main/java/com/yunbao/live/utils/Zeus.kt diff --git a/live/src/main/java/com/yunbao/live/utils/Zeus.kt b/live/src/main/java/com/yunbao/live/utils/Zeus.kt new file mode 100644 index 000000000..4cce351b0 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/utils/Zeus.kt @@ -0,0 +1,90 @@ +package com.yunbao.live.utils + +import android.graphics.Color +import android.graphics.LinearGradient +import android.graphics.Shader +import android.text.Spannable +import android.text.SpannableString +import android.text.style.ForegroundColorSpan +import android.view.View +import android.widget.TextView +import androidx.core.content.ContextCompat +import androidx.core.view.isGone +import androidx.core.view.isInvisible +import androidx.core.view.isVisible +import java.util.regex.Pattern + +//显示控件 +fun View.visible(){ + isVisible = true +} + +//隐藏控件 +fun View.gone(){ + isGone = true +} + +//隐藏控件 +fun View.inVisible(){ + isInvisible = true +} + +//文字颜色渐变 +fun setGradientFont(view: TextView,floatArray: FloatArray,colors : Array) { + view.measure(View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED),0) +// val floats = floatArrayOf(0.5f,1.0f) + val colorsInt = colors.map { Color.parseColor(it) }.toIntArray() + val linearGradient = + LinearGradient(0f, 0f, + view.measuredWidth.toFloat(), + 0f, + colorsInt, + floatArray, + Shader.TileMode.CLAMP) + view.paint.shader = linearGradient + view.invalidate() +} + +/** + *@MethodName: setOnSingleClick + *@Description: 调用控件的点击事件 + *@Author: Yqw + *@Date: 2023/4/21 18:10 + **/ +private var lastClickTime = 0L +private const val internalTime = 500L +interface OnClickListener{ + fun onClick(view : View) +} +fun setOnSingleClick(view: View,onClick : OnClickListener){ + view.setOnClickListener { + if (lastClickTime != 0L && (System.currentTimeMillis()- lastClickTime)< internalTime){ +// lastClickTime = System.currentTimeMillis() +// "Do not click repeatedly!".toastShort + return@setOnClickListener + }else{ + lastClickTime = System.currentTimeMillis() + onClick.onClick(it) + } + } +} + +//设置关键词样式 +fun setSpannable(content: String, keys: Array,color : String): SpannableString { + val msp = SpannableString(content) + for (index in keys.indices){ + val p = Pattern.compile(keys[index]) + val m = p.matcher(msp) + while (m.find()){ + msp.setSpan( + ForegroundColorSpan(Color.parseColor(color)), + m.start(), + m.end(), + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) +// msp.setSpan(StyleSpan(Typeface.BOLD),m.start(),m.end(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) +// msp.setSpan(AbsoluteSizeSpan(25,true),m.start(),m.end(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) +// msp.setSpan(UnderlineSpan(),m.start(),m.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) + } + } + return msp +} \ No newline at end of file diff --git a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java index 361d38488..9d4236e2c 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java @@ -1771,7 +1771,13 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis recycler_prank.setAdapter(comboAdapter); prank_group_title.setText(R.string.combo_vote); } - limitItem(mPrankType,Math.min(prankAndComboList.size(), 4)); + //主播可能打开整蛊功能,但是不设置整蛊礼物,这里会是空列表 + if (!prankAndComboList.isEmpty()){ + limitItem(mPrankType,Math.min(prankAndComboList.size(), 4)); + }else { + prank_group.setVisibility(View.GONE); + prank_small_icon.setVisibility(View.GONE); + } }else { prank_group.setVisibility(View.GONE); prank_small_icon.setVisibility(View.GONE); @@ -1794,11 +1800,13 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis private void limitItem(int prankType,int maxItem){ recycler_prank.post(() -> { View itemView = recycler_prank.getChildAt(0); - int gap = prankType == 1 ? SizeUtils.dp2px(3f) : 0; - int height = (itemView.getHeight() + gap)*maxItem; - ViewGroup.LayoutParams layoutParams = recycler_prank.getLayoutParams(); - layoutParams.height = height; - recycler_prank.setLayoutParams(layoutParams); + if (itemView != null){ + int gap = prankType == 1 ? SizeUtils.dp2px(3f) : 0; + int height = (itemView.getHeight() + gap)*maxItem; + ViewGroup.LayoutParams layoutParams = recycler_prank.getLayoutParams(); + layoutParams.height = height; + recycler_prank.setLayoutParams(layoutParams); + } }); }