pdlivexp/common/src/main/java/com/yunbao/common/views/CustomDrawerPopupView.java

243 lines
7.4 KiB
Java

package com.yunbao.common.views;
import android.content.Context;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.core.DrawerPopupView;
import com.lxj.xpopup.enums.PopupPosition;
import com.yunbao.common.R;
import com.yunbao.common.adapter.CustomDrawerPopupAdapter;
import com.yunbao.common.bean.AnchorRecommendItemModel;
import com.yunbao.common.bean.CustomSidebarInfoModel;
import com.yunbao.common.event.CustomDrawerPopupEvent;
import com.yunbao.common.http.live.LiveNetManager;
import com.yunbao.common.utils.Bus;
import com.yunbao.common.utils.ToastUtil;
import com.yunbao.common.views.weight.ViewClicksAntiShake;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.util.ArrayList;
import java.util.List;
public class CustomDrawerPopupView extends DrawerPopupView {
private Context mContext;
private RecyclerView drawerList;
private CustomDrawerPopupAdapter adapter;
private List<AnchorRecommendItemModel> list = new ArrayList<>();
private String liveId;
public CustomDrawerPopupView setLiveId(String liveId) {
this.liveId = liveId;
return this;
}
public CustomDrawerPopupView setList(List<AnchorRecommendItemModel> list) {
this.list = list;
return this;
}
public CustomDrawerPopupView(@NonNull Context context) {
super(context);
mContext = context;
}
@Override
protected int getImplLayoutId() {
return R.layout.custom_drawer_popup;
}
@Override
protected void onCreate() {
Bus.getOn(this);
super.onCreate();
initView();
initData(null);
}
@Override
public void dismiss() {
Bus.getOff(this);
super.dismiss();
}
private void initView() {
drawerList = findViewById(R.id.drawerList);
adapter = new CustomDrawerPopupAdapter(mContext);
adapter.setList(list).setLiveId(liveId);
drawerList.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false));
drawerList.setAdapter(adapter);
adapter.setListener(new CustomDrawerPopupAdapter.CustomDrawerListener() {
@Override
public void goToLive(AnchorRecommendItemModel model) {
if (callBack != null) {
callBack.goToLive(model);
}
}
});
//连麦互动
ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.live_link_mic), new ViewClicksAntiShake.ViewClicksCallBack() {
@Override
public void onViewClicks() {
dismiss();
if (callBack != null) {
callBack.evenTheWheat();
}
}
});
//特效设置
ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.effects_settings_layout), new ViewClicksAntiShake.ViewClicksCallBack() {
@Override
public void onViewClicks() {
dismiss();
if (callBack != null) {
callBack.effectsSetting();
}
}
});
//滑动设置
ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.slide_settings_layout), new ViewClicksAntiShake.ViewClicksCallBack() {
@Override
public void onViewClicks() {
dismiss();
if (callBack != null) {
callBack.slideSetting();
}
}
});
//小窗设置
ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.float_settings_layout), new ViewClicksAntiShake.ViewClicksCallBack() {
@Override
public void onViewClicks() {
dismiss();
if (callBack != null) {
callBack.floatSetting();
}
}
});
//画质设置
ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.system_notice), new ViewClicksAntiShake.ViewClicksCallBack() {
@Override
public void onViewClicks() {
dismiss();
if (callBack != null) {
callBack.changeVideo();
}
}
});
//更多菜单
ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.online), new ViewClicksAntiShake.ViewClicksCallBack() {
@Override
public void onViewClicks() {
XPopup.Builder builder = new XPopup.Builder(getContext()).atView(findViewById(R.id.more_menu));
builder.hasShadowBg(false)
.isDestroyOnDismiss(true)
.isLightStatusBar(false)
.popupPosition(PopupPosition.Top)
.asCustom(new MoreMenuPopupView(mContext))
.show();
}
});
}
public void initData(List<CustomSidebarInfoModel> data) {
if (data != null) {
adapter.updateData(data);
} else {
LiveNetManager.get(mContext)
.getCustomSidebarInfo(new com.yunbao.common.http.base.HttpCallback<List<CustomSidebarInfoModel>>() {
@Override
public void onSuccess(List<CustomSidebarInfoModel> data) {
adapter.updateData(data);
}
@Override
public void onError(String error) {
ToastUtil.show(error);
}
});
}
}
private CustomDrawerPopupCallBack callBack;
public CustomDrawerPopupView setCallBack(CustomDrawerPopupCallBack callBack) {
this.callBack = callBack;
return this;
}
public interface CustomDrawerPopupCallBack {
void goToLive(AnchorRecommendItemModel model);
void informationTransfer(CustomDrawerPopupEvent event);
void funGamesID(int zfunGamesID);
void showerHtml(String htmlUrl, boolean screen);
//连麦
void evenTheWheat();
void effectsSetting();
void slideSetting();
void floatSetting();
void systemNotice();
void changeVideo();
void online();
void reportLayout();
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void OnCustomDrawerPopupEvent(CustomDrawerPopupEvent event) {
//是否关闭弹窗
if (event.isDisMiss()) {
dismiss();
}
if (callBack != null) {
if (!TextUtils.isEmpty(event.getRightsInterests())) {
callBack.informationTransfer(event);
}
if (event.getActivityId() != 0) {
callBack.funGamesID(event.getActivityId());
}
if (!TextUtils.isEmpty(event.getHtmlUrl())) {
callBack.showerHtml(event.getHtmlUrl(), event.isScreen());
}
if (event.isSystemNotice()) {
dismiss();
callBack.systemNotice();
}
if (event.isOnline()) {
dismiss();
callBack.online();
}
if (event.isReportLayout()) {
dismiss();
callBack.reportLayout();
}
}
if (event.isRefresh()) {
initData(null);
}
}
}