From 0a6471163c5034c3fc69d552275c2c5d98457664 Mon Sep 17 00:00:00 2001 From: 18401019693 Date: Tue, 11 Oct 2022 10:26:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yunbao/live/adapter/LiveChatAdapter.java | 71 +++++++------------ .../yunbao/live/views/LiveRoomViewHolder.java | 2 +- .../live/views/OlineListItemViewHolder.java | 26 +++++++ live/src/main/res/layout/view_oline_item.xml | 24 +++++-- 4 files changed, 71 insertions(+), 52 deletions(-) diff --git a/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java b/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java index 49161eb03..8ee8974e4 100644 --- a/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java @@ -68,16 +68,13 @@ public class LiveChatAdapter extends RecyclerView.Adapter { mList = new ArrayList<>(); mInflater = LayoutInflater.from(context); model = IMLoginManager.get(context).getUserInfo(); - mOnClickListener = new View.OnClickListener() { - @Override - public void onClick(View v) { - Object tag = v.getTag(); - if (tag != null) { - LiveChatBean bean = (LiveChatBean) tag; - if (mOnItemClickListener != null) { - if (bean.getType() != LiveChatBean.SYSTEM) { - mOnItemClickListener.onItemClick(bean, 0); - } + mOnClickListener = v -> { + Object tag = v.getTag(); + if (tag != null) { + LiveChatBean bean = (LiveChatBean) tag; + if (mOnItemClickListener != null) { + if (bean.getType() != LiveChatBean.SYSTEM) { + mOnItemClickListener.onItemClick(bean, 0); } } } @@ -195,23 +192,16 @@ public class LiveChatAdapter extends RecyclerView.Adapter { rv_chat_active.setLayoutManager(gridLayoutManager); rv_chat_active.setAdapter(listAdapter); - tv_chat_active_into.setOnClickListener(new View.OnClickListener() {//点击打开活动 - @Override - public void onClick(View v) { - String url = CommonAppConfig.HOST + "/" + bean.getContent() + "?uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&anchorUid=" + LiveRoomViewHolder.mLiveUid; - Bundle bundle = new Bundle(); - bundle.putString("url", url); - LiveHDDialogFragment fragment = new LiveHDDialogFragment(); - fragment.setArguments(bundle); - fragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveHDDialogFragment"); - } - }); - v_chat_active_close.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - removetItem(bean); - } + //点击打开活动 + tv_chat_active_into.setOnClickListener(v -> { + String url = CommonAppConfig.HOST + "/" + bean.getContent() + "?uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&anchorUid=" + LiveRoomViewHolder.mLiveUid; + Bundle bundle = new Bundle(); + bundle.putString("url", url); + LiveHDDialogFragment fragment = new LiveHDDialogFragment(); + fragment.setArguments(bundle); + fragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveHDDialogFragment"); }); + v_chat_active_close.setOnClickListener(v -> removetItem(bean)); } else if (bean.getType() == -3 || bean.getType() == -4 || bean.getType() == -5) {//整蛊 if (bean.getBubble() != null && !bean.getBubble().equals("")) { //加载.9图聊天气泡 @@ -359,41 +349,31 @@ public class LiveChatAdapter extends RecyclerView.Adapter { } } - public void insertItem(LiveChatBean bean) { + public synchronized void insertItem(LiveChatBean bean) { + if (bean == null) { return; } int size = mList.size(); - if (size > 0) { - if (mList.get(size - 1).getType() == -10) { - mList.remove(size - 1); - size = size - 1; - } - } //设置最大展示99条消息 if (size == 100) { - mList.remove(1); + mList.remove(0); } mList.add(bean); - notifyItemChanged(size); - - LiveChatBean beanNull = new LiveChatBean(); - beanNull.setType(-10); - mList.add(beanNull); - notifyItemChanged(size + 1); if (isSlideToBottom(mRecyclerView)) { - mRecyclerView.scrollToPosition(size + 1); + mRecyclerView.scrollToPosition(getItemCount() - 1); } else { Bus.get().post(new LiveAudienceEvent() .setType(LiveAudienceEvent.LiveAudienceType.NEW_MESSAGE_REMINDER)); - if (bean.getAtUserID()!=null&&bean.getAtUserID().contains(String.valueOf(model.getId()))) { + if (bean.getAtUserID() != null && bean.getAtUserID().contains(String.valueOf(model.getId()))) { Bus.get().post(new LiveAudienceEvent() .setType(LiveAudienceEvent.LiveAudienceType.AT_MESSAGE)); - mPosition = size + 1; + mPosition = size; } } + notifyItemChanged(getItemCount() - 1); } @@ -422,10 +402,11 @@ public class LiveChatAdapter extends RecyclerView.Adapter { public void scrollToBottom() { if (mList.size() > 0) { - mRecyclerView.smoothScrollToPosition(getItemCount()); + mRecyclerView.smoothScrollToPosition(getItemCount() - 1); } } - public void scrollToAt(){ + + public void scrollToAt() { if (mList.size() > 0) { mRecyclerView.smoothScrollToPosition(mPosition); } diff --git a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java index 426416528..a1e4d51ae 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java @@ -813,7 +813,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis mChatRecyclerView.setLayoutParams(params1); mChatRecyclerView.setHasFixedSize(true); - mChatRecyclerView.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false)); + mChatRecyclerView.setLayoutManager(new LinearLayoutManager(mContext)); mChatRecyclerView.addItemDecoration(new TopGradual()); mLiveChatAdapter = new LiveChatAdapter(mContext); mLiveChatAdapter.setOnItemClickListener(new OnItemClickListener() { diff --git a/live/src/main/java/com/yunbao/live/views/OlineListItemViewHolder.java b/live/src/main/java/com/yunbao/live/views/OlineListItemViewHolder.java index fdbd6001a..7d4c7aa4a 100644 --- a/live/src/main/java/com/yunbao/live/views/OlineListItemViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/OlineListItemViewHolder.java @@ -6,22 +6,32 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; +import com.opensource.svgaplayer.SVGADrawable; +import com.opensource.svgaplayer.SVGAImageView; +import com.opensource.svgaplayer.SVGAParser; +import com.opensource.svgaplayer.SVGAVideoEntity; import com.yunbao.common.bean.OlineUserlistModel; import com.yunbao.common.event.OlineEvent; import com.yunbao.common.glide.ImgLoader; import com.yunbao.common.utils.Bus; +import com.yunbao.common.utils.SVGAViewUtils; import com.yunbao.common.views.weight.ClipPathCircleImage; import com.yunbao.common.views.weight.ViewClicksAntiShake; import com.yunbao.live.R; +import java.net.MalformedURLException; +import java.net.URL; + public class OlineListItemViewHolder extends RecyclerView.ViewHolder { private TextView userName; private ClipPathCircleImage avatar; + private SVGAImageView avatarSvaga; public OlineListItemViewHolder(@NonNull View itemView) { super(itemView); userName = itemView.findViewById(R.id.user_name); avatar = itemView.findViewById(R.id.avatar); + avatarSvaga = itemView.findViewById(R.id.avatar_svaga); } /** @@ -30,6 +40,22 @@ public class OlineListItemViewHolder extends RecyclerView.ViewHolder { * @param model 数据 */ public void setData(OlineUserlistModel model) { + try { + new SVGAParser(itemView.getContext()).parse(new URL(model.getDress().getAvatarFrame()), new SVGAParser.ParseCompletion() { + @Override + public void onComplete(SVGAVideoEntity videoItem) { + SVGADrawable drawable = new SVGADrawable(videoItem); + avatarSvaga.setImageDrawable(drawable); + SVGAViewUtils.playEndClear(avatarSvaga,false); + } + + @Override + public void onError() { + } + }); + } catch (MalformedURLException e) { + e.printStackTrace(); + } ImgLoader.displayAvatar(itemView.getContext(), model.getAvatar(), avatar); userName.setText(model.getUserNicename()); ViewClicksAntiShake.clicksAntiShake(itemView, new ViewClicksAntiShake.ViewClicksCallBack() { diff --git a/live/src/main/res/layout/view_oline_item.xml b/live/src/main/res/layout/view_oline_item.xml index 2a70923a5..1232ff5ab 100644 --- a/live/src/main/res/layout/view_oline_item.xml +++ b/live/src/main/res/layout/view_oline_item.xml @@ -9,12 +9,24 @@ android:layout_marginBottom="18dp" android:gravity="center_vertical"> - + + + + + + +