房间内新增私聊提醒

This commit is contained in:
huangjian
2021-11-12 15:35:27 +08:00
parent 850259b1b1
commit a03c1e3b4c
6 changed files with 167 additions and 0 deletions

View File

@@ -1,16 +1,33 @@
package com.yizhuan.erban.avroom.widget;
import android.animation.Keyframe;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.netease.nim.uikit.api.NimUIKit;
import com.netease.nim.uikit.common.util.sys.ScreenUtil;
import com.netease.nimlib.sdk.msg.model.RecentContact;
import com.netease.nimlib.sdk.uinfo.model.UserInfo;
import com.yizhuan.erban.R;
import com.yizhuan.erban.avroom.BottomViewListenerWrapper;
import com.yizhuan.erban.ui.utils.ImageLoadUtils;
import com.yizhuan.tutu.room_chat.activity.RoomMsgActivity;
import com.yizhuan.xchat_android_core.manager.AvRoomDataManager;
import com.yizhuan.xchat_android_core.manager.IMMessageManager;
import com.yizhuan.xchat_android_core.market_verify.MarketVerifyModel;
@@ -19,6 +36,8 @@ import com.yizhuan.xchat_android_core.room.bean.RoomModeType;
import com.yizhuan.xchat_android_core.room.pk.model.PkModel;
import com.yizhuan.xchat_android_core.super_admin.util.SuperAdminUtil;
import com.yizhuan.xchat_android_core.utils.SharedPreferenceUtils;
import com.yizhuan.xchat_android_core.utils.StringExtensionKt;
import com.yizhuan.xchat_android_library.utils.ListUtils;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@@ -56,6 +75,11 @@ public class BottomView extends RelativeLayout implements View.OnClickListener {
private ImageView iconMicQueue;
private ImageView iconRoomMsg;
@Nullable
private PopupWindow msgTipPopupWindow;
@NonNull
private final Runnable msgRunnable = this::dismissMsgPopupWindow;
public BottomView(Context context) {
super(context);
init();
@@ -123,6 +147,8 @@ public class BottomView extends RelativeLayout implements View.OnClickListener {
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
dismissMsgPopupWindow();
iconRoomMsg.removeCallbacks(msgRunnable);
EventBus.getDefault().unregister(this);
}
@@ -153,6 +179,9 @@ public class BottomView extends RelativeLayout implements View.OnClickListener {
@Subscribe(threadMode = ThreadMode.MAIN)
public void onReceiveRecentContactChanged(List<RecentContact> imMessages) {
setRoomMessageUnread(IMMessageManager.get().queryUnreadMsg());
if (!ListUtils.isListEmpty(imMessages)) {
iconRoomMsg.post(() -> showMsgPopup(iconRoomMsg, imMessages.get(0)));
}
}
public void setRoomMessageUnread(int count) {
@@ -338,4 +367,74 @@ public class BottomView extends RelativeLayout implements View.OnClickListener {
public View getSendGiftView() {
return sendGift;
}
private void dismissMsgPopupWindow() {
if (msgTipPopupWindow != null) {
try {
msgTipPopupWindow.dismiss();
}
catch (Exception e){
e.printStackTrace();
}
msgTipPopupWindow = null;
}
}
private void showMsgPopup(View parent, RecentContact recentContact) {
if (parent == null || recentContact == null || recentContact.getUnreadCount() == 0) return;
if (getContext() instanceof Activity && ((Activity) getContext()).isFinishing()) return;
UserInfo userInfo = NimUIKit.getUserInfoProvider().getUserInfo(recentContact.getFromAccount());
if (userInfo == null) return;
parent.removeCallbacks(msgRunnable);
View contentView;
if (msgTipPopupWindow == null) {
contentView = LayoutInflater.from(getContext()).inflate(R.layout.popup_message_tip, null);
msgTipPopupWindow = new PopupWindow(contentView, ScreenUtil.dip2px(90), ScreenUtil.dip2px(55));
msgTipPopupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
msgTipPopupWindow.setAnimationStyle(R.style.style_anim_message_tip);
} else {
contentView = msgTipPopupWindow.getContentView();
View clContent = contentView.findViewById(R.id.cl_content);
Keyframe kx0 = Keyframe.ofFloat(0f, 0);
Keyframe kx1 = Keyframe.ofFloat(0.5f, ScreenUtil.dip2px(54));
Keyframe kx2 = Keyframe.ofFloat(0.5f, -ScreenUtil.dip2px(54));
Keyframe kx3 = Keyframe.ofFloat(1f, 0);
Keyframe ka0 = Keyframe.ofFloat(0f, 1f);
Keyframe ka1 = Keyframe.ofFloat(0.5f, 0f);
Keyframe ka2 = Keyframe.ofFloat(1f, 1f);
PropertyValuesHolder p0 = PropertyValuesHolder.ofKeyframe("translationX", kx0, kx1, kx2, kx3);
PropertyValuesHolder p4 = PropertyValuesHolder.ofKeyframe("alpha", ka0, ka1, ka2);
ObjectAnimator objectAnimator = ObjectAnimator.ofPropertyValuesHolder(clContent, p0, p4);
objectAnimator.setDuration(200);
objectAnimator.start();
}
ImageView ivAvatar = contentView.findViewById(R.id.iv_avatar);
TextView tvNickname = contentView.findViewById(R.id.tv_nickname);
TextView tvContent = contentView.findViewById(R.id.tv_content);
ImageLoadUtils.loadAvatar(userInfo.getAvatar(), ivAvatar);
tvNickname.setText(StringExtensionKt.subAndReplaceDot(userInfo.getName(), 4));
tvContent.setText(recentContact.getContent());
contentView.setOnClickListener(v -> RoomMsgActivity.startForPrivateChat(getContext(), recentContact.getFromAccount()));
int[] vLoc = new int[2];
parent.getLocationInWindow(vLoc);
try {
msgTipPopupWindow.showAtLocation(
parent,
Gravity.START | Gravity.TOP,
vLoc[0] - ScreenUtil.dip2px(30),//(90-30)/2
vLoc[1] - ScreenUtil.dip2px(60)//55+5
);
} catch (Exception e) {
e.printStackTrace();
}
parent.postDelayed(msgRunnable, 3000);
}
}

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:duration="1000"
android:fromAlpha="0.0"
android:toAlpha="1.0"/>
</set>

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:duration="1000"
android:fromAlpha="1.0"
android:toAlpha="0.0"/>
</set>

View File

@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/ll_container"
android:layout_width="90dp"
android:layout_height="55dp"
android:background="@drawable/bg_room_message_popup"
android:orientation="vertical"
android:paddingStart="4dp"
android:paddingTop="4dp"
android:paddingEnd="4dp">
<LinearLayout
android:id="@+id/cl_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.yizhuan.erban.common.widget.CircleImageView
android:id="@+id/iv_avatar"
android:layout_width="25dp"
android:layout_height="25dp"
android:src="@drawable/default_avatar" />
<TextView
android:id="@+id/tv_nickname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="5dp"
android:lines="1"
android:textColor="@color/color_7154EE"
android:textSize="10dp"
tools:text="用户昵称用户昵称称称" />
</LinearLayout>
<TextView
android:id="@+id/tv_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:ellipsize="end"
android:lines="1"
android:textColor="@color/color_333333"
android:textSize="10dp"
tools:text="一二三四五六七八" />
</LinearLayout>

View File

@@ -539,4 +539,9 @@
<item name="bottomSheetStyle">@style/ErbanBottomSheetModel</item>
</style>
<style name="style_anim_message_tip">
<item name="android:windowEnterAnimation">@anim/anim_message_tip_in</item>
<item name="android:windowExitAnimation">@anim/anim_message_tip_out</item>
</style>
</resources>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB