主播直播间新增右下角Banner

This commit is contained in:
zlzw 2022-11-03 16:06:18 +08:00
parent 62f1912a7a
commit cf08f8197b
5 changed files with 349 additions and 74 deletions

View File

@ -271,7 +271,6 @@ public class ACache {
JSONArray obj = new JSONArray(JSONString); JSONArray obj = new JSONArray(JSONString);
return obj; return obj;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
return null; return null;
} }
} }

View File

@ -25,7 +25,6 @@ import androidx.fragment.app.DialogFragment;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.blankj.utilcode.util.GsonUtils;
import com.lzy.okgo.callback.Callback; import com.lzy.okgo.callback.Callback;
import com.lzy.okgo.model.Progress; import com.lzy.okgo.model.Progress;
import com.lzy.okgo.model.Response; import com.lzy.okgo.model.Response;
@ -36,6 +35,7 @@ import com.yunbao.common.CommonAppConfig;
import com.yunbao.common.CommonAppContext; import com.yunbao.common.CommonAppContext;
import com.yunbao.common.Constants; import com.yunbao.common.Constants;
import com.yunbao.common.bean.IMLoginModel; import com.yunbao.common.bean.IMLoginModel;
import com.yunbao.common.bean.LiveBean;
import com.yunbao.common.bean.UserBean; import com.yunbao.common.bean.UserBean;
import com.yunbao.common.dialog.NotCancelableDialog; import com.yunbao.common.dialog.NotCancelableDialog;
import com.yunbao.common.event.LoginInvalidEvent; import com.yunbao.common.event.LoginInvalidEvent;
@ -55,12 +55,9 @@ import com.yunbao.common.utils.ScreenDimenUtil;
import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.ToastUtil;
import com.yunbao.common.utils.WordUtil; import com.yunbao.common.utils.WordUtil;
import com.yunbao.live.R; import com.yunbao.live.R;
import com.yunbao.common.bean.LiveBean;
import com.yunbao.live.bean.LiveGuardInfo; import com.yunbao.live.bean.LiveGuardInfo;
import com.yunbao.live.bean.LiveKsyConfigBean; import com.yunbao.live.bean.LiveKsyConfigBean;
import com.yunbao.live.bean.LiveReceiveGiftBean; import com.yunbao.live.bean.LiveReceiveGiftBean;
import com.yunbao.live.bean.WishlistModel;
import com.yunbao.live.dialog.LiveBeautyDialogFragment;
import com.yunbao.live.dialog.LiveLinkMicListDialogFragment; import com.yunbao.live.dialog.LiveLinkMicListDialogFragment;
import com.yunbao.live.dialog.LiveNewFunctionDialogFragment; import com.yunbao.live.dialog.LiveNewFunctionDialogFragment;
import com.yunbao.live.dialog.LiveNewWishListDialogFragment; import com.yunbao.live.dialog.LiveNewWishListDialogFragment;
@ -71,7 +68,6 @@ import com.yunbao.live.http.LiveHttpConsts;
import com.yunbao.live.http.LiveHttpUtil; import com.yunbao.live.http.LiveHttpUtil;
import com.yunbao.live.interfaces.LiveFunctionClickListener; import com.yunbao.live.interfaces.LiveFunctionClickListener;
import com.yunbao.live.interfaces.LivePushListener; import com.yunbao.live.interfaces.LivePushListener;
import com.yunbao.live.momo.BeautyManager;
import com.yunbao.live.music.LiveMusicDialogFragment; import com.yunbao.live.music.LiveMusicDialogFragment;
import com.yunbao.live.presenter.LiveLinkMicAnchorPresenter; import com.yunbao.live.presenter.LiveLinkMicAnchorPresenter;
import com.yunbao.live.presenter.LiveLinkMicPresenter; import com.yunbao.live.presenter.LiveLinkMicPresenter;
@ -103,7 +99,6 @@ import io.rong.message.TextMessage;
import pl.droidsonroids.gif.GifImageView; import pl.droidsonroids.gif.GifImageView;
/** /**
* Created by cxf on 2018/10/7. * Created by cxf on 2018/10/7.
* 主播直播间 * 主播直播间
@ -142,7 +137,6 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl
public static int backIndex = 0;//0=未判断1=已判断 public static int backIndex = 0;//0=未判断1=已判断
@Override @Override
protected int getLayoutId() { protected int getLayoutId() {
return R.layout.activity_live_anchor; return R.layout.activity_live_anchor;
@ -632,6 +626,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl
} }
if (mLiveAnchorViewHolder == null) { if (mLiveAnchorViewHolder == null) {
mLiveAnchorViewHolder = new LiveRyAnchorViewHolder(mContext, mContainer); mLiveAnchorViewHolder = new LiveRyAnchorViewHolder(mContext, mContainer);
mLiveAnchorViewHolder.setLiveBean(mLiveBean);
mLiveAnchorViewHolder.addToParent(); mLiveAnchorViewHolder.addToParent();
} }
mLiveBottomViewHolder = mLiveAnchorViewHolder; mLiveBottomViewHolder = mLiveAnchorViewHolder;
@ -1269,6 +1264,7 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl
L.e(TAG, content); L.e(TAG, content);
LogUtil.print(mLogFile, content); LogUtil.print(mLogFile, content);
} }
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
public void onOpenDrawer(LiveAudienceEvent event) { public void onOpenDrawer(LiveAudienceEvent event) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();

View File

@ -1,25 +1,53 @@
package com.yunbao.live.views; package com.yunbao.live.views;
import static com.yunbao.live.activity.LiveActivity.mLiveUid;
import static com.yunbao.live.activity.LiveRyAnchorActivity.PKing;
import static com.yunbao.live.activity.LiveRyAnchorActivity.pk_nub;
import static com.yunbao.live.event.LiveAudienceEvent.LiveAudienceType.START_MESSAGE;
import static com.yunbao.live.presenter.LiveRyLinkMicPkPresenter.leaveDRRoom;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import androidx.core.content.ContextCompat; import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import androidx.core.content.ContextCompat;
import com.blankj.utilcode.util.GsonUtils;
import com.ms.banner.Banner;
import com.ms.banner.BannerConfig;
import com.ms.banner.listener.OnBannerClickListener;
import com.yunbao.common.CommonAppConfig; import com.yunbao.common.CommonAppConfig;
import com.yunbao.common.bean.BannerBean;
import com.yunbao.common.bean.IMLoginModel;
import com.yunbao.common.bean.LiveBean;
import com.yunbao.common.bean.MsgModel;
import com.yunbao.common.bean.StarChallengeStatusModel;
import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpCallback;
import com.yunbao.common.http.HttpClient; 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.ToastUtil; import com.yunbao.common.utils.ToastUtil;
import com.yunbao.live.R; import com.yunbao.live.R;
import com.yunbao.live.activity.LiveRyAnchorActivity; import com.yunbao.live.activity.LiveRyAnchorActivity;
import com.yunbao.live.activity.ZhuangBanActivity;
import com.yunbao.live.bean.WishlistModel;
import com.yunbao.live.dialog.LiveHDDialogFragment;
import com.yunbao.live.event.LiveAudienceEvent;
import com.yunbao.live.http.LiveHttpUtil; import com.yunbao.live.http.LiveHttpUtil;
import static com.yunbao.live.activity.LiveRyAnchorActivity.PKing; import org.greenrobot.eventbus.Subscribe;
import static com.yunbao.live.activity.LiveRyAnchorActivity.pk_nub; import org.greenrobot.eventbus.ThreadMode;
import static com.yunbao.live.presenter.LiveRyLinkMicPkPresenter.leaveDRRoom;
import java.util.ArrayList;
import java.util.List;
/** /**
* Created by cxf on 2018/10/9. * Created by cxf on 2018/10/9.
@ -42,6 +70,10 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder {
public static LinearLayout btn_start_dr_pk, btn_start_dr_pk_view, btn_end_pk; public static LinearLayout btn_start_dr_pk, btn_start_dr_pk_view, btn_end_pk;
public static TextView btn_dr_pk_nub; public static TextView btn_dr_pk_nub;
TextView btn_dr; TextView btn_dr;
private Banner mBanner;
private LiveBean mLiveBean;
private List<BannerBean> mBannerList = new ArrayList<>();
private String activityUrl;
public LiveRyAnchorViewHolder(Context context, ViewGroup parentView) { public LiveRyAnchorViewHolder(Context context, ViewGroup parentView) {
@ -56,10 +88,12 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder {
@Override @Override
public void init() { public void init() {
super.init(); super.init();
Bus.getOn(this);
mDrawable0 = ContextCompat.getDrawable(mContext, R.mipmap.icon_live_func_0); mDrawable0 = ContextCompat.getDrawable(mContext, R.mipmap.icon_live_func_0);
mDrawable1 = ContextCompat.getDrawable(mContext, R.mipmap.icon_live_func_1); mDrawable1 = ContextCompat.getDrawable(mContext, R.mipmap.icon_live_func_1);
mBtnFunction = (ImageView) findViewById(R.id.btn_function); mBtnFunction = (ImageView) findViewById(R.id.btn_function);
btn_dr = (TextView) findViewById(R.id.btn_dr); btn_dr = (TextView) findViewById(R.id.btn_dr);
mBanner = (Banner) findViewById(R.id.banner);
mBtnFunction.setImageDrawable(mDrawable0); mBtnFunction.setImageDrawable(mDrawable0);
mBtnFunction.setOnClickListener(this); mBtnFunction.setOnClickListener(this);
mBtnGameClose = findViewById(R.id.btn_close_game); mBtnGameClose = findViewById(R.id.btn_close_game);
@ -177,6 +211,12 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder {
((LiveRyAnchorActivity) mContext).closeLive(); ((LiveRyAnchorActivity) mContext).closeLive();
} }
@Override
public void onDestroy() {
super.onDestroy();
Bus.getOff(this);
}
/** /**
* 显示功能弹窗 * 显示功能弹窗
*/ */
@ -259,4 +299,236 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder {
LiveHttpUtil.setLinkMicEnable(mLinkMicEnable, mChangeLinkMicCallback); LiveHttpUtil.setLinkMicEnable(mLinkMicEnable, mChangeLinkMicCallback);
} }
@Subscribe(threadMode = ThreadMode.MAIN)
public void updateStart(LiveAudienceEvent event) {
if (event.getType() == START_MESSAGE) {
MsgModel msgModel = event.getMsgModel();
StarChallengeStatusModel model = new StarChallengeStatusModel(activityUrl)
.setTaskNum(msgModel.getTaskNum())
.setTaskName1(msgModel.getTaskName1())
.setTaskName2(msgModel.getTaskName2())
.setStarSrc(msgModel.getStarSrc())
.setCurrentStarVal(msgModel.getCurrentStarVal())
.setTargetStarVal(msgModel.getTargetStarVal())
.setAssistSrc(msgModel.getAssistSrc())
.setTargetAssistNum(msgModel.getTargetAssistNum())
.setCurrentAssistNum(msgModel.getCurrentAssistNum());
Log.i("测试", "更新星级任务=" + model);
showStart(model);
}
}
public void initStarData() {
LiveNetManager.get(mContext)
.getStarChallengeStatus(mLiveUid, new com.yunbao.common.http.base.HttpCallback<StarChallengeStatusModel>() {
@Override
public void onSuccess(StarChallengeStatusModel data1) {
activityUrl = data1.getActivityUrl();
showStart(data1);
Log.e("PortraitLiveManager", data1.toString());
}
@Override
public void onError(String error) {
Log.e("PortraitLiveManager", error);
}
});
}
public void initWishList() {
LiveHttpUtil.getWishList(mLiveBean.getUid(), new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
if (info.length > 0) {
String json = info[0];
WishlistModel model = GsonUtils.fromJson(json, WishlistModel.class);
if (model != null && model.getWishlist().size() > 0) {
BannerBean bannerModel = new BannerBean();
bannerModel.setShow_type("2");
bannerModel.setLink(CommonAppConfig.HOST + "/index.php");
bannerModel.setImageUrl(model.getImg());
addWishList(bannerModel);
}
}
}
@Override
public void onFinish() {
}
});
}
public synchronized void showStart(StarChallengeStatusModel data) {
boolean upData = false;
if (mBannerList != null && mBannerList.size() == 0) {
Log.e("PortraitLiveManager", "直接添加星级任务");
BannerBean bannerBean = new BannerBean();
bannerBean.setStart(true);
bannerBean.setModel(data);
mBannerList.add(bannerBean);
} else {
Log.e("PortraitLiveManager", "遍历添加星级任务");
for (BannerBean bean : mBannerList) {
if (bean.isStart()) {
Log.e("PortraitLiveManager", "更新添加星级任务");
bean.setModel(data);
upData = true;
}
}
if (!upData) {
Log.e("PortraitLiveManager", "更新添加星级任务2");
BannerBean bannerBean = new BannerBean();
bannerBean.setStart(true);
bannerBean.setModel(data);
mBannerList.add(bannerBean);
}
}
updateBanner(mBannerList);
}
public void addWishList(BannerBean bannerModel) {
mBannerList.add(bannerModel);
updateBanner(mBannerList);
}
public void showBanner() {
if (mBannerList != null && mBanner != null) {
if (mBannerList.size() == 1) {
mBanner.setAutoPlay(false)
.setPages(mBannerList, new CustomViewHolder())
.setDelayTime(3200)
.setBannerStyle(BannerConfig.NOT_INDICATOR)
.setOnBannerClickListener(new OnBannerClickListener() {
@Override
public void onBannerClick(List datas, int p) {
if (mBannerList != null) {
if (p >= 0 && p < mBannerList.size()) {
IMLoginModel userInfo = IMLoginManager.get(mContext).getUserInfo();
BannerBean bean = mBannerList.get(p);
String type = "";
StringBuffer htmlUrl = new StringBuffer();
//判断是否是星级活动
if (bean.isStart()) {
type = bean.getModel().getType();
htmlUrl.append(CommonAppConfig.HOST)
.append("/")
.append(bean.getModel().getActivityUrl())
.append("&nickname=")
.append(userInfo.getUserNicename())
.append("&token=")
.append(userInfo.getToken())
.append("&anchorUid=")
.append(mLiveUid)
.append("&uid=")
.append(userInfo.getId())
.append("&k=")
.append(System.currentTimeMillis());
} else {
type = bean.getShow_type();
htmlUrl.append(bean.getLink())
.append("?uid=")
.append(userInfo.getId())
.append("&token=")
.append(userInfo.getToken())
.append("&anchorUid=")
.append(mLiveUid)
.append("&t=")
.append(System.currentTimeMillis());
}
if (TextUtils.equals(type, "1")) {
ZhuangBanActivity.forward(mContext, htmlUrl.toString(), false);
} else {
Bundle bundle = new Bundle();
bundle.putString("url", htmlUrl.toString());
LiveHDDialogFragment fragment = new LiveHDDialogFragment();
fragment.setArguments(bundle);
fragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "LiveHDDialogFragment");
}
}
}
}
})
.start();
} else {
mBanner.setAutoPlay(true)
.setPages(mBannerList, new CustomViewHolder())
.setDelayTime(3200)
.setBannerStyle(BannerConfig.NOT_INDICATOR)
.setOnBannerClickListener(new OnBannerClickListener() {
@Override
public void onBannerClick(List datas, int p) {
if (mBannerList != null) {
if (p >= 0 && p < mBannerList.size()) {
IMLoginModel userInfo = IMLoginManager.get(mContext).getUserInfo();
BannerBean bean = mBannerList.get(p);
String type = "";
StringBuffer htmlUrl = new StringBuffer();
//判断是否是星级活动
if (bean.isStart()) {
type = bean.getModel().getType();
htmlUrl.append(CommonAppConfig.HOST)
.append("/")
.append(bean.getModel().getActivityUrl())
.append("&nickname=")
.append(userInfo.getUserNicename())
.append("&token=")
.append(userInfo.getToken())
.append("&anchorUid=")
.append(mLiveUid)
.append("&uid=")
.append(userInfo.getId())
.append("&k=")
.append(System.currentTimeMillis());
} else {
type = bean.getShow_type();
htmlUrl.append(bean.getLink())
.append(bean.getLink().contains("?") ? "&uid=" : "?uid=")
.append(userInfo.getId())
.append("&token=")
.append(userInfo.getToken())
.append("&anchorUid=")
.append(mLiveUid)
.append("&liveUid=")
.append(mLiveUid)
.append("&t=")
.append(System.currentTimeMillis())
.append("&g=Appapi&m=Wish&a=index");
}
if (TextUtils.equals(type, "1")) {
ZhuangBanActivity.forward(mContext, htmlUrl.toString(), false);
} else {
Bundle bundle = new Bundle();
bundle.putString("url", htmlUrl.toString());
LiveHDDialogFragment fragment = new LiveHDDialogFragment();
fragment.setArguments(bundle);
fragment.show(((LiveRyAnchorActivity) mContext).getSupportFragmentManager(), "LiveHDDialogFragment");
}
}
}
}
})
.start();
}
}
}
public void updateBanner(List<BannerBean> list) {
mBannerList = list;
mBanner.update(list);
if (mBannerList.size() > 1) {
mBanner.setAutoPlay(true);
}
}
public void setLiveBean(LiveBean mLiveBean) {
this.mLiveBean = mLiveBean;
showBanner();
initStarData();
initWishList();
}
} }

View File

@ -1,11 +1,20 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom" android:layout_gravity="bottom"
android:orientation="vertical" android:orientation="vertical">
>
<com.ms.banner.Banner
android:id="@+id/banner"
android:layout_width="78dp"
android:layout_height="106dp"
android:layout_gravity="right"
android:layout_marginBottom="5dp"
app:delay_time="5000"
app:indicator_height="8dp"
app:indicator_width="8dp" />
<LinearLayout <LinearLayout
android:id="@+id/btn_start_dr_pk_view" android:id="@+id/btn_start_dr_pk_view"
@ -16,28 +25,28 @@
android:orientation="vertical"> android:orientation="vertical">
<LinearLayout android:id="@+id/btn_start_dr_pk" <LinearLayout
android:id="@+id/btn_start_dr_pk"
android:layout_width="100dp" android:layout_width="100dp"
android:layout_height="40dp" android:layout_height="40dp"
android:background="@mipmap/btn_big_blue" android:background="@mipmap/btn_big_blue"
android:orientation="vertical" android:gravity="center"
android:gravity="center"> android:orientation="vertical">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="開始PK" android:text="開始PK"
android:textColor="#ffffffff" android:textColor="#ffffffff"
android:textSize="12sp" android:textSize="12sp" />
/>
<TextView android:id="@+id/btn_dr_pk_nub" <TextView
android:id="@+id/btn_dr_pk_nub"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="剩餘次數:0" android:text="剩餘次數:0"
android:textColor="#ffe1e1e1" android:textColor="#ffe1e1e1"
android:textSize="8sp" android:textSize="8sp" />
/>
</LinearLayout> </LinearLayout>
@ -49,29 +58,31 @@
<LinearLayout <LinearLayout
android:layout_width="40dp" android:layout_width="40dp"
android:layout_height="40dp" android:layout_height="40dp"
android:background="@mipmap/btn_purple"
android:layout_marginTop="10dp" android:layout_marginTop="10dp"
android:background="@mipmap/btn_purple"
android:gravity="center"> android:gravity="center">
<TextView android:id="@+id/btn_dr" <TextView
android:id="@+id/btn_dr"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center" android:gravity="center"
android:text="邀請 android:text="邀請
主播" 主播"
android:textColor="#ffffffff" android:textColor="#ffffffff"
android:textSize="10sp" android:textSize="10sp" />
/>
</LinearLayout> </LinearLayout>
<LinearLayout android:id="@+id/btn_end_pk" <LinearLayout
android:id="@+id/btn_end_pk"
android:layout_width="40dp" android:layout_width="40dp"
android:layout_height="40dp" android:layout_height="40dp"
android:background="@mipmap/btn_white"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp" android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:background="@mipmap/btn_white"
android:gravity="center"> android:gravity="center">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -79,8 +90,7 @@
android:text="結束 android:text="結束
PK" PK"
android:textColor="#ffb1b1b1" android:textColor="#ffb1b1b1"
android:textSize="10sp" android:textSize="10sp" />
/>
</LinearLayout> </LinearLayout>
@ -94,8 +104,8 @@ PK"
android:layout_width="50dp" android:layout_width="50dp"
android:layout_height="50dp" android:layout_height="50dp"
android:layout_gravity="right" android:layout_gravity="right"
android:layout_marginBottom="5dp"
android:layout_marginRight="10dp" android:layout_marginRight="10dp"
android:layout_marginBottom="5dp"
android:background="@drawable/bg_live_link_mic" android:background="@drawable/bg_live_link_mic"
android:gravity="center_horizontal" android:gravity="center_horizontal"
android:orientation="vertical" android:orientation="vertical"
@ -130,9 +140,8 @@ PK"
android:layout_alignParentRight="true" android:layout_alignParentRight="true"
android:layout_marginRight="5dp" android:layout_marginRight="5dp"
android:padding="5dp" android:padding="5dp"
android:visibility="invisible"
android:src="@mipmap/icon_live_close" android:src="@mipmap/icon_live_close"
/> android:visibility="invisible" />
<ImageView <ImageView
android:id="@+id/btn_msg" android:id="@+id/btn_msg"
@ -158,8 +167,7 @@ PK"
android:layout_toLeftOf="@id/btn_function" android:layout_toLeftOf="@id/btn_function"
android:padding="6dp" android:padding="6dp"
android:src="@mipmap/icon_live_pk" android:src="@mipmap/icon_live_pk"
android:visibility="gone" android:visibility="gone" />
/>
<TextView <TextView
android:id="@+id/et_input" android:id="@+id/et_input"