fix [私聊消息-直播中无正在直播标识]

This commit is contained in:
zlzw 2024-03-23 16:49:47 +08:00
parent d08861a082
commit c20708d633
6 changed files with 152 additions and 24 deletions

View File

@ -1297,4 +1297,8 @@ public interface PDLiveApi {
@GET("/api/public/?service=Pdlinfos.getIsSet")
Observable<ResponseModel<FirstLoginBean>> isFirstLogin(
);
@GET("/api/public/?service=Pdlinfos.getIsLive")
Observable<ResponseModel<List<Integer>>> getUserLiveStatus(
@Query("ids")String ids
);
}

View File

@ -3522,6 +3522,25 @@ public class LiveNetManager {
}
}).isDisposed();
}
public void getUserLiveStatus(String ids,HttpCallback<List<Integer>> 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<Throwable>() {
@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);

View File

@ -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<UiMessage> listener) {
super(listener);
}
@ -83,8 +94,22 @@ public class PDLiveMessageListAdapter extends MessageListAdapter {
});
TextView tv = holder.getView(R.id.rc_time);
long sentTime = mDataList.get(position).getSentTime();
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,6 +224,7 @@ 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 "";
@ -246,6 +273,7 @@ public class PDLiveMessageListAdapter extends MessageListAdapter {
return formatTime;
}
}
public static String formatDate(Date date, String fromat) {
if (TextUtils.isEmpty(fromat)) {
return "";

View File

@ -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<List<Integer>>() {
@Override
public void onSuccess(List<Integer> 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;
}

View File

@ -32,25 +32,60 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/ll_content" />
<RelativeLayout
android:layout_width="@dimen/rc_message_portrait_size"
android:layout_height="@dimen/rc_message_portrait_size"
android:id="@+id/rc_left_portrait_layout"
app:layout_constraintStart_toEndOf="@id/rc_selected"
app:layout_constraintTop_toTopOf="@id/ll_content"
app:layout_goneMarginStart="@dimen/rc_margin_size_12">
<ImageView
android:id="@+id/rc_left_portrait"
android:layout_width="@dimen/rc_message_portrait_size"
android:layout_height="@dimen/rc_message_portrait_size"
android:layout_marginStart="@dimen/rc_margin_size_4"
android:src="@color/rc_secondary_color"
app:layout_constraintStart_toEndOf="@id/rc_selected"
android:src="@color/rc_secondary_color" />
<pl.droidsonroids.gif.GifImageView
android:id="@+id/left_liveStatus"
android:layout_width="wrap_content"
android:layout_height="12dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:src="@mipmap/icon_liveing"
tools:visibility="visible"
android:visibility="gone" />
</RelativeLayout>
<RelativeLayout
android:layout_width="@dimen/rc_message_portrait_size"
android:layout_height="@dimen/rc_message_portrait_size"
android:layout_marginEnd="@dimen/rc_margin_size_12"
android:id="@+id/rc_right_portrait_layout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/ll_content"
app:layout_goneMarginStart="@dimen/rc_margin_size_12" />
app:layout_goneMarginTop="@dimen/rc_margin_size_20" >
<ImageView
android:id="@+id/rc_right_portrait"
android:layout_width="@dimen/rc_message_portrait_size"
android:layout_height="@dimen/rc_message_portrait_size"
android:layout_marginEnd="@dimen/rc_margin_size_12"
android:src="@color/rc_secondary_color"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/ll_content"
app:layout_goneMarginTop="@dimen/rc_margin_size_20" />
/>
<pl.droidsonroids.gif.GifImageView
android:id="@+id/right_liveStatus"
android:layout_width="wrap_content"
android:layout_height="12dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:src="@mipmap/icon_liveing"
tools:visibility="visible"
android:visibility="gone" />
</RelativeLayout>
<LinearLayout
android:id="@+id/ll_content"
@ -59,8 +94,8 @@
android:layout_marginStart="@dimen/rc_margin_size_8"
android:layout_marginEnd="@dimen/rc_margin_size_8"
android:orientation="vertical"
app:layout_constraintEnd_toStartOf="@id/rc_right_portrait"
app:layout_constraintStart_toEndOf="@id/rc_left_portrait"
app:layout_constraintEnd_toStartOf="@id/rc_right_portrait_layout"
app:layout_constraintStart_toEndOf="@id/rc_left_portrait_layout"
app:layout_constraintTop_toBottomOf="@id/rc_time">
<TextView

View File

@ -182,7 +182,6 @@ public class PDLiveConversationActivity extends AbsActivity implements View.OnCl
* 数据的设置
*/
private void initData() {
targetId = getIntent().getStringExtra("targetId");
NoviceInstructorModel model = NoviceInstructorManager.get(this).getNoviceInstructor();
//绑定聊天用户id
@ -219,7 +218,8 @@ public class PDLiveConversationActivity extends AbsActivity implements View.OnCl
private void initView() {
try {
// 添加会话界面
conversationFragment = new PDLiveConversationFragment();
targetId = getIntent().getStringExtra("targetId");
conversationFragment = new PDLiveConversationFragment(targetId);
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.container, conversationFragment);