From 842ef05dc784aa645b6d471a0fbc2363285daa8f Mon Sep 17 00:00:00 2001 From: 18401019693 Date: Mon, 17 Oct 2022 14:48:19 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=B4=E6=92=AD=E7=BB=93=E6=9D=9F=EF=BC=8C?= =?UTF-8?q?=E6=82=AC=E6=B5=AE=E7=AA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yunbao/common/event/LiveFloatEvent.java | 10 + .../com/yunbao/live/views/LiveFloatView.java | 27 +- .../live/views/PortraitLiveManager.java | 4 +- main/src/main/AndroidManifest.xml | 4 + .../yunbao/main/activity/MainActivity.java | 63 ++- .../PDLiveConversationListActivity.java | 38 +- .../main/views/MainMessageViewHolder.java | 403 ++++++++++++++++++ .../src/main/res/layout/view_main_message.xml | 143 +++++++ 8 files changed, 628 insertions(+), 64 deletions(-) create mode 100644 main/src/main/java/com/yunbao/main/views/MainMessageViewHolder.java create mode 100644 main/src/main/res/layout/view_main_message.xml diff --git a/common/src/main/java/com/yunbao/common/event/LiveFloatEvent.java b/common/src/main/java/com/yunbao/common/event/LiveFloatEvent.java index f66639ecb..3bf782a3e 100644 --- a/common/src/main/java/com/yunbao/common/event/LiveFloatEvent.java +++ b/common/src/main/java/com/yunbao/common/event/LiveFloatEvent.java @@ -11,6 +11,16 @@ public class LiveFloatEvent extends BaseModel { private int mLiveType; private int mLiveSDK; private int mLiveTypeVal; + private boolean isTime = true; + + public boolean isTime() { + return isTime; + } + + public LiveFloatEvent setTime(boolean time) { + isTime = time; + return this; + } public LiveBean getmLiveBean() { return mLiveBean; diff --git a/live/src/main/java/com/yunbao/live/views/LiveFloatView.java b/live/src/main/java/com/yunbao/live/views/LiveFloatView.java index 6d4da4631..e2d8ba290 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveFloatView.java +++ b/live/src/main/java/com/yunbao/live/views/LiveFloatView.java @@ -1,6 +1,7 @@ package com.yunbao.live.views; import android.app.Activity; +import android.text.TextUtils; import android.util.Log; import android.view.Gravity; import android.view.View; @@ -46,12 +47,15 @@ public class LiveFloatView implements Function1 { return instance; } - public void builderFloat(Activity mContext, String url) { + public void builderFloat(Activity mContext, String url,String tag) { + if (TextUtils.isEmpty(tag)){ + tag = TAG; + } liveOnInvokeView = new LiveOnInvokeView(); this.mContext = mContext; this.url = url; EasyFloat.with(mContext) - .setTag(TAG) + .setTag(tag) .setLayout(R.layout.view_flaot_live, liveOnInvokeView) .setShowPattern(ShowPattern.CURRENT_ACTIVITY) .setGravity(Gravity.END | Gravity.CENTER_VERTICAL, 0, 200) @@ -88,15 +92,20 @@ public class LiveFloatView implements Function1 { if (callback != null) { callback.invoke(aBoolean); } - builder.dismiss(new Function0() { - @Override - public Unit invoke() { - if (mPlayer != null && mPlayer.isPlaying() == 1) { - mPlayer.stopPlay(); - } - return null; + builder.dismiss(() -> { + if (mPlayer != null && mPlayer.isPlaying() == 1) { + mPlayer.stopPlay(); } + return null; }); + builder.hide(view12 -> { + if (mPlayer != null && mPlayer.isPlaying() == 1) { + mPlayer.pauseAudio(); + mPlayer.pauseVideo(); + } + return null; + }); + return null; }); return null; diff --git a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java index 1c8021341..12f0e7e80 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -384,7 +384,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe mContext.finish(); } else { EventBus.getDefault() - .post(new LiveFloatEvent() + .postSticky(new LiveFloatEvent() .setmLiveBean(mLiveBean) .setmLiveSDK(mLiveSDK) .setmLiveType(mLiveType) @@ -400,7 +400,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe @Override public void onCancel() { EventBus.getDefault() - .post(new LiveFloatEvent() + .postSticky(new LiveFloatEvent() .setmLiveBean(mLiveBean) .setmLiveSDK(mLiveSDK) .setmLiveType(mLiveType) diff --git a/main/src/main/AndroidManifest.xml b/main/src/main/AndroidManifest.xml index e1790638b..e9afd0342 100644 --- a/main/src/main/AndroidManifest.xml +++ b/main/src/main/AndroidManifest.xml @@ -2,6 +2,10 @@ + + + + diff --git a/main/src/main/java/com/yunbao/main/activity/MainActivity.java b/main/src/main/java/com/yunbao/main/activity/MainActivity.java index ea9aa880b..85e4c173d 100644 --- a/main/src/main/java/com/yunbao/main/activity/MainActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/MainActivity.java @@ -40,6 +40,7 @@ import com.google.firebase.messaging.FirebaseMessaging; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import com.jakewharton.rxbinding3.view.RxView; +import com.lzf.easyfloat.EasyFloat; import com.tencent.imsdk.v2.V2TIMCallback; import com.tencent.imsdk.v2.V2TIMManager; import com.tencent.imsdk.v2.V2TIMSDKConfig; @@ -111,6 +112,7 @@ import com.yunbao.main.views.MainHomeShopViewHolder; import com.yunbao.main.views.MainHomeVideoViewHolder; import com.yunbao.main.views.MainHomeViewHolder; import com.yunbao.main.views.MainMeViewHolder; +import com.yunbao.main.views.MainMessageViewHolder; import com.yunbao.video.utils.VideoStorge; import org.greenrobot.eventbus.EventBus; @@ -148,6 +150,7 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene private MainHomeLiveViewHolder mHomeLiveViewHolder; private MainHomeViewHolder mainHomeViewHolder; private MainHomeCommunityViewHolder mMainHomeCommunityViewHolder; + private MainMessageViewHolder mainMessageViewHolder; private MainHomeVideoViewHolder mainHomeVideoViewHolder; private MainHomeShopViewHolder mListShopViewHolder; private ChatListViewHolder mChatListViewHolder; @@ -252,10 +255,9 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene }); } else if (getIntent().getStringExtra("type") != null && getIntent().getStringExtra("type").equals("2")) { //跳转消息列表 - Bundle bundle = new Bundle(); - bundle.putInt(PDLiveConversationListActivity.MESSAGENUMBER, messageNumber); - bundle.putInt(PDLiveConversationListActivity.NUMBERME, numberMe); - ConversationIMListManager.get(this).jumpConversationList(bundle); + mViewPager.setCurrentItem(2); + mTabButtonGroup.setCurPosition(2); + } else if (getIntent().getStringExtra("type") != null && getIntent().getStringExtra("type").equals("8")) { WebViewActivity.forward(mContext, getIntent().getStringExtra("activityUrl"), true); } @@ -450,9 +452,8 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene //选中监听 mTabButtonGroup.addTabButtonGroupChangeListener((view, index) -> { + if (index == 0) { -// floatBanner.setVisibility(View.VISIBLE); -// findViewById(R.id.banner_click).setVisibility(View.VISIBLE); isfloatBannernet = true; initAnchorRecommendBanner(); } else { @@ -934,11 +935,8 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene mMainHomeCommunityViewHolder = new MainHomeCommunityViewHolder(mContext, parent, this);//社区 vh = mMainHomeCommunityViewHolder; } else if (position == 2) { - //跳转消息列表 - Bundle bundle = new Bundle(); - bundle.putInt(PDLiveConversationListActivity.MESSAGENUMBER, messageNumber); - bundle.putInt(PDLiveConversationListActivity.NUMBERME, numberMe); - ConversationIMListManager.get(this).jumpConversationList(bundle); + mainMessageViewHolder = new MainMessageViewHolder(this, parent); + vh = mainMessageViewHolder; } else if (position == 3) { mMeViewHolder = new MainMeViewHolder(mContext, parent); vh = mMeViewHolder; @@ -1110,6 +1108,7 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene @Subscribe(threadMode = ThreadMode.MAIN) public void onPDLiveConversationListEvent(PDLiveConversationListEvent event) { + if (event.getPage() == 11) { finish(); } else if (event.getPage() == 17) { @@ -1183,11 +1182,9 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene @Subscribe(threadMode = ThreadMode.MAIN) public void onInstructorOperationEvent(InstructorOperationEvent event) { //跳转消息列表 - Bundle bundle = new Bundle(); - bundle.putInt(PDLiveConversationListActivity.MESSAGENUMBER, messageNumber); - bundle.putInt(PDLiveConversationListActivity.NUMBERME, numberMe); - bundle.putString(PDLiveConversationListActivity.POP, NoviceInstructorManager.get(this).getHomeZdyPop()); - ConversationIMListManager.get(mContext).jumpConversationList(bundle); + mViewPager.setCurrentItem(2); + mTabButtonGroup.setCurPosition(2); + mainMessageViewHolder.setHomeZdyPop(NoviceInstructorManager.get(this).getHomeZdyPop()); } /** @@ -1218,10 +1215,8 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene @Override public void onClick(View v) { //跳转消息列表 - Bundle bundle = new Bundle(); - bundle.putInt(PDLiveConversationListActivity.MESSAGENUMBER, messageNumber); - bundle.putInt(PDLiveConversationListActivity.NUMBERME, numberMe); - ConversationIMListManager.get(mContext).jumpConversationList(bundle); + mViewPager.setCurrentItem(2); + mTabButtonGroup.setCurPosition(2); } }); } else { @@ -1248,24 +1243,16 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene @Subscribe(threadMode = ThreadMode.MAIN) public void onLiveFloatEvent(LiveFloatEvent event) { - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - LiveFloatView.getInstance() - .setCallback(new LiveFloatView.LiveFloatViewCallback() { - @Override - public void invoke(Boolean aBoolean) { -// if (aBoolean) { -// mContext.finish(); -// } else { -// ToastUtil.show("未打开悬浮窗权限"); -// } - } - }) - .cacheLiveData(event.getmLiveBean(), event.getmLiveType(), event.getmLiveSDK(), event.getmLiveTypeVal()) - .builderFloat(mContext, event.getmLiveBean().getPull()); - } - },1500); + if (event.isTime()) { + new Handler().postDelayed(() -> LiveFloatView.getInstance() + .cacheLiveData(event.getmLiveBean(), event.getmLiveType(), event.getmLiveSDK(), event.getmLiveTypeVal()) + .builderFloat(mContext, event.getmLiveBean().getPull(), "Main"), 1500); + } else { + new Handler().post(() -> LiveFloatView.getInstance() + .cacheLiveData(event.getmLiveBean(), event.getmLiveType(), event.getmLiveSDK(), event.getmLiveTypeVal()) + .builderFloat(mContext, event.getmLiveBean().getPull(), "Main")); + } + } diff --git a/main/src/main/java/com/yunbao/main/activity/PDLiveConversationListActivity.java b/main/src/main/java/com/yunbao/main/activity/PDLiveConversationListActivity.java index 901d59d24..a61736459 100644 --- a/main/src/main/java/com/yunbao/main/activity/PDLiveConversationListActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/PDLiveConversationListActivity.java @@ -28,6 +28,7 @@ import com.binioter.guideview.Guide; import com.binioter.guideview.GuideBuilder; import com.facebook.appevents.AppEventsLogger; import com.google.firebase.analytics.FirebaseAnalytics; +import com.lzf.easyfloat.EasyFloat; import com.opensource.svgaplayer.SVGADrawable; import com.opensource.svgaplayer.SVGAImageView; import com.opensource.svgaplayer.SVGAParser; @@ -35,7 +36,9 @@ import com.opensource.svgaplayer.SVGAVideoEntity; import com.yunbao.common.activity.AbsActivity; import com.yunbao.common.activity.WebViewActivity; import com.yunbao.common.bean.ImUserInfoModel; +import com.yunbao.common.bean.LiveBean; import com.yunbao.common.custom.TabButtonGroup; +import com.yunbao.common.event.LiveFloatEvent; import com.yunbao.common.event.MessageIMEvent; import com.yunbao.common.event.UpdateTablePointMe; import com.yunbao.common.glide.ImgLoader; @@ -54,11 +57,11 @@ import com.yunbao.common.views.weight.ViewClicksAntiShake; import com.yunbao.live.activity.LiveAudienceActivity; import com.yunbao.live.activity.SystemMessageActivity; import com.yunbao.live.bean.ImUserBean; -import com.yunbao.common.bean.LiveBean; import com.yunbao.live.event.RecommendLiveRoomEvent; import com.yunbao.live.http.ImHttpUtil; import com.yunbao.live.http.LiveHttpUtil; import com.yunbao.live.presenter.LiveRoomCheckLivePresenter; +import com.yunbao.live.views.LiveFloatView; import com.yunbao.main.R; import com.yunbao.main.adapter.SystemMessageAdapter; import com.yunbao.main.dialog.MainStartDialogFragment; @@ -91,8 +94,8 @@ public class PDLiveConversationListActivity extends AbsActivity implements View. private TextView redPoint; private View redpointMe; private SystemMessageAdapter messageAdapter; - private ProcessResultUtil mProcessResultUtil; private TextView textNewsNotice, textNewsInteraction, textNewsOnline; + private ProcessResultUtil mProcessResultUtil; private ImageView newsIconClearance; private Handler netHandler = new Handler(); private String type = null; @@ -146,7 +149,7 @@ public class PDLiveConversationListActivity extends AbsActivity implements View. public void onComplete(SVGAVideoEntity videoItem) { SVGADrawable drawable = new SVGADrawable(videoItem); guidSvga.setImageDrawable(drawable); - SVGAViewUtils.playEndClear(guidSvga,false); + SVGAViewUtils.playEndClear(guidSvga, false); } @Override @@ -192,25 +195,26 @@ public class PDLiveConversationListActivity extends AbsActivity implements View. mTabButtonGroup.addTabButtonGroupChangeListener((view, index) -> { Log.e(CLASSNAME, "onPageSelected:" + index); if (index != 2) { + EasyFloat.hide("PDLiveConversationList"); //打开主页菜单,关闭消息中心 EventBus.getDefault().post(new PDLiveConversationListEvent().setPage(index)); //防止重新加载多个 startActivity(new Intent(mContext, MainActivity.class)); + } }); newsIconClearance.setOnClickListener(this); - container.post(new Runnable() { - @Override - public void run() { - String homeZdyPop = getIntent().getStringExtra(POP); - if (TextUtils.equals(homeZdyPop, "1")) { - showGuideView(); - NoviceInstructorManager.get(mContext).setHomeZdyPop(""); - } - + container.post(() -> { + String homeZdyPop = getIntent().getStringExtra(POP); + if (TextUtils.equals(homeZdyPop, "1")) { + showGuideView(); + NoviceInstructorManager.get(mContext).setHomeZdyPop(""); } - }); + }); + if (EasyFloat.isShow("LiveFloatView")) { + EasyFloat.show("LiveFloatView"); + } } private void showStartDialog() { @@ -440,7 +444,6 @@ public class PDLiveConversationListActivity extends AbsActivity implements View. DialogUitl.showSimpleDialog(mContext, null, getString(R.string.clear_unread_messages), false, new DialogUitl.SimpleCallback3() { @Override public void onConfirmClick(Dialog dialog) { -// ConversationIMListManager.get(mContext).getConversationListByPage(true); LiveNetManager.get(mContext) .setMessageReadAll(new com.yunbao.common.http.base.HttpCallback() { @Override @@ -455,7 +458,6 @@ public class PDLiveConversationListActivity extends AbsActivity implements View. ToastUtil.show(error); } }); -// IMCenter.getInstance().clearMessagesUnreadStatus(); MessageIMManager.get(mContext).setSystemNumber(0); EventBus.getDefault().post(new MessageIMEvent().setNumber(0)); } @@ -631,5 +633,11 @@ public class PDLiveConversationListActivity extends AbsActivity implements View. }); } + @Subscribe(threadMode = ThreadMode.MAIN, sticky = true) + public void onLiveFloatEvent(LiveFloatEvent event) { + new Handler().post(() -> LiveFloatView.getInstance() + .cacheLiveData(event.getmLiveBean(), event.getmLiveType(), event.getmLiveSDK(), event.getmLiveTypeVal()) + .builderFloat(mContext, event.getmLiveBean().getPull(),"PDLiveConversationList")); + } } diff --git a/main/src/main/java/com/yunbao/main/views/MainMessageViewHolder.java b/main/src/main/java/com/yunbao/main/views/MainMessageViewHolder.java new file mode 100644 index 000000000..998074409 --- /dev/null +++ b/main/src/main/java/com/yunbao/main/views/MainMessageViewHolder.java @@ -0,0 +1,403 @@ +package com.yunbao.main.views; + +import android.app.Activity; +import android.content.Intent; +import android.os.Handler; +import android.text.TextUtils; +import android.util.Log; +import android.view.View; +import android.view.ViewGroup; +import android.widget.FrameLayout; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; + +import androidx.fragment.app.FragmentActivity; +import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentTransaction; + +import com.adjust.sdk.Adjust; +import com.adjust.sdk.AdjustEvent; +import com.alibaba.fastjson.JSON; +import com.binioter.guideview.Guide; +import com.binioter.guideview.GuideBuilder; +import com.facebook.appevents.AppEventsLogger; +import com.google.firebase.analytics.FirebaseAnalytics; +import com.opensource.svgaplayer.SVGADrawable; +import com.opensource.svgaplayer.SVGAImageView; +import com.opensource.svgaplayer.SVGAParser; +import com.opensource.svgaplayer.SVGAVideoEntity; +import com.yunbao.common.activity.WebViewActivity; +import com.yunbao.common.bean.ImUserInfoModel; +import com.yunbao.common.glide.ImgLoader; +import com.yunbao.common.http.HttpCallback; +import com.yunbao.common.manager.IMLoginManager; +import com.yunbao.common.manager.NoviceInstructorManager; +import com.yunbao.common.manager.imrongcloud.MessageIMManager; +import com.yunbao.common.utils.DeviceUtils; +import com.yunbao.common.utils.SVGAViewUtils; +import com.yunbao.common.views.AbsMainViewHolder; +import com.yunbao.common.views.weight.ViewClicksAntiShake; +import com.yunbao.live.activity.SystemMessageActivity; +import com.yunbao.live.bean.ImUserBean; +import com.yunbao.live.http.ImHttpUtil; +import com.yunbao.main.R; +import com.yunbao.main.activity.MainActivity; +import com.yunbao.main.adapter.SystemMessageAdapter; +import com.yunbao.main.manager.imrongcloud.ConversationIMListManager; + +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import io.rong.imkit.conversationlist.ConversationListFragment; + +/** + * 消息中心 + */ +public class MainMessageViewHolder extends AbsMainViewHolder { + + private ConversationListFragment conversationListFragment; + private FrameLayout container; + private SystemMessageAdapter messageAdapter; + private TextView textNewsNotice, textNewsInteraction, textNewsOnline; + private String type = null; + private List listUserBean = new ArrayList<>(); + private LinearLayout topLayout, ltNodataMsg; + private ImageView imgNewsNotice, imgNewsInteraction, imgNewsOnline; + private Handler netHandler; + private MainActivity mContext; + + private String homeZdyPop; + + public MainMessageViewHolder setHomeZdyPop(String homeZdyPop) { + this.homeZdyPop = homeZdyPop; + if (TextUtils.equals(homeZdyPop, "1")) { + showGuideView(); + NoviceInstructorManager.get(mContext).setHomeZdyPop(""); + } + return this; + } + + public MainMessageViewHolder(MainActivity context, ViewGroup parentView) { + super(context, parentView); + mContext = context; + } + + @Override + protected int getLayoutId() { + return R.layout.view_main_message; + } + + @Override + public void init() { + EventBus.getDefault().register(this); + //菜单 + container = (FrameLayout) findViewById(R.id.container); + textNewsNotice = (TextView) findViewById(R.id.text_news_notice); + textNewsInteraction = (TextView) findViewById(R.id.text_news_interaction); + textNewsOnline = (TextView) findViewById(R.id.text_news_online); + topLayout = (LinearLayout) findViewById(R.id.top_layout); + ltNodataMsg = (LinearLayout) findViewById(R.id.lt_nodata_msg); + imgNewsNotice = (ImageView) findViewById(R.id.img_news_notice); + imgNewsInteraction = (ImageView) findViewById(R.id.img_news_interaction); + imgNewsOnline = (ImageView) findViewById(R.id.img_news_online); + netHandler = new Handler(); + initData(); + } + + @Override + public void release() { + super.release(); + EventBus.getDefault().unregister(this); + } + + //展示引导层 + private void showGuideView() { + MessageGuideView guideView = new MessageGuideView((Activity) mContext); + //top_noback + GuideBuilder builder = new GuideBuilder(); + builder.setTargetView(topLayout) + .setAlpha(180) + .setHighTargetCorner(20) + .setHighTargetPadding(10); + builder.setOverlayTarget(true); + builder.setAutoDismiss(false); + + builder.addComponent(guideView); + Guide guide = builder.createGuide(); + guide.show((Activity) mContext); + //引导界面设置 + View container = guideView.getContainer(); + SVGAImageView guidSvga = container.findViewById(R.id.guide_svga); + LinearLayout guideLayout = container.findViewById(R.id.guide_layout); + ImageView politicalInstructor = container.findViewById(R.id.political_instructor); + //设置界面宽度 + ViewGroup.LayoutParams layoutParams = guideLayout.getLayoutParams(); + layoutParams.width = DeviceUtils.getScreenWidth((Activity) mContext); + guideLayout.setLayoutParams(layoutParams); + //设置svga动图 + new SVGAParser(mContext).decodeFromAssets("guide.svga", new SVGAParser.ParseCompletion() { + @Override + public void onComplete(SVGAVideoEntity videoItem) { + SVGADrawable drawable = new SVGADrawable(videoItem); + guidSvga.setImageDrawable(drawable); + SVGAViewUtils.playEndClear(guidSvga, false); + } + + @Override + public void onError() { + Log.e("errqs", "errl"); + } + }, null); + //点击事件 + ViewClicksAntiShake.clicksAntiShake(politicalInstructor, () -> { + String targetId = ConversationIMListManager.get(mContext).getTargetId(); + if (!TextUtils.isEmpty(targetId)) { + ConversationIMListManager.get(mContext).jumpConversation((Activity) mContext, targetId); + guide.dismiss(); + } + }); + } + + /** + * 初始化数据 + */ + private void initData() { + IMLoginManager.get(mContext).checkInstructor(); + container.post(new Runnable() { + @Override + public void run() { + netHandler.post(imUserInfoRunnable); + } + }); + if (IMLoginManager.get(mContext).hintChat()) { + container.setVisibility(View.GONE); + ltNodataMsg.setVisibility(View.VISIBLE); + } else { + container.setVisibility(View.VISIBLE); + ltNodataMsg.setVisibility(View.GONE); + //展示会话列表 + conversationListFragment = new ConversationListFragment(); + FragmentManager manager = ((FragmentActivity) mContext).getSupportFragmentManager(); + FragmentTransaction transaction = manager.beginTransaction(); + transaction.replace(R.id.container, conversationListFragment); + transaction.commit(); + //自定义空数据背景View + conversationListFragment.setEmptyView(com.yunbao.live.R.layout.view_layout_msg); + //刷新列表内用户信息 + ConversationIMListManager.get(mContext).addUserInfoProvider(); + } + //获取一下系统通知 + MessageIMManager.get(mContext).getSystemMessages(); + } + + + /** + * 系統消息獲取 + */ + private Runnable imUserInfoRunnable = new Runnable() { + @Override + public void run() { + //获取系统消息列表 + ImHttpUtil.getImUserInfo("", new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (code == 0) { + mContext.runOnUiThread(() -> { + listUserBean = JSON.parseArray(Arrays.toString(info), ImUserBean.class); + for (ImUserBean userBean : listUserBean) { + switch (userBean.getType()) { + //官方通知 + case "1": + if (TextUtils.isEmpty(userBean.getNum()) || TextUtils.equals("0", userBean.getNum())) { + textNewsNotice.setVisibility(View.GONE); + } else { + textNewsNotice.setVisibility(View.VISIBLE); + textNewsNotice.setText(userBean.getNum()); + } + ImgLoader.display(mContext, userBean.getNewImage(), imgNewsNotice); + ViewClicksAntiShake.clicksAntiShake(imgNewsNotice, () -> { + type = userBean.getType(); + netHandler.post(systemNumberRunnable); + mContext.startActivity(new Intent(mContext, SystemMessageActivity.class) + .putExtra("type", userBean.getType()) + .putExtra("uid", "") + .putExtra("title", userBean.getTitle()) + .putExtra("headImg", "")); + }); + break; + //互動消息 + case "2": + if (TextUtils.isEmpty(userBean.getNum()) || TextUtils.equals("0", userBean.getNum())) { + textNewsInteraction.setVisibility(View.GONE); + } else { + textNewsInteraction.setVisibility(View.VISIBLE); + textNewsInteraction.setText(userBean.getNum()); + } + ImgLoader.display(mContext, userBean.getNewImage(), imgNewsInteraction); + ViewClicksAntiShake.clicksAntiShake(imgNewsInteraction, () -> { + type = userBean.getType(); + netHandler.post(systemNumberRunnable); + mContext.startActivity(new Intent(mContext, SystemMessageActivity.class) + .putExtra("type", userBean.getType()) + .putExtra("uid", "") + .putExtra("title", userBean.getTitle()) + .putExtra("headImg", "")); + }); + break; + //在線客服 + case "3": + if (TextUtils.isEmpty(userBean.getNum()) || TextUtils.equals("0", userBean.getNum())) { + textNewsOnline.setVisibility(View.GONE); + } else { + textNewsOnline.setVisibility(View.VISIBLE); + textNewsOnline.setText(userBean.getNum()); + } + ImgLoader.display(mContext, userBean.getNewImage(), imgNewsOnline); + ViewClicksAntiShake.clicksAntiShake(imgNewsOnline, () -> { + type = userBean.getType(); + netHandler.post(systemNumberRunnable); + FirebaseAnalytics.getInstance(mContext).logEvent("FS_customer_service", null); + AppEventsLogger.newLogger(mContext).logEvent("FB_customer_service"); + AdjustEvent adjustEvent1 = new AdjustEvent("ww5z2p"); + Adjust.trackEvent(adjustEvent1); + if (userBean.getLink() != null && !"".equals(userBean.getLink())) { + WebViewActivity.forward(mContext, userBean.getLink()); + } else { + mContext.startActivity(new Intent(mContext, SystemMessageActivity.class) + .putExtra("type", userBean.getType()) + .putExtra("uid", "") + .putExtra("title", userBean.getTitle()) + .putExtra("headImg", "")); + } + }); + break; + } + } + + }); + + } + } + }); + } + }; + //修改小紅點 + private Runnable systemNumberRunnable = new Runnable() { + @Override + public void run() { + mContext.runOnUiThread(() -> { + int systemNumber = 0; + for (ImUserBean userBean : listUserBean) { + //未读消息数 + String number = userBean.getNum(); + + switch (userBean.getType()) { + //官方通知 + case "1": + if (TextUtils.equals(type, userBean.getType())) { + number = null; + textNewsNotice.setVisibility(View.GONE); + } + break; + //互動消息 + case "2": + if (TextUtils.equals(type, userBean.getType())) { + number = null; + textNewsInteraction.setVisibility(View.GONE); + } + break; + //在線客服 + case "3": + if (TextUtils.equals(type, userBean.getType())) { + number = null; + textNewsOnline.setVisibility(View.GONE); + } + break; + } + + //未读消息不为空并且大于0 + try { + if (!TextUtils.isEmpty(number) && Integer.parseInt(number) > 0) { + systemNumber = Integer.parseInt(number) + systemNumber; + } + } catch (NumberFormatException e) { + systemNumber = systemNumber + 0; + } + + } + type = null; + MessageIMManager.get(mContext).setSystemNumber(systemNumber); + }); + + } + }; + + //更新系統消息 + @Subscribe(threadMode = ThreadMode.MAIN) + public void onImUserInfoModel(ImUserInfoModel model) { + messageAdapter.upDataMessage(model); + int systemNumber = 0; + for (ImUserBean userBean : listUserBean) { + //未读消息数 + String number = userBean.getNum(); + //未读消息不为空并且大于0 + try { + if (!TextUtils.isEmpty(number) && Integer.parseInt(number) > 0) { + systemNumber = Integer.parseInt(number) + systemNumber; + } + } catch (NumberFormatException e) { + systemNumber = systemNumber + 0; + } + } + switch (model.getType()) { + //官方通知 + case "1": + if (textNewsNotice.getVisibility() == View.GONE) { + textNewsNotice.setVisibility(View.GONE); + textNewsNotice.setText(""); + } else { + String number = textNewsNotice.getText().toString().trim(); + int numberInt = Integer.parseInt(number) + 1; + textNewsNotice.setVisibility(View.VISIBLE); + textNewsNotice.setText(String.valueOf(numberInt)); + } + + break; + //互動消息 + case "2": + if (textNewsInteraction.getVisibility() == View.GONE) { + textNewsInteraction.setVisibility(View.GONE); + textNewsInteraction.setText(""); + } else { + String number = textNewsInteraction.getText().toString().trim(); + int numberInt = Integer.parseInt(number) + 1; + textNewsInteraction.setVisibility(View.VISIBLE); + textNewsInteraction.setText(String.valueOf(numberInt)); + } + + + break; + //在線客服 + case "3": + if (textNewsOnline.getVisibility() == View.GONE) { + textNewsOnline.setVisibility(View.GONE); + textNewsOnline.setText(""); + } else { + String number = textNewsOnline.getText().toString().trim(); + int numberInt = Integer.parseInt(number) + 1; + textNewsOnline.setVisibility(View.VISIBLE); + textNewsOnline.setText(String.valueOf(numberInt)); + } + break; + } + systemNumber = systemNumber + 1; + MessageIMManager.get(mContext).setSystemNumber(systemNumber); + + } +} diff --git a/main/src/main/res/layout/view_main_message.xml b/main/src/main/res/layout/view_main_message.xml new file mode 100644 index 000000000..bb86e3c20 --- /dev/null +++ b/main/src/main/res/layout/view_main_message.xml @@ -0,0 +1,143 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file