package com.bw.zhuangao4yuekaofuxi_3.zhibo.view;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.Constraints;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.blankj.utilcode.util.SPUtils;
import com.bumptech.glide.Glide;
import com.bw.lib_common.db.entivity.Meoyinof;
import com.bw.lib_common.db.entiy.DanMuEntiy;
import com.bw.lib_common.db.entiy.LiWuEnity;
import com.bw.lib_common.db.entiy.VideoEntiy;
import com.bw.lib_common.ent.DBList;
import com.bw.lib_common.ent.HuanXinEntiy;
import com.bw.lib_mvp.view.BaseMvpActivity;
import com.bw.zhuangao4yuekaofuxi_3.R;
import com.bw.zhuangao4yuekaofuxi_3.zhibo.adapter.HuanxinAdapter;
import com.bw.zhuangao4yuekaofuxi_3.zhibo.adapter.ZhiBoAdapter;
import com.bw.zhuangao4yuekaofuxi_3.zhibo.presenter.ZhiBoLc;
import com.bw.zhuangao4yuekaofuxi_3.zhibo.presenter.ZhiBoPresenter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemChildClickListener;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.hyphenate.EMCallBack;
import com.hyphenate.EMChatRoomChangeListener;
import com.hyphenate.EMMessageListener;
import com.hyphenate.EMValueCallBack;
import com.hyphenate.chat.EMChatRoom;
import com.hyphenate.chat.EMClient;
import com.hyphenate.chat.EMCustomMessageBody;
import com.hyphenate.chat.EMMessage;
import com.hyphenate.chat.core.EMChatConfigPrivate;
import com.kaisengao.likeview.like.KsgLikeView;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import master.flame.danmaku.controller.DrawHandler;
import master.flame.danmaku.danmaku.model.BaseDanmaku;
import master.flame.danmaku.danmaku.model.DanmakuTimer;
import master.flame.danmaku.danmaku.model.IDanmakus;
import master.flame.danmaku.danmaku.model.android.DanmakuContext;
import master.flame.danmaku.danmaku.model.android.Danmakus;
import master.flame.danmaku.danmaku.parser.BaseDanmakuParser;
import master.flame.danmaku.ui.widget.DanmakuView;
@Route(path = "/app/ZhiBoActivity")
public class ZhiBoActivity extends BaseMvpActivity<ZhiBoPresenter>implements ZhiBoLc.V {
@Autowired
VideoEntiy videoentiy;
private ConstraintLayout zong;
private StandardGSYVideoPlayer stazhi;
private ConstraintLayout constraintLayout;
private ImageView zhibotouxiang;
private TextView zhibozuozhe;
private TextView dianznanum;
private Button zhiboguanzhu;
private DanmakuView zhibodianmu;
private LinearLayout linearLayout;
private EditText liaotianed;
private ImageView liaotianfasong;
private ImageView zhibodanmu;
private ImageView zhiboliwu;
private ImageView zuobidianzan;
private KsgLikeView quxian;
private RecyclerView liaotian;
private LinearLayout liwulIN;
private TextView yve;
private ImageView liwuzhao;
private TextView liwuqian;
private TextView guan;
private RecyclerView recliwu;
private Button liwufasong;
private Button chongzhi;
private LinearLayout danmufasong;
private EditText zhibodianmued;
private ImageView zhibodianmufasong;
private DanmakuContext danmakuContext;
private ZhiBoAdapter zhiBoAdapter;
private List<LiWuEnity>liWuEnityList=new ArrayList<>();
private LiWuEnity liWuEnity;
private String hxid="221833963044866";
private HuanxinAdapter huanxinAdapter;
private List<HuanXinEntiy>huanXinEntiyList=new ArrayList<>();
@Override
protected void initView() {
initId();
ARouter.getInstance().inject(this);
}
@Override
protected void initData() {
/**
* 视频
*/
stazhi.setUp(videoentiy.getVideopath(),false,"");
stazhi.getBackButton().setVisibility(View.GONE);
stazhi.startPlayLogic();
/**
* 头像
*/
Glide.with(this).load(videoentiy.getHeadpath()).circleCrop().into(zhibotouxiang);
/**
* 点赞数
*/
dianznanum.setText("1.3W");
/**
* 作者
*/
zhibozuozhe.setText(videoentiy.getAuthname());
/**
* 初始化弹幕
*/
initDan();
//金钱展示
int userid = SPUtils.getInstance().getInt("userid");
Meoyinof meoyinof= DBList.getDbList().meoycha(userid);
yve.setText(meoyinof.getMeoyqian()+"");
/**
* 初始化聊天室
*/
iniHuan();
/**
* 礼物延迟
*/
zhiboliwu.postDelayed(new Runnable() {
@Override
public void run() {
presenter.LiWuEnity();
}
},500);
}
private void initDan() {
zhibodianmu.clear();
danmakuContext=DanmakuContext.create();
zhibodianmu.prepare(new BaseDanmakuParser() {
@Override
protected IDanmakus parse() {
return new Danmakus();
}
},danmakuContext);
zhibodianmu.setCallback(new DrawHandler.Callback() {
@Override
public void prepared() {
/**
* 启动
*/
zhibodianmu.start();
//请求
presenter.DanMuEntiy(videoentiy.getId());
}
@Override
public void updateTimer(DanmakuTimer timer) {
}
@Override
public void danmakuShown(BaseDanmaku danmaku) {
}
@Override
public void drawingFinished() {
}
});
}
@Override
protected ZhiBoPresenter creastpresenter() {
return new ZhiBoPresenter();
}
@Override
protected int getLayouId() {
return R.layout.activity_zhi_bo;
}
/**
* 各种方法成功失败
* @param liWuEnities
*/
@Override
public void LiWuCheng(ArrayList<LiWuEnity> liWuEnities) {
liWuEnityList.addAll(liWuEnities);
zhiBoAdapter.notifyDataSetChanged();
}
@Override
public void LiWuBai(String error) {
onError("没有礼物数据");
}
@Override
public void DanMuEntiyCheng(ArrayList<DanMuEntiy> danMuEntiys) {
if(danMuEntiys!=null){
BaseDanmaku danmaku;
for(DanMuEntiy danMuEntiy:danMuEntiys){
danmaku=danmakuContext.mDanmakuFactory.createDanmaku(DanmakuView.LAYOUT_DIRECTION_RTL,danmakuContext);
danmaku.text=danMuEntiy.getText();
danmaku.textColor= Color.WHITE;
danmaku.textSize=35f;
zhibodianmu.addDanmaku(danmaku);
}
zhibodianmu.start();
}
}
@Override
public void DanMuEntiyBai(String error) {
onError("弹幕没有数据");
}
/**
* 全局ID
*/
private void initId() {
zong = (ConstraintLayout) findViewById(R.id.zong);
stazhi = (StandardGSYVideoPlayer) findViewById(R.id.stazhi);
constraintLayout = (ConstraintLayout) findViewById(R.id.constraintLayout);
zhibotouxiang = (ImageView) findViewById(R.id.zhibotouxiang);
dianznanum = (TextView) findViewById(R.id.dianznanum);
zhiboguanzhu = (Button) findViewById(R.id.zhiboguanzhu);
zhibodianmu = (DanmakuView) findViewById(R.id.zhibodianmu);
linearLayout = (LinearLayout) findViewById(R.id.linearLayout);
liaotianed = (EditText) findViewById(R.id.liaotianed);
liaotianfasong = (ImageView) findViewById(R.id.liaotianfasong);
zhibodanmu = (ImageView) findViewById(R.id.zhibodanmu);
zhiboliwu = (ImageView) findViewById(R.id.zhiboliwu);
zuobidianzan = (ImageView) findViewById(R.id.zuobidianzan);
quxian = (KsgLikeView) findViewById(R.id.quxian);
liaotian = (RecyclerView) findViewById(R.id.liaotian);
liwulIN = (LinearLayout) findViewById(R.id.liwulIN);
yve = (TextView) findViewById(R.id.yve);
liwuzhao = (ImageView) findViewById(R.id.liwuzhao);
liwuqian = (TextView) findViewById(R.id.liwuqian);
guan = (TextView) findViewById(R.id.guan);
recliwu = (RecyclerView) findViewById(R.id.recliwu);
liwufasong = (Button) findViewById(R.id.liwufasong);
chongzhi = (Button) findViewById(R.id.chongzhi);
danmufasong = (LinearLayout) findViewById(R.id.danmufasong);
zhibodianmued = (EditText) findViewById(R.id.zhibodianmued);
zhibodianmufasong = (ImageView) findViewById(R.id.zhibodianmufasong);
/**
* 礼物展示赋值
*/
recliwu.setLayoutManager(new GridLayoutManager(this,3));
zhiBoAdapter=new ZhiBoAdapter(R.layout.im_item_zhio,liWuEnityList);
recliwu.setAdapter(zhiBoAdapter);
//点击礼物赋值
zhiBoAdapter.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
liWuEnity=zhiBoAdapter.getData().get(position);
Glide.with(ZhiBoActivity.this).load(liWuEnity.getGiftpath()).into(liwuzhao);
liwuqian.setText(liWuEnity.getPrice()+"抖币");
}
});
liwufasong.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int userid = SPUtils.getInstance().getInt("userid");
Meoyinof meoyinof= DBList.getDbList().meoycha(userid);
if(meoyinof.getMeoyqian()>liWuEnity.getPrice()){
float v=meoyinof.getMeoyqian()-liWuEnity.getPrice();
meoyinof.setMeoyqian(v);
DBList.getDbList().meoyupdate(meoyinof);
yve.setText(v+"");
ImageView imageView=new ImageView(ZhiBoActivity.this);
ConstraintLayout.LayoutParams layoutParams=new Constraints.LayoutParams(200,200);
imageView.setLayoutParams(layoutParams);
Glide.with(ZhiBoActivity.this).load(liWuEnity.getGiftpath()).circleCrop().into(imageView);
zong.addView(imageView);
ObjectAnimator animator=ObjectAnimator.ofFloat(imageView,"Rotation",0,360);
AnimatorSet animatorSet=new AnimatorSet();
animatorSet.setDuration(2000);
animatorSet.play(animator);
animatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationCancel(Animator animation) {
super.onAnimationCancel(animation);
}
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
if(imageView!=null){
zong.removeView(imageView);
}
}
@Override
public void onAnimationRepeat(Animator animation) {
super.onAnimationRepeat(animation);
}
@Override
public void onAnimationStart(Animator animation) {
super.onAnimationStart(animation);
}
});
animatorSet.start();
}else {
onError("余额不足请充值");
}
}
});
//曲线添加礼物图片
quxian.addLikeImages(
R.drawable.gift_9,
R.drawable.ic_gift,
R.drawable.ic_gouwuche,
R.drawable.ic_shoucangyellow,
R.drawable.ic_xihuanred
);
//发送弹幕
zhibodanmu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
danmufasong.setVisibility(View.VISIBLE);
}
});
zhibodianmufasong.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String s = zhibodianmued.getText().toString();
BaseDanmaku danmaku;
danmaku=danmakuContext.mDanmakuFactory.createDanmaku(DanmakuView.LAYOUT_DIRECTION_RTL,danmakuContext);
danmaku.text=s;
danmaku.textSize=35f;
danmaku.textColor=Color.WHITE;
zhibodianmu.addDanmaku(danmaku);
zhibodianmu.start();
danmufasong.setVisibility(View.GONE);
}
});
//发送爱心
zuobidianzan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
quxian.addFavor();
}
});
//打开礼物
zhiboliwu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
liwulIN.setVisibility(View.VISIBLE);
}
});
//关闭礼物页面
guan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
liwulIN.setVisibility(View.GONE);
}
});
//充值
chongzhi.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ARouter.getInstance().build("/app/ZhifuActivity").navigation();
}
});
/**
* 环信消息
*/
huanxinAdapter=new HuanxinAdapter(R.layout.im_tiem_huanxin,huanXinEntiyList);
liaotian.setAdapter(huanxinAdapter);
LinearLayoutManager linearLayoutManager=new LinearLayoutManager(this);
linearLayoutManager.setStackFromEnd(true);
liaotian.setLayoutManager(linearLayoutManager);
/**
* 环信发送
*/
liaotianfasong.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
runOnUiThread(new Runnable() {
@Override
public void run() {
String s = liaotianed.getText().toString();
String cuerr= EMClient.getInstance().getCurrentUser();
HashMap<String,String>map=new HashMap<>();
map.put("message",s);
Modes(hxid, "text", map, new EMCallBack() {
@Override
public void onSuccess() {
runOnUiThread(new Runnable() {
@Override
public void run() {
liaotianed.setText("");
HuanXinEntiy huanXinEntiy=new HuanXinEntiy(cuerr,s);
huanxinAdapter.getData().add(huanXinEntiy);
huanxinAdapter.notifyDataSetChanged();
liaotian.scrollToPosition(huanxinAdapter.getData().size()-1);
}
});
}
@Override
public void onError(int code, String error) {
}
});
}
});
}
});
}
/**
* 环信初始化
*/
private void iniHuan() {
new Thread(new Runnable() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
EMClient.getInstance().chatroomManager().joinChatRoom(hxid, new EMValueCallBack<EMChatRoom>() {
@Override
public void onSuccess(EMChatRoom value) {
// 注册聊天室回调
EMClient.getInstance().chatroomManager().addChatRoomChangeListener(roomChangeListener);
//消息
EMClient.getInstance().chatManager().addMessageListener(messageListener);
}
@Override
public void onError(int error, String errorMsg) {
ZhiBoActivity.this.onError("加入失败");
}
});
}
});
}
}).start();
}
/**
* 消息监听
*/
EMMessageListener messageListener=new EMMessageListener() {
@Override
public void onMessageReceived(List<EMMessage> messages) {
runOnUiThread(new Runnable() {
@Override
public void run() {
for (EMMessage emMessage:messages){
//姓名
String name=emMessage.getFrom();
//消息
EMCustomMessageBody body= (EMCustomMessageBody) emMessage.getBody();
//键位值
Map<String,String>map=body.getParams();
//实体类
String vent=body.event();
HuanXinEntiy huanXinEntiy=null;
String message=map.get("message");
if("text".equals(vent)){
huanXinEntiy=new HuanXinEntiy(name,message);
}
if(huanXinEntiy!=null){
huanxinAdapter.getData().add(huanXinEntiy);
huanxinAdapter.notifyDataSetChanged();
liaotian.scrollToPosition(huanxinAdapter.getData().size()-1);
}
}
}
});
}
};
/**
* 聊天室监听
*/
EMChatRoomChangeListener roomChangeListener=new EMChatRoomChangeListener() {
@Override
public void onChatRoomDestroyed(String roomId, String roomName) {
}
@Override
public void onMemberJoined(String roomId, String participant) {
Map<String,String>map=new HashMap<>();
map.put("message",participant+"加入聊天室");
Modes(hxid,"text",map,null);
}
@Override
public void onMemberExited(String roomId, String roomName, String participant) {
Map<String,String>map=new HashMap<>();
map.put("message",participant+"退出聊天室");
Modes(hxid,"text",map,null);
}
@Override
public void onRemovedFromChatRoom(int reason, String roomId, String roomName, String participant) {
}
@Override
public void onMuteListAdded(String chatRoomId, List<String> mutes, long expireTime) {
}
@Override
public void onMuteListRemoved(String chatRoomId, List<String> mutes) {
}
@Override
public void onWhiteListAdded(String chatRoomId, List<String> whitelist) {
}
@Override
public void onWhiteListRemoved(String chatRoomId, List<String> whitelist) {
}
@Override
public void onAllMemberMuteStateChanged(String chatRoomId, boolean isMuted) {
}
@Override
public void onAdminAdded(String chatRoomId, String admin) {
}
@Override
public void onAdminRemoved(String chatRoomId, String admin) {
}
@Override
public void onOwnerChanged(String chatRoomId, String newOwner, String oldOwner) {
}
@Override
public void onAnnouncementChanged(String chatRoomId, String announcement) {
}
};
public void Modes(String to, String event, Map<String ,String> params, EMCallBack emClient){
EMMessage customMessage = EMMessage.createSendMessage(EMMessage.Type.CUSTOM);
// `event` 为需要传递的自定义消息事件,比如礼物消息,可以设置:
EMCustomMessageBody customBody = new EMCustomMessageBody(event);
// `params` 类型为 `Map<String, String>`。
customBody.setParams(params);
customMessage.addBody(customBody);
// `to` 指另一方环信用户 ID(或者群组 ID,聊天室 ID)
customMessage.setTo(to);
// 如果是群聊,设置 `ChatType` 为 `GroupChat`,该参数默认是单聊(`Chat`)。
customMessage.setChatType(EMMessage.ChatType.ChatRoom);
if(emClient!=null){
customMessage.setMessageStatusCallback(emClient);
}
// 发送消息
EMClient.getInstance().chatManager().sendMessage(customMessage);
}
}
专高4直播页面聊天
最新推荐文章于 2024-08-18 21:00:02 发布