From a03c1e3b4c0f9acea2bcd4689b1bde5ee1502ac3 Mon Sep 17 00:00:00 2001 From: huangjian Date: Fri, 12 Nov 2021 15:35:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=BF=E9=97=B4=E5=86=85=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E7=A7=81=E8=81=8A=E6=8F=90=E9=86=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../erban/avroom/widget/BottomView.java | 99 ++++++++++++++++++ app/src/main/res/anim/anim_message_tip_in.xml | 7 ++ .../main/res/anim/anim_message_tip_out.xml | 7 ++ app/src/main/res/layout/popup_message_tip.xml | 49 +++++++++ app/src/main/res/values/styles.xml | 5 + .../drawable-xhdpi/bg_room_message_popup.png | Bin 0 -> 1140 bytes 6 files changed, 167 insertions(+) create mode 100644 app/src/main/res/anim/anim_message_tip_in.xml create mode 100644 app/src/main/res/anim/anim_message_tip_out.xml create mode 100644 app/src/main/res/layout/popup_message_tip.xml create mode 100644 app/src/module_labour_union/res/drawable-xhdpi/bg_room_message_popup.png diff --git a/app/src/main/java/com/yizhuan/erban/avroom/widget/BottomView.java b/app/src/main/java/com/yizhuan/erban/avroom/widget/BottomView.java index cef488d81..d9b561cb5 100644 --- a/app/src/main/java/com/yizhuan/erban/avroom/widget/BottomView.java +++ b/app/src/main/java/com/yizhuan/erban/avroom/widget/BottomView.java @@ -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 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); + } + } diff --git a/app/src/main/res/anim/anim_message_tip_in.xml b/app/src/main/res/anim/anim_message_tip_in.xml new file mode 100644 index 000000000..1edfeccc4 --- /dev/null +++ b/app/src/main/res/anim/anim_message_tip_in.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/anim_message_tip_out.xml b/app/src/main/res/anim/anim_message_tip_out.xml new file mode 100644 index 000000000..3186b3d6a --- /dev/null +++ b/app/src/main/res/anim/anim_message_tip_out.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/popup_message_tip.xml b/app/src/main/res/layout/popup_message_tip.xml new file mode 100644 index 000000000..06c813a70 --- /dev/null +++ b/app/src/main/res/layout/popup_message_tip.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 9148dd2c5..3a33e133b 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -539,4 +539,9 @@ @style/ErbanBottomSheetModel + + diff --git a/app/src/module_labour_union/res/drawable-xhdpi/bg_room_message_popup.png b/app/src/module_labour_union/res/drawable-xhdpi/bg_room_message_popup.png new file mode 100644 index 0000000000000000000000000000000000000000..ea2251a000e9e9295e54af46a7d88d3a4378b449 GIT binary patch literal 1140 zcmeAS@N?(olHy`uVBq!ia0vp^>wq|mgAGWkmS*`dFtAvAx;TbZ#J!zm+Z`J!;db5I zLrZXr*8!y)H*Q88x#r|yAoff?LPAl%F=??Ix1^6E<3xi5hcD_ZpHlO?1U3k2uNFDD zWTT*N3eWmC1(JDfEoWxlIr*XD+Pb#WcE4?^ZM#q3Owaq+aq;f&#^eKm4@@5@7}yni zBy8vW!+VFdj&&Wgec07w*JfY4#=onYfPMC8|_|;p>cHFI%*;b!ui4ni@{ZBHZHIaTx3GTME|zbT4!l%+SK%Vj&&9{NL|}*2k-e;Y zrcAmqM~LAaPvPR11q zAL-S8-p5+QCDV6nTH^opEP2fFVOOU<<;|;mtXIFoVngrqd&vh@A8<^Nc_brrBbQ0~ zfJMV!rWkg;@T))GEd1zESZ*D8>(|}CN+0+>C>s2WyZS@;2iJ~}(E2r57cJK;-XR?I z?%ngo^^J>#^{Ve&nSU%XBC*^ps8GG=^}B;_m>(!7$Yhio)kVmd{JVSdXx!#6VU7}) zIZD1ucmKE8XYkhRT=>IoATQ;UQbaM_z?I| zQ}pG#kCQLt&--xa_j!vOp;wnK-!pf*K8MCTu8;_u@B7$mm}G8jdJ_8}CG_u}rs$n5 zkJjC5d?&X*+m3k;=O5F!;@<57p{8-wmSG+b?29&?J$xW#Zvn70VeoYIb6Mw<&;$V1 C2?AvR literal 0 HcmV?d00001