直播间的滚动修复直播间聊天问题,侧边栏改为fragment

This commit is contained in:
18401019693 2022-08-22 18:11:00 +08:00
parent 318a3dcf8c
commit 6250e1d012
12 changed files with 419 additions and 205 deletions

View File

@ -6,6 +6,16 @@ import com.yunbao.common.bean.BaseModel;
public class LiveAudienceEvent extends BaseModel {
private LiveAudienceType type;
private ActiveModel model = new ActiveModel();
private String avatar = "";
public String getAvatar() {
return avatar;
}
public LiveAudienceEvent setAvatar(String avatar) {
this.avatar = avatar;
return this;
}
public ActiveModel getModel() {
return model;

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
>
<translate
android:duration="200"
android:fromXDelta="100%p"
android:toXDelta="0"
/>
</set>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="200"
android:fromXDelta="0"
android:toXDelta="100%p"
/>
</set>

View File

@ -66,7 +66,10 @@
<item name="android:windowEnterAnimation">@anim/left_anim_enter</item>
<item name="android:windowExitAnimation">@anim/left_anim_exit</item>
</style>
<style name="RightLeftToAnim" parent="android:Animation">
<item name="android:windowEnterAnimation">@anim/right_anim_enter</item>
<item name="android:windowExitAnimation">@anim/right_anim_exit</item>
</style>
<style name="groupLast" parent="AppTheme">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">1dp</item>

View File

@ -54,6 +54,7 @@ import com.yunbao.live.dialog.LiveGuardDialogFragment;
import com.yunbao.live.dialog.LiveHDDialogFragment;
import com.yunbao.live.dialog.LiveMicUserDialogFragment;
import com.yunbao.live.dialog.LiveWishListDialogFragment4Audience;
import com.yunbao.live.dialog.SidebarLiveAudience;
import com.yunbao.live.event.LinkMicTxAccEvent;
import com.yunbao.live.event.LiveRoomChangeEvent;
import com.yunbao.live.http.LiveHttpConsts;
@ -688,7 +689,12 @@ public class LiveAudienceActivity extends LiveActivity {
switch (event.getType()) {
case SIDEBAR:
//从右边打开侧边栏
manager.openDrawer();
SidebarLiveAudience sidebarLiveAudience = new SidebarLiveAudience();
bundle.putString("Avatar", mLiveBean.getAvatar());
sidebarLiveAudience.setArguments(bundle);
sidebarLiveAudience.show(getSupportFragmentManager(), "SidebarLiveAudience");
// manager.openDrawer();
break;
case BOTTOM_COLLECTION:
LiveTotalDialog liveTotalDialog = new LiveTotalDialog();

View File

@ -8,8 +8,10 @@ import androidx.recyclerview.widget.RecyclerView;
import com.yunbao.common.adapter.RefreshAdapter;
import com.yunbao.common.bean.AnchorRecommendItemModel;
import com.yunbao.common.bean.SlideInfoModel;
import com.yunbao.live.R;
import com.yunbao.live.views.SidebarLiveItemViewHolder;
import com.yunbao.live.views.SidebarViewHoler;
import java.util.ArrayList;
import java.util.List;
@ -21,6 +23,9 @@ public class SidebarAdapter extends RefreshAdapter<AnchorRecommendItemModel> {
private int mHeight;
private Context mContext;
private List<AnchorRecommendItemModel> itemModelList = new ArrayList<>();
private List<SlideInfoModel> data = new ArrayList<>();
private static final int HEAD = 1;
private static final int NORMAL = 0;
public SidebarAdapter(Context context, int height) {
super(context);
@ -31,10 +36,15 @@ public class SidebarAdapter extends RefreshAdapter<AnchorRecommendItemModel> {
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
if (viewType == HEAD) {
return new SidebarViewHoler(mInflater.inflate(R.layout.view_sidebar_live_audience_top, parent, false));
} else {
return new SidebarLiveItemViewHolder(mInflater.inflate(R.layout.item_sidebar_lives, parent, false));
}
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
if (holder instanceof SidebarLiveItemViewHolder) {
@ -46,9 +56,20 @@ public class SidebarAdapter extends RefreshAdapter<AnchorRecommendItemModel> {
}
}
});
} else if (holder instanceof SidebarViewHoler) {
SidebarViewHoler sidebarViewHoler = (SidebarViewHoler) holder;
sidebarViewHoler.onBanner(data);
}
}
@Override
public int getItemViewType(int position) {
if (position == 0) {
return HEAD;
}
return NORMAL;
}
/**
* 添加数据
*
@ -57,4 +78,10 @@ public class SidebarAdapter extends RefreshAdapter<AnchorRecommendItemModel> {
public void addData(List<AnchorRecommendItemModel> list) {
refreshData(list);
}
public SidebarAdapter setData(List<SlideInfoModel> data) {
this.data = data;
notifyDataSetChanged();
return this;
}
}

View File

@ -0,0 +1,171 @@
package com.yunbao.live.dialog;
import android.os.Bundle;
import android.view.Display;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import androidx.recyclerview.widget.GridLayoutManager;
import com.alibaba.fastjson.JSON;
import com.yunbao.common.bean.AnchorRecommendItemModel;
import com.yunbao.common.bean.AnchorRecommendModel;
import com.yunbao.common.bean.SlideInfoModel;
import com.yunbao.common.custom.CommonRefreshView;
import com.yunbao.common.custom.ItemDecoration;
import com.yunbao.common.dialog.AbsDialogFragment;
import com.yunbao.common.glide.ImgLoader;
import com.yunbao.common.http.HttpCallback;
import com.yunbao.common.http.main.MainNetManager;
import com.yunbao.common.utils.DeviceUtils;
import com.yunbao.common.utils.RouteUtil;
import com.yunbao.live.R;
import com.yunbao.live.activity.LiveAudienceActivity;
import com.yunbao.live.adapter.SidebarAdapter;
import com.yunbao.live.bean.LiveBean;
import com.yunbao.live.http.LiveHttpUtil;
import com.yunbao.live.presenter.LiveRoomCheckLivePresenter;
import java.util.List;
/**
* 直播间侧边栏
*/
public class SidebarLiveAudience extends AbsDialogFragment {
//侧边栏背景
private ImageView sidebarBack;
//侧边栏刷新列表
public CommonRefreshView sidebarList;
//侧边栏适配器
private SidebarAdapter sidebarAdapter;
@Override
protected int getLayoutId() {
return R.layout.view_sidebar_live_audience;
}
@Override
protected int getDialogStyle() {
return com.yunbao.common.R.style.dialog2;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Bundle bundle = getArguments();
sidebarBack = (ImageView) findViewById(R.id.sidebar_back);
if (bundle != null) {
String avatar = bundle.getString("Avatar");
//侧边栏背景
ImgLoader.displayBlurLive(mContext, avatar, sidebarBack);
}
sidebarList = (CommonRefreshView) findViewById(R.id.sidebarList);
GridLayoutManager gridLayoutManager = new GridLayoutManager(mContext, 2, GridLayoutManager.VERTICAL, false);
gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
if (position == 0) {
return 2;
}
return 1;
}
});
sidebarList.setLayoutManager(gridLayoutManager);
sidebarList.setEmptyLayoutId(R.layout.view_no_data_live);
sidebarList.setLoadMoreEnable(false);
ItemDecoration decoration = new ItemDecoration(mContext, 0x00000000, 6, 0);
decoration.setOnlySetItemOffsetsButNoDraw(true);
sidebarList.setItemDecoration(decoration);
Display mDisplay = getActivity().getWindowManager().getDefaultDisplay();
sidebarAdapter = new SidebarAdapter(mContext, mDisplay.getHeight());
sidebarAdapter.setHasStableIds(true);
sidebarList.setRecyclerViewAdapter(sidebarAdapter);
sidebarList.setDataHelperNew(new CommonRefreshView.DataHelperNew() {
@Override
public void loadData(int p) {
}
@Override
public void refresh() {
//推荐位
MainNetManager.get(getActivity())
.anchorRecommend("10", new com.yunbao.common.http.base.HttpCallback<AnchorRecommendModel>() {
@Override
public void onSuccess(AnchorRecommendModel anchorRecommendModel) {
if (getActivity().isFinishing()) return;
//侧边栏
MainNetManager.get(getActivity())
.getHot(1, new com.yunbao.common.http.base.HttpCallback<List<SlideInfoModel>>() {
@Override
public void onSuccess(List<SlideInfoModel> data) {
List<AnchorRecommendItemModel> list = anchorRecommendModel.getList();
list.add(0, new AnchorRecommendItemModel());
sidebarAdapter.addData(list);
sidebarList.onFinish();
sidebarAdapter.setData(data);
}
@Override
public void onError(String error) {
}
});
}
@Override
public void onError(String error) {
}
});
}
});
sidebarList.initData();
sidebarAdapter.setOnItemClickListener((bean, position) -> gotoLive(bean.getUid()));
}
@Override
protected boolean canCancel() {
return true;
}
@Override
protected void setWindowAttributes(Window window) {
window.setWindowAnimations(com.yunbao.common.R.style.RightLeftToAnim);
WindowManager.LayoutParams params = window.getAttributes();
params.width = DeviceUtils.getScreenWidth(getActivity()) / 3 * 2;
params.height = WindowManager.LayoutParams.MATCH_PARENT;
params.gravity = Gravity.RIGHT;
window.setAttributes(params);
}
/**
* 前往直播间
*/
private void gotoLive(final String liveId) {
LiveHttpUtil.getLiveInfo(liveId, new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
if (code == 0 && info.length > 0) {
LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class);
LiveRoomCheckLivePresenter mCheckLivePresenter = new LiveRoomCheckLivePresenter(getActivity(), (liveBean1, liveType, liveTypeVal, liveSdk) -> {
if (liveBean1 == null) {
return;
}
LiveAudienceActivity.forward(getActivity(), liveBean1, liveType, liveTypeVal, "", 0, liveSdk);
(getActivity()).finish();
});
mCheckLivePresenter.checkLive(liveBean);
} else {
RouteUtil.forwardUserHome(getActivity(), liveId, 0);
getActivity().finish();
}
}
});
}
}

View File

@ -119,16 +119,10 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
private Intent mIntent;
//直播间背景
private ImageView liveBack;
//侧边栏轮播
private Banner mBanner;
//侧边栏刷新列表
public CommonRefreshView sidebarList;
//侧边栏适配器
private SidebarAdapter sidebarAdapter;
//侧边栏背景
private ImageView sidebarBack;
//侧滑布局
private DrawerLayout drawerLayout;
// private DrawerLayout drawerLayout;
//直播间拆分布局
private LiveRoomPlayViewHolder mLivePlayViewHolder;
//头部布局
@ -204,31 +198,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
//直播页面背景
liveBack = mRootContainer.findViewById(R.id.live_back);
//侧边栏
drawerLayout = mRootContainer.findViewById(R.id.drawer_layout);
FrameLayout leftDrawer = mRootContainer.findViewById(R.id.left_drawer);
DrawerLayout.LayoutParams layoutParams = (DrawerLayout.LayoutParams) leftDrawer.getLayoutParams();
layoutParams.width = DeviceUtils.getScreenWidth(mContext) / 3 * 2;
leftDrawer.setLayoutParams(layoutParams);
sidebarList = mRootContainer.findViewById(R.id.sidebarList);
sidebarBack = mRootContainer.findViewById(R.id.sidebar_back);
//禁止滑动打开侧边栏
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
sidebarList.setEmptyLayoutId(R.layout.view_no_data_live);
GridLayoutManager gridLayoutManager = new GridLayoutManager(mContext, 2, GridLayoutManager.VERTICAL, false);
sidebarList.setLayoutManager(gridLayoutManager);
sidebarList.setLoadMoreEnable(false);
ItemDecoration decoration = new ItemDecoration(mContext, 0x00000000, 6, 0);
decoration.setOnlySetItemOffsetsButNoDraw(true);
sidebarList.setItemDecoration(decoration);
Display mDisplay = mContext.getWindowManager().getDefaultDisplay();
sidebarAdapter = new SidebarAdapter(mContext, mDisplay.getHeight());
//侧边栏轮播
mBanner = mRootContainer.findViewById(R.id.banner);
sidebarAdapter.setOnItemClickListener((bean, position) -> gotoLive(bean.getUid()));
sidebarAdapter.setHasStableIds(true);
sidebarList.setRecyclerViewAdapter(sidebarAdapter);
}
@ -263,57 +233,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
//直播间背景
ImgLoader.displayBlurLive(mContext, mLiveBean.getAvatar(), liveBack);
//侧边栏背景
ImgLoader.displayBlurLive(mContext, mLiveBean.getAvatar(), sidebarBack);
sidebarList.setDataHelperNew(new CommonRefreshView.DataHelperNew() {
@Override
public void loadData(int p) {
}
@Override
public void refresh() {
//推荐位
MainNetManager.get(mContext)
.anchorRecommend("10", new com.yunbao.common.http.base.HttpCallback<AnchorRecommendModel>() {
@Override
public void onSuccess(AnchorRecommendModel data) {
if (mContext.isFinishing()) return;
sidebarAdapter.addData(data.getList());
sidebarList.onFinish();
}
@Override
public void onError(String error) {
}
});
}
});
sidebarList.initData();
mBanner.setOutlineProvider(new ViewOutlineProvider() {
@Override
public void getOutline(View view, Outline outline) {
outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), 10);
}
});
mBanner.setClipToOutline(true);
//侧边栏
MainNetManager.get(mContext)
.getHot(1, new com.yunbao.common.http.base.HttpCallback<List<SlideInfoModel>>() {
@Override
public void onSuccess(List<SlideInfoModel> data) {
mContext.runOnUiThread(() -> onBanner(data));
}
@Override
public void onError(String error) {
}
});
mLivePlayViewHolder.setCover(data.getThumb());
mLivePlayViewHolder.play(data.getPull());
mLiveRoomViewHolder.setAvatar(data.getAvatar());
@ -1177,62 +1097,9 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
countDownTimer.start();
}
/**
* 侧滑轮播
*/
public void onBanner(List<SlideInfoModel> data) {
if (data == null || data.size() == 0 || mBanner == null) {
return;
}
if (mBanner.isStart()) {
mBanner.update(data);
} else {
mBanner.setAutoPlay(true)
.setPages(data, new SlideInBannerViewHolder())
.setDelayTime(3000)
.setOnBannerClickListener((datas, p) -> {
if (p >= 0 && p < data.size()) {
SlideInfoModel bean = data.get(p);
if (bean != null) {
String link = bean.getSlideUrl();
if (link.contains("http")) {
WebViewActivity.forward(mContext, link, true);
} else {
gotoLive(link);
}
}
}
}).start();
}
}
/**
* 前往直播间
*/
private void gotoLive(final String liveId) {
LiveHttpUtil.getLiveInfo(liveId, new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
if (code == 0 && info.length > 0) {
LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class);
LiveRoomCheckLivePresenter mCheckLivePresenter = new LiveRoomCheckLivePresenter(mContext, (liveBean1, liveType, liveTypeVal, liveSdk) -> {
if (liveBean1 == null) {
return;
}
LiveAudienceActivity.forward(mContext, liveBean1, liveType, liveTypeVal, "", 0, liveSdk);
mContext.finish();
});
mCheckLivePresenter.checkLive(liveBean);
} else {
RouteUtil.forwardUserHome(mContext, liveId, 0);
mContext.finish();
}
}
});
}
/**
* 暂停播放
@ -1370,9 +1237,9 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
}
}
public void openDrawer() {
drawerLayout.openDrawer(GravityCompat.END);
}
// public void openDrawer() {
// drawerLayout.openDrawer(GravityCompat.END);
// }
public void onLinkMicTxAccEvent(LinkMicTxAccEvent e) {
if (mLivePlayViewHolder != null && mLivePlayViewHolder instanceof LivePlayTxViewHolder) {

View File

@ -0,0 +1,91 @@
package com.yunbao.live.views;
import android.app.Activity;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.alibaba.fastjson.JSON;
import com.ms.banner.Banner;
import com.yunbao.common.activity.WebViewActivity;
import com.yunbao.common.bean.SlideInfoModel;
import com.yunbao.common.http.HttpCallback;
import com.yunbao.common.utils.RouteUtil;
import com.yunbao.common.views.SlideInBannerViewHolder;
import com.yunbao.live.R;
import com.yunbao.live.activity.LiveAudienceActivity;
import com.yunbao.live.bean.LiveBean;
import com.yunbao.live.http.LiveHttpUtil;
import com.yunbao.live.presenter.LiveRoomCheckLivePresenter;
import java.util.List;
public class SidebarViewHoler extends RecyclerView.ViewHolder {
//侧边栏轮播
private Banner mBanner;
public SidebarViewHoler(@NonNull View itemView) {
super(itemView);
//侧边栏轮播
mBanner = itemView.findViewById(R.id.banner);
}
/**
* 侧滑轮播
*/
public void onBanner(List<SlideInfoModel> data) {
if (data == null || data.size() == 0 || mBanner == null) {
return;
}
if (mBanner.isStart()) {
mBanner.update(data);
} else {
mBanner.setAutoPlay(true)
.setPages(data, new SlideInBannerViewHolder())
.setDelayTime(3000)
.setOnBannerClickListener((datas, p) -> {
if (p >= 0 && p < data.size()) {
SlideInfoModel bean = data.get(p);
if (bean != null) {
String link = bean.getSlideUrl();
if (link.contains("http")) {
WebViewActivity.forward(itemView.getContext(), link, true);
} else {
gotoLive(link);
}
}
}
}).start();
}
}
/**
* 前往直播间
*/
private void gotoLive(final String liveId) {
LiveHttpUtil.getLiveInfo(liveId, new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
if (code == 0 && info.length > 0) {
LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class);
LiveRoomCheckLivePresenter mCheckLivePresenter = new LiveRoomCheckLivePresenter(itemView.getContext(), (liveBean1, liveType, liveTypeVal, liveSdk) -> {
if (liveBean1 == null) {
return;
}
LiveAudienceActivity.forward(itemView.getContext(), liveBean1, liveType, liveTypeVal, "", 0, liveSdk);
((Activity) itemView.getContext()).finish();
});
mCheckLivePresenter.checkLive(liveBean);
} else {
RouteUtil.forwardUserHome(itemView.getContext(), liveId, 0);
((Activity) itemView.getContext()).finish();
}
}
});
}
}

View File

@ -52,65 +52,6 @@
android:visibility="gone" />
</FrameLayout>
<FrameLayout
android:id="@+id/left_drawer"
android:layout_width="260dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="@mipmap/live_bg"
android:choiceMode="singleChoice"
android:dividerHeight="0dp"
android:orientation="vertical"
android:scrollbars="none">
<ImageView
android:id="@+id/sidebar_back"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop" />
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#90000000" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingStart="8dp"
android:paddingTop="56dp"
android:paddingEnd="8dp">
<com.ms.banner.Banner
android:id="@+id/banner"
android:layout_width="match_parent"
android:layout_height="77dp"
android:layout_marginBottom="5dp"
app:delay_time="3000"
app:indicator_drawable_selected="@drawable/bg_home_indicator_selected"
app:indicator_drawable_unselected="@drawable/bg_home_indicator_unselected"
app:indicator_height="8dp"
app:indicator_margin="6dp"
app:indicator_width="8dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="@string/recommended_for_you"
android:textColor="#FFF6F7FB"
android:textSize="14sp" />
<com.yunbao.common.custom.CommonRefreshView
android:id="@+id/sidebarList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp" />
</LinearLayout>
</FrameLayout>
</com.yunbao.common.views.weight.MyDrawerLayout>

View File

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/sidebar_back"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop" />
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#90000000" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingStart="8dp"
android:paddingEnd="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingStart="8dp"
android:paddingTop="56dp"
android:paddingEnd="8dp">
<com.yunbao.common.custom.CommonRefreshView
android:id="@+id/sidebarList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp">
</com.yunbao.common.custom.CommonRefreshView>
</LinearLayout>
</LinearLayout>
</FrameLayout>

View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.ms.banner.Banner
android:id="@+id/banner"
android:layout_width="match_parent"
android:layout_height="77dp"
android:layout_marginBottom="5dp"
app:delay_time="3000"
app:indicator_drawable_selected="@drawable/bg_home_indicator_selected"
app:indicator_drawable_unselected="@drawable/bg_home_indicator_unselected"
app:indicator_height="8dp"
app:indicator_margin="6dp"
app:indicator_width="8dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="@string/recommended_for_you"
android:textColor="#FFF6F7FB"
android:textSize="14sp" />
</LinearLayout>
</FrameLayout>