我的界面-->消息中心和短剧的跳转

This commit is contained in:
老皮 2024-09-11 17:15:58 +08:00
parent 1985eebfb1
commit f1670965b9
8 changed files with 608 additions and 2 deletions

View File

@ -57,6 +57,8 @@ public class RouteUtil {
public static final String PATH_FEEDBACK_ACTIVITY = "/main/FeedbackActivity";
public static final String PATH_FEEDBACK_EDIT_ACTIVITY = "/main/FeedbackEditActivity";
public static final String PATH_LIVE_PUNISHACTIVITY = "/live/PunishActivity";
public static final String PATH_NEW_MESSAGE = "/main/NewMessageActivity";
public static final String PATH_Community_Video= "/main/CommunityVideoActivity";
public static void forwardCommunityActivity() {

View File

@ -175,6 +175,12 @@
<activity
android:name=".activity.FeedbackEditActivity"
android:screenOrientation="portrait" />
<activity android:name=".activity.NewMessageActivity"
android:screenOrientation="portrait" />
<activity android:name=".activity.CommunityVideoActivity"
android:screenOrientation="portrait" />
</application>
</manifest>

View File

@ -0,0 +1,14 @@
package com.yunbao.main.activity;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.yunbao.common.activity.AbsActivity;
import com.yunbao.common.utils.RouteUtil;
import com.yunbao.main.R;
@Route(path = RouteUtil.PATH_Community_Video)
public class CommunityVideoActivity extends AbsActivity {
@Override
protected int getLayoutId() {
return R.layout.activity_community_video;
}
}

View File

@ -0,0 +1,30 @@
package com.yunbao.main.activity;
import android.os.Bundle;
import android.view.View;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.yunbao.common.activity.AbsActivity;
import com.yunbao.common.utils.RouteUtil;
import com.yunbao.main.R;
import com.yunbao.main.views.MainMessageViewHolder;
import com.yunbao.main.views.MainMessageViewHolderForActivity;
@Route(path = RouteUtil.PATH_NEW_MESSAGE)
public class NewMessageActivity extends AbsActivity {
@Override
protected int getLayoutId() {
return R.layout.activity_new_message;
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ConstraintLayout viewById = findViewById(R.id.parent_view);
MainMessageViewHolderForActivity holder = new MainMessageViewHolderForActivity(this, viewById);
holder.addToParent();
}
}

View File

@ -406,11 +406,11 @@ public class MainMeViewHolder extends AbsMainViewHolder implements OnItemClickLi
case 100:
// 精彩短劇
RouteUtil.forwardActivity(RouteUtil.PATH_Community_Video);
break;
case 101:
// 消息中心
RouteUtil.forwardActivity(RouteUtil.PATH_NEW_MESSAGE);
break;
}
} else {

View File

@ -0,0 +1,534 @@
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.util.TypedValue;
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.alibaba.fastjson.JSON;
import com.binioter.guideview.Guide;
import com.binioter.guideview.GuideBuilder;
import com.facebook.appevents.AppEventsLogger;
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.ImUserInfoModel;
import com.yunbao.common.bean.LiveBean;
import com.yunbao.common.glide.ImgLoader;
import com.yunbao.common.http.HttpCallback;
import com.yunbao.common.http.LiveHttpUtil;
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.LiveRoomCheckLivePresenter;
import com.yunbao.common.utils.MobclickAgent;
import com.yunbao.common.utils.RouteUtil;
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.event.RecommendLiveRoomEvent;
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 MainMessageViewHolderForActivity extends AbsMainViewHolder {
private ConversationListFragment conversationListFragment;
private FrameLayout container;
private SystemMessageAdapter messageAdapter;
private TextView textNewsNotice, textNewsInteraction, textNewsOnline, textSystemMessages;
private String type = null;
private List<ImUserBean> listUserBean = new ArrayList<>();
private LinearLayout topLayout, ltNodataMsg;
private ImageView imgNewsNotice, imgNewsInteraction, imgNewsOnline, imgSystemMessages;
private Handler netHandler;
private Activity mContext;
private String homeZdyPop;
public MainMessageViewHolderForActivity setHomeZdyPop(String homeZdyPop) {
this.homeZdyPop = homeZdyPop;
if (TextUtils.equals(homeZdyPop, "1")) {
showGuideView();
NoviceInstructorManager.get(mContext).setHomeZdyPop("");
}
return this;
}
public MainMessageViewHolderForActivity(Activity context, ViewGroup parentView) {
super(context, parentView);
mContext = context;
}
@Override
protected int getLayoutId() {
return R.layout.view_main_message;
}
@Override
public void onResume() {
super.onResume();
initData();
}
@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);
textSystemMessages = (TextView) findViewById(R.id.text_system_messages);
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);
imgSystemMessages = (ImageView) findViewById(R.id.img_system_messages);
imgNewsOnline = (ImageView) findViewById(R.id.img_news_online);
netHandler = new Handler();
}
@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);
int numberInt = Integer.parseInt(userBean.getNum());
if (numberInt > 99) {
textNewsNotice.setTextSize(TypedValue.COMPLEX_UNIT_SP, 9);
textNewsNotice.setText("99+");
} else {
textNewsNotice.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
textNewsNotice.setText(String.valueOf(numberInt));
}
}
ImgLoader.display(mContext, userBean.getNewImage(), imgNewsNotice);
ViewClicksAntiShake.clicksAntiShake(imgNewsNotice, () -> {
MobclickAgent.onEvent(mContext, "information_official_notice", "官方通知");
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);
int numberInt = Integer.parseInt(userBean.getNum());
if (numberInt > 99) {
textNewsInteraction.setTextSize(TypedValue.COMPLEX_UNIT_SP, 9);
textNewsInteraction.setText("99+");
} else {
textNewsInteraction.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
textNewsInteraction.setText(String.valueOf(numberInt));
}
}
ImgLoader.display(mContext, userBean.getNewImage(), imgNewsInteraction);
ViewClicksAntiShake.clicksAntiShake(imgNewsInteraction, () -> {
MobclickAgent.onEvent(mContext, "information_system_interactive", "互動消息");
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);
int numberInt = Integer.parseInt(userBean.getNum());
if (numberInt > 99) {
textNewsOnline.setTextSize(TypedValue.COMPLEX_UNIT_SP, 9);
textNewsOnline.setText("99+");
} else {
textNewsOnline.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
textNewsOnline.setText(String.valueOf(numberInt));
}
}
ImgLoader.display(mContext, userBean.getNewImage(), imgNewsOnline);
ViewClicksAntiShake.clicksAntiShake(imgNewsOnline, () -> {
MobclickAgent.onEvent(mContext, "information_system_service", "在線客服");
type = userBean.getType();
netHandler.post(systemNumberRunnable);
AppEventsLogger.newLogger(mContext).logEvent("FB_customer_service");
if (userBean.getLink() != null && !"".equals(userBean.getLink())) {
// WebViewActivity.forward(mContext, userBean.getLink());
RouteUtil.forwardCustomerService(userBean.getLink());
} else {
mContext.startActivity(new Intent(mContext, SystemMessageActivity.class)
.putExtra("type", userBean.getType())
.putExtra("uid", "")
.putExtra("title", userBean.getTitle())
.putExtra("headImg", ""));
}
});
break;
//系统消息
case "4":
if (TextUtils.isEmpty(userBean.getNum()) || TextUtils.equals("0", userBean.getNum())) {
textSystemMessages.setVisibility(View.GONE);
} else {
textSystemMessages.setVisibility(View.VISIBLE);
int numberInt = Integer.parseInt(userBean.getNum());
if (numberInt > 99) {
textSystemMessages.setTextSize(TypedValue.COMPLEX_UNIT_SP, 9);
textSystemMessages.setText("99+");
} else {
textSystemMessages.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
textSystemMessages.setText(String.valueOf(numberInt));
}
}
ImgLoader.display(mContext, userBean.getNewImage(), imgSystemMessages);
ViewClicksAntiShake.clicksAntiShake(imgSystemMessages, () -> {
MobclickAgent.onEvent(mContext, "information_system_notice", "系统消息");
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;
}
}
});
}
}
});
}
};
//修改小紅點
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;
//在線客服
case "4":
if (TextUtils.equals(type, userBean.getType())) {
number = null;
textSystemMessages.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();
textNewsNotice.setVisibility(View.VISIBLE);
int numberInt = Integer.parseInt(number) + 1;
if (numberInt > 99) {
textNewsNotice.setTextSize(TypedValue.COMPLEX_UNIT_SP, 9);
textNewsNotice.setText("99+");
} else {
textNewsNotice.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
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);
if (numberInt > 99) {
textNewsInteraction.setTextSize(TypedValue.COMPLEX_UNIT_SP, 9);
textNewsInteraction.setText("99+");
} else {
textNewsInteraction.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
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);
if (numberInt > 99) {
textNewsOnline.setTextSize(TypedValue.COMPLEX_UNIT_SP, 9);
textNewsOnline.setText("99+");
} else {
textNewsOnline.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
textNewsOnline.setText(String.valueOf(numberInt));
}
}
break; //在線客服
case "4":
if (textSystemMessages.getVisibility() == View.GONE) {
textSystemMessages.setVisibility(View.GONE);
textSystemMessages.setText("");
} else {
String number = textSystemMessages.getText().toString().trim();
int numberInt = Integer.parseInt(number) + 1;
textSystemMessages.setVisibility(View.VISIBLE);
if (numberInt > 99) {
textSystemMessages.setTextSize(TypedValue.COMPLEX_UNIT_SP, 9);
textSystemMessages.setText("99+");
} else {
textSystemMessages.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
textSystemMessages.setText(String.valueOf(numberInt));
}
}
break;
}
systemNumber = systemNumber + 1;
MessageIMManager.get(mContext).setSystemNumber(systemNumber);
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onRecommendLiveRoomEvent(RecommendLiveRoomEvent event) {
LiveHttpUtil.getLiveInfo(event.getLiveuid(), new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
if (code == 0 && info.length > 0) {
LiveBean liveBean = JSON.parseObject(info[0], LiveBean.class);
new LiveRoomCheckLivePresenter(mContext, liveBean.getUid(), liveBean.getStream(), new LiveRoomCheckLivePresenter.NewActionListener() {
@Override
public void onLiveRoomChanged(String liveUid, String stream, int liveType, String liveTypeVal, String liveSdk,boolean isSw) {
RouteUtil.forwardLiveAudienceActivity(liveBean, liveType, Integer.parseInt(liveSdk), Integer.parseInt(liveTypeVal),isSw);
}
@Override
public void onCheckError(String contextError) {
}
});
} else {
RouteUtil.forwardUserHome(mContext, event.getLiveuid(), 0);
}
}
});
}
}

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.yunbao.main.fragment.MainHomeCommunityVideoFragment"
android:id="@+id/fragment"
/>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="@+id/parent_view"
android:layout_height="match_parent">
</androidx.constraintlayout.widget.ConstraintLayout>