6.7.0用户端更新:修复空指针
This commit is contained in:
parent
c5de062171
commit
eeb1cc008a
90
live/src/main/java/com/yunbao/live/utils/Zeus.kt
Normal file
90
live/src/main/java/com/yunbao/live/utils/Zeus.kt
Normal 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
|
||||||
|
}
|
@ -1771,7 +1771,13 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis
|
|||||||
recycler_prank.setAdapter(comboAdapter);
|
recycler_prank.setAdapter(comboAdapter);
|
||||||
prank_group_title.setText(R.string.combo_vote);
|
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 {
|
}else {
|
||||||
prank_group.setVisibility(View.GONE);
|
prank_group.setVisibility(View.GONE);
|
||||||
prank_small_icon.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){
|
private void limitItem(int prankType,int maxItem){
|
||||||
recycler_prank.post(() -> {
|
recycler_prank.post(() -> {
|
||||||
View itemView = recycler_prank.getChildAt(0);
|
View itemView = recycler_prank.getChildAt(0);
|
||||||
int gap = prankType == 1 ? SizeUtils.dp2px(3f) : 0;
|
if (itemView != null){
|
||||||
int height = (itemView.getHeight() + gap)*maxItem;
|
int gap = prankType == 1 ? SizeUtils.dp2px(3f) : 0;
|
||||||
ViewGroup.LayoutParams layoutParams = recycler_prank.getLayoutParams();
|
int height = (itemView.getHeight() + gap)*maxItem;
|
||||||
layoutParams.height = height;
|
ViewGroup.LayoutParams layoutParams = recycler_prank.getLayoutParams();
|
||||||
recycler_prank.setLayoutParams(layoutParams);
|
layoutParams.height = height;
|
||||||
|
recycler_prank.setLayoutParams(layoutParams);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user