From f2a3f55e52d661ce84cf44e4836da99251dd2cec Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Tue, 11 Oct 2022 14:11:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EBanner=E8=BF=9B=E5=85=A5?= =?UTF-8?q?=E7=9B=B4=E6=92=AD=E9=97=B4=E7=9B=B4=E6=8E=A5=E5=94=A4=E8=B5=B7?= =?UTF-8?q?=E6=96=B0=E4=BA=BA=E7=89=B9=E6=83=A0=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=96=B0=E4=BA=BA=E7=89=B9=E6=83=A0URL=E4=B8=BAnull=E6=97=B6?= =?UTF-8?q?=E4=BE=9D=E6=97=A7=E6=89=93=E5=BC=80=E5=BC=B9=E6=A1=86=20?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=96=B0=E4=BA=BA=E7=89=B9=E6=83=A0=E7=BA=A2?= =?UTF-8?q?=E7=82=B9=E5=85=A5=E5=8F=A3=20=E8=B0=83=E6=95=B4=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=89=8B=E5=8A=A8=E4=B8=8B=E8=BD=BDsvga=E5=A6=82?= =?UTF-8?q?=E7=BD=91=E7=BB=9C=E5=A4=B1=E8=B4=A5=E6=97=B6=E7=9A=84=E6=93=8D?= =?UTF-8?q?=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yunbao/common/bean/BannerBean.java | 10 +++++ .../com/yunbao/common/bean/NewPeopleInfo.java | 10 +++++ .../yunbao/common/utils/GiftCacheUtil.java | 38 +++++++++++-------- .../live/activity/LiveAudienceActivity.java | 33 ++++++++++++---- .../yunbao/live/adapter/LiveGiftAdapter.java | 12 +++++- .../live/dialog/LiveHDDialogFragment.java | 25 ------------ .../live/views/LiveAudienceViewHolder.java | 35 +++++++++-------- .../live/views/PortraitLiveManager.java | 2 +- .../main/res/layout/view_live_audience.xml | 3 +- .../main/views/MainHomeLiveViewHolder.java | 11 +++++- 10 files changed, 107 insertions(+), 72 deletions(-) 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 0cfa15ea8..2a239371c 100644 --- a/common/src/main/java/com/yunbao/common/bean/BannerBean.java +++ b/common/src/main/java/com/yunbao/common/bean/BannerBean.java @@ -13,6 +13,7 @@ public class BannerBean { private String mLink; private String show_type; private String mIntoUrl; + private int type; private StarChallengeStatusModel model; @@ -71,4 +72,13 @@ public class BannerBean { public void setmIntoUrl(String intoUrl) { mIntoUrl = intoUrl; } + + @JSONField(name = "type") + public int getType() { + return type; + } + @JSONField(name = "type") + public void setType(int type) { + this.type = type; + } } diff --git a/common/src/main/java/com/yunbao/common/bean/NewPeopleInfo.java b/common/src/main/java/com/yunbao/common/bean/NewPeopleInfo.java index e5a548232..40cec76b1 100644 --- a/common/src/main/java/com/yunbao/common/bean/NewPeopleInfo.java +++ b/common/src/main/java/com/yunbao/common/bean/NewPeopleInfo.java @@ -16,6 +16,8 @@ public class NewPeopleInfo extends BaseModel{ private int isShow;//是否展示入口 @SerializedName("link") private String link;//入口地址 + @SerializedName("red_show") + private int showRed=0; public boolean getChargeHidden() { return chargeHidden==1; @@ -49,6 +51,14 @@ public class NewPeopleInfo extends BaseModel{ this.link = link; } + public int getShowRed() { + return showRed; + } + + public void setShowRed(int showRed) { + this.showRed = showRed; + } + @NonNull @Override public String toString() { diff --git a/common/src/main/java/com/yunbao/common/utils/GiftCacheUtil.java b/common/src/main/java/com/yunbao/common/utils/GiftCacheUtil.java index aba29e875..63284e4b1 100644 --- a/common/src/main/java/com/yunbao/common/utils/GiftCacheUtil.java +++ b/common/src/main/java/com/yunbao/common/utils/GiftCacheUtil.java @@ -10,6 +10,7 @@ import com.yunbao.common.http.CommonHttpConsts; import com.yunbao.common.interfaces.CommonCallback; import java.io.File; +import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; @@ -25,7 +26,7 @@ public class GiftCacheUtil { private Handler handler = new Handler(Looper.getMainLooper()); private boolean pause = false; private boolean downloading = false; - private int clickId = 0; + private List clickId = new ArrayList<>(); private GiftCacheUtil() { } @@ -107,9 +108,10 @@ public class GiftCacheUtil { downloadCache.put(bean.getId(), bean); } } - public void addDownloadList(List list){ + + public void addDownloadList(List list) { for (LiveGiftBean bean : list) { - downloadCache.put(bean.getId(),bean); + downloadCache.put(bean.getId(), bean); } } @@ -124,16 +126,18 @@ public class GiftCacheUtil { * 插队优先下载指定id礼物 */ public void downloadGiftForId(LiveGiftBean bean, CommonCallback mDownloadGifCallback) { - if(checkGiftIsDownload(bean.getId())){ + if (checkGiftIsDownload(bean.getId())) { mDownloadGifCallback.callback(null); return; } - this.clickId = bean.getId(); + clickId.add(bean.getId()+""); getFile(getDownloadSaveName(bean.getId()), bean.getSwf(), "0", new CommonCallback() { @Override public void callback(File bean) { - GiftCacheUtil.this.clickId = -1; - downloadCache.remove(getIdForFileName(bean.getName())); + if(bean!=null) { + clickId.remove(getIdForFileName(bean.getName())+""); + downloadCache.remove(getIdForFileName(bean.getName())); + } mDownloadGifCallback.callback(bean); } }); @@ -149,7 +153,7 @@ public class GiftCacheUtil { /** * 恢复下载 */ - public void restart(){ + public void restart() { pause = false; startDownload(); } @@ -159,7 +163,9 @@ public class GiftCacheUtil { */ public void resetStatus() { downloading = false; - pause=false; + pause = false; + clickId.clear(); + downloadCache.clear(); } /** @@ -192,13 +198,13 @@ public class GiftCacheUtil { /** * 开始下载 */ - private void startDownload(){ + private void startDownload() { new Thread(() -> { File dir = new File(CommonAppConfig.GIF_PATH); DownloadUtil downloadUtil = new DownloadUtil(); Object[] ids = downloadCache.keySet().toArray(); - for (Object _id :ids) { - int id= (int) _id; + for (Object _id : ids) { + int id = (int) _id; if (pause) { return; } @@ -212,7 +218,7 @@ public class GiftCacheUtil { if (bean == null) { continue; } - if (clickId == id) { + if (clickId.contains(id+"")) { continue; } if (bean.getSwf().isEmpty()) { @@ -225,11 +231,11 @@ public class GiftCacheUtil { downloadCache.remove(getIdForFileName(file.getName())); if (downloadCache.isEmpty()) { downloading = false; - }else{ + } else { //单线程下载,以便插队下载和及时停止下载 startDownload(); } - // handler.post(() -> commonCallback.callback(file)); + // handler.post(() -> commonCallback.callback(file)); commonCallback.callback(file); } @@ -246,7 +252,7 @@ public class GiftCacheUtil { }); break; } - if(downloadCache.isEmpty()){ + if (downloadCache.isEmpty()) { resetStatus(); } }).start(); diff --git a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java index eb9509475..9ad6fa1d9 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java @@ -87,6 +87,7 @@ import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Map; /** * Created by cxf on 2018/10/10. @@ -323,6 +324,7 @@ public class LiveAudienceActivity extends LiveActivity { manager.onAdd(liveBean1, liveType, liveTypeVal, liveSdk); //加载完页面后再后台静默下载礼物svga downloadAllGift(); + over(); } }); @@ -336,7 +338,11 @@ public class LiveAudienceActivity extends LiveActivity { } } }; - + private void over(){ + if("NEWUSER".equals(getIntent().getStringExtra("OPEN"))){ + manager.mLiveAudienceViewHolder.openNewPeopleDialog(); + } + } /** * 打开礼物窗口 @@ -897,6 +903,11 @@ public class LiveAudienceActivity extends LiveActivity { */ public static void forward(Context context, LiveBean liveBean, int liveType, int liveTypeVal, String key, int position, int liveSdk) { + forward(context, liveBean, liveType, liveTypeVal, key, null, position, liveSdk); + } + + public static void forward(Context context, LiveBean liveBean, int liveType, + int liveTypeVal, String key, Map map, int position, int liveSdk) { Intent intent = new Intent(context, LiveAudienceActivity.class); intent.putExtra(Constants.LIVE_BEAN, liveBean); intent.putExtra(Constants.LIVE_TYPE, liveType); @@ -905,9 +916,13 @@ public class LiveAudienceActivity extends LiveActivity { intent.putExtra(Constants.LIVE_POSITION, position); intent.putExtra(Constants.LIVE_SDK, liveSdk); intent.putExtra(Constants.LIVE_SDK, liveSdk); + if (map != null) { + for (String _key : map.keySet()) { + intent.putExtra(_key, map.get(_key)); + } + } intent.putExtra("landscape", liveBean.getLandscape()); context.startActivity(intent); - } @@ -946,9 +961,10 @@ public class LiveAudienceActivity extends LiveActivity { /** * 后台下载所有礼物 */ - private void downloadAllGift(){ + private void downloadAllGift() { LiveHttpUtil.getNewGiftList(new HttpCallback() { - List giftBeanList=new ArrayList<>(); + List giftBeanList = new ArrayList<>(); + @Override public void onSuccess(int code, String msg, String[] info) { if (code == 0 && info.length > 0) { @@ -958,20 +974,21 @@ public class LiveAudienceActivity extends LiveActivity { CommonAppConfig.getInstance().setGiftListJson(obj.getString("listarray")); for (Object o : list) { - JSONObject item= (JSONObject) o; + JSONObject item = (JSONObject) o; List giftlist = JSONArray.parseArray(item.getJSONArray("giftlist").toJSONString(), LiveGiftBean.class); for (LiveGiftBean bean : giftlist) { - if(!bean.getSwf().isEmpty()){ + if (!bean.getSwf().isEmpty()) { giftBeanList.add(bean); } } } GiftCacheUtil.getInstance().setDownloadList(giftBeanList); GiftCacheUtil.getInstance().setCallback(new CommonCallback() { - int index=0; + int index = 0; + @Override public void callback(File bean) { - if(bean!=null){ + if (bean != null) { index++; Bus.get().post(new GiftCacheUtil.GiftDownloadStatus(index, giftBeanList.size(), GiftCacheUtil.getIdForFileName(bean.getName()))); } diff --git a/live/src/main/java/com/yunbao/live/adapter/LiveGiftAdapter.java b/live/src/main/java/com/yunbao/live/adapter/LiveGiftAdapter.java index 3303cd246..c7284bed0 100644 --- a/live/src/main/java/com/yunbao/live/adapter/LiveGiftAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/LiveGiftAdapter.java @@ -28,6 +28,8 @@ import com.yunbao.common.glide.ImgLoader; import com.yunbao.common.interfaces.CommonCallback; import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.utils.GiftCacheUtil; +import com.yunbao.common.utils.ToastUtil; +import com.yunbao.common.utils.WordUtil; import com.yunbao.live.R; import com.yunbao.live.custom.GiftMarkView; @@ -199,8 +201,14 @@ public class LiveGiftAdapter extends RecyclerView.Adapter { GiftCacheUtil.getInstance().downloadGiftForId(bean, new CommonCallback() { @Override public void callback(File bean) { - mLoadingLayout.setVisibility(View.GONE); - GiftCacheUtil.getInstance().restart(); + if(bean==null){ + ToastUtil.show(WordUtil.getString(R.string.load_failure_2)); + mLoading.setImageResource(R.mipmap.icon_download_gift); + mLoading.getAnimation().cancel(); + }else { + mLoadingLayout.setVisibility(View.GONE); + } + GiftCacheUtil.getInstance().restart(); } }); }); 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 341571bac..02eac1439 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveHDDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveHDDialogFragment.java @@ -53,16 +53,11 @@ public class LiveHDDialogFragment extends AbsDialogFragment { private int showType = 0; private boolean isFullWindow = false; private String roomId; - private WebInterface webInterface; public LiveHDDialogFragment() { } - public void setWebInterface(WebInterface webInterface) { - this.webInterface = webInterface; - } - /** * 弹出全屏对话框 * @@ -263,19 +258,6 @@ public class LiveHDDialogFragment extends AbsDialogFragment { } - @JavascriptInterface - public void androidShowUserPreferentialRedDot() { - if (webInterface != null) { - webInterface.showUserPreferentialRedDot(); - } - } - - @JavascriptInterface - public void androidHideUserPreferentialRedDot() { - if (webInterface != null) { - webInterface.hideUserPreferentialRedDot(); - } - } } private LiveRoomCheckLivePresenter mCheckLivePresenter; @@ -344,11 +326,4 @@ public class LiveHDDialogFragment extends AbsDialogFragment { mWebView.destroy(); } - public abstract static class WebInterface { - public void showUserPreferentialRedDot() { - } - - public void hideUserPreferentialRedDot() { - } - } } diff --git a/live/src/main/java/com/yunbao/live/views/LiveAudienceViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveAudienceViewHolder.java index 9ecb96a00..def93acad 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveAudienceViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveAudienceViewHolder.java @@ -298,10 +298,10 @@ public class LiveAudienceViewHolder extends AbsLiveViewHolder { LiveRoomViewHolder.insertChat(lvBean2, 1); } }, 10000);//3秒后执行Runnable中的run方法 - getNewPeopleInfo(); + getNewPeopleInfo(false); } - public void getNewPeopleInfo() { + public void getNewPeopleInfo(boolean show) { API.get().pdLiveApi(mContext) .getNewPeopleInfo() .subscribeOn(Schedulers.io()) @@ -315,6 +315,12 @@ public class LiveAudienceViewHolder extends AbsLiveViewHolder { } else { newPeopleUrl = CommonAppConfig.HOST + "/" + peopleInfo.getLink(); } + setUserPreferentialRedDot(peopleInfo.getShowRed() == 1); + if (show) { + openNewPeopleDialog(); + } + } else { + liveNewPeople.setVisibility(View.GONE); } }, Throwable::printStackTrace).isDisposed(); } @@ -351,7 +357,11 @@ public class LiveAudienceViewHolder extends AbsLiveViewHolder { /** * 打开新人特惠对话框 */ - private void openNewPeopleDialog() { + public void openNewPeopleDialog() { + if (newPeopleUrl == null) { + getNewPeopleInfo(true); + return; + } Bundle bundle = new Bundle(); String url = newPeopleUrl + "&g=Appapi&m=Turntable&a=tricky"; url += "&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" @@ -360,19 +370,6 @@ public class LiveAudienceViewHolder extends AbsLiveViewHolder { bundle.putInt("show_type", 0); LiveHDDialogFragment liveHDDialogFragment = new LiveHDDialogFragment(); liveHDDialogFragment.setArguments(bundle); - liveHDDialogFragment.setWebInterface(new LiveHDDialogFragment.WebInterface(){ - @Override - public void showUserPreferentialRedDot() { - super.showUserPreferentialRedDot(); - setUserPreferentialRedDot(true); - } - - @Override - public void hideUserPreferentialRedDot() { - super.hideUserPreferentialRedDot(); - setUserPreferentialRedDot(false); - } - }); liveHDDialogFragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveHDDialogFragment"); } @@ -408,11 +405,13 @@ public class LiveAudienceViewHolder extends AbsLiveViewHolder { /** * 显示/隐藏新人特惠礼物红点 + * * @param show true显示 false隐藏 */ - private void setUserPreferentialRedDot(boolean show){ - mNewPeopleRedDot.setVisibility(show?View.VISIBLE:View.GONE); + private void setUserPreferentialRedDot(boolean show) { + mNewPeopleRedDot.setVisibility(show ? View.VISIBLE : 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 bacfda760..bdd685bf5 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -133,7 +133,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe //头部布局 private LiveRoomViewHolder mLiveRoomViewHolder; //底部布局 - private LiveAudienceViewHolder mLiveAudienceViewHolder; + public LiveAudienceViewHolder mLiveAudienceViewHolder; //观众与主播连麦逻辑 private LiveLinkMicPresenter mLiveLinkMicPresenter; private LiveBean mLiveBean; diff --git a/live/src/main/res/layout/view_live_audience.xml b/live/src/main/res/layout/view_live_audience.xml index 2c0fa5c85..a99af09ad 100644 --- a/live/src/main/res/layout/view_live_audience.xml +++ b/live/src/main/res/layout/view_live_audience.xml @@ -369,6 +369,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerInParent="true" + android:visibility="invisible" android:src="@mipmap/live_icon_newpeople_en" /> + android:visibility="invisible" /> diff --git a/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java b/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java index 8c4a6cb4d..a003abd51 100644 --- a/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/MainHomeLiveViewHolder.java @@ -54,7 +54,9 @@ import org.greenrobot.eventbus.ThreadMode; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * Created by cxf on 2018/9/22. @@ -79,6 +81,7 @@ public class MainHomeLiveViewHolder extends AbsMainHomeChildViewHolder implement private int intoIndex = 0; private List new_data; private boolean isHave = false; + private Map gotoRoomKey=new HashMap<>(); public MainHomeLiveViewHolder(Context context, ViewGroup parentView) { super(context, parentView); @@ -312,7 +315,10 @@ public class MainHomeLiveViewHolder extends AbsMainHomeChildViewHolder implement return; } intoIndex = 1; - LiveAudienceActivity.forward(mContext, liveBean, liveType, liveTypeVal, "", 0, liveSdk); + if(gotoRoomKey.isEmpty()){ + gotoRoomKey=null; + } + LiveAudienceActivity.forward(mContext, liveBean, liveType, liveTypeVal, "",gotoRoomKey, 0, liveSdk); } }); @@ -345,6 +351,9 @@ public class MainHomeLiveViewHolder extends AbsMainHomeChildViewHolder implement BannerBean bean = mBannerList.get(p); if (bean != null) { String link = bean.getLink(); + if(bean.getType()==2){ + gotoRoomKey.put("OPEN","NEWUSER"); + } if (link.contains("http")) { WebViewActivity.forward(mContext, link, true); } else {