6.7.0用户端更新:修复空指针

This commit is contained in:
余前卫 2024-06-12 16:42:27 +08:00
parent c5de062171
commit eeb1cc008a
2 changed files with 104 additions and 6 deletions

View File

@ -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<String>) {
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<String>,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
}

View File

@ -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);
}
});
}