diff --git a/common/src/main/java/com/yunbao/common/bean/BannerBean.java b/common/src/main/java/com/yunbao/common/bean/BannerBean.java index c95b9a437..0cfa15ea8 100644 --- a/common/src/main/java/com/yunbao/common/bean/BannerBean.java +++ b/common/src/main/java/com/yunbao/common/bean/BannerBean.java @@ -7,11 +7,33 @@ import com.alibaba.fastjson.annotation.JSONField; */ public class BannerBean { + //是否是星标 + private boolean isStart = false; private String mImageUrl; private String mLink; private String show_type; private String mIntoUrl; + private StarChallengeStatusModel model; + + public boolean isStart() { + return isStart; + } + + public BannerBean setStart(boolean start) { + isStart = start; + return this; + } + + public StarChallengeStatusModel getModel() { + return model; + } + + public BannerBean setModel(StarChallengeStatusModel model) { + this.model = model; + return this; + } + public String getShow_type() { return show_type; } diff --git a/common/src/main/java/com/yunbao/common/bean/StarChallengeStatusModel.java b/common/src/main/java/com/yunbao/common/bean/StarChallengeStatusModel.java new file mode 100644 index 000000000..58cd6a217 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/bean/StarChallengeStatusModel.java @@ -0,0 +1,112 @@ +package com.yunbao.common.bean; + +import com.google.gson.annotations.SerializedName; + +public class StarChallengeStatusModel extends BaseModel { + //当前星级 + @SerializedName("taskNum") + private String taskNum; + //当前总星值 + @SerializedName("currentStarVal") + private String currentStarVal; + //目标总星值 + @SerializedName("targetStarVal") + private String targetStarVal; + //当前助力数 + @SerializedName("currentAssistNum") + private String currentAssistNum; + //目标助力数 + @SerializedName("targetAssistNum") + private String targetAssistNum; + //总星值图标 + @SerializedName("starSrc") + private String starSrc; + //助力图标 + @SerializedName("assistSrc") + private String assistSrc; + @SerializedName("taskName1") + private String taskName1; + @SerializedName("taskName2") + private String taskName2; + + public String getTaskName1() { + return taskName1; + } + + public StarChallengeStatusModel setTaskName1(String taskName1) { + this.taskName1 = taskName1; + return this; + } + + public String getTaskName2() { + return taskName2; + } + + public StarChallengeStatusModel setTaskName2(String taskName2) { + this.taskName2 = taskName2; + return this; + } + + public String getTaskNum() { + return taskNum; + } + + public BaseModel setTaskNum(String taskNum) { + this.taskNum = taskNum; + return this; + } + + public String getCurrentStarVal() { + return currentStarVal; + } + + public BaseModel setCurrentStarVal(String currentStarVal) { + this.currentStarVal = currentStarVal; + return this; + } + + public String getTargetStarVal() { + return targetStarVal; + } + + public BaseModel setTargetStarVal(String targetStarVal) { + this.targetStarVal = targetStarVal; + return this; + } + + public String getCurrentAssistNum() { + return currentAssistNum; + } + + public BaseModel setCurrentAssistNum(String currentAssistNum) { + this.currentAssistNum = currentAssistNum; + return this; + } + + public String getTargetAssistNum() { + return targetAssistNum; + } + + public BaseModel setTargetAssistNum(String targetAssistNum) { + this.targetAssistNum = targetAssistNum; + return this; + } + + public String getStarSrc() { + return starSrc; + } + + public BaseModel setStarSrc(String starSrc) { + this.starSrc = starSrc; + return this; + } + + public String getAssistSrc() { + return assistSrc; + } + + public BaseModel setAssistSrc(String assistSrc) { + this.assistSrc = assistSrc; + return this; + } +} diff --git a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java index acaf1a8a9..aa95757ee 100644 --- a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java +++ b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java @@ -15,6 +15,7 @@ import com.yunbao.common.bean.NobleTrumpetModel; import com.yunbao.common.bean.SearchModel; import com.yunbao.common.bean.SetAttentsModel; import com.yunbao.common.bean.SlideInBannerModel; +import com.yunbao.common.bean.StarChallengeStatusModel; import com.yunbao.common.bean.VipModel; import java.util.List; @@ -232,4 +233,12 @@ public interface PDLiveApi { */ @GET("/api/public/?service=Noble.getNobleRankHideUserList") Observable> getNobleRankHideUserList(); + + /** + *获取当前星级 + * @param liveUid + * @return + */ + @GET("/api/public/?service=StarChallenge.getStarChallengeStatus") + Observable> getStarChallengeStatus(@Query("liveUid") String liveUid); } diff --git a/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java b/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java index fdbeabb9a..84c26b000 100644 --- a/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java +++ b/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java @@ -10,8 +10,10 @@ import com.yunbao.common.bean.LiveInfoModel; import com.yunbao.common.bean.NobleRankHideUserListModel; import com.yunbao.common.bean.NobleTrumpetModel; import com.yunbao.common.bean.SetAttentsModel; +import com.yunbao.common.bean.StarChallengeStatusModel; import com.yunbao.common.bean.VipModel; import com.yunbao.common.http.API; +import com.yunbao.common.http.ResponseModel; import com.yunbao.common.http.base.HttpCallback; import java.util.List; @@ -213,4 +215,22 @@ public class LiveNetManager { callback.onError(throwable.getMessage()); }).isDisposed(); } + + /** + * 获取当前星级 + */ + public void getStarChallengeStatus(String liveUid, HttpCallback callback) { + API.get().pdLiveApi(mContext) + .getStarChallengeStatus(liveUid) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(starChallengeStatusModelResponseModel -> { + if (callback != null) { + callback.onSuccess(starChallengeStatusModelResponseModel.getData().getInfo()); + } + }, throwable -> { + if (callback != null) + callback.onError(throwable.getMessage()); + }).isDisposed(); + } } diff --git a/common/src/main/java/com/yunbao/common/views/weight/ProgressView.java b/common/src/main/java/com/yunbao/common/views/weight/ProgressView.java new file mode 100644 index 000000000..fcf6f838e --- /dev/null +++ b/common/src/main/java/com/yunbao/common/views/weight/ProgressView.java @@ -0,0 +1,136 @@ +package com.yunbao.common.views.weight; + +import android.content.Context; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.RectF; +import android.util.AttributeSet; +import android.view.View; + +/** + * 横向进度条(星级) + */ +public class ProgressView extends View { + /** + * 进度条最大值 + */ + private float maxCount; + /** + * 进度条当前值 + */ + private float currentCount; + /** + * 画笔 + */ + private Paint mPaint; + private int mWidth, mHeight; + + public ProgressView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + public ProgressView(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public ProgressView(Context context) { + super(context); + } + + /*** + * 设置最大的进度值 + */ + public void setMaxCount(float maxCount) { + + this.maxCount = maxCount; + + } + + /** + * 得到最大进度值 + */ + public double getMaxCount() { + return maxCount; + } + + /*** + * 设置当前的进度值 + * @param currentCount + */ + public void setCurrentCount(float currentCount) { + this.currentCount = currentCount > maxCount ? maxCount : currentCount; + /** + * invalidate()是用来刷新View的,必须是在UI线程中进行工作。比如在修改某个view的显示时, + * 调用invalidate()才能看到重新绘制的界面。invalidate()的调用是把之前的旧的view从主UI + * 线程队列中pop掉。 + */ + invalidate(); + } + + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + mPaint = new Paint(); + //设置抗锯齿效果 + mPaint.setAntiAlias(true); + + int round = mHeight; + /** + * RectF:绘制矩形,四个参数分别是left,top,right,bottom + * 类型是单精度浮点数 + */ + RectF rf = new RectF(0, 0, mWidth, mHeight); + /*绘制圆角矩形,背景色为画笔颜色*/ + /*设置progress内部是灰色*/ + mPaint.setColor(Color.parseColor("#F6CCDA")); + RectF rectBlackBg = new RectF(2, 2, mWidth - 2, mHeight - 2); + canvas.drawRoundRect(rectBlackBg, round, round, mPaint); + //设置进度条进度及颜色 + float section = currentCount / maxCount; + RectF rectProgressBg = new RectF(3, 3, (mWidth - 3) * section, mHeight - 3); + if (section != 0.0f) { + mPaint.setColor(Color.parseColor("#F85F73")); + } else { + mPaint.setColor(Color.TRANSPARENT); + } + canvas.drawRoundRect(rectProgressBg, round, round, mPaint); + } + + //dip * scale + 0.5f * (dip >= 0 ? 1 : -1) + private int dipToPx(int dip) { + float scale = getContext().getResources().getDisplayMetrics().density; + return (int) (dip * scale + 0.5f * (dip >= 0 ? 1 : -1));//加0.5是为了四舍五入 + } + + /** + * 指定自定义控件在屏幕上的大小,onMeasure方法的两个参数是由上一层控件 + *

+ * 传入的大小,而且是模式和尺寸混合在一起的数值,需要MeasureSpec.getMode(widthMeasureSpec) + *

+ * 得到模式,MeasureSpec.getSize(widthMeasureSpec)得到尺寸 + */ + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec); + int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec); + int widthSpecSize = MeasureSpec.getSize(widthMeasureSpec); + int heightSpecSize = MeasureSpec.getSize(heightMeasureSpec); + //MeasureSpec.EXACTLY,精确尺寸 + if (widthSpecMode == MeasureSpec.EXACTLY || widthSpecMode == MeasureSpec.AT_MOST) { + mWidth = widthSpecSize; + } else { + mWidth = 0; + } + //MeasureSpec.AT_MOST,最大尺寸,只要不超过父控件允许的最大尺寸即可,MeasureSpec.UNSPECIFIED未指定尺寸 + if (heightSpecMode == MeasureSpec.AT_MOST || heightSpecMode == MeasureSpec.UNSPECIFIED) { + mHeight = dipToPx(20); + } else { + mHeight = heightSpecSize; + } + //设置控件实际大小 + setMeasuredDimension(mWidth, mHeight); + + } +} diff --git a/common/src/main/res/mipmap-xxhdpi/icon_start.png b/common/src/main/res/mipmap-xxhdpi/icon_start.png new file mode 100644 index 000000000..abf5d20b8 Binary files /dev/null and b/common/src/main/res/mipmap-xxhdpi/icon_start.png differ diff --git a/common/src/main/res/mipmap-xxhdpi/icon_start_number.png b/common/src/main/res/mipmap-xxhdpi/icon_start_number.png new file mode 100644 index 000000000..0eb0588ff Binary files /dev/null and b/common/src/main/res/mipmap-xxhdpi/icon_start_number.png differ diff --git a/common/src/main/res/mipmap-xxhdpi/start_level.png b/common/src/main/res/mipmap-xxhdpi/start_level.png new file mode 100644 index 000000000..7d9b66724 Binary files /dev/null and b/common/src/main/res/mipmap-xxhdpi/start_level.png differ diff --git a/common/src/main/res/values/strings.xml b/common/src/main/res/values/strings.xml index 01e0203fa..8210d5524 100644 --- a/common/src/main/res/values/strings.xml +++ b/common/src/main/res/values/strings.xml @@ -921,6 +921,8 @@ 在線觀眾 觀眾 無法@自己 + 總星值 + 助力人數 diff --git a/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java b/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java index 67306f83b..ac1402fa3 100644 --- a/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java @@ -173,7 +173,7 @@ public class LiveChatAdapter extends RecyclerView.Adapter { itemView.setTag(bean); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); - params.setMargins(0, 0, DpUtil.dp2px(80), 12); + params.setMargins(0, 0, DpUtil.dp2px(95), 12); mBg.setLayoutParams(params); if (bean.getType() == 6) {//大作战活动 view_action_game.setVisibility(View.VISIBLE); diff --git a/live/src/main/java/com/yunbao/live/views/CustomViewHolder.java b/live/src/main/java/com/yunbao/live/views/CustomViewHolder.java index 0618c4a35..f36ad600d 100644 --- a/live/src/main/java/com/yunbao/live/views/CustomViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/CustomViewHolder.java @@ -1,28 +1,72 @@ package com.yunbao.live.views; import android.content.Context; +import android.text.TextUtils; +import android.view.LayoutInflater; import android.view.View; -import android.view.ViewGroup; +import android.widget.FrameLayout; import android.widget.ImageView; +import android.widget.TextView; import com.bumptech.glide.Glide; import com.ms.banner.holder.BannerViewHolder; import com.yunbao.common.bean.BannerBean; +import com.yunbao.common.views.weight.ProgressView; +import com.yunbao.live.R; public class CustomViewHolder implements BannerViewHolder { @Override public View createView(Context context, int position, BannerBean data) { // 返回mImageView页面布局 - ImageView imageView = new ImageView(context); - ViewGroup.LayoutParams params = new ViewGroup.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT - ); - imageView.setLayoutParams(params); - imageView.setScaleType(ImageView.ScaleType.FIT_XY); - Glide.with(context).load(data.getImageUrl()).into(imageView); + LayoutInflater inflater = LayoutInflater.from(context); - return imageView; + View contextView = inflater.inflate(R.layout.view_start_level, null); + + FrameLayout startContext = contextView.findViewById(R.id.start_context); + ImageView bannerBack = contextView.findViewById(R.id.banner_back); + ImageView iconStart = contextView.findViewById(R.id.icon_start); + ImageView iconStartNumber = contextView.findViewById(R.id.icon_start_number); + ProgressView totalStarProgress = contextView.findViewById(R.id.total_star_progress); + ProgressView assistProgress = contextView.findViewById(R.id.assist_progress); + TextView currentStart = contextView.findViewById(R.id.current_start); + TextView targetStart = contextView.findViewById(R.id.target_start); + TextView totalStarValue = contextView.findViewById(R.id.total_star_value); + TextView numberOfPeopleAssisted = contextView.findViewById(R.id.number_of_people_assisted); + TextView targetAssist = contextView.findViewById(R.id.target_assist_num); + TextView currentAssist = contextView.findViewById(R.id.current_assist_num); + if (data.isStart()) { + startContext.setVisibility(View.VISIBLE); + Glide.with(context).load(R.mipmap.start_level).into(bannerBack); + Glide.with(context) + .load(data.getModel().getStarSrc()) + .error(R.mipmap.icon_start) + .into(iconStart); + Glide.with(context) + .load(data.getModel().getAssistSrc()) + .error(R.mipmap.icon_start_number) + .into(iconStartNumber); + int targetStarVal = TextUtils.isEmpty(data.getModel().getTargetStarVal()) ? 100 : Integer.parseInt(data.getModel().getTargetStarVal()); + int currentStarVal = TextUtils.isEmpty(data.getModel().getCurrentStarVal()) ? 0 : Integer.parseInt(data.getModel().getCurrentStarVal()); + int targetAssistNum = TextUtils.isEmpty(data.getModel().getTargetAssistNum()) ? 0 : Integer.parseInt(data.getModel().getTargetAssistNum()); + int currentAssistNum = TextUtils.isEmpty(data.getModel().getCurrentAssistNum()) ? 0 : Integer.parseInt(data.getModel().getCurrentAssistNum()); + totalStarProgress.setMaxCount(targetStarVal); + assistProgress.setMaxCount(targetAssistNum); + totalStarProgress.setCurrentCount(currentStarVal); + assistProgress.setCurrentCount(currentAssistNum); + currentStart.setText(String.valueOf(currentStarVal)); + targetStart.setText("/" + targetStarVal); + totalStarValue.setText(TextUtils.isEmpty(data.getModel().getTaskName1()) ? context.getString(R.string.total_star_value) : data.getModel().getTaskName1()); + numberOfPeopleAssisted.setText(TextUtils.isEmpty(data.getModel().getTaskName2()) ? context.getString(R.string.total_star_value) : data.getModel().getTaskName2()); + targetAssist.setText("/" + targetAssistNum); + currentAssist.setText(String.valueOf(currentAssistNum)); + } else { + String imagerUrl = data.getImageUrl().replace("qny", "downs"); + Glide.with(context).load(imagerUrl).into(bannerBack); + startContext.setVisibility(View.GONE); + } + + return contextView; } } 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 fccdebe3d..426416528 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java @@ -65,6 +65,7 @@ import com.yunbao.common.bean.HourRank; import com.yunbao.common.bean.LevelBean; import com.yunbao.common.bean.LiveGiftBean; import com.yunbao.common.bean.MsgModel; +import com.yunbao.common.bean.StarChallengeStatusModel; import com.yunbao.common.bean.UserBean; import com.yunbao.common.glide.ImgLoader; import com.yunbao.common.http.API; @@ -1024,6 +1025,17 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis reloadIM(); } + public void showStart(StarChallengeStatusModel data) { + if (mBannerList2 == null) { + mBannerList2 = new ArrayList<>(); + } + BannerBean bannerBean = new BannerBean(); + bannerBean.setStart(true); + bannerBean.setModel(data); + mBannerList2.add(bannerBean); + showBanner2(); + } + public void hideFloatMsg() { msgLayout.setVisibility(View.GONE); } diff --git a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java index 358f220b2..bacfda760 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -37,6 +37,7 @@ import com.yunbao.common.CommonAppConfig; import com.yunbao.common.CommonAppContext; import com.yunbao.common.Constants; import com.yunbao.common.bean.MsgModel; +import com.yunbao.common.bean.StarChallengeStatusModel; import com.yunbao.common.bean.UserBean; import com.yunbao.common.custom.MyViewPager; import com.yunbao.common.event.FollowEvent; @@ -45,6 +46,7 @@ import com.yunbao.common.http.CommonHttpConsts; import com.yunbao.common.http.CommonHttpUtil; import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpClient; +import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.utils.Bus; import com.yunbao.common.utils.DialogUitl; @@ -284,7 +286,23 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mLiveRoomViewHolder.initHourRankList(); } }); + /** + * 获取当前直播间星级 + */ + LiveNetManager.get(mContext) + .getStarChallengeStatus(mLiveBean.getUid(), new com.yunbao.common.http.base.HttpCallback() { + @Override + public void onSuccess(StarChallengeStatusModel data) { + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.showStart(data); + } + } + @Override + public void onError(String error) { + + } + }); } @Override @@ -1531,11 +1549,12 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe */ public void showNewMessage() { if (mLiveRoomViewHolder != null) { - mLiveRoomViewHolder.showNewMessage( ); + mLiveRoomViewHolder.showNewMessage(); } } - public void showAtMessage(){ - if (mLiveRoomViewHolder!=null){ + + public void showAtMessage() { + if (mLiveRoomViewHolder != null) { mLiveRoomViewHolder.showAtMessage(); } } diff --git a/live/src/main/res/layout/view_live_room.xml b/live/src/main/res/layout/view_live_room.xml index 45c9d118c..86080e552 100644 --- a/live/src/main/res/layout/view_live_room.xml +++ b/live/src/main/res/layout/view_live_room.xml @@ -91,8 +91,8 @@ diff --git a/live/src/main/res/layout/view_start_level.xml b/live/src/main/res/layout/view_start_level.xml new file mode 100644 index 000000000..f2a95ba8a --- /dev/null +++ b/live/src/main/res/layout/view_start_level.xml @@ -0,0 +1,148 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file