From b6c80f095d48a74a35228d3fb7ff122aedcac291 Mon Sep 17 00:00:00 2001 From: 18401019693 Date: Mon, 25 Jul 2022 17:56:21 +0800 Subject: [PATCH] 11111 --- common/build.gradle | 2 + .../dialog/MessageLongClickPopuwindow.java | 6 +- .../manager/imrongcloud/MessageIMManager.java | 1 - .../com/yunbao/common/utils/FileUtil.java | 43 +++++++++ .../res/layout/view_message_long_click.xml | 18 +++- .../res/mipmap-xxhdpi}/icon_message_copy.png | Bin .../res/mipmap-xxhdpi}/icon_message_quote.png | Bin .../live/dialog/PDLiveMessageListAdapter.java | 17 ++-- .../live/views/InputPanelViewHolder.java | 69 +++++++++++++- .../res/layout/rc_conversationlist_item.xml | 3 +- .../ConversationIMListManager.java | 4 + main/src/main/res/values/rc_config.xml | 89 ++++++++++++++++++ 12 files changed, 234 insertions(+), 18 deletions(-) rename {live/src/main/java/com/yunbao/live => common/src/main/java/com/yunbao/common}/dialog/MessageLongClickPopuwindow.java (80%) rename {live => common}/src/main/res/layout/view_message_long_click.xml (79%) rename {live/src/main/res/mipmap-xhdpi => common/src/main/res/mipmap-xxhdpi}/icon_message_copy.png (100%) rename {live/src/main/res/mipmap-xhdpi => common/src/main/res/mipmap-xxhdpi}/icon_message_quote.png (100%) create mode 100644 main/src/main/res/values/rc_config.xml diff --git a/common/build.gradle b/common/build.gradle index 520452acc..d7c4cca51 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -155,6 +155,8 @@ dependencies { //此处以集成 5.1.2 版本为例 api 'cn.rongcloud.sdk:im_lib:5.1.3.10' // 即时通讯基础能力库 api 'cn.rongcloud.sdk:im_kit:5.1.3.10' // 即时通讯 UI 基础组件 + //融云小视频模块 + api 'cn.rongcloud.sdk:sight:5.1.2' api 'com.facebook.android:facebook-login:8.2.0' api 'com.facebook.android:facebook-android-sdk:[5,6)' diff --git a/live/src/main/java/com/yunbao/live/dialog/MessageLongClickPopuwindow.java b/common/src/main/java/com/yunbao/common/dialog/MessageLongClickPopuwindow.java similarity index 80% rename from live/src/main/java/com/yunbao/live/dialog/MessageLongClickPopuwindow.java rename to common/src/main/java/com/yunbao/common/dialog/MessageLongClickPopuwindow.java index 6a8d0c685..1562414a3 100644 --- a/live/src/main/java/com/yunbao/live/dialog/MessageLongClickPopuwindow.java +++ b/common/src/main/java/com/yunbao/common/dialog/MessageLongClickPopuwindow.java @@ -1,11 +1,12 @@ -package com.yunbao.live.dialog; +package com.yunbao.common.dialog; import android.app.Activity; import android.view.LayoutInflater; import android.view.View; +import android.widget.LinearLayout; import android.widget.PopupWindow; -import com.yunbao.live.R; +import com.yunbao.common.R; /** * 消息長按彈窗 @@ -14,6 +15,7 @@ public class MessageLongClickPopuwindow { private Activity mContext; private View popupView; private PopupWindow popupWindow; + private LinearLayout copyLinear; public MessageLongClickPopuwindow(Activity context) { this.mContext = context; diff --git a/common/src/main/java/com/yunbao/common/manager/imrongcloud/MessageIMManager.java b/common/src/main/java/com/yunbao/common/manager/imrongcloud/MessageIMManager.java index a1b534f65..f38ad18c4 100644 --- a/common/src/main/java/com/yunbao/common/manager/imrongcloud/MessageIMManager.java +++ b/common/src/main/java/com/yunbao/common/manager/imrongcloud/MessageIMManager.java @@ -226,7 +226,6 @@ public class MessageIMManager { */ @Override public boolean onMessageLongClick(Context context, View view, Message message) { - ToastUtil.show(message.getContent().toString()); return true; } diff --git a/common/src/main/java/com/yunbao/common/utils/FileUtil.java b/common/src/main/java/com/yunbao/common/utils/FileUtil.java index 7dcb8ddcb..7e18855b0 100644 --- a/common/src/main/java/com/yunbao/common/utils/FileUtil.java +++ b/common/src/main/java/com/yunbao/common/utils/FileUtil.java @@ -1,5 +1,7 @@ package com.yunbao.common.utils; +import android.media.MediaMetadataRetriever; + import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -29,4 +31,45 @@ public class FileUtil { } } } + + /** + * 获取 视频 或 音频 时长 + * @param path 视频 或 音频 文件路径 + * @return 时长 毫秒值 + */ + public static long getDuration(String path){ + android.media.MediaMetadataRetriever mmr = new android.media.MediaMetadataRetriever(); + long duration=0; + try { + if (path!= null) { + mmr.setDataSource(path); + } + String time = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); + duration= Long.parseLong(time); + } catch (Exception ex) { + } finally { + mmr.release(); + } + return duration; + } + /** + * Android 音乐播放器应用里,读出的音乐时长为 long 类型以毫秒数为单位,例如:将 234736 转化为分钟和秒应为 03:55 (包含四舍五入) + * @param duration 音乐时长 + * @return + */ + public static String timeParse(long duration) { + String time = "" ; + long minute = duration / 60000 ; + long seconds = duration % 60000 ; + long second = Math.round((float)seconds/1000) ; + if( minute < 10 ){ + time += "0" ; + } + time += minute+":" ; + if( second < 10 ){ + time += "0" ; + } + time += second ; + return time ; + } } diff --git a/live/src/main/res/layout/view_message_long_click.xml b/common/src/main/res/layout/view_message_long_click.xml similarity index 79% rename from live/src/main/res/layout/view_message_long_click.xml rename to common/src/main/res/layout/view_message_long_click.xml index 8f8a5c0c7..32f2e9f1a 100644 --- a/live/src/main/res/layout/view_message_long_click.xml +++ b/common/src/main/res/layout/view_message_long_click.xml @@ -1,7 +1,7 @@ 2) { + sendFile(filePath); + } else { + sendSightExtension(filePath, duration); + } + Log.e("InputPanelViewHolder", "时长" + duration + "文件大小"); + + + } + + /** + * 发送小视频消息 + * + * @param filePath 文件路径 + * @param duration 视频时长 + */ + private void sendSightExtension(String filePath, long duration) { + long seconds = duration % 60000 ; + long second = Math.round((float)seconds/1000) ; + Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; + Uri localUri = Uri.parse("file://" + filePath); + SightMessage sightMessage = SightMessage.obtain(localUri, (int) second); + Message message = Message.obtain(targetId, conversationType, sightMessage); + 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); + } + });// + } + + /** + * 发送文件消息 + * + * @param filePath 文件路径 + */ + private void sendFile(String filePath) { + Message message; + Uri localUri = Uri.parse("file://" + filePath); Conversation.ConversationType conversationType = Conversation.ConversationType.PRIVATE; @@ -273,10 +338,8 @@ public class InputPanelViewHolder extends LinearLayout implements View.OnClickLi ToastUtil.show(errorCode.msg); } }); - } - /** * 多媒体信息 */ diff --git a/live/src/main/res/layout/rc_conversationlist_item.xml b/live/src/main/res/layout/rc_conversationlist_item.xml index 7f3354c54..0631d8c53 100644 --- a/live/src/main/res/layout/rc_conversationlist_item.xml +++ b/live/src/main/res/layout/rc_conversationlist_item.xml @@ -59,6 +59,7 @@ android:id="@+id/rc_conversation_read_receipt" android:layout_width="30dp" android:layout_height="15dp" + android:layout_marginTop="4dp" android:layout_marginEnd="4dp" android:visibility="gone" /> @@ -76,7 +77,7 @@ android:singleLine="true" android:text="你好,朋友!" android:textColor="@color/rc_secondary_color" - android:textSize="@dimen/rc_font_text_third_size" /> + android:textSize="15dp" /> providerManager = RongConfigCenter.conversationListConfig().getProviderManager(); //用自定义模板替换 SDK 原有模板 providerManager.replaceProvider(PrivateConversationProvider.class, new PDLiveCustomConversationProvider()); + //注册小视频模块 + RongExtensionManager.getInstance().registerExtensionModule(new SightExtensionModule()); //会话列表监听事件 RongIM.setConversationListBehaviorListener(listener); } diff --git a/main/src/main/res/values/rc_config.xml b/main/src/main/res/values/rc_config.xml new file mode 100644 index 000000000..9efe0ce80 --- /dev/null +++ b/main/src/main/res/values/rc_config.xml @@ -0,0 +1,89 @@ + + + + 10 + + + true + + + true + + + + + + + + + + /RongCloud/Image/ + + + /RongCloud/Video/ + + + /RongCloud/File/ + + + true + + 120 + + 300 + + + true + + + true + + + 120 + + + true + + + + + false + + + true + + + true + + + + true + + + true + + + 1024 + + + false + + + 100 + + + false + + + true + + + true + + + 10 + + 10 + + 10 + \ No newline at end of file