11111
This commit is contained in:
@@ -6,7 +6,9 @@ import android.content.ClipboardManager;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
@@ -16,6 +18,7 @@ import android.widget.TextView;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.tencent.imsdk.conversation.ConversationManager;
|
||||
import com.yunbao.common.CommonAppConfig;
|
||||
import com.yunbao.common.Constants;
|
||||
import com.yunbao.common.activity.AbsActivity;
|
||||
@@ -88,6 +91,8 @@ import org.greenrobot.eventbus.ThreadMode;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import io.rong.imkit.utils.RouteUtils;
|
||||
|
||||
/**
|
||||
* Created by cxf on 2018/10/7.
|
||||
*/
|
||||
@@ -108,9 +113,6 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL
|
||||
protected LiveLinkMicAnchorPresenter mLiveLinkMicAnchorPresenter;//主播与主播连麦逻辑
|
||||
protected LiveLinkMicPkPresenter mLiveLinkMicPkPresenter;//主播与主播PK逻辑
|
||||
public static LiveRyLinkMicPkPresenter mLiveRyLinkMicPkPresenter;//主播与主播PK逻辑
|
||||
|
||||
// public static LiveLinkMicDrPkPresenter liveLinkMicDrPkPresenter;//多人PK
|
||||
// protected GamePresenter mGamePresenter;
|
||||
public static SocketClient mSocketClient;
|
||||
public static SocketRyClient mSocketRyClient;
|
||||
|
||||
@@ -129,7 +131,6 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL
|
||||
protected KeyBoardHeightUtil2 mKeyBoardHeightUtil;
|
||||
protected int mChatLevel;//发言等级限制
|
||||
protected int mDanMuLevel;//弹幕等级限制
|
||||
// private MobShareUtil mMobShareUtil;
|
||||
private ProcessImageUtil mImageUtil;
|
||||
private boolean mFirstConnectSocket;//是否是第一次连接成功socket
|
||||
private boolean mGamePlaying;//是否在游戏中
|
||||
@@ -301,16 +302,6 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL
|
||||
*/
|
||||
@Override
|
||||
public void onSendGift(LiveReceiveGiftBean bean) {
|
||||
// if (bean.isAllServerNotify()){
|
||||
// if (!mIsAnchor){
|
||||
// if (mLiveRoomViewHolder != null) {
|
||||
// //全服通知时,不显示聊天列表里面的 送礼 消息
|
||||
// //mLiveRoomViewHolder.insertChat(bean.getLiveChatBean());
|
||||
// mLiveRoomViewHolder.showGiftMessage(bean);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
|
||||
//购买守护
|
||||
if (bean.ismTypeBuyGuard()) {
|
||||
@@ -867,16 +858,10 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL
|
||||
|
||||
@Override
|
||||
public void onGameNz(JSONObject obj) {
|
||||
// if (mGamePresenter != null) {
|
||||
// mGamePresenter.onGameNzSocket(obj);
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGameEbb(JSONObject obj) {
|
||||
// if (mGamePresenter != null) {
|
||||
// mGamePresenter.onGameEbbSocket(obj);
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -898,7 +883,6 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL
|
||||
fragment.setArguments(bundle);
|
||||
fragment.show(getSupportFragmentManager(), "LiveInputDialogFragment");
|
||||
} else {
|
||||
// ToastUtil.show(getResources().getString(R.string.live_issend));
|
||||
showTaskDialog();
|
||||
}
|
||||
}
|
||||
@@ -934,40 +918,12 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL
|
||||
* 打开私信列表窗口
|
||||
*/
|
||||
public void openChatListWindow() {
|
||||
LiveChatListDialogFragment fragment = new LiveChatListDialogFragment();
|
||||
if (!mIsAnchor) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(Constants.LIVE_UID, mLiveUid);
|
||||
fragment.setArguments(bundle);
|
||||
}
|
||||
fragment.show(getSupportFragmentManager(), "LiveChatListDialogFragment");
|
||||
RouteUtils.registerActivity(RouteUtils.RongActivityType.ConversationActivity, PDLIiveChatActivity.class);
|
||||
Intent intent = new Intent(mContext, PDLIiveChatActivity.class);
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开私信聊天窗口
|
||||
*/
|
||||
public void openChatRoomWindow(UserBean userBean, boolean following) {
|
||||
ConfigBean configBean = CommonAppConfig.getInstance().getConfig();
|
||||
if (configBean == null) {
|
||||
return;
|
||||
}
|
||||
int letterSwitch = configBean.getPriMsgSwitch();
|
||||
if (letterSwitch == 0) {
|
||||
ToastUtil.show("私信功能暂不可用");
|
||||
return;
|
||||
}
|
||||
if (mKeyBoardHeightUtil == null) {
|
||||
mKeyBoardHeightUtil = new KeyBoardHeightUtil2(mContext, super.findViewById(android.R.id.content), this);
|
||||
mKeyBoardHeightUtil.start();
|
||||
}
|
||||
LiveChatRoomDialogFragment fragment = new LiveChatRoomDialogFragment();
|
||||
fragment.setImageUtil(mImageUtil);
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable(Constants.USER_BEAN, userBean);
|
||||
bundle.putBoolean(Constants.FOLLOW, following);
|
||||
fragment.setArguments(bundle);
|
||||
fragment.show(getSupportFragmentManager(), "LiveChatRoomDialogFragment");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发 弹幕 消息
|
||||
@@ -1041,14 +997,6 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* 发 送礼物 消息
|
||||
*/
|
||||
// public void sendGiftMessage(LiveGiftBean giftBean, String giftToken) {
|
||||
// int guardType = mLiveGuardInfo != null ? mLiveGuardInfo.getMyGuardType() : Constants.GUARD_TYPE_NONE;
|
||||
//
|
||||
// SocketChatUtil.sendGiftMessage(giftBean.getType(), giftToken, mLiveUid,guardType,"0");
|
||||
// }
|
||||
|
||||
/**
|
||||
* 发 送礼物 消息 增加主播名字
|
||||
@@ -1286,28 +1234,6 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 分享直播间
|
||||
*/
|
||||
// public void shareLive(String type, MobCallback callback) {
|
||||
// ConfigBean configBean = CommonAppConfig.getInstance().getConfig();
|
||||
// if (configBean == null) {
|
||||
// return;
|
||||
// }
|
||||
// if (mMobShareUtil == null) {
|
||||
// mMobShareUtil = new MobShareUtil();
|
||||
// }
|
||||
// ShareData data = new ShareData();
|
||||
// data.setTitle(configBean.getLiveShareTitle());
|
||||
// data.setDes(mLiveBean.getUserNiceName() + configBean.getLiveShareDes());
|
||||
// data.setImgUrl(mLiveBean.getAvatarThumb());
|
||||
// String webUrl = configBean.getDownloadApkUrl();
|
||||
// if (Constants.MOB_WX.equals(type) || Constants.MOB_WX_PYQ.equals(type)) {
|
||||
// webUrl = configBean.getLiveWxShareUrl() + mLiveUid;
|
||||
// }
|
||||
// data.setWebUrl(webUrl);
|
||||
// mMobShareUtil.execute(type, data, callback);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 监听关注变化事件
|
||||
@@ -1321,23 +1247,6 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 监听私信未读消息数变化事件
|
||||
*/
|
||||
// @Subscribe(threadMode = ThreadMode.MAIN)
|
||||
// public void onImUnReadCountEvent(ImUnReadCountEvent e) {
|
||||
// String unReadCount = e.getUnReadCount();
|
||||
// if (!TextUtils.isEmpty(unReadCount) && mLiveBottomViewHolder != null) {
|
||||
// mLiveBottomViewHolder.setUnReadCount(unReadCount);
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* 获取私信未读消息数量
|
||||
*/
|
||||
// protected String getImUnReadCount() {
|
||||
// return ImMessageUtil.getInstance().getAllUnReadMsgCount();
|
||||
// }
|
||||
|
||||
/**
|
||||
* 监听钻石数量变化事件
|
||||
@@ -1351,9 +1260,6 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL
|
||||
}
|
||||
|
||||
public void onCoinChanged(String coin) {
|
||||
// if (mGamePresenter != null) {
|
||||
// mGamePresenter.setLastCoin(coin);
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1388,20 +1294,6 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL
|
||||
fragment.show(getSupportFragmentManager(), "LiveGuardDialogFragment");
|
||||
}
|
||||
|
||||
/**
|
||||
* 打開在线粉絲團
|
||||
*/
|
||||
public void openFansListWindow() {
|
||||
|
||||
LiveFansFragment fragment = new LiveFansFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
|
||||
//粉絲團粉絲團
|
||||
//不是粉絲
|
||||
bundle.putString(Constants.URL, CommonAppConfig.HOST + "/h5/live/fansRank.html" + "?uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&anchorUid=" + mLiveUid);
|
||||
fragment.setArguments(bundle);
|
||||
fragment.show(getSupportFragmentManager(), "LiveGuardDialogFragment");
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开观看列表弹窗
|
||||
@@ -1496,19 +1388,9 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL
|
||||
* 打开幸运礼物说明
|
||||
*/
|
||||
public void openLuckGiftTip() {
|
||||
// if (mLiveLuckGiftTipViewHolder == null) {
|
||||
UserBean u = CommonAppConfig.getInstance().getUserBean();
|
||||
String url = CommonAppConfig.HOST + "/h5/Nobility.html?nickname=" + u.getUserNiceName() + "&usernobId=" + u.getNoble_id() + "&token=" + CommonAppConfig.getInstance().getToken() + "&uid=" + CommonAppConfig.getInstance().getUid() + "&anchorUid=" + mLiveUid + "&anchorName=" + mAncherName;
|
||||
startActivity(new Intent(this, ZhuangBanActivity.class).putExtra("url", url));
|
||||
Log.e("aaa", url);
|
||||
// mLiveLuckGiftTipViewHolder = new LiveWebViewHolder(mContext, mPageContainer,url);
|
||||
// mLiveLuckGiftTipViewHolder.subscribeActivityLifeCycle();
|
||||
// mLiveLuckGiftTipViewHolder.addToParent();
|
||||
// }
|
||||
// mLiveLuckGiftTipViewHolder.show();
|
||||
// if (CommonAppConfig.LIVE_ROOM_SCROLL && !mIsAnchor) {
|
||||
// ((LiveAudienceActivity) this).setScrollFrozen(true);
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1621,15 +1503,9 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL
|
||||
if (mLiveLuckGiftTipViewHolder != null) {
|
||||
mLiveLuckGiftTipViewHolder.release();
|
||||
}
|
||||
// if (mMobShareUtil != null) {
|
||||
// mMobShareUtil.release();
|
||||
// }
|
||||
if (mImageUtil != null) {
|
||||
mImageUtil.release();
|
||||
}
|
||||
// if (mGamePresenter != null) {
|
||||
// mGamePresenter.release();
|
||||
// }
|
||||
if (mLiveRoomViewHolder.mHandler != null) {
|
||||
mLiveRoomViewHolder.mHandler.removeCallbacksAndMessages(null);
|
||||
}
|
||||
|
||||
@@ -1182,17 +1182,9 @@ public class LiveAudienceActivity extends LiveActivity {
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (mLiveAudienceViewHolder != null) {
|
||||
mLiveAudienceViewHolder.getChatPoint();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//红点(消息中心)
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onUpdateFieldEvent(UpdateTablePoint updateTablePoint) {
|
||||
if (mLiveAudienceViewHolder != null) {
|
||||
mLiveAudienceViewHolder.getChatPoint();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -8,11 +8,6 @@ import android.media.RingtoneManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.cardview.widget.CardView;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
@@ -23,6 +18,12 @@ import android.widget.LinearLayout;
|
||||
import android.widget.PopupWindow;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.cardview.widget.CardView;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.adjust.sdk.Adjust;
|
||||
import com.adjust.sdk.AdjustEvent;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
@@ -57,12 +58,9 @@ import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import io.rong.imlib.RongCoreClient;
|
||||
import io.rong.imlib.RongIMClient;
|
||||
import io.rong.imlib.listener.OnReceiveMessageWrapperListener;
|
||||
import io.rong.imlib.model.Conversation;
|
||||
import io.rong.imlib.model.Message;
|
||||
import io.rong.imlib.model.ReceivedProfile;
|
||||
import io.rong.message.RecallNotificationMessage;
|
||||
import io.rong.message.TextMessage;
|
||||
|
||||
@@ -156,8 +154,6 @@ public class MyTUIConversationFragment extends Fragment {
|
||||
|
||||
ImHttpUtil.cancel(ImHttpConsts.GET_SYSTEM_MESSAGE_LIST);
|
||||
ImHttpUtil.cancel(ImHttpConsts.GET_IM_USER_INFO);
|
||||
RongCoreClient.removeOnReceiveMessageListener(listener);
|
||||
listener = null;
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
@@ -172,14 +168,14 @@ public class MyTUIConversationFragment extends Fragment {
|
||||
mAdapter.setActionListener(new ImListAdapter.ActionListener() {
|
||||
@Override
|
||||
public void onItemClick(ImUserBean bean) {
|
||||
if(bean.getContent().equals("在線客服")){
|
||||
if (bean.getContent().equals("在線客服")) {
|
||||
mFirebaseAnalytics.logEvent("FS_customer_service", null);
|
||||
logger.logEvent("FB_customer_service");
|
||||
|
||||
AdjustEvent adjustEvent1 = new AdjustEvent("ww5z2p");
|
||||
Adjust.trackEvent(adjustEvent1);
|
||||
|
||||
}else if(bean.getContent().equals("新手指導員")){
|
||||
} else if (bean.getContent().equals("新手指導員")) {
|
||||
mFirebaseAnalytics.logEvent("FS_guide", null);
|
||||
logger.logEvent("FB_guide", null);
|
||||
AdjustEvent adjustEvent1 = new AdjustEvent("m0nfpn");
|
||||
@@ -209,7 +205,6 @@ public class MyTUIConversationFragment extends Fragment {
|
||||
});
|
||||
mRecyclerView.setAdapter(mAdapter);
|
||||
|
||||
RongCoreClient.addOnReceiveMessageListener(listener);
|
||||
RongIMClient.setOnRecallMessageListener(listenerBack);
|
||||
|
||||
Constants.nowId = "";
|
||||
@@ -298,35 +293,6 @@ public class MyTUIConversationFragment extends Fragment {
|
||||
});
|
||||
}
|
||||
|
||||
//获取新信息
|
||||
OnReceiveMessageWrapperListener listener = new OnReceiveMessageWrapperListener() {
|
||||
@Override
|
||||
public void onReceivedMessage(Message message, ReceivedProfile profile) {
|
||||
Log.d("刷新消息", "message=" + message);
|
||||
Log.i("Log", "message=" + message);
|
||||
if (message.getTargetId() != null && !"".endsWith(message.getTargetId())) {
|
||||
String firstIndex = message.getTargetId().substring(0, 1);
|
||||
if (!"g".endsWith(firstIndex) && !"__system__".endsWith(message.getTargetId())) {
|
||||
String firstIndexRM = "";
|
||||
String firstIndexRM2 = "";
|
||||
if (message.getObjectName().equals("RC:TxtMsg")) {
|
||||
TextMessage rongMsg = (TextMessage) message.getContent();
|
||||
if (rongMsg.getContent().length() > 4) {
|
||||
firstIndexRM = rongMsg.getContent().substring(0, 5);
|
||||
}
|
||||
if (rongMsg.getContent().length() > 9) {
|
||||
firstIndexRM2 = rongMsg.getContent().substring(0, 10);
|
||||
}
|
||||
}
|
||||
if (!"{\"msg".equals(firstIndexRM) && !"{\"retcode\"".equals(firstIndexRM2)) {
|
||||
//切换回主线程做UI操作
|
||||
mHandler.sendEmptyMessage(runOnUI);
|
||||
messageHandler = message;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//撤回消息
|
||||
RongIMClient.OnRecallMessageListener listenerBack = new RongIMClient.OnRecallMessageListener() {
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.yunbao.live.activity;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.Gravity;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
|
||||
import com.yunbao.common.activity.AbsActivity;
|
||||
import com.yunbao.live.R;
|
||||
|
||||
import io.rong.imkit.conversationlist.ConversationListFragment;
|
||||
|
||||
/**
|
||||
* 直播页面聊天列表
|
||||
*/
|
||||
public class PDLIiveChatActivity extends AbsActivity {
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.activity_pd_chat;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void main(Bundle savedInstanceState) {
|
||||
super.main(savedInstanceState);
|
||||
windowColor();
|
||||
initView();
|
||||
}
|
||||
|
||||
public void windowColor() {
|
||||
Window window = getWindow();
|
||||
//取消设置Window半透明的Flag
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
||||
//添加Flag把状态栏设为可绘制模式
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
||||
//设置状态栏为透明/或者需要的颜色
|
||||
window.setStatusBarColor(getResources().getColor(R.color.transparent));
|
||||
|
||||
getWindow().setGravity(Gravity.BOTTOM);//设置显示在底部 默认在中间
|
||||
WindowManager.LayoutParams lp = getWindow().getAttributes();
|
||||
lp.width = WindowManager.LayoutParams.MATCH_PARENT;//设置宽度满屏
|
||||
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
|
||||
getWindow().setAttributes(lp);
|
||||
setFinishOnTouchOutside(true);//允许点击空白处关闭
|
||||
|
||||
}
|
||||
/**
|
||||
* 初始化控件
|
||||
*/
|
||||
private void initView() {
|
||||
//展示会话列表
|
||||
ConversationListFragment conversationListFragment = new ConversationListFragment();
|
||||
FragmentManager manager = getSupportFragmentManager();
|
||||
FragmentTransaction transaction = manager.beginTransaction();
|
||||
transaction.replace(R.id.container, conversationListFragment);
|
||||
transaction.commit();
|
||||
//自定义空数据背景View
|
||||
conversationListFragment.setEmptyView(com.yunbao.live.R.layout.view_layout_msg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
package com.yunbao.live.activity;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
|
||||
import com.blankj.utilcode.util.GsonUtils;
|
||||
import com.yunbao.common.activity.AbsActivity;
|
||||
import com.yunbao.common.activity.SelectImageActivity;
|
||||
import com.yunbao.common.bean.IMLoginModel;
|
||||
import com.yunbao.common.bean.ImageEntity;
|
||||
import com.yunbao.common.manager.IMLoginManager;
|
||||
import com.yunbao.live.R;
|
||||
import com.yunbao.live.bean.SearchUserBean;
|
||||
import com.yunbao.live.dialog.MenuPopuwWindow;
|
||||
import com.yunbao.live.views.InputPanelViewHolder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import io.rong.imkit.conversation.ConversationFragment;
|
||||
import io.rong.imkit.userinfo.RongUserInfoManager;
|
||||
import io.rong.imlib.model.UserInfo;
|
||||
|
||||
/**
|
||||
* 聊天会话界面
|
||||
*/
|
||||
public class PDLiveConversationActivity extends AbsActivity implements View.OnClickListener {
|
||||
private ConversationFragment conversationFragment;
|
||||
private PDLiveConversationActivity mContext;
|
||||
private InputPanelViewHolder inputPanel;
|
||||
private TextView titleView;
|
||||
private ImageView imgMore, imBack;
|
||||
private boolean isAdmin = false;
|
||||
private final int PERMISSION_REQUEST_CODE = 0;
|
||||
private final int SELECT_VIDEO_REQUEST = 0x0002;
|
||||
private final int SELECT_IMAGE_REQUEST = 0x0001;
|
||||
private ArrayList<ImageEntity> mSelectImages = new ArrayList<>();
|
||||
private String targetId = "";
|
||||
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.activity_conversation;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void main() {
|
||||
super.main();
|
||||
mContext = this;
|
||||
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
|
||||
initView();
|
||||
initData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据的设置
|
||||
*/
|
||||
private void initData() {
|
||||
targetId = getIntent().getStringExtra("targetId");
|
||||
//绑定聊天用户id
|
||||
inputPanel.setTargetId(targetId);
|
||||
//获取用户信息
|
||||
UserInfo userInfo = RongUserInfoManager.getInstance().getUserInfo(targetId);
|
||||
titleView.setText(userInfo.getName());
|
||||
if (!TextUtils.isEmpty(userInfo.getExtra())) {
|
||||
SearchUserBean userBean = GsonUtils.fromJson(userInfo.getExtra(), SearchUserBean.class);
|
||||
//新手指导员
|
||||
if (TextUtils.isEmpty(userBean.getIs_admin()) && TextUtils.equals(userBean.getIs_admin(), "1")) {
|
||||
isAdmin = true;
|
||||
} else {//非指导员
|
||||
isAdmin = false;
|
||||
}
|
||||
Log.e("PDLiveConversation", userInfo.getExtra());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化布局
|
||||
*/
|
||||
private void initView() {
|
||||
// 添加会话界面
|
||||
conversationFragment = new ConversationFragment();
|
||||
FragmentManager manager = getSupportFragmentManager();
|
||||
FragmentTransaction transaction = manager.beginTransaction();
|
||||
transaction.replace(R.id.container, conversationFragment);
|
||||
transaction.commit();
|
||||
inputPanel = findViewById(R.id.input_panel);
|
||||
titleView = findViewById(R.id.titleView);
|
||||
imgMore = findViewById(R.id.img_more);
|
||||
imBack = findViewById(R.id.btn_back);
|
||||
imgMore.setOnClickListener(this);
|
||||
imBack.setOnClickListener(this);
|
||||
findViewById(R.id.container).setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
InputMethodManager imm = (InputMethodManager)
|
||||
getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
inputPanel.addMediaMessageCallback(new InputPanelViewHolder.MediaMessageCallback() {
|
||||
@Override
|
||||
public void choosePic(int intoIndex) {
|
||||
jumpPic(intoIndex);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int id = v.getId();
|
||||
//菜单
|
||||
if (id == R.id.img_more) {
|
||||
IMLoginModel model = IMLoginManager.get(mContext).getUserInfo();
|
||||
new MenuPopuwWindow(mContext).setIsAdmin(model.getIsAdmin(), targetId).show(imgMore);
|
||||
} else if (id == R.id.btn_back) {//返回
|
||||
onBackPressed();
|
||||
}
|
||||
}
|
||||
|
||||
//intoIndex 1=调用相机,2=照片选取,3=视频选取
|
||||
public void jumpPic(int intoIndex) {
|
||||
//选择图片
|
||||
int isPermission1 = ContextCompat.checkSelfPermission(mContext, Manifest.permission.READ_EXTERNAL_STORAGE);
|
||||
int isPermission2 = ContextCompat.checkSelfPermission(mContext, Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
if (isPermission1 == PackageManager.PERMISSION_GRANTED && isPermission2 == PackageManager.PERMISSION_GRANTED) {
|
||||
startActivity(intoIndex);
|
||||
} else {
|
||||
//申请权限
|
||||
ActivityCompat.requestPermissions(mContext, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE);
|
||||
}
|
||||
}
|
||||
|
||||
private void startActivity(int intoIndex) {
|
||||
mSelectImages.clear();
|
||||
Intent intent = new Intent(mContext, SelectImageActivity.class);
|
||||
intent.putParcelableArrayListExtra("selected_images", mSelectImages);
|
||||
intent.putExtra("intoIndex", intoIndex);
|
||||
if (intoIndex == 3) {
|
||||
startActivityForResult(intent, SELECT_VIDEO_REQUEST);
|
||||
} else {
|
||||
startActivityForResult(intent, SELECT_IMAGE_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (resultCode == RESULT_OK) {
|
||||
if (requestCode == SELECT_IMAGE_REQUEST && data != null) {
|
||||
ArrayList<ImageEntity> selectImages = data.getParcelableArrayListExtra(SelectImageActivity.EXTRA_RESULT);
|
||||
for (ImageEntity entity : selectImages) {
|
||||
inputPanel.sendImageFile(entity.getPath());
|
||||
}
|
||||
|
||||
} else if (requestCode == SELECT_VIDEO_REQUEST && data != null) {
|
||||
ArrayList<ImageEntity> selectImages = data.getParcelableArrayListExtra(SelectImageActivity.EXTRA_RESULT);
|
||||
for (ImageEntity entity : selectImages) {
|
||||
inputPanel.sendVideoFile(entity.getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,13 +16,9 @@ import com.yunbao.live.views.SystemMessageViewHolder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
||||
import io.rong.imlib.RongCoreClient;
|
||||
import io.rong.imlib.RongIMClient;
|
||||
import io.rong.imlib.listener.OnReceiveMessageWrapperListener;
|
||||
import io.rong.imlib.model.Conversation;
|
||||
import io.rong.imlib.model.Message;
|
||||
import io.rong.imlib.model.ReceivedProfile;
|
||||
import io.rong.message.TextMessage;
|
||||
|
||||
/**
|
||||
* Created by cxf on 2018/11/24.
|
||||
@@ -58,7 +54,6 @@ public class SystemMessageActivity extends AbsActivity {
|
||||
if ("-2".equals(type)) {
|
||||
type = "-1";
|
||||
type2 = "-2";
|
||||
RongCoreClient.addOnReceiveMessageListener(listener);
|
||||
} else {
|
||||
type2 = "0";
|
||||
}
|
||||
@@ -110,7 +105,6 @@ public class SystemMessageActivity extends AbsActivity {
|
||||
Constants.remarks = "";
|
||||
Constants.isAdmin = "";
|
||||
if ("-2".equals(type2)) {
|
||||
RongCoreClient.removeOnReceiveMessageListener(listener);
|
||||
}
|
||||
super.onDestroy();
|
||||
}
|
||||
@@ -142,40 +136,6 @@ public class SystemMessageActivity extends AbsActivity {
|
||||
}
|
||||
}
|
||||
|
||||
//获取新信息
|
||||
private OnReceiveMessageWrapperListener listener = new OnReceiveMessageWrapperListener() {
|
||||
@Override
|
||||
public void onReceivedMessage(Message message, ReceivedProfile profile) {
|
||||
Log.i("Log", "message=" + message);
|
||||
if (message.getTargetId() != null && !"".endsWith(message.getTargetId())) {
|
||||
String firstIndex = message.getTargetId().substring(0, 1);
|
||||
if (!"g".endsWith(firstIndex) && !"__system__".endsWith(message.getTargetId())) {
|
||||
String firstIndexRM = "";
|
||||
String firstIndexRM2 = "";
|
||||
if (message.getObjectName().equals("RC:TxtMsg")) {
|
||||
TextMessage rongMsg = (TextMessage) message.getContent();
|
||||
if (rongMsg.getContent().length() > 4) {
|
||||
firstIndexRM = rongMsg.getContent().substring(0, 5);
|
||||
}
|
||||
if (rongMsg.getContent().length() > 9) {
|
||||
firstIndexRM2 = rongMsg.getContent().substring(0, 10);
|
||||
}
|
||||
}
|
||||
if (!"{\"msg".equals(firstIndexRM) && !"{\"retcode\"".equals(firstIndexRM2)) {
|
||||
if (message.getObjectName().equals("RC:TxtMsg")) {
|
||||
getNewMsg(message);
|
||||
} else if (message.getObjectName().equals("RC:ImgMsg")) {
|
||||
getNewMsg(message);
|
||||
} else if (message.getObjectName().equals("RC:SightMsg")) {
|
||||
getNewMsg(message);
|
||||
}
|
||||
cleanMessage(message.getTargetId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//清除指定会话未读数
|
||||
private void cleanMessage(String toId) {
|
||||
|
||||
@@ -90,4 +90,5 @@ public class SystemMessageAdapter extends RefreshAdapter<SystemMessageBean> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,10 +2,14 @@ package com.yunbao.live.bean;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.yunbao.common.bean.UserBean;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Created by cxf on 2017/8/14.
|
||||
* IM 聊天用户 实体类
|
||||
@@ -112,4 +116,23 @@ public class ImUserBean {
|
||||
public void setUserId(String userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 会话列表展示时间
|
||||
*/
|
||||
public String getLastDate() {
|
||||
if (!TextUtils.isEmpty(addtime)&&!TextUtils.equals(addtime,"0")) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||
Date currenTimeZone;
|
||||
if (TextUtils.equals(type, "-1")) {
|
||||
currenTimeZone = new Date(Long.parseLong(addtime));
|
||||
} else {
|
||||
currenTimeZone = new Date(Long.parseLong(addtime + "000"));
|
||||
}
|
||||
return sdf.format(currenTimeZone);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,14 +3,8 @@ package com.yunbao.live.dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.media.Ringtone;
|
||||
import android.media.RingtoneManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import androidx.cardview.widget.CardView;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
@@ -24,6 +18,10 @@ import android.widget.LinearLayout;
|
||||
import android.widget.PopupWindow;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.cardview.widget.CardView;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.google.gson.Gson;
|
||||
@@ -56,12 +54,9 @@ import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import io.rong.imlib.RongCoreClient;
|
||||
import io.rong.imlib.RongIMClient;
|
||||
import io.rong.imlib.listener.OnReceiveMessageWrapperListener;
|
||||
import io.rong.imlib.model.Conversation;
|
||||
import io.rong.imlib.model.Message;
|
||||
import io.rong.imlib.model.ReceivedProfile;
|
||||
import io.rong.message.RecallNotificationMessage;
|
||||
import io.rong.message.TextMessage;
|
||||
|
||||
@@ -162,7 +157,6 @@ public class LiveChatListDialogFragment extends AbsDialogFragment {
|
||||
ImHttpUtil.cancel(ImHttpConsts.GET_SYSTEM_MESSAGE_LIST);
|
||||
ImHttpUtil.cancel(ImHttpConsts.GET_IM_USER_INFO);
|
||||
Constants.isShowLiveDialog = false;
|
||||
RongCoreClient.removeOnReceiveMessageListener(listener);
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
@@ -209,7 +203,6 @@ public class LiveChatListDialogFragment extends AbsDialogFragment {
|
||||
});
|
||||
mRecyclerView.setAdapter(mAdapter);
|
||||
|
||||
RongCoreClient.addOnReceiveMessageListener(listener);
|
||||
RongIMClient.setOnRecallMessageListener(listenerBack);
|
||||
|
||||
Constants.nowId = "";
|
||||
@@ -299,59 +292,6 @@ public class LiveChatListDialogFragment extends AbsDialogFragment {
|
||||
});
|
||||
}
|
||||
|
||||
//获取新信息
|
||||
OnReceiveMessageWrapperListener listener = new OnReceiveMessageWrapperListener() {
|
||||
@Override
|
||||
public void onReceivedMessage(Message message, ReceivedProfile profile) {
|
||||
Log.i("Log", "message=" + message);
|
||||
if (message.getTargetId() != null && !"".endsWith(message.getTargetId())) {
|
||||
String firstIndex = message.getTargetId().substring(0, 1);
|
||||
if (!"g".endsWith(firstIndex) && !"__system__".endsWith(message.getTargetId())) {
|
||||
String firstIndexRM = "";
|
||||
String firstIndexRM2 = "";
|
||||
if (message.getObjectName().equals("RC:TxtMsg")) {
|
||||
TextMessage rongMsg = (TextMessage) message.getContent();
|
||||
if (rongMsg.getContent().length() > 4) {
|
||||
firstIndexRM = rongMsg.getContent().substring(0, 5);
|
||||
}
|
||||
if (rongMsg.getContent().length() > 9) {
|
||||
firstIndexRM2 = rongMsg.getContent().substring(0, 10);
|
||||
}
|
||||
}
|
||||
if (!"{\"msg".equals(firstIndexRM) && !"{\"retcode\"".equals(firstIndexRM2)) {
|
||||
if (lt_nodata_msg.getVisibility() == View.VISIBLE) {
|
||||
lt_nodata_msg.setVisibility(View.GONE);
|
||||
}
|
||||
if (systemMessageActivity != null && !Constants.nowId.equals("")) {
|
||||
if (Constants.isShowLiveDialog) {//直播间单聊插入消息
|
||||
if (message.getObjectName().equals("RC:TxtMsg")) {
|
||||
systemMessageActivity.getNewMsg(message);
|
||||
} else if (message.getObjectName().equals("RC:ImgMsg")) {
|
||||
systemMessageActivity.getNewMsg(message);
|
||||
} else if (message.getObjectName().equals("RC:SightMsg")) {
|
||||
systemMessageActivity.getNewMsg(message);
|
||||
}
|
||||
cleanMessage(null, message.getTargetId());
|
||||
}
|
||||
} else {
|
||||
if (systemMessageActivity.nowUid != null && !message.getTargetId().equals(systemMessageActivity.nowUid)) {
|
||||
//新信息提示
|
||||
try {
|
||||
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
|
||||
Ringtone r = RingtoneManager.getRingtone(getActivity(), notification);
|
||||
r.play();
|
||||
} catch (Exception e) {
|
||||
e.getMessage();
|
||||
}
|
||||
}
|
||||
getChatPoint();
|
||||
getOneUserChat(message.getTargetId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//撤回消息
|
||||
RongIMClient.OnRecallMessageListener listenerBack = new RongIMClient.OnRecallMessageListener() {
|
||||
|
||||
138
live/src/main/java/com/yunbao/live/dialog/MenuPopuwWindow.java
Normal file
138
live/src/main/java/com/yunbao/live/dialog/MenuPopuwWindow.java
Normal file
@@ -0,0 +1,138 @@
|
||||
package com.yunbao.live.dialog;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.PopupWindow;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.yunbao.common.utils.ToastUtil;
|
||||
import com.yunbao.live.R;
|
||||
|
||||
import io.rong.imlib.RongIMClient;
|
||||
|
||||
/**
|
||||
* 聊天菜单弹窗
|
||||
*/
|
||||
public class MenuPopuwWindow implements View.OnClickListener {
|
||||
private Activity mContext;
|
||||
private String userId;
|
||||
private View popupView;
|
||||
private TextView tvBlack, tvBlackMove;
|
||||
private LinearLayout ltRemarks;
|
||||
private PopupWindow popupWindow;
|
||||
|
||||
public MenuPopuwWindow(Activity context) {
|
||||
this.mContext = context;
|
||||
popupView = LayoutInflater.from(mContext).inflate(R.layout.popwindow_chat_more, null);
|
||||
initView();
|
||||
}
|
||||
|
||||
public MenuPopuwWindow setIsAdmin(String isAdmin, String userId) {
|
||||
this.userId = userId;
|
||||
|
||||
if (TextUtils.equals(isAdmin, "1")) {
|
||||
tvBlack.setVisibility(View.GONE);
|
||||
tvBlackMove.setVisibility(View.GONE);
|
||||
ltRemarks.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
ltRemarks.setVisibility(View.GONE);
|
||||
RongIMClient.getInstance().getBlacklistStatus(userId, new RongIMClient.ResultCallback<RongIMClient.BlacklistStatus>() {
|
||||
@Override
|
||||
public void onSuccess(RongIMClient.BlacklistStatus blacklistStatus) {
|
||||
if (blacklistStatus == RongIMClient.BlacklistStatus.IN_BLACK_LIST) {
|
||||
tvBlackMove.setVisibility(View.VISIBLE);
|
||||
tvBlack.setVisibility(View.GONE);
|
||||
} else {
|
||||
tvBlack.setVisibility(View.VISIBLE);
|
||||
tvBlackMove.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(RongIMClient.ErrorCode errorCode) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化组件
|
||||
*/
|
||||
private void initView() {
|
||||
tvBlack = popupView.findViewById(R.id.tv_black);
|
||||
tvBlackMove = popupView.findViewById(R.id.tv_black_move);
|
||||
ltRemarks = popupView.findViewById(R.id.lt_remarks);
|
||||
tvBlack.setOnClickListener(this);
|
||||
tvBlackMove.setOnClickListener(this);
|
||||
ltRemarks.setOnClickListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 展示弹窗
|
||||
*
|
||||
* @param view 显示在什么组件的下面
|
||||
* @return
|
||||
*/
|
||||
public void show(View view) {
|
||||
popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
|
||||
popupWindow.showAsDropDown(view);
|
||||
WindowManager.LayoutParams lp = mContext.getWindow().getAttributes();
|
||||
lp.alpha = 0.8f;
|
||||
mContext.getWindow().setAttributes(lp);
|
||||
popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss() {
|
||||
lp.alpha = 1f;
|
||||
mContext.getWindow().setAttributes(lp);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int id = v.getId();
|
||||
//拉黑
|
||||
if (id == R.id.tv_black) {
|
||||
RongIMClient.getInstance().addToBlacklist(userId, new RongIMClient.OperationCallback() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
ToastUtil.show(mContext.getResources().getString(R.string.black_succer));
|
||||
popupWindow.dismiss();
|
||||
tvBlack.setVisibility(View.VISIBLE);
|
||||
tvBlackMove.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(RongIMClient.ErrorCode errorCode) {
|
||||
ToastUtil.show(errorCode.msg);
|
||||
popupWindow.dismiss();
|
||||
}
|
||||
});
|
||||
} else if (id == R.id.tv_black_move) {//移出黑名单
|
||||
RongIMClient.getInstance().removeFromBlacklist(userId, new RongIMClient.OperationCallback() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
ToastUtil.show(mContext.getResources().getString(R.string.black_succer_more));
|
||||
popupWindow.dismiss();
|
||||
tvBlackMove.setVisibility(View.VISIBLE);
|
||||
tvBlack.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(RongIMClient.ErrorCode errorCode) {
|
||||
ToastUtil.show(errorCode.msg);
|
||||
popupWindow.dismiss();
|
||||
}
|
||||
});
|
||||
} else if (id == R.id.lt_remarks) {//添加备注
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
155
live/src/main/java/com/yunbao/live/utils/FileSizeUtil.java
Normal file
155
live/src/main/java/com/yunbao/live/utils/FileSizeUtil.java
Normal file
@@ -0,0 +1,155 @@
|
||||
package com.yunbao.live.utils;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
|
||||
public class FileSizeUtil {
|
||||
|
||||
public static final int SIZETYPE_B = 1;//获取文件大小单位为B的double值
|
||||
public static final int SIZETYPE_KB = 2;//获取文件大小单位为KB的double值
|
||||
public static final int SIZETYPE_MB = 3;//获取文件大小单位为MB的double值
|
||||
public static final int SIZETYPE_GB = 4;//获取文件大小单位为GB的double值
|
||||
|
||||
/**
|
||||
* 获取文件指定文件的指定单位的大小
|
||||
*
|
||||
* @param filePath 文件路径
|
||||
* @param sizeType 获取大小的类型1为B、2为KB、3为MB、4为GB
|
||||
* @return double值的大小
|
||||
*/
|
||||
public static double getFileOrFilesSize(String filePath, int sizeType) {
|
||||
File file = new File(filePath);
|
||||
long blockSize = 0;
|
||||
try {
|
||||
if (file.isDirectory()) {
|
||||
blockSize = getFileSizes(file);
|
||||
} else {
|
||||
blockSize = getFileSize(file);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.e("获取文件大小", "获取失败!");
|
||||
}
|
||||
return FormetFileSize(blockSize, sizeType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用此方法自动计算指定文件或指定文件夹的大小
|
||||
*
|
||||
* @param filePath 文件路径
|
||||
* @return 计算好的带B、KB、MB、GB的字符串
|
||||
*/
|
||||
public static String getAutoFileOrFilesSize(String filePath) {
|
||||
File file = new File(filePath);
|
||||
long blockSize = 0;
|
||||
try {
|
||||
if (file.isDirectory()) {
|
||||
blockSize = getFileSizes(file);
|
||||
} else {
|
||||
blockSize = getFileSize(file);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.e("获取文件大小", "获取失败!");
|
||||
}
|
||||
return FormetFileSize(blockSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定文件大小
|
||||
*
|
||||
* @param file
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private static long getFileSize(File file) throws Exception {
|
||||
long size = 0;
|
||||
if (file.exists()) {
|
||||
FileInputStream fis = null;
|
||||
fis = new FileInputStream(file);
|
||||
size = fis.available();
|
||||
} else {
|
||||
file.createNewFile();
|
||||
Log.e("获取文件大小", "文件不存在!");
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定文件夹
|
||||
*
|
||||
* @param f
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private static long getFileSizes(File f) throws Exception {
|
||||
long size = 0;
|
||||
File flist[] = f.listFiles();
|
||||
for (int i = 0; i < flist.length; i++) {
|
||||
if (flist[i].isDirectory()) {
|
||||
size = size + getFileSizes(flist[i]);
|
||||
} else {
|
||||
size = size + getFileSize(flist[i]);
|
||||
}
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换文件大小
|
||||
*
|
||||
* @param fileS
|
||||
* @return
|
||||
*/
|
||||
private static String FormetFileSize(long fileS) {
|
||||
DecimalFormat df = new DecimalFormat("#.00");
|
||||
String fileSizeString = "";
|
||||
String wrongSize = "0B";
|
||||
if (fileS == 0) {
|
||||
return wrongSize;
|
||||
}
|
||||
if (fileS < 1024) {
|
||||
fileSizeString = df.format((double) fileS) + "B";
|
||||
} else if (fileS < 1048576) {
|
||||
fileSizeString = df.format((double) fileS / 1024) + "KB";
|
||||
} else if (fileS < 1073741824) {
|
||||
fileSizeString = df.format((double) fileS / 1048576) + "MB";
|
||||
} else {
|
||||
fileSizeString = df.format((double) fileS / 1073741824) + "GB";
|
||||
}
|
||||
return fileSizeString;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换文件大小,指定转换的类型
|
||||
*
|
||||
* @param fileS
|
||||
* @param sizeType
|
||||
* @return
|
||||
*/
|
||||
private static double FormetFileSize(long fileS, int sizeType) {
|
||||
DecimalFormat df = new DecimalFormat("#.00");
|
||||
double fileSizeLong = 0;
|
||||
switch (sizeType) {
|
||||
case SIZETYPE_B:
|
||||
fileSizeLong = Double.valueOf(df.format((double) fileS));
|
||||
break;
|
||||
case SIZETYPE_KB:
|
||||
fileSizeLong = Double.valueOf(df.format((double) fileS / 1024));
|
||||
break;
|
||||
case SIZETYPE_MB:
|
||||
fileSizeLong = Double.valueOf(df.format((double) fileS / 1048576));
|
||||
break;
|
||||
case SIZETYPE_GB:
|
||||
fileSizeLong = Double.valueOf(df.format((double) fileS / 1073741824));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return fileSizeLong;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,293 @@
|
||||
package com.yunbao.live.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.yunbao.common.utils.ToastUtil;
|
||||
import com.yunbao.live.R;
|
||||
import com.yunbao.live.utils.FileSizeUtil;
|
||||
|
||||
import io.rong.imkit.IMCenter;
|
||||
import io.rong.imlib.IRongCallback;
|
||||
import io.rong.imlib.RongIMClient;
|
||||
import io.rong.imlib.model.Conversation;
|
||||
import io.rong.imlib.model.Message;
|
||||
import io.rong.message.FileMessage;
|
||||
import io.rong.message.ImageMessage;
|
||||
import io.rong.message.TextMessage;
|
||||
|
||||
/**
|
||||
* 自定义输入区
|
||||
*/
|
||||
public class InputPanelViewHolder extends LinearLayout implements View.OnClickListener {
|
||||
private ImageView inputPanelAddBtn;
|
||||
private EditText editBtn;
|
||||
public Button inputPanelSendBtn;
|
||||
//接收方的用户id
|
||||
private String targetId;
|
||||
//是否可以发送消息
|
||||
private boolean isSend = false;
|
||||
private LinearLayout pluginList;
|
||||
|
||||
|
||||
/**
|
||||
* 必传字段
|
||||
*
|
||||
* @param targetId 接收方的用户id
|
||||
* @return
|
||||
*/
|
||||
public InputPanelViewHolder setTargetId(String targetId) {
|
||||
this.targetId = targetId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public InputPanelViewHolder(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public InputPanelViewHolder(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
View inputPanelView = View.inflate(context, R.layout.view_input_panel, this);
|
||||
initView(inputPanelView);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化布局
|
||||
*/
|
||||
private void initView(View inputPanelView) {
|
||||
inputPanelAddBtn = inputPanelView.findViewById(R.id.input_panel_add_btn);
|
||||
editBtn = inputPanelView.findViewById(R.id.edit_btn);
|
||||
inputPanelSendBtn = inputPanelView.findViewById(R.id.input_panel_send_btn);
|
||||
pluginList = inputPanelView.findViewById(R.id.plugin_list);
|
||||
editBtn.addTextChangedListener(mEditTextWatcher);
|
||||
inputPanelSendBtn.setOnClickListener(this);
|
||||
inputPanelAddBtn.setOnClickListener(this);
|
||||
editBtn.setOnClickListener(this);
|
||||
inputPanelView.findViewById(R.id.lt_photo_button).setOnClickListener(this);
|
||||
inputPanelView.findViewById(R.id.lt_choospic_button).setOnClickListener(this);
|
||||
inputPanelView.findViewById(R.id.lt_video_button).setOnClickListener(this);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int id = v.getId();
|
||||
//点击加号拓展按钮
|
||||
if (id == R.id.input_panel_add_btn) {
|
||||
showPlugin();
|
||||
//点击发送按钮
|
||||
} else if (id == R.id.input_panel_send_btn) {
|
||||
sendMessage();
|
||||
} else if (id == R.id.edit_btn) {
|
||||
if (pluginList.getVisibility() == VISIBLE) {
|
||||
pluginList.setVisibility(GONE);
|
||||
}
|
||||
} else if (id == R.id.lt_photo_button) {
|
||||
if (messageCallback != null) {
|
||||
messageCallback.choosePic(1);
|
||||
}
|
||||
} else if (id == R.id.lt_choospic_button) {
|
||||
if (messageCallback != null) {
|
||||
messageCallback.choosePic(2);
|
||||
}
|
||||
} else if (id == R.id.lt_video_button) {
|
||||
if (messageCallback != null) {
|
||||
messageCallback.choosePic(3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 展示拓展插件列表
|
||||
*/
|
||||
private void showPlugin() {
|
||||
if (pluginList.getVisibility() == VISIBLE) {
|
||||
pluginList.setVisibility(GONE);
|
||||
} else {
|
||||
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.showSoftInput(editBtn, InputMethodManager.SHOW_FORCED);
|
||||
|
||||
imm.hideSoftInputFromWindow(editBtn.getWindowToken(), 0); //强制隐藏键盘
|
||||
pluginList.setVisibility(VISIBLE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送文字消息
|
||||
*/
|
||||
private void sendMessage() {
|
||||
if (!isSend) return;
|
||||
if (!TextUtils.isEmpty(editBtn.getText()) && !TextUtils.isEmpty(editBtn.getText().toString().trim())) {
|
||||
String text = editBtn.getText().toString();
|
||||
editBtn.setText("");
|
||||
Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE;
|
||||
TextMessage messageContent = TextMessage.obtain(text);
|
||||
Message message = Message.obtain(targetId, conversationType, messageContent);
|
||||
IMCenter.getInstance().sendMessage(message, null, null, new IRongCallback.ISendMessageCallback() {
|
||||
|
||||
@Override
|
||||
public void onAttached(Message message) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(Message message) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Message message, RongIMClient.ErrorCode errorCode) {
|
||||
|
||||
}
|
||||
});
|
||||
} else {
|
||||
ToastUtil.show("不可以发送空消息");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private TextWatcher mEditTextWatcher = new TextWatcher() {
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
//存入草稿
|
||||
Conversation.ConversationType types = Conversation.ConversationType.PRIVATE;
|
||||
if (s != null && s.length() != 0) {
|
||||
isSend = true;
|
||||
inputPanelSendBtn.setBackground(getResources().getDrawable(R.mipmap.btn_sand1));
|
||||
} else {
|
||||
isSend = false;
|
||||
IMCenter.getInstance().saveTextMessageDraft(types, targetId, editBtn.getText().toString(), null);
|
||||
inputPanelSendBtn.setBackground(getResources().getDrawable(R.mipmap.btn_sand));
|
||||
}
|
||||
int offset;
|
||||
if (count == 0) {
|
||||
int var10000 = start + before;
|
||||
offset = -before;
|
||||
} else {
|
||||
offset = count;
|
||||
}
|
||||
if (offset != 0) {
|
||||
RongIMClient.getInstance().sendTypingStatus(types, targetId, "RC:TxtMsg");
|
||||
}
|
||||
}
|
||||
|
||||
public void afterTextChanged(Editable s) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 发送媒体消息
|
||||
*
|
||||
* @param imagePath
|
||||
*/
|
||||
public void sendImageFile(String imagePath) {
|
||||
if (pluginList.getVisibility() == VISIBLE) {
|
||||
pluginList.setVisibility(GONE);
|
||||
}
|
||||
Uri localUri = Uri.parse("file://" + imagePath);
|
||||
ImageMessage imageMessage = ImageMessage.obtain(localUri, localUri);
|
||||
Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE;
|
||||
Message message = Message.obtain(targetId, conversationType, imageMessage);
|
||||
|
||||
IMCenter.getInstance().sendMediaMessage(message, null, null, new IRongCallback.ISendMediaMessageCallback() {
|
||||
@Override
|
||||
public void onProgress(Message message, int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCanceled(Message message) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttached(Message message) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(Message message) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(final Message message, final RongIMClient.ErrorCode errorCode) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void sendVideoFile(String filePath) {
|
||||
if (pluginList.getVisibility() == VISIBLE) {
|
||||
pluginList.setVisibility(GONE);
|
||||
}
|
||||
Message message;
|
||||
double fileSize = FileSizeUtil.getFileOrFilesSize(filePath, FileSizeUtil.SIZETYPE_MB);
|
||||
Uri localUri = Uri.parse("file://" + filePath);
|
||||
Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE;
|
||||
|
||||
|
||||
FileMessage videoMessage = FileMessage.obtain(getContext(), localUri);
|
||||
|
||||
message = Message.obtain(targetId, conversationType, videoMessage);
|
||||
|
||||
IMCenter.getInstance().sendMediaMessage(message, null, null, new IRongCallback.ISendMediaMessageCallback() {
|
||||
@Override
|
||||
public void onProgress(Message message, int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCanceled(Message message) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttached(Message message) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(Message message) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(final Message message, final RongIMClient.ErrorCode errorCode) {
|
||||
ToastUtil.show(errorCode.msg);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 多媒体信息
|
||||
*/
|
||||
public interface MediaMessageCallback {
|
||||
void choosePic(int intoIndex);
|
||||
}
|
||||
|
||||
private MediaMessageCallback messageCallback;
|
||||
|
||||
public void addMediaMessageCallback(MediaMessageCallback callback) {
|
||||
messageCallback = callback;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,7 +6,6 @@ import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.CountDownTimer;
|
||||
import android.os.Handler;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -14,35 +13,27 @@ import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.yunbao.common.CommonAppConfig;
|
||||
import com.yunbao.common.Constants;
|
||||
import com.yunbao.common.event.UpdateTablePoint;
|
||||
import com.yunbao.common.http.HttpCallback;
|
||||
import com.yunbao.common.http.HttpClient;
|
||||
import com.yunbao.common.manager.imrongcloud.MessageIMManager;
|
||||
import com.yunbao.common.utils.ToastUtil;
|
||||
import com.yunbao.live.R;
|
||||
import com.yunbao.live.activity.LiveActivity;
|
||||
import com.yunbao.live.activity.LiveAudienceActivity;
|
||||
import com.yunbao.live.bean.ImUserBean;
|
||||
import com.yunbao.live.bean.LiveChatBean;
|
||||
import com.yunbao.live.dialog.LiveHDDialogFragment;
|
||||
import com.yunbao.live.dialog.LiveMicUserDialogFragment;
|
||||
import com.yunbao.live.dialog.LivePromotionDialogFragment;
|
||||
import com.yunbao.live.http.ImHttpUtil;
|
||||
import com.yunbao.live.http.LiveHttpUtil;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import io.rong.imlib.RongIMClient;
|
||||
import io.rong.imlib.model.Conversation;
|
||||
|
||||
/**
|
||||
* Created by cxf on 2018/10/9.
|
||||
* 观众直播间逻辑
|
||||
@@ -118,7 +109,7 @@ public class LiveAudienceViewHolder extends AbsLiveViewHolder {
|
||||
|
||||
v_msg_redpoint = (View) findViewById(R.id.v_msg_redpoint);
|
||||
//获取系统未读消息
|
||||
getSystemMessages();
|
||||
MessageIMManager.get(context).getSystemMessages();
|
||||
EventBus.getDefault().register(LiveAudienceViewHolder.this);
|
||||
}
|
||||
|
||||
@@ -363,73 +354,6 @@ public class LiveAudienceViewHolder extends AbsLiveViewHolder {
|
||||
public void timeOver() {
|
||||
}
|
||||
|
||||
public void getChatPoint() {
|
||||
if (v_msg_redpoint.getVisibility() == View.GONE) {
|
||||
Conversation.ConversationType[] conversationTypes = {Conversation.ConversationType.PRIVATE, Conversation.ConversationType.GROUP};
|
||||
boolean containBlocked = true;
|
||||
RongIMClient.getInstance().getUnreadCount(conversationTypes, containBlocked,
|
||||
new RongIMClient.ResultCallback<Integer>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(Integer unReadCount) {
|
||||
//未读消息大于0更改红点状态
|
||||
if (unReadCount > 0)
|
||||
changeMessagePoint(unReadCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(RongIMClient.ErrorCode ErrorCode) {
|
||||
changeMessagePoint(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统消息(有未读数展示红点)
|
||||
*/
|
||||
private void getSystemMessages() {
|
||||
//获取系统消息列表
|
||||
ImHttpUtil.getImUserInfo("", new HttpCallback() {
|
||||
@Override
|
||||
public void onSuccess(int code, String msg, String[] info) {
|
||||
if (code == 0) {
|
||||
//获取系统消息列表
|
||||
List<ImUserBean> listUserBean = JSON.parseArray(Arrays.toString(info), ImUserBean.class);
|
||||
if (listUserBean != null && listUserBean.size() >= 2) {
|
||||
//目前就三条消息,需求判断前两条消息是否有未读消息
|
||||
for (int i = 0; i < listUserBean.size() - 2; i++) {
|
||||
//消息对象
|
||||
ImUserBean userBean = listUserBean.get(i);
|
||||
//未读消息数
|
||||
String number = userBean.getNum();
|
||||
//未读消息不为空并且大于0
|
||||
if (!TextUtils.isEmpty(number) && Integer.parseInt(number) > 0) {
|
||||
context.runOnUiThread(() -> changeMessagePoint(Integer.parseInt(number)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 更改消息红点的状态
|
||||
*
|
||||
* @param number 未读消息
|
||||
*/
|
||||
private void changeMessagePoint(int number) {
|
||||
//发送通知更改,菜单红点
|
||||
EventBus.getDefault().post(new UpdateTablePoint(number));
|
||||
if (v_msg_redpoint.getVisibility() == View.VISIBLE && number > 0) return;
|
||||
if (number > 0) {
|
||||
v_msg_redpoint.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
v_msg_redpoint.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
//红点(直播页面)
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
|
||||
@@ -778,7 +778,6 @@ public class SystemMessageViewHolder extends AbsViewHolder implements View.OnCli
|
||||
lt_remarks.setVisibility(View.GONE);
|
||||
}
|
||||
PopupWindow popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
|
||||
// popupWindow.showAsDropDown(view, view.getWidth(), -view.getHeight());
|
||||
popupWindow.showAsDropDown(view);
|
||||
WindowManager.LayoutParams lp = nowActivity.getWindow().getAttributes();
|
||||
lp.alpha = 0.8f;
|
||||
|
||||
Reference in New Issue
Block a user