f617dabe9e81c28507ad3860971855982a784d00.svn-base
14.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
/**
* @author 郎咸智
* 下午4:16:53
*/
package com.ivt.android.me.model.seelive;
import java.util.ArrayList;
import java.util.List;
import org.jivesoftware.smackx.muc.MultiUserChat;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import com.ivt.android.me.MainApplication;
import com.ivt.android.me.R;
import com.ivt.android.me.api.LiveApiBean;
import com.ivt.android.me.bean.BeanUser;
import com.ivt.android.me.bean.ChatMessageBean;
import com.ivt.android.me.bean.DanmuBean;
import com.ivt.android.me.bean.JoinRoomBean;
import com.ivt.android.me.bean.JoinRoomEntity;
import com.ivt.android.me.bean.LiveDataBean;
import com.ivt.android.me.bean.MeMessage;
import com.ivt.android.me.bean.Min;
import com.ivt.android.me.bean.UserBean;
import com.ivt.android.me.bean.UserEntity;
import com.ivt.android.me.constant.BaseInfo;
import com.ivt.android.me.constant.CodeUtils;
import com.ivt.android.me.constant.XmppType;
import com.ivt.android.me.model.uplive.LiveView;
import com.ivt.android.me.ui.activity.seelive.SeeLiveActivity;
import com.ivt.android.me.ui.dialog.RedPDialog;
import com.ivt.android.me.ui.dialog.UpliveCloseTrueDialog;
import com.ivt.android.me.ui.myview.BarrageLayout;
import com.ivt.android.me.ui.myview.GifTool;
import com.ivt.android.me.ui.myview.GiftShowTool;
import com.ivt.android.me.utils.httputil.HttpUtils;
import com.ivt.android.me.utils.httputil.HttpUtils.HttpCallback;
import com.ivt.android.me.utils.httputil.JsonUtils;
import com.ivt.android.me.utils.publics.LogUtil;
import com.ivt.android.me.utils.publics.MyToastUtils;
import com.ivt.android.me.utils.publics.SharePreferenceUtil;
import com.ivt.android.me.utils.xmpp.XmppConnectionTool;
import com.ivt.android.me.utils.xmpp.XmppMessageType;
/**
* @author 郎咸智
* @version 创建时间:2016-8-25 下午4:16:53 类说明
*/
public class SeeLiveModle implements ISeeLiveFragment {
public static UserEntity owner = new UserEntity();
private LiveView liveView;
public LiveDataBean dataBean;
private MultiUserChat muc;
private BarrageLayout danmakuLayout;
private DanmuBean danmu;
private LinearLayout flLayout;
private ImageView bigIv;
private RedPDialog dialog;
private UpliveCloseTrueDialog closedia;
private Context context;
private GiftShowTool gst;
private GifTool gif;
private String liveId;
private String roomid;
private String ownerId;
private boolean isChatAuth = false;
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case CodeUtils.XMPP_MSG_IN:
Bundle bd = msg.getData();
String body = bd.getString("msg");
receiveMsg(body);
break;
case 0:
isChatAuth = (boolean) msg.obj;
if (isChatAuth) {
MyToastUtils.showToast(context, "你已经被禁言");
}
break;
case 1:
dataBean.setMemberList((ArrayList<String>) XmppConnectionTool
.getInstance().findMulitUser(muc));
dataBean.setRoomPeopleNums(dataBean.getMemberList().size());
liveView.initHeadView();
liveView.notifyNums();
break;
}
}
};
public SeeLiveModle(@NonNull LiveView liveView, View view, Context context) {
super();
this.liveView = liveView;
this.context = context;
this.liveId = SeeLiveActivity.liveId;
this.roomid = SeeLiveActivity.jid;
this.ownerId = SeeLiveActivity.ownerId;
dataBean = new LiveDataBean();
danmakuLayout = (BarrageLayout) view.findViewById(R.id.dmv);
bigIv = (ImageView) view.findViewById(R.id.gift_iv);
flLayout = (LinearLayout) view.findViewById(R.id.gift_item);
}
@Override
public JoinRoomEntity GetOwnerInfo() {
return dataBean.getRoominfo();
}
@Override
public void JoinRoom() {
// 请求的路径
String requestUrl = LiveApiBean.loginLiveRoom(BaseInfo.UserId,
BaseInfo.Captcha, liveId, ownerId);
HttpUtils.get(requestUrl, new HttpCallback() {
@Override
public void onSuccess(String data) {
JoinRoomBean bean = JsonUtils.deserialize(data,
JoinRoomBean.class);
if (bean.getCode() == 0) {
dataBean.setRoominfo(bean.getData());
dataBean.setMeTang(dataBean.getRoominfo().getMecointotal());
liveView.SetOwnerInfo();
liveView.notifyMetang();
} else if (bean.getCode() == 3001) {
Long mtt = (long) 0;
Long peoplenum = (long) 0;
if (bean.getMeTotal() != null) {
mtt = bean.getMeTotal();
}
if (bean.getAudienceTotalNum() != null) {
peoplenum = bean.getAudienceTotalNum();
}
if (closedia == null) {
closedia = new UpliveCloseTrueDialog(context,
R.style.dialog, 2, new Long(peoplenum).intValue(), new Long(mtt).intValue());
if (closedia != null) {
Activity a = (Activity) context;
if (!a.isFinishing()) {
closedia.show();
}
}
}
}
}
});
new Thread() {
public void run() {
muc = XmppConnectionTool.getInstance().joinRoom(roomid,
BaseInfo.UserId);
handler.sendEmptyMessage(1);
};
}.start();
XmppConnectionTool.getInstance().addGroupChatListener(handler);
gst = new GiftShowTool(context, flLayout);
gif = new GifTool(context, bigIv);
BaseInfo.Islive = false;
MainApplication.Islive = false;
}
public void agaJoinRoom() {
muc = XmppConnectionTool.getInstance().joinRoom(roomid, BaseInfo.UserId);
XmppConnectionTool.getInstance().addGroupChatListener(handler);
dataBean.setRoomPeopleNums(dataBean.getMemberList().size());
liveView.initHeadView();
liveView.notifyNums();
}
@Override
public void LeaveRoom() {
XmppConnectionTool.getInstance().removeGroupChatListener();
XmppConnectionTool.getInstance().leaveFromChatRoom(muc);
String requestUrl = LiveApiBean.logoutLiveRoom(BaseInfo.UserId,BaseInfo.Captcha, liveId, ownerId);
HttpUtils.get(requestUrl, new HttpCallback() {
@Override
public void onSuccess(String data) {
}
});
}
@Override
public String getRoomNums() {
return dataBean.getRoomPeopleNums() + "";
}
@Override
public List<BeanUser> getMucList() {
List<BeanUser> list = dataBean.getMucList();
return list;
}
@Override
public void receiveMsg(String msg) {
ChatMessageBean cmb = null;
try {
// 判断是否是合法的json格式
cmb = JsonUtils.deserialize(msg, ChatMessageBean.class);
} catch (Exception e) {
LogUtil.d("UpLiveModle", "这里收到了一条不合法的消息数据");
return;
}
LogUtil.d("监听聊天信息:===============" + cmb.toString());
XmppType type = cmb.getMsgType();
if (type == null) {
return;
}
String message = cmb.getMsgBody();
UserEntity user = cmb.getUserInfo();
switch (type) {
case kSystemMessageType:
dataBean.addMsg(new BeanUser(user.getUserId(), "直播消息", "", message,
XmppMessageType.COLOR_TYPE_XT, user.getLevel(), user));
break;
case kNormalRoomChatMessageType:
dataBean.addMsg(new BeanUser(user.getUserId(), user.getUserName(),
"", message, XmppMessageType.COLOR_TYPE_MSG, user
.getLevel(), user));
break;
case kDanMuRoomChatMessageType:
if (cmb.getMsgBody() == null) {
return;
}
synchronized (MainApplication.getInstance()) {
if (danmu != null) {
danmu = null;
}
danmu = new DanmuBean(user.getAvatar(), user.getUserName()
+ ":" + message);
danmakuLayout.addData(danmu);
danmakuLayout.startAnimator();
dataBean.addMsg(new BeanUser(user.getUserId(), user
.getUserName(), "", message,
XmppMessageType.COLOR_TYPE_BAR, user.getLevel(), user));
danmu = null;
}
break;
// case CodeUtils.XMMT_JOINROOM:
// break;
case kBigGiftType:
operation(cmb.getGiftNumber(), cmb.getGiftPrice());
gif.addGift(cmb.getGiftPic());
gif.showGifta();
dataBean.addMsg(new BeanUser(user.getUserId(), user.getUserName(),
"", message, XmppMessageType.COLOR_TYPE_GIF, user
.getLevel(), user));
break;
case kSmallGiftType:
// 参数1 为头像路径
MeMessage mem = new MeMessage(user.getAvatar(),
cmb.getGiftNumber(), message, cmb.getGiftPic(),
user.getUserName(), cmb.getMsgTime(), user.getUserId());
gst.addGift(mem);
// 发通知 让计算直播间的蜜糖数
operation(cmb.getGiftNumber(), cmb.getGiftPrice());
dataBean.addMsg(new BeanUser(user.getUserId(), user.getUserName(),
"", message, XmppMessageType.COLOR_TYPE_ANI, user
.getLevel(), user));
break;
case kPrivateRedPacketType:
dataBean.addMsg(new BeanUser(user.getUserId(), user.getUserName(),
"", message, XmppMessageType.COLOR_TYPE_SRHB, user
.getLevel(), user));
operation(cmb.getGiftNumber(), cmb.getGiftPrice());
break;
case kGroupRedPacketType:
int redid = cmb.getGiftId();
dataBean.addMsg(new BeanUser(user.getUserId(), user.getUserName(),
"", cmb.getMsgBody(), XmppMessageType.COLOR_TYPE_MSG, user
.getLevel(), user));
dataBean.addMsg(new BeanUser(user.getUserId(), user.getUserName(),
"", user.getAvatar(), XmppMessageType.COLOR_TYPE_REDP,
redid + "", user.getSex(), user.getLevel(), user));
if (redid != 0) {
dialog = null;
dialog = new RedPDialog(context, R.style.dialog, redid + "",
user.getUserName(), user.getAvatar(), user.getSex(),
user.getLevel());
if (dialog != null) {
Activity a = (Activity) context;
if (!a.isFinishing()) {
dialog.show();
}
}
}
break;
case kSetBanSendMessageType:
if (BaseInfo.UserId.equals(user.getUserId() + "")) {
isChatAuth = true;
MyToastUtils.showToast(context, "你已被禁言");
} else {
dataBean.addMsg(new BeanUser(user.getUserId(), "直播消息", user
.getUserName(), message,
XmppMessageType.COLOR_TYPE_MSG, user.getLevel(), user));
}
break;
case kCancelBanSendMessageType:
if (BaseInfo.UserId.equals(user.getUserId() + "")) {
isChatAuth = false;
MyToastUtils.showToast(context, "你已被取消禁言");
} else {
dataBean.addMsg(new BeanUser(user.getUserId(), "直播消息", user
.getUserName(), message,
XmppMessageType.COLOR_TYPE_MSG, user.getLevel(), user));
}
break;
case kSetManagerType:
if (BaseInfo.UserId.equals(user.getUserId() + "")) {
SharePreferenceUtil.setValue(context, "isAdmin" + liveId, true);
MyToastUtils.showToast(context, "你已成为管理员");
} else {
dataBean.addMsg(new BeanUser(user.getUserId(), "直播消息", user
.getUserName(), message,
XmppMessageType.COLOR_TYPE_MSG, user.getLevel(), user));
}
break;
case kCancelManagerType:
if (BaseInfo.UserId.equals(user.getUserId() + "")) {
SharePreferenceUtil
.setValue(context, "isAdmin" + liveId, false);
MyToastUtils.showToast(context, "你已被解除管理员权限");
} else {
dataBean.addMsg(new BeanUser(user.getUserId(), "直播消息", user
.getUserName(), message,
XmppMessageType.COLOR_TYPE_MSG, user.getLevel(), user));
}
break;
case kQuitRoomType:
if (!BaseInfo.UserId.equalsIgnoreCase(user.getUserId() + "")) {
if (closedia == null) {
closedia = new UpliveCloseTrueDialog(context,
R.style.dialog, 2, cmb.getGiftNumber(),
cmb.getGiftPrice());
if (closedia != null) {
Activity a = (Activity) context;
if (!a.isFinishing()) {
closedia.show();
}
}
}
}
break;
// case CodeUtils.XMMT_OWNER_LEAVE:// 主播暂时离开
// if (BaseInfo.UserId.equals(user.getUserId())) {
// return;
// }
// switch (mm.getGiftNums()) {
// case 1:
// live_leave.setVisibility(View.VISIBLE);
// // time.start();
// break;
// case 0:
// // time.cancel();
// live_leave.setVisibility(View.GONE);
// break;
// }
// break;
default:
break;
}
liveView.notifyMsg();
}
@Override
public void sendMsg(String msg, XmppType type) {
if (isChatAuth) {
MyToastUtils.showToast(context, "你已经被禁言");
return;
}
ChatMessageBean bean = new ChatMessageBean(msg, type);
String me = JsonUtils.serialize(bean);
try {
if (type == XmppType.kDanMuRoomChatMessageType) {
SendDanMu(me);
} else {
muc.sendMessage(me);
}
} catch (Exception e) {
e.printStackTrace();
agaJoinRoom();
}
}
public void sendMssg(ChatMessageBean bean) {
String me = JsonUtils.serialize(bean);
try {
muc.sendMessage(me);
} catch (Exception e) {
e.printStackTrace();
agaJoinRoom();
}
}
@Override
public List<String> getMemberList() {
return dataBean.getMemberList();
}
@Override
public void chechChatAuth(String userId) {
String requestUrl = LiveApiBean.chechChatAuth(userId, liveId);
HttpUtils.get(requestUrl, new HttpCallback() {
@Override
public void onSuccess(String data) {
Min mm = JsonUtils.deserialize(data, Min.class);
Message message = new Message();
message.what = 0;
message.obj = mm.isState();
handler.sendMessage(message);
}
});
}
private void SendDanMu(final String msgType) {
// 请求的路径
String requestUrl = LiveApiBean.sendBulletScreenMessage(
BaseInfo.UserId, BaseInfo.Captcha, Integer.parseInt(liveId));
HttpUtils.get(requestUrl, new HttpCallback() {
@Override
public void onSuccess(String data) {
// TODO Auto-generated method stub
UserBean user1 = JsonUtils.deserialize(data, UserBean.class);
if (user1.getCode() == 0) {
try {
muc.sendMessage(msgType);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
agaJoinRoom();
}
} else if (user1.getCode() == 1009) {
MyToastUtils.showToast(MainApplication.getInstance(),
"中国币不足,请充值");
} else {
MyToastUtils.showToast(MainApplication.getInstance(),
"发送失败");
}
}
@Override
public void onError(String msg) {
// TODO Auto-generated method stub
super.onError(msg);
MyToastUtils.showToast(MainApplication.getInstance(), "发送失败");
}
});
}
@Override
public void operation(int nums, int price) {
// TODO Auto-generated method stub
int meTang = nums * price;
int mt = dataBean.getMeTang();
int zongtang = meTang + mt;
dataBean.setMeTang(zongtang);
liveView.notifyMetang();
}
@Override
public int getMeTang() {
// TODO Auto-generated method stub
return dataBean.getMeTang();
}
}