diff --git a/app/src/main/java/com/shayu/phonelive/AppContext.java b/app/src/main/java/com/shayu/phonelive/AppContext.java index 33f2e91c7..c4ed7dc61 100644 --- a/app/src/main/java/com/shayu/phonelive/AppContext.java +++ b/app/src/main/java/com/shayu/phonelive/AppContext.java @@ -29,7 +29,11 @@ import com.yunbao.common.CommonAppContext; import com.yunbao.common.Constants; import com.yunbao.common.http.CommonHttpUtil; import com.yunbao.common.http.HttpCallback; +import com.yunbao.common.manager.imrongcloud.InstructorSendReward; +import com.yunbao.common.manager.imrongcloud.InstructorSendRewardProvider; import com.yunbao.common.manager.imrongcloud.MessageIMManager; +import com.yunbao.common.manager.imrongcloud.RecommendLiveRoom; +import com.yunbao.live.views.RecommendLiveRoomProvider; import com.yunbao.common.manager.imrongcloud.RongcloudIMManager; import com.yunbao.common.utils.L; import com.yunbao.common.utils.SpUtil; @@ -40,12 +44,13 @@ import com.yunbao.main.activity.MsgSettActivity; import java.io.File; import java.io.IOException; +import java.util.ArrayList; +import io.rong.imkit.config.RongConfigCenter; import io.rong.imlib.RongIMClient; import io.rong.imlib.model.Conversation; +import io.rong.imlib.model.MessageContent; import io.rong.message.TextMessage; -import io.rong.push.RongPushClient; -import io.rong.push.pushconfig.PushConfig; import static com.yunbao.live.socket.SocketClient.mSocketHandler; @@ -166,6 +171,14 @@ public class AppContext extends CommonAppContext { //初始化融云 RongcloudIMManager.initRongIM(this); + ArrayList> myMessages = new ArrayList<>(); + myMessages.add(RecommendLiveRoom.class); + myMessages.add(InstructorSendReward.class); + + RongIMClient.registerMessageType(myMessages); + // 注册自定义消息模板 + RongConfigCenter.conversationConfig().addMessageProvider(new InstructorSendRewardProvider()); + RongConfigCenter.conversationConfig().addMessageProvider(new RecommendLiveRoomProvider(getApplicationContext())); RongcloudIMManager.addRongcloudIMOnReceiveMessageListener(new RongIMClient.OnReceiveMessageWrapperListener() { @Override diff --git a/common/src/main/java/com/yunbao/common/bean/RecommendLiveRoomModel.java b/common/src/main/java/com/yunbao/common/bean/RecommendLiveRoomModel.java new file mode 100644 index 000000000..f8cdf1b07 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/bean/RecommendLiveRoomModel.java @@ -0,0 +1,58 @@ +package com.yunbao.common.bean; + +import com.google.gson.annotations.SerializedName; + +public class RecommendLiveRoomModel extends BaseModel { + + /** + * liveuid : 97714 + * user_nicename : rongyun004 + * avatar : https://downs.yaoulive.com/20220329113227_c661f791c5fc878c2ef357ee022f9fbc?imageView2/2/w/600/h/600 + * title : + */ + + @SerializedName("liveuid") + private String liveuid; + @SerializedName("user_nicename") + private String userNicename; + @SerializedName("avatar") + private String avatar; + @SerializedName("title") + private String title; + + public String getLiveuid() { + return liveuid; + } + + public RecommendLiveRoomModel setLiveuid(String liveuid) { + this.liveuid = liveuid; + return this; + } + + public String getUserNicename() { + return userNicename; + } + + public RecommendLiveRoomModel setUserNicename(String userNicename) { + this.userNicename = userNicename; + return this; + } + + public String getAvatar() { + return avatar; + } + + public RecommendLiveRoomModel setAvatar(String avatar) { + this.avatar = avatar; + return this; + } + + public String getTitle() { + return title; + } + + public RecommendLiveRoomModel setTitle(String title) { + this.title = title; + return this; + } +} diff --git a/common/src/main/java/com/yunbao/common/manager/imrongcloud/InstructorSendReward.java b/common/src/main/java/com/yunbao/common/manager/imrongcloud/InstructorSendReward.java new file mode 100644 index 000000000..98a8d2f78 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/manager/imrongcloud/InstructorSendReward.java @@ -0,0 +1,30 @@ +package com.yunbao.common.manager.imrongcloud; + +import android.annotation.SuppressLint; +import android.os.Parcel; + +import io.rong.imlib.MessageTag; +import io.rong.imlib.model.MessageContent; + +@SuppressLint("ParcelCreator") +@MessageTag(value = "InstructorSendReward", flag = MessageTag.ISCOUNTED) +public class InstructorSendReward extends MessageContent { + public InstructorSendReward(byte[] data) { + super(data); + } + + @Override + public byte[] encode() { + return new byte[0]; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + + } +} diff --git a/common/src/main/java/com/yunbao/common/manager/imrongcloud/InstructorSendRewardProvider.java b/common/src/main/java/com/yunbao/common/manager/imrongcloud/InstructorSendRewardProvider.java new file mode 100644 index 000000000..3fd1c0c85 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/manager/imrongcloud/InstructorSendRewardProvider.java @@ -0,0 +1,84 @@ +package com.yunbao.common.manager.imrongcloud; + +import android.content.Context; +import android.text.Spannable; +import android.view.ViewGroup; + +import java.util.List; + +import io.rong.imkit.conversation.messgelist.provider.BaseMessageItemProvider; +import io.rong.imkit.model.UiMessage; +import io.rong.imkit.widget.adapter.IViewProviderListener; +import io.rong.imkit.widget.adapter.ViewHolder; +import io.rong.imlib.model.MessageContent; + +/** + * 自定义消息模板 + */ +public class InstructorSendRewardProvider extends BaseMessageItemProvider { + /** + * 创建 ViewHolder + * + * @param viewGroup 父 ViewGroup + * @param viewType 视图类型 + * @return ViewHolder + */ + @Override + protected ViewHolder onCreateMessageContentViewHolder(ViewGroup viewGroup, int viewType) { + return null; + } + + /** + * 设置消息视图里各 view 的值 + * + * @param holder ViewHolder + * @param parentHolder 父布局的 ViewHolder + * @param instructorSendReward 此展示模板对应的消息 + * @param uiMessage {@link UiMessage} + * @param position 消息位置 + * @param list 列表 + * @param listener ViewModel 的点击事件监听器。如果某个子 view 的点击事件需要 ViewModel 处理,可通过此监听器回调。 + */ + @Override + protected void bindMessageContentViewHolder(ViewHolder holder, ViewHolder parentHolder, InstructorSendReward instructorSendReward, UiMessage uiMessage, int position, List list, IViewProviderListener listener) { + + } + + /** + * @param holder ViewHolder + * @param instructorSendReward 自定义消息 + * @param uiMessage {@link UiMessage} + * @param position 位置 + * @param list 列表数据 + * @param listener ViewModel 的点击事件监听器。如果某个子 view 的点击事件需要 ViewModel 处理,可通过此监听器回调。 + * @return 点击事件是否被消费 + */ + @Override + protected boolean onItemClick(ViewHolder holder, InstructorSendReward instructorSendReward, UiMessage uiMessage, int position, List list, IViewProviderListener listener) { + return false; + } + + /** + * 根据消息内容,判断是否为本模板需要展示的消息类型 + * + * @param messageContent 消息内容 + * @return 本模板是否处理。 + */ + @Override + protected boolean isMessageViewType(MessageContent messageContent) { + return messageContent instanceof InstructorSendReward; + } + + /** + * 在会话列表页某条会话最后一条消息为该类型消息时,会话里需要展示的内容。 + * 比如: 图片消息在会话里需要展示为"图片",那返回对应的字符串资源即可。 + * + * @param context 上下文 + * @param instructorSendReward 消息内容 + * @return 会话里需要展示的字符串资源 + */ + @Override + public Spannable getSummarySpannable(Context context, InstructorSendReward instructorSendReward) { + return null; + } +} diff --git a/common/src/main/java/com/yunbao/common/manager/imrongcloud/RecommendLiveRoom.java b/common/src/main/java/com/yunbao/common/manager/imrongcloud/RecommendLiveRoom.java new file mode 100644 index 000000000..e699e9094 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/manager/imrongcloud/RecommendLiveRoom.java @@ -0,0 +1,115 @@ +package com.yunbao.common.manager.imrongcloud; + +import android.annotation.SuppressLint; +import android.os.Parcel; +import android.os.Parcelable; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.UnsupportedEncodingException; + +import io.rong.common.ParcelUtils; +import io.rong.imlib.MessageTag; +import io.rong.imlib.model.MessageContent; + +@MessageTag(value = "RecommendLiveRoom", flag = MessageTag.ISCOUNTED) +public class RecommendLiveRoom extends MessageContent implements Parcelable { + // 自定义消息变量,可以有多个 + private String content; + + public RecommendLiveRoom setContent(String content) { + this.content = content; + return this; + } + + public String getContent() { + return content; + } + + public RecommendLiveRoom(byte[] data) { + if (data == null) { + return; + } + String jsonStr = null; + try { + jsonStr = new String(data, "UTF-8"); + } catch (UnsupportedEncodingException e) { + } + if (jsonStr == null) { + return; + } + + try { + JSONObject jsonObj = new JSONObject(jsonStr); + // 消息携带用户信息时, 自定义消息需添加下面代码 + if (jsonObj.has("user")) { + setUserInfo(parseJsonToUserInfo(jsonObj.getJSONObject("user"))); + } + // 用于群组聊天, 消息携带 @ 人信息时, 自定义消息需添加下面代码 + if (jsonObj.has("mentionedInfo")) { + setMentionedInfo(parseJsonToMentionInfo(jsonObj.getJSONObject("mentionedInfo"))); + } + // 将所有自定义变量从收到的 json 解析并赋值 + if (jsonObj.has("content")) { + content = jsonObj.optString("content"); + } + } catch (JSONException e) { + } + } + + /** + * 将本地消息对象序列化为消息数据。 + * + * @return 消息数据。 + */ + @Override + public byte[] encode() { + JSONObject jsonObj = new JSONObject(); + try { + // 消息携带用户信息时, 自定义消息需添加下面代码 + if (getJSONUserInfo() != null) { + jsonObj.putOpt("user", getJSONUserInfo()); + } + // 用于群组聊天, 消息携带 @ 人信息时, 自定义消息需添加下面代码 + if (getJsonMentionInfo() != null) { + jsonObj.putOpt("mentionedInfo", getJsonMentionInfo()); + } + // 将所有自定义消息的内容,都序列化至 json 对象中 + jsonObj.put("content", this.content); + } catch (JSONException e) { + } + + try { + return jsonObj.toString().getBytes("UTF-8"); + } catch (UnsupportedEncodingException e) { + } + return null; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + ParcelUtils.writeToParcel(dest, getExtra()); + ParcelUtils.writeToParcel(dest, content); + } + public static final Creator CREATOR = new Creator() { + @Override + public RecommendLiveRoom createFromParcel(Parcel source) { + return new RecommendLiveRoom(source); + } + + @Override + public RecommendLiveRoom[] newArray(int size) { + return new RecommendLiveRoom[size]; + } + }; + public RecommendLiveRoom(Parcel in) { + setExtra(ParcelUtils.readFromParcel(in)); + setContent(ParcelUtils.readFromParcel(in)); + } +} diff --git a/common/src/main/java/com/yunbao/common/manager/imrongcloud/RongcloudIMManager.java b/common/src/main/java/com/yunbao/common/manager/imrongcloud/RongcloudIMManager.java index d7f055a1e..0bc787c92 100644 --- a/common/src/main/java/com/yunbao/common/manager/imrongcloud/RongcloudIMManager.java +++ b/common/src/main/java/com/yunbao/common/manager/imrongcloud/RongcloudIMManager.java @@ -16,6 +16,8 @@ import com.yunbao.common.manager.IMLoginManager; import org.greenrobot.eventbus.EventBus; +import java.util.ArrayList; + import io.rong.imkit.GlideKitImageEngine; import io.rong.imkit.IMCenter; import io.rong.imkit.RongIM; @@ -23,6 +25,7 @@ import io.rong.imkit.config.RongConfigCenter; import io.rong.imlib.RongIMClient; import io.rong.imlib.model.Conversation; import io.rong.imlib.model.Message; +import io.rong.imlib.model.MessageContent; import static com.yunbao.common.CommonAppContext.isReady; @@ -46,8 +49,11 @@ public class RongcloudIMManager { public static void initRongIM(Application application) { //第三个参数代表是否开启推送 RongIM.init(application, RONG_IM_KEY, true); + + Log.e(CLASSNAME, "initRongIM:"); initPhotoGlide(); + } private static RongIMClient.OnReceiveMessageWrapperListener mListener; diff --git a/common/src/main/res/layout/view_recommend_live_room.xml b/common/src/main/res/layout/view_recommend_live_room.xml new file mode 100644 index 000000000..19955dcef --- /dev/null +++ b/common/src/main/res/layout/view_recommend_live_room.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/common/src/main/res/mipmap-xxhdpi/btn_golive.png b/common/src/main/res/mipmap-xxhdpi/btn_golive.png new file mode 100644 index 000000000..4b890a52c Binary files /dev/null and b/common/src/main/res/mipmap-xxhdpi/btn_golive.png differ diff --git a/common/src/main/res/mipmap-xxhdpi/tab_recommend.png b/common/src/main/res/mipmap-xxhdpi/tab_recommend.png new file mode 100644 index 000000000..da6a03e69 Binary files /dev/null and b/common/src/main/res/mipmap-xxhdpi/tab_recommend.png differ diff --git a/common/src/main/res/values-en/strings.xml b/common/src/main/res/values-en/strings.xml index 5c3cc7452..0ed6aac4b 100644 --- a/common/src/main/res/values-en/strings.xml +++ b/common/src/main/res/values-en/strings.xml @@ -870,4 +870,5 @@ Limited ride And limited avatar frame Shield gift effect Shield car effect You are in the current live room + has recommended an anchor to you! diff --git a/common/src/main/res/values/strings.xml b/common/src/main/res/values/strings.xml index 814fe5ca2..4309ba804 100644 --- a/common/src/main/res/values/strings.xml +++ b/common/src/main/res/values/strings.xml @@ -884,6 +884,7 @@ 屏蔽座駕特效 您已在當前直播間 是否清空未讀消息 + 向您推薦了一名主播! 人氣票 系統通知 在線客服 diff --git a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java index 3d9f643d2..aa3d405a1 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java @@ -51,6 +51,7 @@ import com.yunbao.common.utils.DialogUitl; import com.yunbao.common.utils.DpUtil; import com.yunbao.common.utils.L; import com.yunbao.common.utils.ProcessResultUtil; +import com.yunbao.common.utils.RouteUtil; import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.views.weight.VerticalViewPager; import com.yunbao.live.R; @@ -67,6 +68,7 @@ import com.yunbao.live.dialog.SidebarLiveAudience; import com.yunbao.live.event.LinkMicTxAccEvent; import com.yunbao.live.event.LiveAudienceEvent; import com.yunbao.live.event.LiveRoomChangeEvent; +import com.yunbao.live.event.RecommendLiveRoomEvent; import com.yunbao.live.http.ImHttpUtil; import com.yunbao.live.http.LiveHttpConsts; import com.yunbao.live.http.LiveHttpUtil; @@ -848,6 +850,8 @@ public class LiveAudienceActivity extends LiveActivity { } }); } + + @Override public boolean canBackPressed() { return super.canBackPressed(); diff --git a/live/src/main/java/com/yunbao/live/activity/PDLIiveChatActivity.java b/live/src/main/java/com/yunbao/live/activity/PDLIiveChatActivity.java index 11a236b47..348f1033d 100644 --- a/live/src/main/java/com/yunbao/live/activity/PDLIiveChatActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/PDLIiveChatActivity.java @@ -25,13 +25,22 @@ import com.yunbao.common.http.HttpCallback; import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.manager.InstructorRemarkManager; import com.yunbao.common.manager.imrongcloud.MessageIMManager; +import com.yunbao.common.utils.Bus; +import com.yunbao.common.utils.RouteUtil; import com.yunbao.live.R; import com.yunbao.live.adapter.SystemChatMessageAdapter; import com.yunbao.live.bean.ImUserBean; +import com.yunbao.live.bean.LiveBean; import com.yunbao.live.bean.SearchUserBean; -import com.yunbao.live.http.ImHttpUtil; +import com.yunbao.live.event.LiveRoomChangeEvent; +import com.yunbao.live.event.RecommendLiveRoomEvent; +import com.yunbao.live.http.LiveHttpUtil; +import com.yunbao.live.presenter.LiveRoomCheckLivePresenter; + +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; -import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -56,6 +65,7 @@ public class PDLIiveChatActivity extends FragmentActivity { windowColor(); initView(); initData(); + Bus.getOn(this); } @@ -181,4 +191,32 @@ public class PDLIiveChatActivity extends FragmentActivity { }, true); } + + @Override + protected void onDestroy() { + super.onDestroy(); + Bus.getOff(this); + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onRecommendLiveRoomEvent(RecommendLiveRoomEvent event) { + LiveHttpUtil.getLiveInfo(event.getLiveuid(), new 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); + LiveRoomCheckLivePresenter mCheckLivePresenter = new LiveRoomCheckLivePresenter(mContext, (liveBean1, liveType, liveTypeVal, liveSdk) -> { + if (liveBean1 == null) { + return; + } + EventBus.getDefault().post(new LiveRoomChangeEvent(liveBean, liveType, liveTypeVal)); + finish(); + }); + mCheckLivePresenter.checkLive(liveBean); + } else { + RouteUtil.forwardUserHome(mContext, event.getLiveuid(), 0); + } + } + }); + } } diff --git a/live/src/main/java/com/yunbao/live/bean/ImUserBean.java b/live/src/main/java/com/yunbao/live/bean/ImUserBean.java index 4877313c1..d83fea755 100644 --- a/live/src/main/java/com/yunbao/live/bean/ImUserBean.java +++ b/live/src/main/java/com/yunbao/live/bean/ImUserBean.java @@ -2,6 +2,7 @@ package com.yunbao.live.bean; import android.text.TextUtils; +import com.google.gson.annotations.SerializedName; import com.yunbao.common.bean.BaseModel; import java.text.SimpleDateFormat; @@ -27,6 +28,17 @@ public class ImUserBean extends BaseModel { String is_admin; String isDelet; String _method_ = "";//融雲消息類型 + @SerializedName("new_image") + private String newImage; + + public String getNewImage() { + return newImage; + } + + public ImUserBean setNewImage(String newImage) { + this.newImage = newImage; + return this; + } public String getTitle() { return title; diff --git a/live/src/main/java/com/yunbao/live/dialog/PDLIiveChatConversationFragment.java b/live/src/main/java/com/yunbao/live/dialog/PDLIiveChatConversationFragment.java new file mode 100644 index 000000000..2a56793f9 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/dialog/PDLIiveChatConversationFragment.java @@ -0,0 +1,222 @@ +package com.yunbao.live.dialog; + +import android.Manifest; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.os.Bundle; +import android.text.TextUtils; +import android.util.Log; +import android.view.Gravity; +import android.view.View; +import android.view.Window; +import android.view.WindowManager; +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.adjust.sdk.Adjust; +import com.adjust.sdk.AdjustEvent; +import com.blankj.utilcode.util.GsonUtils; +import com.facebook.appevents.AppEventsLogger; +import com.google.firebase.analytics.FirebaseAnalytics; +import com.yunbao.common.activity.SelectImageActivity; +import com.yunbao.common.bean.IMLoginModel; +import com.yunbao.common.bean.ImageEntity; +import com.yunbao.common.bean.NoviceInstructorModel; +import com.yunbao.common.dialog.AbsDialogFragment; +import com.yunbao.common.http.CommonHttpUtil; +import com.yunbao.common.http.HttpCallback; +import com.yunbao.common.manager.IMLoginManager; +import com.yunbao.common.manager.NoviceInstructorManager; +import com.yunbao.live.R; +import com.yunbao.live.bean.SearchUserBean; +import com.yunbao.live.views.InputPanelViewHolder; +import com.yunbao.live.views.PDLiveConversationFragment; + +import java.util.ArrayList; + +import io.rong.imkit.userinfo.RongUserInfoManager; +import io.rong.imlib.RongIMClient; +import io.rong.imlib.model.Conversation; +import io.rong.imlib.model.UserInfo; + +/** + * 半屏聊天框 + */ +public class PDLIiveChatConversationFragment extends AbsDialogFragment implements View.OnClickListener { + private PDLiveConversationFragment conversationFragment; + private InputPanelViewHolder inputPanel; + private TextView titleView; + private ImageView imgMore, imBack; + private String targetId = ""; + private final int PERMISSION_REQUEST_CODE = 0; + private final int SELECT_VIDEO_REQUEST = 0x0002; + private final int SELECT_IMAGE_REQUEST = 0x0001; + private ArrayList mSelectImages = new ArrayList<>(); + private boolean isAdmin = false; + @Override + protected int getLayoutId() { + return R.layout.fragment_chat_conversation; + } + + @Override + protected int getDialogStyle() { + return R.style.dialog; + } + + @Override + protected boolean canCancel() { + return false; + } + + @Override + protected void setWindowAttributes(Window window) { + window.setWindowAnimations(R.style.bottomToTopAnim); + WindowManager.LayoutParams params = window.getAttributes(); + params.width = WindowManager.LayoutParams.MATCH_PARENT; + params.height = WindowManager.LayoutParams.WRAP_CONTENT; + params.gravity = Gravity.BOTTOM; + window.setAttributes(params); + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + initView(); + initData(); + } + + /** + * 初始化 + */ + private void initView() { + // 添加会话界面 + targetId = getArguments().getString("targetId"); + conversationFragment = new PDLiveConversationFragment(); + conversationFragment.initConversation(targetId, Conversation.ConversationType.PRIVATE, null); + FragmentManager manager = getChildFragmentManager(); + FragmentTransaction transaction = manager.beginTransaction(); + transaction.replace(R.id.container, conversationFragment); + transaction.commit(); + inputPanel = (InputPanelViewHolder) findViewById(R.id.input_panel); + titleView = (TextView) findViewById(R.id.titleView); + imgMore = (ImageView) findViewById(R.id.img_more); + imBack = (ImageView) findViewById(R.id.btn_back); + + imgMore.setOnClickListener(this); + imBack.setOnClickListener(this); + + inputPanel.addMediaMessageCallback(new InputPanelViewHolder.MediaMessageCallback() { + @Override + public void choosePic(int intoIndex) { + jumpPic(intoIndex); + } + }); + } + + /** + * 数据的设置 + */ + private void initData() { + NoviceInstructorModel model = NoviceInstructorManager.get(getActivity()).getNoviceInstructor(); + if (model != null && !TextUtils.isEmpty(model.getMsgZdySendText())) { + inputPanel.setPresetInformation(model.getMsgZdySendText()); + } + //绑定聊天用户id + inputPanel.setTargetId(targetId); + //获取用户信息 + UserInfo userInfo = RongUserInfoManager.getInstance().getUserInfo(targetId); + if (null != userInfo) { + 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; + imgMore.setVisibility(View.GONE); + AdjustEvent adjustEvent1 = new AdjustEvent("exlgn3"); + Adjust.trackEvent(adjustEvent1); + CommonHttpUtil.setAdvertisingChannels("exlgn3", new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (code == 0) { + FirebaseAnalytics.getInstance(mContext).logEvent("FS_director_read", null); + AppEventsLogger.newLogger(mContext).logEvent("FB_director_read"); + } + } + }); + + } else {//非指导员 + isAdmin = false; + imgMore.setVisibility(View.VISIBLE); + } + inputPanel.setAdmin(isAdmin); + Log.e("PDLiveConversation", userInfo.getExtra()); + } + } else { + titleView.setText("系統消息"); + inputPanel.setVisibility(View.GONE); + } + getDraft(); + } + + @Override + public void onClick(View v) { + int id = v.getId(); + //菜单 + if (id == R.id.img_more) { + IMLoginModel model = IMLoginManager.get(mContext).getUserInfo(); + new MenuPopuwWindow(getActivity()).setIsAdmin(model.getIsAdmin(), targetId).show(imgMore); + } else if (id == R.id.btn_back) {//返回 + dismiss(); + } + } + + //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(getActivity(), 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); + } + } + /** + * 获取草稿箱信息系 + */ + private void getDraft() { + RongIMClient.getInstance().getTextMessageDraft(Conversation.ConversationType.PRIVATE, targetId, new RongIMClient.ResultCallback() { + @Override + public void onSuccess(String s) { + if (!TextUtils.isEmpty(inputPanel.getPresetInformation())) + inputPanel.setPresetInformation(s); + } + + @Override + public void onError(RongIMClient.ErrorCode errorCode) { + + } + }); + } +} diff --git a/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java b/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java index 7492bfb7e..df87443dc 100644 --- a/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java +++ b/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java @@ -17,6 +17,7 @@ public class LiveAudienceEvent extends BaseModel { private int liveType; private int liveTypeVal; + public int getLiveType() { return liveType; } diff --git a/live/src/main/java/com/yunbao/live/event/RecommendLiveRoomEvent.java b/live/src/main/java/com/yunbao/live/event/RecommendLiveRoomEvent.java new file mode 100644 index 000000000..06517d722 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/event/RecommendLiveRoomEvent.java @@ -0,0 +1,21 @@ +package com.yunbao.live.event; + +import com.google.gson.annotations.SerializedName; +import com.yunbao.common.bean.BaseModel; + +/** + * 聊天界面跳转直播间 + */ +public class RecommendLiveRoomEvent extends BaseModel { + @SerializedName("liveuid") + private String liveuid; + + public String getLiveuid() { + return liveuid; + } + + public RecommendLiveRoomEvent setLiveuid(String liveuid) { + this.liveuid = liveuid; + return this; + } +} diff --git a/live/src/main/java/com/yunbao/live/views/RecommendLiveRoomProvider.java b/live/src/main/java/com/yunbao/live/views/RecommendLiveRoomProvider.java new file mode 100644 index 000000000..056add0b7 --- /dev/null +++ b/live/src/main/java/com/yunbao/live/views/RecommendLiveRoomProvider.java @@ -0,0 +1,78 @@ +package com.yunbao.live.views; + +import android.content.Context; +import android.net.Uri; +import android.text.Spannable; +import android.text.SpannableString; +import android.text.TextUtils; +import android.view.ViewGroup; + +import com.google.gson.Gson; +import com.yunbao.common.R; +import com.yunbao.common.bean.RecommendLiveRoomModel; +import com.yunbao.common.manager.imrongcloud.RecommendLiveRoom; +import com.yunbao.common.utils.Bus; +import com.yunbao.live.event.RecommendLiveRoomEvent; + +import org.greenrobot.eventbus.EventBus; + +import java.util.List; + +import io.rong.imkit.conversation.messgelist.provider.BaseMessageItemProvider; +import io.rong.imkit.model.UiMessage; +import io.rong.imkit.widget.adapter.IViewProviderListener; +import io.rong.imkit.widget.adapter.ViewHolder; +import io.rong.imlib.model.MessageContent; + +/** + * 自定义消息模板 + */ +public class RecommendLiveRoomProvider extends BaseMessageItemProvider { + private Context mContext; + + public RecommendLiveRoomProvider(Context context) { + this.mContext = context; + } + + @Override + protected ViewHolder onCreateMessageContentViewHolder(ViewGroup viewGroup, int i) { + + return ViewHolder.createViewHolder(mContext, viewGroup, R.layout.view_recommend_live_room); + } + + @Override + protected void bindMessageContentViewHolder(ViewHolder viewHolder, ViewHolder viewHolder1, RecommendLiveRoom recommendLiveRoom, UiMessage uiMessage, int i, List list, IViewProviderListener iViewProviderListener) { + if (uiMessage.getMessage().getContent() instanceof RecommendLiveRoom) { + + RecommendLiveRoom liveRoom = (RecommendLiveRoom) uiMessage.getMessage().getContent(); + RecommendLiveRoomModel model = new Gson().fromJson(liveRoom.getContent(), RecommendLiveRoomModel.class); + viewHolder.setImageUri(R.id.live_bg, Uri.parse(model.getAvatar())); + viewHolder.setText(R.id.host_name, model.getUserNicename()); + } + } + + @Override + protected boolean onItemClick(ViewHolder viewHolder, RecommendLiveRoom recommendLiveRoom, UiMessage uiMessage, int i, List list, IViewProviderListener iViewProviderListener) { + if (uiMessage.getMessage().getContent() instanceof RecommendLiveRoom) { + RecommendLiveRoom liveRoom = (RecommendLiveRoom) uiMessage.getMessage().getContent(); + RecommendLiveRoomModel model = new Gson().fromJson(liveRoom.getContent(), RecommendLiveRoomModel.class); + Bus.get().post(new RecommendLiveRoomEvent().setLiveuid(model.getLiveuid())); + EventBus.getDefault().post(new RecommendLiveRoomEvent().setLiveuid(model.getLiveuid())); + } + return true; + } + + @Override + protected boolean isMessageViewType(MessageContent messageContent) { + return messageContent instanceof RecommendLiveRoom; + } + + @Override + public Spannable getSummarySpannable(Context context, RecommendLiveRoom recommendLiveRoom) { + String politicalInstructor = ""; + if (recommendLiveRoom != null && !TextUtils.isEmpty(recommendLiveRoom.getContent())) { + RecommendLiveRoomModel model = new Gson().fromJson(recommendLiveRoom.getContent(), RecommendLiveRoomModel.class); + } + return new SpannableString(politicalInstructor + mContext.getString(R.string.live_room_air_ticket)); + } +} diff --git a/live/src/main/res/layout/fragment_chat_conversation.xml b/live/src/main/res/layout/fragment_chat_conversation.xml new file mode 100644 index 000000000..8c8ad3e10 --- /dev/null +++ b/live/src/main/res/layout/fragment_chat_conversation.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/live/src/main/res/layout/rc_conversationlist_item.xml b/live/src/main/res/layout/rc_conversationlist_item.xml index 93ebf0431..331e14de7 100644 --- a/live/src/main/res/layout/rc_conversationlist_item.xml +++ b/live/src/main/res/layout/rc_conversationlist_item.xml @@ -10,9 +10,9 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginStart="8dp" - android:visibility="gone" android:layout_marginTop="5dp" - android:layout_marginEnd="8dp"> + android:layout_marginEnd="8dp" + android:visibility="gone"> diff --git a/live/src/main/res/layout/view_input_panel.xml b/live/src/main/res/layout/view_input_panel.xml index 39edf6596..9a979e213 100644 --- a/live/src/main/res/layout/view_input_panel.xml +++ b/live/src/main/res/layout/view_input_panel.xml @@ -35,6 +35,7 @@ android:layout_marginEnd="5dp" android:layout_marginBottom="6.5dp" android:layout_weight="1" + android:textColor="#161616" android:background="@drawable/rc_ext_panel_editbox_background" android:maxLines="4" /> diff --git a/main/src/main/java/com/yunbao/main/activity/MainActivity.java b/main/src/main/java/com/yunbao/main/activity/MainActivity.java index d46603ece..1db750513 100644 --- a/main/src/main/java/com/yunbao/main/activity/MainActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/MainActivity.java @@ -23,24 +23,16 @@ import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.RelativeLayout; import android.widget.TextView; -import android.widget.Toast; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import androidx.viewpager.widget.ViewPager; -import com.adjust.sdk.Adjust; -import com.adjust.sdk.AdjustEvent; import com.alibaba.android.arouter.facade.annotation.Route; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; -import com.android.billingclient.api.BillingResult; import com.android.billingclient.api.Purchase; -import com.android.billingclient.api.PurchaseHistoryRecord; -import com.android.billingclient.api.PurchaseHistoryResponseListener; import com.android.billingclient.api.SkuDetails; -import com.facebook.appevents.AppEventsConstants; import com.google.android.gms.tasks.OnCompleteListener; import com.google.android.gms.tasks.Task; import com.google.firebase.messaging.FirebaseMessaging; @@ -53,7 +45,6 @@ import com.tencent.imsdk.v2.V2TIMSDKConfig; import com.tencent.imsdk.v2.V2TIMSDKListener; import com.tencent.imsdk.v2.V2TIMUserFullInfo; import com.yunbao.common.CommonAppConfig; -import com.yunbao.common.CommonAppContext; import com.yunbao.common.Constants; import com.yunbao.common.activity.AbsActivity; import com.yunbao.common.activity.WebViewActivity; @@ -140,17 +131,12 @@ import io.reactivex.disposables.Disposable; import io.rong.imkit.config.RongConfigCenter; import io.rong.imkit.notification.NotificationConfig; import io.rong.imlib.RongIMClient; -import kotlin.Unit; - -import static com.yunbao.common.CommonAppContext.isReady; -import static com.yunbao.common.CommonAppContext.logger; -import static com.yunbao.common.CommonAppContext.mFirebaseAnalytics; -import static com.yunbao.live.activity.SystemMessageActivity.type; - import io.rong.imlib.model.Message; import io.rong.push.PushManager; import io.rong.push.PushType; -import kotlin.*; +import kotlin.Unit; + +import static com.yunbao.common.CommonAppContext.isReady; @Route(path = RouteUtil.PATH_MAIN) public class MainActivity extends AbsActivity implements MainAppBarLayoutListener { @@ -242,9 +228,9 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene @Override public boolean onRecheck(@NonNull String skuType, @NonNull Purchase purchase, boolean isSelf) { - Log.e(TAG,purchase.getSku()+"s"+purchase.getOrderId()+"sds"+purchase.getPurchaseToken()); + Log.e(TAG, purchase.getSku() + "s" + purchase.getOrderId() + "sds" + purchase.getPurchaseToken()); //谷歌掉单处理 - CommonHttpUtil.Google_sec_pay(purchase.getPurchaseToken(),purchase.getOrderId(),purchase.getSku(),new HttpCallback() { + CommonHttpUtil.Google_sec_pay(purchase.getPurchaseToken(), purchase.getOrderId(), purchase.getSku(), new HttpCallback() { @Override public void onSuccess(int code, String msg, String[] info) { @@ -341,7 +327,7 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene RCRTCConfig.Builder config = RCRTCConfig.Builder.create(); RCRTCEngine.getInstance().init(MainActivity.this, config.build()); //推送跳直播间 - if(getIntent().getStringExtra("liveid")!=null){ + if (getIntent().getStringExtra("liveid") != null) { LiveHttpUtil.getLiveInfo(getIntent().getStringExtra("liveid") + "", new HttpCallback() { @Override public void onSuccess(int code, String msg, String[] info) { @@ -365,13 +351,13 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene } } }); - }else if(getIntent().getStringExtra("type")!=null&&getIntent().getStringExtra("type").equals("2")){ + } else if (getIntent().getStringExtra("type") != null && getIntent().getStringExtra("type").equals("2")) { //跳转消息列表 Bundle bundle = new Bundle(); bundle.putInt(PDLiveConversationListActivity.MESSAGENUMBER, messageNumber); bundle.putInt(PDLiveConversationListActivity.NUMBERME, numberMe); ConversationIMListManager.get(this).jumpConversationList(bundle); - }else if(getIntent().getStringExtra("type")!=null&&getIntent().getStringExtra("type").equals("8")){ + } else if (getIntent().getStringExtra("type") != null && getIntent().getStringExtra("type").equals("8")) { WebViewActivity.forward(mContext, getIntent().getStringExtra("activityUrl"), true); } FirebaseMessaging.getInstance().getToken() diff --git a/main/src/main/java/com/yunbao/main/activity/PDLiveConversationListActivity.java b/main/src/main/java/com/yunbao/main/activity/PDLiveConversationListActivity.java index ff86667ae..00eeb2ed8 100644 --- a/main/src/main/java/com/yunbao/main/activity/PDLiveConversationListActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/PDLiveConversationListActivity.java @@ -44,11 +44,17 @@ import com.yunbao.common.manager.imrongcloud.MessageIMManager; import com.yunbao.common.utils.DeviceUtils; import com.yunbao.common.utils.DialogUitl; import com.yunbao.common.utils.ProcessResultUtil; +import com.yunbao.common.utils.RouteUtil; import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.views.weight.ViewClicksAntiShake; +import com.yunbao.live.activity.LiveAudienceActivity; import com.yunbao.live.activity.SystemMessageActivity; import com.yunbao.live.bean.ImUserBean; +import com.yunbao.live.bean.LiveBean; +import com.yunbao.live.event.RecommendLiveRoomEvent; import com.yunbao.live.http.ImHttpUtil; +import com.yunbao.live.http.LiveHttpUtil; +import com.yunbao.live.presenter.LiveRoomCheckLivePresenter; import com.yunbao.main.R; import com.yunbao.main.adapter.SystemMessageAdapter; import com.yunbao.main.dialog.MainStartDialogFragment; @@ -193,7 +199,7 @@ public class PDLiveConversationListActivity extends AbsActivity implements View. container.post(new Runnable() { @Override public void run() { - showGuideView(); +// showGuideView(); } }); } @@ -261,7 +267,7 @@ public class PDLiveConversationListActivity extends AbsActivity implements View. textNewsNotice.setVisibility(View.VISIBLE); textNewsNotice.setText(userBean.getNum()); } - ImgLoader.display(mContext, userBean.getImage(), imgNewsNotice); + ImgLoader.display(mContext, userBean.getNewImage(), imgNewsNotice); ViewClicksAntiShake.clicksAntiShake(imgNewsNotice, () -> { type = userBean.getType(); netHandler.post(systemNumberRunnable); @@ -280,7 +286,7 @@ public class PDLiveConversationListActivity extends AbsActivity implements View. textNewsInteraction.setVisibility(View.VISIBLE); textNewsInteraction.setText(userBean.getNum()); } - ImgLoader.display(mContext, userBean.getImage(), imgNewsInteraction); + ImgLoader.display(mContext, userBean.getNewImage(), imgNewsInteraction); ViewClicksAntiShake.clicksAntiShake(imgNewsInteraction, () -> { type = userBean.getType(); netHandler.post(systemNumberRunnable); @@ -299,7 +305,7 @@ public class PDLiveConversationListActivity extends AbsActivity implements View. textNewsOnline.setVisibility(View.VISIBLE); textNewsOnline.setText(userBean.getNum()); } - ImgLoader.display(mContext, userBean.getImage(), imgNewsOnline); + ImgLoader.display(mContext, userBean.getNewImage(), imgNewsOnline); ViewClicksAntiShake.clicksAntiShake(imgNewsOnline, () -> { type = userBean.getType(); netHandler.post(systemNumberRunnable); @@ -585,4 +591,24 @@ public class PDLiveConversationListActivity extends AbsActivity implements View. MessageIMManager.get(mContext).setSystemNumber(systemNumber); } + @Subscribe(threadMode = ThreadMode.MAIN) + public void onRecommendLiveRoomEvent(RecommendLiveRoomEvent event) { + LiveHttpUtil.getLiveInfo(event.getLiveuid(), new 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); + LiveRoomCheckLivePresenter mCheckLivePresenter = new LiveRoomCheckLivePresenter(mContext, (liveBean1, liveType, liveTypeVal, liveSdk) -> { + if (liveBean1 == null) { + return; + } + LiveAudienceActivity.forward(mContext, liveBean1, liveType, liveTypeVal, "", 0, liveSdk); + }); + mCheckLivePresenter.checkLive(liveBean); + } else { + RouteUtil.forwardUserHome(mContext, event.getLiveuid(), 0); + } + } + }); + } } diff --git a/main/src/main/java/com/yunbao/main/manager/imrongcloud/ConversationIMListManager.java b/main/src/main/java/com/yunbao/main/manager/imrongcloud/ConversationIMListManager.java index 9bba5a866..845713d7a 100644 --- a/main/src/main/java/com/yunbao/main/manager/imrongcloud/ConversationIMListManager.java +++ b/main/src/main/java/com/yunbao/main/manager/imrongcloud/ConversationIMListManager.java @@ -22,12 +22,14 @@ import com.yunbao.common.utils.RouteUtil; import com.yunbao.live.activity.PDLIiveChatActivity; import com.yunbao.live.activity.PDLiveConversationActivity; import com.yunbao.live.bean.SearchUserBean; +import com.yunbao.live.dialog.PDLIiveChatConversationFragment; import com.yunbao.main.activity.PDLiveConversationListActivity; import com.yunbao.main.dialog.ConversationPopuwWindow; import com.yunbao.main.utils.PDLiveCustomConversationProvider; import com.yunbao.main.utils.PDLiveMessageProcessor; import com.yunbao.main.utils.PDSightMessageItemProvider; +import java.util.ArrayList; import java.util.List; import io.rong.imkit.IMCenter; @@ -43,6 +45,7 @@ import io.rong.imkit.utils.RouteUtils; import io.rong.imkit.widget.adapter.ProviderManager; import io.rong.imlib.RongIMClient; import io.rong.imlib.model.Conversation; +import io.rong.imlib.model.MessageContent; import io.rong.imlib.model.UserInfo; import io.rong.sight.SightExtensionModule; @@ -71,6 +74,7 @@ public class ConversationIMListManager { RongExtensionManager.getInstance().registerExtensionModule(new SightExtensionModule()); //自定义小视频消息模板 RongConfigCenter.conversationConfig().replaceMessageProvider(SightMessageItemProvider.class, new PDSightMessageItemProvider()); + //会话列表监听事件 RongIM.setConversationListBehaviorListener(listener); } @@ -275,7 +279,16 @@ public class ConversationIMListManager { */ @Override public boolean onConversationClick(Context context, View view, BaseUiConversation baseUiConversation) { - jumpConversation((Activity) context, baseUiConversation.mCore.getTargetId()); + if (context instanceof PDLIiveChatActivity) { + Bundle bundle = new Bundle(); + bundle.putString("targetId", baseUiConversation.mCore.getTargetId()); + PDLIiveChatActivity activity = (PDLIiveChatActivity) context; + PDLIiveChatConversationFragment fragment = new PDLIiveChatConversationFragment(); + fragment.setArguments(bundle); + fragment.show(activity.getSupportFragmentManager(), "PDLIiveChatConversationFragment"); + } else { + jumpConversation((Activity) context, baseUiConversation.mCore.getTargetId()); + } return true; } }; diff --git a/main/src/main/java/com/yunbao/main/utils/PDLiveCustomConversationProvider.java b/main/src/main/java/com/yunbao/main/utils/PDLiveCustomConversationProvider.java index cd34f10ba..6142d3e55 100644 --- a/main/src/main/java/com/yunbao/main/utils/PDLiveCustomConversationProvider.java +++ b/main/src/main/java/com/yunbao/main/utils/PDLiveCustomConversationProvider.java @@ -64,7 +64,7 @@ public class PDLiveCustomConversationProvider extends BaseConversationProvider { holder.setText(R.id.conversation_title, userInfo.getName()); if (uiConversation.mCore.getLatestMessage() instanceof TextMessage) { TextMessage message = (TextMessage) uiConversation.mCore.getLatestMessage(); - holder.setText(R.id.rc_conversation_content, message.getContent()); + holder.setText(R.id.conversation_content, message.getContent()); } if (uiConversation.mCore.getUnreadMessageCount() == 0) { holder.setVisible(R.id.conversation_unread, false);