From c20708d633c75effda99f227e7b290844b80fc1c Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Sat, 23 Mar 2024 16:49:47 +0800 Subject: [PATCH] =?UTF-8?q?fix=20[=E7=A7=81=E8=81=8A=E6=B6=88=E6=81=AF-?= =?UTF-8?q?=E7=9B=B4=E6=92=AD=E4=B8=AD=E6=97=A0=E6=AD=A3=E5=9C=A8=E7=9B=B4?= =?UTF-8?q?=E6=92=AD=E6=A0=87=E8=AF=86]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yunbao/common/http/PDLiveApi.java | 4 ++ .../common/http/live/LiveNetManager.java | 19 +++++++ .../live/dialog/PDLiveMessageListAdapter.java | 48 ++++++++++++---- .../views/PDLiveConversationFragment.java | 44 +++++++++++++- live/src/main/res/layout/rc_message_item.xml | 57 +++++++++++++++---- .../activity/PDLiveConversationActivity.java | 4 +- 6 files changed, 152 insertions(+), 24 deletions(-) diff --git a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java index 61c5339bf..d160b8684 100644 --- a/common/src/main/java/com/yunbao/common/http/PDLiveApi.java +++ b/common/src/main/java/com/yunbao/common/http/PDLiveApi.java @@ -1297,4 +1297,8 @@ public interface PDLiveApi { @GET("/api/public/?service=Pdlinfos.getIsSet") Observable> isFirstLogin( ); + @GET("/api/public/?service=Pdlinfos.getIsLive") + Observable>> getUserLiveStatus( + @Query("ids")String ids + ); } diff --git a/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java b/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java index 347a90133..70479bfd2 100644 --- a/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java +++ b/common/src/main/java/com/yunbao/common/http/live/LiveNetManager.java @@ -3522,6 +3522,25 @@ public class LiveNetManager { } }).isDisposed(); } + public void getUserLiveStatus(String ids,HttpCallback> callback) { + API.get().pdLiveApi(mContext) + .getUserLiveStatus(ids) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(roomMicStatusModelResponseModel -> { + if (callback != null) { + callback.onSuccess(roomMicStatusModelResponseModel.getData().getInfo()); + } + }, new Consumer() { + @Override + public void accept(Throwable throwable) throws Exception { + throwable.printStackTrace(); + if (callback != null) { + callback.onError(mContext.getString(R.string.net_error)); + } + } + }).isDisposed(); + } private MultipartBody.Part createUploadFile(File file) { RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); return MultipartBody.Part.createFormData("file", file.getName(), requestBody); diff --git a/live/src/main/java/com/yunbao/live/dialog/PDLiveMessageListAdapter.java b/live/src/main/java/com/yunbao/live/dialog/PDLiveMessageListAdapter.java index 470c0915d..5c92c4b43 100644 --- a/live/src/main/java/com/yunbao/live/dialog/PDLiveMessageListAdapter.java +++ b/live/src/main/java/com/yunbao/live/dialog/PDLiveMessageListAdapter.java @@ -36,6 +36,17 @@ import io.rong.imlib.model.MessageContent; * 会话页面更改已读未读 */ public class PDLiveMessageListAdapter extends MessageListAdapter { + private boolean isLeftLive = false; + private boolean isRightLive = false; + + public void setLeftLive(boolean leftLive) { + isLeftLive = leftLive; + } + + public void setRightLive(boolean rightLive) { + isRightLive = rightLive; + } + public PDLiveMessageListAdapter(IViewProviderListener listener) { super(listener); } @@ -47,28 +58,28 @@ public class PDLiveMessageListAdapter extends MessageListAdapter { MessageContent content = mDataList.get(position).getMessage().getContent(); ImageView readReceipt = holder.getConvertView().findViewById(R.id.rc_read_receipt); TextView rcEdit = holder.getConvertView().findViewById(R.id.rc_edit); - if (rcEdit!=null){ + if (rcEdit != null) { rcEdit.setVisibility(View.GONE); } holder.getConvertView().setBackgroundColor(Color.parseColor("#00000000")); holder.itemView.setBackgroundColor(Color.parseColor("#00000000")); ImageView readReceiptNew = holder.getConvertView().findViewById(R.id.rc_read_receipt_new); - if (readReceiptNew!=null){ - if (messageDirection==Message.MessageDirection.SEND){ + if (readReceiptNew != null) { + if (messageDirection == Message.MessageDirection.SEND) { readReceiptNew.setVisibility(View.VISIBLE); - }else { + } else { readReceiptNew.setVisibility(View.GONE); } - if (readReceipt.getVisibility()==View.VISIBLE) { + if (readReceipt.getVisibility() == View.VISIBLE) { readReceiptNew.setBackgroundResource(R.mipmap.icon_message_read); } else { readReceiptNew.setBackgroundResource(R.mipmap.icon_message_unread); } - if (readReceipt!=null){ + if (readReceipt != null) { readReceipt.setVisibility(View.GONE); } - if(content instanceof MessageChatTipsContent){ + if (content instanceof MessageChatTipsContent) { readReceiptNew.setVisibility(View.GONE); } } @@ -83,8 +94,22 @@ public class PDLiveMessageListAdapter extends MessageListAdapter { }); TextView tv = holder.getView(R.id.rc_time); long sentTime = mDataList.get(position).getSentTime(); - tv.setText(getDateTimeString(sentTime,true, holder.getContext())); - + boolean isSender = mDataList.get(position).getMessage().getMessageDirection().equals(Message.MessageDirection.SEND); + tv.setText(getDateTimeString(sentTime, true, holder.getContext())); + if (holder.getView(R.id.left_liveStatus) != null) { + if (isLeftLive && !isSender) { + holder.getView(R.id.left_liveStatus).setVisibility(View.VISIBLE); + } else if (!isSender) { + holder.getView(R.id.left_liveStatus).setVisibility(View.GONE); + } + } + if (holder.getView(R.id.right_liveStatus)!=null) { + if (isRightLive && isSender) { + holder.getView(R.id.right_liveStatus).setVisibility(View.VISIBLE); + } else { + holder.getView(R.id.right_liveStatus).setVisibility(View.GONE); + } + } } @@ -137,6 +162,7 @@ public class PDLiveMessageListAdapter extends MessageListAdapter { return formatDate; } } + public static int judgeDate(Date date) { Calendar calendarToday = Calendar.getInstance(); calendarToday.set(11, 0); @@ -198,13 +224,14 @@ public class PDLiveMessageListAdapter extends MessageListAdapter { String timeFormat = Settings.System.getString(context.getContentResolver(), "time_12_24"); return timeFormat != null && timeFormat.equals("24"); } + private static String getTimeString(long dateMillis, Context context) { if (dateMillis <= 0L) { return ""; } else { Date date = new Date(dateMillis); String formatTime; - if (isTime24Hour(context)||true) { + if (isTime24Hour(context) || true) { formatTime = formatDate(date, "HH:mm"); } else { Calendar calendarTime = Calendar.getInstance(); @@ -246,6 +273,7 @@ public class PDLiveMessageListAdapter extends MessageListAdapter { return formatTime; } } + public static String formatDate(Date date, String fromat) { if (TextUtils.isEmpty(fromat)) { return ""; diff --git a/live/src/main/java/com/yunbao/live/views/PDLiveConversationFragment.java b/live/src/main/java/com/yunbao/live/views/PDLiveConversationFragment.java index 90a0c3d0d..0a42a1e67 100644 --- a/live/src/main/java/com/yunbao/live/views/PDLiveConversationFragment.java +++ b/live/src/main/java/com/yunbao/live/views/PDLiveConversationFragment.java @@ -10,10 +10,15 @@ import androidx.annotation.Nullable; import androidx.lifecycle.Observer; import com.yunbao.common.event.PDChatInputModeEvent; +import com.yunbao.common.http.base.HttpCallback; +import com.yunbao.common.http.live.LiveNetManager; +import com.yunbao.common.manager.IMLoginManager; import com.yunbao.live.dialog.PDLiveMessageListAdapter; import org.greenrobot.eventbus.EventBus; +import java.util.List; + import io.rong.imkit.conversation.ConversationFragment; import io.rong.imkit.conversation.MessageListAdapter; import io.rong.imkit.conversation.extension.InputMode; @@ -23,6 +28,16 @@ import io.rong.imkit.conversation.extension.RongExtensionViewModel; * 聊天详情页面 */ public class PDLiveConversationFragment extends ConversationFragment { + PDLiveMessageListAdapter adapter; + private String targetId = ""; + + public PDLiveConversationFragment(String targetId) { + this.targetId = targetId; + } + + public PDLiveConversationFragment() { + } + @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); @@ -47,9 +62,36 @@ public class PDLiveConversationFragment extends ConversationFragment { }); } + @Override + public void onResume() { + super.onResume(); + String ids = String.format("%s,%s", targetId, IMLoginManager.get(getContext()).getUserInfo().getId()); + LiveNetManager.get(getContext()) + .getUserLiveStatus(ids, new HttpCallback>() { + @Override + public void onSuccess(List data) { + if(data.isEmpty()){ + adapter.setLeftLive(false); + adapter.setRightLive(false); + adapter.notifyDataSetChanged(); + return; + } + adapter.setLeftLive(data.contains(Integer.parseInt(targetId))); + adapter.setRightLive(data.contains((int) IMLoginManager.get(getContext()).getUserInfo().getId())); + adapter.notifyDataSetChanged(); + } + + @Override + public void onError(String error) { + + } + }); + } + @Override protected MessageListAdapter onResolveAdapter() { - return new PDLiveMessageListAdapter(this); + adapter = new PDLiveMessageListAdapter(this); + return adapter; } diff --git a/live/src/main/res/layout/rc_message_item.xml b/live/src/main/res/layout/rc_message_item.xml index 496b5e44e..1372854f5 100644 --- a/live/src/main/res/layout/rc_message_item.xml +++ b/live/src/main/res/layout/rc_message_item.xml @@ -32,25 +32,60 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="@id/ll_content" /> - + app:layout_goneMarginStart="@dimen/rc_margin_size_12"> - + + + + + + + app:layout_goneMarginTop="@dimen/rc_margin_size_20" > + + + + + + +