From 31b7667a3d3523feeb9cbf6e8bdd00d6a8fe86ad Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Tue, 30 Aug 2022 11:32:56 +0800 Subject: [PATCH] =?UTF-8?q?add:=E6=96=B0=E5=A2=9E=E5=B0=8F=E6=97=B6?= =?UTF-8?q?=E6=A6=9C=E5=8A=9F=E8=83=BD=20fix:=E8=B0=83=E6=95=B4=E5=A4=96?= =?UTF-8?q?=E9=83=A8=E7=B1=BB=E8=B0=83=E7=94=A8=E7=83=AD=E5=BA=A6textView?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/yunbao/common/Constants.java | 2 + .../java/com/yunbao/common/bean/HourRank.java | 70 +++++++++++ .../com/yunbao/common/http/PDLiveApi.java | 7 ++ .../yunbao/live/activity/LiveActivity.java | 12 +- .../yunbao/live/adapter/LiveChatAdapter.java | 7 +- .../live/dialog/LiveHDDialogFragment.java | 5 + .../live/socket/SocketMessageListener.java | 6 + .../yunbao/live/socket/SocketRyClient.java | 8 ++ .../yunbao/live/views/LiveRoomViewHolder.java | 109 ++++++++++++++---- .../live/views/PortraitLiveManager.java | 11 +- live/src/main/res/layout/view_wish_list.xml | 7 +- 11 files changed, 213 insertions(+), 31 deletions(-) create mode 100644 common/src/main/java/com/yunbao/common/bean/HourRank.java diff --git a/common/src/main/java/com/yunbao/common/Constants.java b/common/src/main/java/com/yunbao/common/Constants.java index ab1f75031..91deaaf15 100644 --- a/common/src/main/java/com/yunbao/common/Constants.java +++ b/common/src/main/java/com/yunbao/common/Constants.java @@ -163,6 +163,8 @@ public class Constants { public static final String SOCKET_LUCK_WIN = "luckWin";//幸运礼物中奖 public static final String SOCKET_PRIZE_POOL_WIN = "jackpotWin";//奖池中奖 public static final String SOCKET_PRIZE_POOL_UP = "jackpotUp";//奖池升级 + public static final String SOCKET_HOUR = "SendHourChart";//小时榜更新 + //游戏socket public static final String SOCKET_GAME_ZJH = "startGame";//炸金花 public static final String SOCKET_GAME_HD = "startLodumaniGame";//海盗船长 diff --git a/common/src/main/java/com/yunbao/common/bean/HourRank.java b/common/src/main/java/com/yunbao/common/bean/HourRank.java new file mode 100644 index 000000000..c9a53ac62 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/bean/HourRank.java @@ -0,0 +1,70 @@ +package com.yunbao.common.bean; + +import com.google.gson.annotations.SerializedName; + +/** + * 小时榜实体类 + */ +public class HourRank extends BaseModel{ + @SerializedName("liveuid") + String liveuid; + @SerializedName("hourchart_h5_url") + String url; + @SerializedName("rank") + long rank; + @SerializedName("starlightVal") + long starlightVal; + @SerializedName("isshow") + int isshow; + + public String getLiveuid() { + return liveuid; + } + + public void setLiveuid(String liveuid) { + this.liveuid = liveuid; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public long getRank() { + return rank; + } + + public void setRank(long rank) { + this.rank = rank; + } + + public long getStarlightVal() { + return starlightVal; + } + + public void setStarlightVal(long starlightVal) { + this.starlightVal = starlightVal; + } + + public int getIsshow() { + return isshow; + } + + public void setIsshow(int isshow) { + this.isshow = isshow; + } + + @Override + public String toString() { + return "HourRank{" + + "liveuid='" + liveuid + '\'' + + ", url='" + url + '\'' + + ", rank=" + rank + + ", starlightVal=" + starlightVal + + ", isshow=" + isshow + + '}'; + } +} 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 abb5122a5..70716c535 100644 --- a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java +++ b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java @@ -5,6 +5,7 @@ import com.yunbao.common.bean.AnchorRecommendModel; import com.yunbao.common.bean.BaseModel; import com.yunbao.common.bean.ContributeModel; import com.yunbao.common.bean.FaceBookUpModel; +import com.yunbao.common.bean.HourRank; import com.yunbao.common.bean.IMLoginModel; import com.yunbao.common.bean.LiveInfoModel; import com.yunbao.common.bean.MsgSwitchDetailModel; @@ -205,4 +206,10 @@ public interface PDLiveApi { @GET("/api/public/?service=Tx.setBeginShowMsgSwitch") Observable>> setBeginShowMsgSwitch(@Query("status") String status,@Query("isAll") String isAll,@Query("liveuid") String liveuid); + /** + * 小时榜接口 + * @param liveuid 直播间id + */ + @GET("/api/public/?service=Live.getHourChartRank") + Observable>> getHourChartRank(@Query("liveuid")String liveuid); } diff --git a/live/src/main/java/com/yunbao/live/activity/LiveActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveActivity.java index 25d86311b..6b8e03168 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveActivity.java @@ -276,9 +276,10 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL mLiveLinkMicPresenter.onAudienceLeaveRoom(bean); } try { - if (mLiveRoomViewHolder.room_hot != null) { + if (mLiveRoomViewHolder!=null) { if (!"".equals(bean.getHot_num()) && !"0".equals(bean.getHot_num())) { - mLiveRoomViewHolder.room_hot.setText(formatBigNum.formatBigNum(bean.getHot_num())); + // mLiveRoomViewHolder.room_hot.setText(formatBigNum.formatBigNum(bean.getHot_num())); + mLiveRoomViewHolder.setHotData(formatBigNum.formatBigNum(bean.getHot_num())); } } } catch (Exception e) { @@ -501,6 +502,13 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL } } + @Override + public void onHourRank(LiveChatBean bean,JSONObject ranks) { + if(mLiveRoomViewHolder!=null){ + mLiveRoomViewHolder.setHourRankData(ranks.getInteger(mLiveUid)); + } + } + /** * 观众与主播连麦 主播收到观众的连麦申请 */ 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 b639182f8..6969580d6 100644 --- a/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java @@ -42,6 +42,7 @@ import java.util.List; */ public class LiveChatAdapter extends RecyclerView.Adapter { + public final static int MSG_HOUR_RANK_CHANGE=-100;//收到小时榜推送,发送一条弹幕 private Context mContext; private List mList; @@ -319,7 +320,11 @@ public class LiveChatAdapter extends RecyclerView.Adapter { mTextView.setText(R.string.automatic_chat); bean.setHeart(position); } - } else { + }else if(bean.getType()==MSG_HOUR_RANK_CHANGE){ + mBg.setBackgroundResource(R.drawable.bg_chat_automatic_item); + mTextView.setText(bean.getContent()); + bean.setHeart(position); + }else { if (bean.getBubble() != null && !bean.getBubble().equals("")) { //加载.9图聊天气泡 LoadDian9TuUtil.loadDian9Tu(mContext, mBg, bean.getBubble(), 1); diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveHDDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/LiveHDDialogFragment.java index 80fb75167..99ba043ce 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveHDDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveHDDialogFragment.java @@ -20,6 +20,7 @@ import android.webkit.JavascriptInterface; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; +import android.widget.LinearLayout; import com.adjust.sdk.Adjust; import com.adjust.sdk.AdjustEvent; @@ -145,6 +146,10 @@ public class LiveHDDialogFragment extends AbsDialogFragment { }else { findViewById(R.id.title_laout).setVisibility(View.VISIBLE); } + if(bundle.getInt("height",-1)!=-1) { + LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, bundle.getInt("height",-1)); + mWebView.setLayoutParams(params); + } mWebView.loadUrl(bundle.getString("url")); mWebView.setWebViewClient(new WebViewClient() { @Override diff --git a/live/src/main/java/com/yunbao/live/socket/SocketMessageListener.java b/live/src/main/java/com/yunbao/live/socket/SocketMessageListener.java index a8e291161..fe4426d69 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketMessageListener.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketMessageListener.java @@ -324,4 +324,10 @@ public interface SocketMessageListener { * 整蛊消息 */ void prankTurntable(String msgtype, int time, JSONObject jsonObject); + + /** + * 小时榜更新 + * + */ + void onHourRank(LiveChatBean bean,JSONObject ranks); } diff --git a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java index a5751c5fb..b00c85be3 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java @@ -25,6 +25,7 @@ import com.yunbao.common.utils.WordUtil; import com.yunbao.live.R; import com.yunbao.live.activity.LiveAudienceActivity; import com.yunbao.live.activity.LiveRyAnchorActivity; +import com.yunbao.live.adapter.LiveChatAdapter; import com.yunbao.live.bean.LiveBuyGuardMsgBean; import com.yunbao.live.bean.LiveChatBean; import com.yunbao.live.bean.LiveDanMuBean; @@ -368,6 +369,13 @@ public class SocketRyClient { case Constants.SOCKET_PRIZE_POOL_UP://奖池升级 mListener.onPrizePoolUp(map.getString("uplevel")); break; + case Constants.SOCKET_HOUR://小时榜 + liveChatBean=new LiveChatBean(); + liveChatBean.setId("-1"); + liveChatBean.setType(LiveChatAdapter.MSG_HOUR_RANK_CHANGE); + liveChatBean.setContent(map.getJSONObject("ct").getString("text")); + mListener.onHourRank(liveChatBean, map.getJSONObject("ct").getJSONObject("new_rank")); + break; //游戏socket case Constants.SOCKET_GAME_ZJH://游戏 智勇三张 if (CommonAppConfig.GAME_ENABLE) { 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 c95f388e4..7466b5055 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java @@ -24,7 +24,6 @@ import android.widget.TextView; import android.widget.ViewFlipper; import androidx.annotation.Nullable; -import androidx.recyclerview.widget.DefaultItemAnimator; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -51,9 +50,11 @@ import com.opensource.svgaplayer.SVGAVideoEntity; import com.yunbao.common.CommonAppConfig; import com.yunbao.common.Constants; import com.yunbao.common.bean.BannerBean; +import com.yunbao.common.bean.HourRank; import com.yunbao.common.bean.LevelBean; import com.yunbao.common.bean.UserBean; import com.yunbao.common.glide.ImgLoader; +import com.yunbao.common.http.API; import com.yunbao.common.http.CommonHttpConsts; import com.yunbao.common.http.CommonHttpUtil; import com.yunbao.common.http.HttpCallback; @@ -112,8 +113,9 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.List; -import java.util.Random; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.schedulers.Schedulers; import pl.droidsonroids.gif.GifImageView; import static com.yunbao.common.CommonAppContext.logger; @@ -254,6 +256,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis private LiveUserGiftBean nowGuardUser; private ViewFlipper wishListFlipper; private List wishlist = new ArrayList<>(); + private TextView mHourRank, mHotText; public LiveRoomViewHolder(boolean isRys, int forActivity, Context context, ViewGroup parentView, GifImageView gifImageView, SVGAImageView svgaImageView, ViewGroup liveGiftPrizePoolContainer, WindowManager windowManager) { super(context, parentView); @@ -1065,31 +1068,88 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis }); } /** - * 初始化小时榜。 - * 等待接口 - * TextView得独立出来用来替换数字 + * 初始化小时榜 */ protected void initHourRankList(){ - ((Activity)mContext).runOnUiThread(()->{ - ViewFlipper flipper= (ViewFlipper) findViewById(R.id.hour_rank_list); - for (int i = 0; i < 2; i++) { - LinearLayout.LayoutParams params=new LinearLayout.LayoutParams(DpUtil.dp2px(44),DpUtil.dp2px(16)); - View wish = LayoutInflater.from(mContext).inflate(R.layout.view_wish_list, null); - ImageView wishPic = wish.findViewById(R.id.wish_pic); - TextView wishIndex = wish.findViewById(R.id.wish_index); - if(i==0) { - wishPic.setImageResource(R.drawable.live_tags_hot); - }else{ - wishPic.setImageResource(R.drawable.live_tags_hour_list); - } - wishPic.setLayoutParams(params); - wishIndex.setText(new Random().nextInt(5000)+""); - flipper.addView(wish); - } - flipper.startFlipping(); - }); + ViewFlipper flipper= (ViewFlipper) findViewById(R.id.hour_rank_list); + LinearLayout.LayoutParams params=new LinearLayout.LayoutParams(DpUtil.dp2px(44),DpUtil.dp2px(16)); + API.get().pdLiveApi(mContext).getHourChartRank(mLiveUid) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(listResponseModel -> { + List info = listResponseModel.getData().getInfo(); + if(!info.isEmpty()){ + View hotView=LayoutInflater.from(mContext).inflate(R.layout.view_wish_list,null); + View hourView=LayoutInflater.from(mContext).inflate(R.layout.view_wish_list,null); + ImageView hotPic = hotView.findViewById(R.id.wish_pic); + ImageView hourPic = hourView.findViewById(R.id.wish_pic); + mHotText =hotView.findViewById(R.id.wish_index); + mHourRank=hourView.findViewById(R.id.wish_index); + + hotPic.setImageResource(R.drawable.live_tags_hot); + hourPic.setImageResource(R.drawable.live_tags_hour_list); + hotPic.setLayoutParams(params); + hourPic.setLayoutParams(params); + flipper.addView(hotView); + flipper.addView(hourView); + + flipper.setOnClickListener(view -> { + Bundle bundle=new Bundle(); + String path=info.get(0).getUrl(); + if(!path.startsWith("/")){ + path="/"+path; + } + String url=CommonAppConfig.HOST+path; + url += "&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + + CommonAppConfig.getInstance().getToken() + "&liveuid=" + mLiveUid; + + bundle.putString("url", url); + // bundle.putInt("height", DpUtil.dp2px(500)); + bundle.putInt("show_type", 0); + LiveHDDialogFragment liveHDDialogFragment = new LiveHDDialogFragment(); + liveHDDialogFragment.setArguments(bundle); + liveHDDialogFragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveHDDialogFragment"); + }); + flipper.startFlipping(); + } + }, Throwable::printStackTrace) + .isDisposed(); } + /** + * 星光值转带k的字符 + * @param val 值 + * @retur 字符串 + */ + private String starlightValToString(long val){ + if(val>1000) { + double tmp =(double)val / 1000; + return tmp + "k"; + }else{ + return val+""; + } + } + + /** + * 设置小时榜 + * @param rank 小时榜 + */ + public void setHourRankData(int rank){ + if(mHourRank!=null) { + mHourRank.setText(formatBigNum.formatBigNum(rank + "")); + } + } + + /** + * 设置热度值 + * @param hot 热度值 + */ + public void setHotData(String hot){ + if(mHotText!=null) { + mHotText.setText(hot); + } + + } /** * 更新心愿单进度 * @@ -1819,6 +1879,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis mLiveEnterRoomAnimPresenter.enterRoom(bean); } room_hot.setText(formatBigNum.formatBigNum(bean.getLiveChatBean().getHot_num())); + setHotData(formatBigNum.formatBigNum(bean.getLiveChatBean().getHot_num())); LiveUserGiftBean chatBean = bean.getUserBean(); if (chatBean != null && nowGuardUser != null) { LiveUserGiftBean tmp = null; @@ -1917,6 +1978,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis public void showGiftMessage(LiveReceiveGiftBean bean) { mVotes.setText(bean.getVotes()); room_hot.setText(formatBigNum.formatBigNum(bean.getHot_num())); + setHotData(formatBigNum.formatBigNum(bean.getLiveChatBean().getHot_num())); mTvMedalRank.setText(bean.getMedalRankNum()); if (mLiveGiftAnimPresenter == null) { mLiveGiftAnimPresenter = new LiveGiftAnimPresenter(mContext, mContentView, mGifImageView, mSVGAImageView, mLiveGiftPrizePoolContainer, windowManager); @@ -1930,6 +1992,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis public void showGiftMessage(LiveReceiveGiftBean bean, boolean isAncher) { mVotes.setText(bean.getVotes()); room_hot.setText(formatBigNum.formatBigNum(bean.getHot_num())); + setHotData(formatBigNum.formatBigNum(bean.getLiveChatBean().getHot_num())); mTvMedalRank.setText(bean.getMedalRankNum()); //开通粉丝勋章成功弹窗 if (!isAncher && bean.getMedalFirstGet() != null && bean.getMedalFirstGet().equals("1") 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 49fc3f1a3..c9232a10b 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -578,9 +578,9 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe try { if (mLiveRoomViewHolder != null) { mLiveRoomViewHolder.onExitRoom(bean); - if (mLiveRoomViewHolder.room_hot != null) { + if (mLiveRoomViewHolder != null) { if (!"".equals(bean.getHot_num()) && !"0".equals(bean.getHot_num())) { - mLiveRoomViewHolder.room_hot.setText(formatBigNum.formatBigNum(bean.getHot_num())); + mLiveRoomViewHolder.setHotData(formatBigNum.formatBigNum(bean.getHot_num())); } } } @@ -916,6 +916,13 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe } } + @Override + public void onHourRank(LiveChatBean bean, JSONObject ranks) { + if(mLiveRoomViewHolder!=null){ + mLiveRoomViewHolder.setHourRankData(ranks.getInteger(liveID)); + } + } + private PagerAdapter pagerAdapter = new PagerAdapter() { @Override public int getCount() { diff --git a/live/src/main/res/layout/view_wish_list.xml b/live/src/main/res/layout/view_wish_list.xml index 63ce6c19d..70dacdddc 100644 --- a/live/src/main/res/layout/view_wish_list.xml +++ b/live/src/main/res/layout/view_wish_list.xml @@ -15,13 +15,14 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="2dp" - android:scrollHorizontally="true" + android:ellipsize="marquee" + android:focusable="true" android:focusableInTouchMode="true" android:marqueeRepeatLimit="marquee_forever" + android:scrollHorizontally="true" android:singleLine="true" + android:text="0" android:textColor="#FFFFFFFF" - android:focusable="true" - android:ellipsize="marquee" android:textSize="10sp" /> \ No newline at end of file