387 lines
14 KiB
Java
387 lines
14 KiB
Java
package com.yunbao.live.views;
|
|
|
|
import android.app.Activity;
|
|
import android.content.Context;
|
|
import android.text.TextUtils;
|
|
import android.util.Log;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.widget.ImageView;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.RelativeLayout;
|
|
import android.widget.TextView;
|
|
|
|
import androidx.recyclerview.widget.GridLayoutManager;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.yunbao.common.bean.AnchorRecommendModel;
|
|
import com.yunbao.common.bean.IMLoginModel;
|
|
import com.yunbao.common.bean.LiveBean;
|
|
import com.yunbao.common.bean.SetAttentsModel;
|
|
import com.yunbao.common.event.CloseEvent;
|
|
import com.yunbao.common.glide.ImgLoader;
|
|
import com.yunbao.common.http.base.HttpCallback;
|
|
import com.yunbao.common.http.live.LiveNetManager;
|
|
import com.yunbao.common.http.main.MainNetManager;
|
|
import com.yunbao.common.manager.IMLoginManager;
|
|
import com.yunbao.common.utils.Bus;
|
|
import com.yunbao.common.utils.MicStatusManager;
|
|
import com.yunbao.common.utils.RouteUtil;
|
|
import com.yunbao.common.utils.StringUtil;
|
|
import com.yunbao.common.utils.ToastUtil;
|
|
import com.yunbao.common.views.AbsViewHolder;
|
|
import com.yunbao.common.views.weight.ClipPathCircleImage;
|
|
import com.yunbao.live.R;
|
|
import com.yunbao.live.activity.LiveAnchorActivity;
|
|
import com.yunbao.live.activity.LiveAudienceActivity;
|
|
import com.yunbao.live.activity.LiveRyAnchorActivity;
|
|
import com.yunbao.live.adapter.SearchRecommendBodyAdapter;
|
|
import com.yunbao.live.event.JumpUserHomeEvent;
|
|
import com.yunbao.common.event.LiveRoomChangeEvent;
|
|
import com.yunbao.common.http.LiveHttpConsts;
|
|
import com.yunbao.common.http.LiveHttpUtil;
|
|
import com.yunbao.common.utils.LiveRoomCheckLivePresenter;
|
|
|
|
import org.greenrobot.eventbus.EventBus;
|
|
import org.greenrobot.eventbus.Subscribe;
|
|
import org.greenrobot.eventbus.ThreadMode;
|
|
|
|
/**
|
|
* Created by cxf on 2018/10/9.
|
|
*/
|
|
|
|
public class LiveEndViewHolder extends AbsViewHolder implements View.OnClickListener {
|
|
|
|
private ImageView mAvatar1;
|
|
//直播类型
|
|
private static LiveOfType type;
|
|
|
|
private static TextView liveDurationUser, liveNameUser,
|
|
goHomeUser, anchorName, liveDurationAnchor, liveVotes, liveWatchNum;
|
|
private RelativeLayout userLiveEnd, anchorLiveEnd;
|
|
private ClipPathCircleImage clipImageUser, clipImageanchor;
|
|
private LinearLayout followUser, listShow;
|
|
private ImageView changeBatchUser;
|
|
private RecyclerView likeList;
|
|
private SearchRecommendBodyAdapter adapter;
|
|
private IMLoginModel model = null;
|
|
|
|
public LiveEndViewHolder(Context context, ViewGroup parentView, String uid) {
|
|
super(context, parentView);
|
|
model = IMLoginManager.get(mContext).getUserInfo();
|
|
if (TextUtils.equals(model.getId() + "", uid)) {
|
|
type = LiveOfType.ANCHOR;
|
|
} else {
|
|
type = LiveOfType.USER;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected int getLayoutId() {
|
|
return R.layout.view_live_end;
|
|
}
|
|
|
|
@Override
|
|
public void init() {
|
|
Bus.getOn(this);
|
|
mAvatar1 = (ImageView) findViewById(R.id.avatar_1);
|
|
userLiveEnd = (RelativeLayout) findViewById(R.id.user_live_end);
|
|
anchorLiveEnd = (RelativeLayout) findViewById(R.id.anchor_live_end);
|
|
if (type == LiveOfType.USER) {
|
|
initViewOfUser();
|
|
initDataOfUser();
|
|
anchorLiveEnd.setVisibility(View.GONE);
|
|
} else {
|
|
userLiveEnd.setVisibility(View.GONE);
|
|
initViewOfAnchor();
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* 加载用户猜你喜欢数据
|
|
*/
|
|
private void initDataOfUser() {
|
|
MainNetManager.get((Activity) mContext)
|
|
.anchorRecommend("3", new HttpCallback<AnchorRecommendModel>() {
|
|
@Override
|
|
public void onSuccess(AnchorRecommendModel data) {
|
|
if (((Activity) mContext).isFinishing()) return;
|
|
if (data.getListShow() == 1) {
|
|
listShow.setVisibility(View.VISIBLE);
|
|
} else {
|
|
listShow.setVisibility(View.GONE);
|
|
}
|
|
if (data.getUpShow() == 1) {
|
|
changeBatchUser.setVisibility(View.VISIBLE);
|
|
} else {
|
|
changeBatchUser.setVisibility(View.GONE);
|
|
}
|
|
if (data.getList().size() > 2) {
|
|
listShow.setVisibility(View.VISIBLE);
|
|
//组装搜索历史数据
|
|
adapter.showData(data.getList());
|
|
} else {
|
|
listShow.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onError(String error) {
|
|
ToastUtil.show( R.string.net_error);
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 用户界面控件初始化
|
|
*/
|
|
private void initViewOfUser() {
|
|
liveDurationUser = (TextView) findViewById(R.id.live_duration_user);
|
|
|
|
liveNameUser = (TextView) findViewById(R.id.live_name_user);
|
|
goHomeUser = (TextView) findViewById(R.id.go_home_user);
|
|
|
|
clipImageUser = (ClipPathCircleImage) findViewById(R.id.clip_image_user);
|
|
|
|
followUser = (LinearLayout) findViewById(R.id.follow_user);
|
|
listShow = (LinearLayout) findViewById(R.id.list_show);
|
|
changeBatchUser = (ImageView) findViewById(R.id.change_batch_user);
|
|
likeList = (RecyclerView) findViewById(R.id.like_list);
|
|
goHomeUser.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
if (mContext instanceof LiveAnchorActivity) {
|
|
((LiveAnchorActivity) mContext).superBackPressed();
|
|
} else if (mContext instanceof LiveAudienceActivity) {
|
|
((LiveAudienceActivity) mContext).exitLiveRoom();
|
|
} else if (mContext instanceof LiveRyAnchorActivity) {
|
|
((LiveRyAnchorActivity) mContext).superBackPressed();
|
|
|
|
}
|
|
Bus.get().post(new CloseEvent());
|
|
}
|
|
});
|
|
GridLayoutManager gridLayoutManager = new GridLayoutManager(mContext, 3);
|
|
likeList.setLayoutManager(gridLayoutManager);
|
|
adapter = new SearchRecommendBodyAdapter((Activity) mContext);
|
|
likeList.setAdapter(adapter);
|
|
changeBatchUser.setOnClickListener(v -> initDataOfUser());
|
|
|
|
}
|
|
|
|
/**
|
|
* 主播界面控件初始化
|
|
*/
|
|
private void initViewOfAnchor() {
|
|
clipImageanchor = (ClipPathCircleImage) findViewById(R.id.clip_image_anchor);
|
|
anchorName = (TextView) findViewById(R.id.anchor_name);
|
|
liveDurationAnchor = (TextView) findViewById(R.id.live_duration_anchor);
|
|
liveVotes = (TextView) findViewById(R.id.live_votes);
|
|
liveWatchNum = (TextView) findViewById(R.id.live_watch_num);
|
|
findViewById(R.id.go_home_anchor)
|
|
.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
if (mContext instanceof LiveAnchorActivity) {
|
|
((LiveAnchorActivity) mContext).superBackPressed();
|
|
} else if (mContext instanceof LiveAudienceActivity) {
|
|
((LiveAudienceActivity) mContext).exitLiveRoom();
|
|
} else if (mContext instanceof LiveRyAnchorActivity) {
|
|
((LiveRyAnchorActivity) mContext).superBackPressed();
|
|
|
|
}
|
|
Bus.get().post(new CloseEvent());
|
|
}
|
|
});
|
|
}
|
|
|
|
public static void upData(String votes, String length, int nums, String uname) {
|
|
Log.e("收", votes + "votes" + length + "length" + nums + "nums");
|
|
if (type == LiveOfType.USER) {
|
|
if (liveDurationUser != null) {
|
|
liveDurationUser.setText(length);
|
|
}
|
|
if (liveNameUser != null) {
|
|
liveNameUser.setText(uname);
|
|
}
|
|
} else {
|
|
if (liveDurationAnchor != null) {
|
|
liveDurationAnchor.setText(length);
|
|
}
|
|
if (liveVotes != null) {
|
|
liveVotes.setText(votes);
|
|
}
|
|
if (liveWatchNum != null) {
|
|
liveWatchNum.setText(StringUtil.toWan(nums));
|
|
}
|
|
}
|
|
}
|
|
|
|
public void upData(String votes, String length, long nums) {
|
|
Log.e("收", votes + "votes" + length + "length" + nums + "nums");
|
|
if (type == LiveOfType.USER) {
|
|
if (liveDurationUser != null) {
|
|
liveDurationUser.setText(length);
|
|
}
|
|
|
|
} else {
|
|
if (liveDurationAnchor != null) {
|
|
liveDurationAnchor.setText(length);
|
|
}
|
|
if (liveVotes != null) {
|
|
liveVotes.setText(votes);
|
|
}
|
|
if (liveWatchNum != null) {
|
|
liveWatchNum.setText(StringUtil.toWan(nums));
|
|
}
|
|
}
|
|
}
|
|
|
|
public void showData(LiveBean liveBean, final String stream) {
|
|
if (TextUtils.equals(model.getId() + "", liveBean.getUid())) {
|
|
type = LiveOfType.ANCHOR;
|
|
} else {
|
|
type = LiveOfType.USER;
|
|
}
|
|
if (type == LiveOfType.USER) {
|
|
initViewOfUser();
|
|
initDataOfUser();
|
|
anchorLiveEnd.setVisibility(View.GONE);
|
|
userLiveEnd.setVisibility(View.VISIBLE);
|
|
} else {
|
|
anchorLiveEnd.setVisibility(View.VISIBLE);
|
|
userLiveEnd.setVisibility(View.GONE);
|
|
initViewOfAnchor();
|
|
}
|
|
if (liveBean != null && type == LiveOfType.USER) {
|
|
model = IMLoginManager.get(mContext).getUserInfo();
|
|
|
|
ImgLoader.displayAvatar(mContext, liveBean.getAvatar(), clipImageUser);
|
|
|
|
followUser.setVisibility(TextUtils.equals(liveBean.getIsattention(), "1") ? View.GONE : View.VISIBLE);
|
|
followUser.setOnClickListener(v -> {
|
|
LiveNetManager.get(mContext)
|
|
.setAttents(String.valueOf(liveBean.getUid()), new HttpCallback<SetAttentsModel>() {
|
|
@Override
|
|
public void onSuccess(SetAttentsModel data) {
|
|
followUser.setVisibility(View.GONE);
|
|
}
|
|
|
|
@Override
|
|
public void onError(String error) {
|
|
}
|
|
});
|
|
});
|
|
} else {
|
|
anchorName.setText(liveBean.getUserNiceName());
|
|
ImgLoader.displayAvatar(mContext, liveBean.getAvatar(), clipImageanchor);
|
|
}
|
|
ImgLoader.displayBlur(mContext, liveBean.getAvatar(), mAvatar1);
|
|
}
|
|
|
|
@Override
|
|
public void onClick(View v) {
|
|
if (mContext instanceof LiveAnchorActivity) {
|
|
((LiveAnchorActivity) mContext).superBackPressed();
|
|
} else if (mContext instanceof LiveAudienceActivity) {
|
|
((LiveAudienceActivity) mContext).exitLiveRoom();
|
|
} else if (mContext instanceof LiveRyAnchorActivity) {
|
|
((LiveRyAnchorActivity) mContext).superBackPressed();
|
|
|
|
}
|
|
Bus.get().post(new CloseEvent());
|
|
}
|
|
|
|
@Override
|
|
public void onDestroy() {
|
|
LiveHttpUtil.cancel(LiveHttpConsts.GET_LIVE_END_INFO);
|
|
Bus.getOff(this);
|
|
}
|
|
|
|
/**
|
|
* 结束的类型
|
|
*/
|
|
public enum LiveOfType {
|
|
USER(0, "用户"),
|
|
ANCHOR(1, "主播");
|
|
private int type = 0;
|
|
private String name = "";
|
|
|
|
LiveOfType(int type, String name) {
|
|
this.type = type;
|
|
this.name = name;
|
|
}
|
|
|
|
public int getType() {
|
|
return type;
|
|
}
|
|
|
|
public LiveOfType setType(int type) {
|
|
this.type = type;
|
|
return this;
|
|
}
|
|
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
|
|
public LiveOfType setName(String name) {
|
|
this.name = name;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 跳转用户首页
|
|
*/
|
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
public void onJumpUserHome(JumpUserHomeEvent event) {
|
|
LiveHttpUtil.getLiveInfo(event.getModel().getId() + "", new com.yunbao.common.http.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);
|
|
|
|
new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() {
|
|
@Override
|
|
public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk) {
|
|
if (liveBean == null) {
|
|
return;
|
|
}
|
|
if (MicStatusManager.getInstance().isMic(liveUid)) {
|
|
MicStatusManager.getInstance().showDownMicDialog(mContext);
|
|
return;
|
|
}
|
|
EventBus.getDefault().post(new LiveRoomChangeEvent(liveBean, liveType, Integer.parseInt(liveTypeVal)).setLiveEnd(true));
|
|
}
|
|
|
|
@Override
|
|
public void onCheckError(String contextError) {
|
|
|
|
}
|
|
});
|
|
Bus.get().post(new CloseEvent());
|
|
} else {
|
|
Bus.get().post(new CloseEvent());
|
|
RouteUtil.forwardUserHome(mContext, String.valueOf(event.getModel().getId()), 0);
|
|
if (mContext instanceof LiveAnchorActivity) {
|
|
((LiveAnchorActivity) mContext).superBackPressed();
|
|
} else if (mContext instanceof LiveAudienceActivity) {
|
|
((LiveAudienceActivity) mContext).exitLiveRoom();
|
|
} else if (mContext instanceof LiveRyAnchorActivity) {
|
|
((LiveRyAnchorActivity) mContext).superBackPressed();
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
|
|
}
|
|
|
|
}
|