邀请粉丝和推送通知栏处理

This commit is contained in:
oujunhui
2020-07-31 19:43:17 +08:00
parent 10a5cf3cf0
commit fbafbf240d
17 changed files with 210 additions and 17 deletions

View File

@@ -144,6 +144,7 @@ import com.yizhuan.xchat_android_core.im.custom.bean.OpenRoomNotiAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.OpenSignInAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.RedPackageAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.RedPacketAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.RoomInviteFansAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.SysMsgAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.SysMsgV2Attachment;
import com.yizhuan.xchat_android_core.level.event.CharmLevelUpEvent;
@@ -451,6 +452,8 @@ public class MainActivity extends BaseMvpActivity<IMainView, MainPresenter>
NimUIKit.registerMsgItemViewHolder(InAppSharingMiniWorldAttachment.class, InAppSharingMsgViewHolder.class);
NimUIKit.registerMsgItemViewHolder(InAppSharingTeamAttachment.class, InAppSharingMsgViewHolder.class);
NimUIKit.registerMsgItemViewHolder(LuckyMoneyTipsAttachment.class, LuckyMoneyTipsViewHolder.class);
//邀请
// NimUIKit.registerMsgItemViewHolder(RoomInviteFansAttachment.class, LuckyMoneyTipsViewHolder.class);
NimUIKit.setSessionListener(listener);
NimUIKit.setContactEventListener(listener1);

View File

@@ -6,6 +6,7 @@ import android.util.Log;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.coorchice.library.utils.LogUtils;
import com.netease.nimlib.sdk.NimIntent;
import com.netease.nimlib.sdk.msg.constant.MsgTypeEnum;
import com.netease.nimlib.sdk.msg.model.IMMessage;
@@ -18,6 +19,9 @@ import com.yizhuan.xchat_android_core.auth.AuthModel;
import com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.OpenRoomNotiAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.OpenSignInAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.RedPackageAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.RoomInviteFansAttachment;
import com.yizhuan.xchat_android_library.utils.LogUtil;
import com.yizhuan.xchat_android_library.utils.UIUtils;
import java.util.ArrayList;
@@ -73,6 +77,10 @@ public class NimMiddleActivity extends BaseActivity {
}
}
/**
* 推送通知栏点击
* @param intent
*/
private void parseNotifyIntent(Intent intent) {
if (intent == null) {
return;
@@ -82,6 +90,7 @@ public class NimMiddleActivity extends BaseActivity {
ArrayList<IMMessage> messages = (ArrayList<IMMessage>) intent.getSerializableExtra(NimIntent.EXTRA_NOTIFY_CONTENT);
if (messages != null && messages.size() > 0) {
IMMessage imMessage = messages.get(messages.size() - 1);
LogUtils.i( "getMsgType:"+imMessage.getMsgType() );
if (imMessage.getMsgType() == MsgTypeEnum.custom) {
CustomAttachment attachment = (CustomAttachment) imMessage.getAttachment();
if (attachment.getFirst() == CustomAttachment.CUSTOM_MSG_HEADER_TYPE_OPEN_ROOM_NOTI) {
@@ -94,7 +103,24 @@ public class NimMiddleActivity extends BaseActivity {
&& !UIUtils.isTopActivity(this, SignInActivity.class.getSimpleName())) {
SignInActivity.start(this);
}
} else if (attachment.getFirst() == CustomAttachment.CUSTOM_MSG_RED_PACKAGE){
if (attachment.getSecond() == CustomAttachment.CUSTOM_MSG_SUB_RED_PACKAGE_RECEIVE_ALL_DIAMOND){
RedPackageAttachment redPackageAttachment = (RedPackageAttachment) attachment;
AVRoomActivity.start(this, redPackageAttachment.getRedPackageNotifyInfo().getRoomUid());
}
} else if (attachment.getFirst() == CustomAttachment.CUSTOM_MSG_PUSH_NOTIFIFICATION){
if (attachment.getSecond() == CustomAttachment.CUSTOM_MSG_SUB_PUSH_NOTIFICATION_IN_ROOM){
RoomInviteFansAttachment noticeAttachment = (RoomInviteFansAttachment) attachment;
if (noticeAttachment.getRoomInviteFansInfo() == null){
return;
}
AVRoomActivity.start(this, noticeAttachment.getRoomInviteFansInfo().getData().getRoomUid());
}
}
}else if (imMessage.getMsgType() == MsgTypeEnum.notification){
LogUtils.i( "MsgTypeEnum.notification");
}else if (imMessage.getMsgType() == MsgTypeEnum.text){
LogUtils.i( "MsgTypeEnum.text");
}
}
finish();

View File

@@ -34,6 +34,7 @@ import com.netease.mobsec.rjsb.watchman;
import com.netease.nim.uikit.api.NimUIKit;
import com.netease.nim.uikit.common.util.log.LogUtil;
import com.netease.nimlib.sdk.NIMClient;
import com.netease.nimlib.sdk.NotificationFoldStyle;
import com.netease.nimlib.sdk.SDKOptions;
import com.netease.nimlib.sdk.StatusBarNotificationConfig;
import com.netease.nimlib.sdk.mixpush.MixPushConfig;
@@ -73,6 +74,8 @@ import com.yizhuan.xchat_android_core.family.model.FamilyModel;
import com.yizhuan.xchat_android_core.gift.GiftModel;
import com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.OpenSignInAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.RoomInviteFansAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.RoomInviteFansInfo;
import com.yizhuan.xchat_android_core.interceptor.NoParamsInterceptor;
import com.yizhuan.xchat_android_core.interceptor.ParamsInterceptor;
import com.yizhuan.xchat_android_core.manager.IMMessageManager;
@@ -121,6 +124,7 @@ import static com.yizhuan.xchat_android_constants.XChatConstants.XM_APP_ID;
import static com.yizhuan.xchat_android_constants.XChatConstants.XM_APP_KEY;
import static com.yizhuan.xchat_android_constants.XChatConstants.XM_CERTIFICATE_NAME;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_HEADER_TYPE_OPEN_ROOM_NOTI;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_PUSH_NOTIFIFICATION;
/**
* @author chenran
@@ -347,6 +351,7 @@ public class XChatApplication extends Application {
config.ledARGB = Color.GREEN;
config.ledOnMs = 1000;
config.ledOffMs = 1500;
config.notificationFoldStyle = NotificationFoldStyle.CONTACT;
// 通知铃声的uri字符串
config.notificationSound = "android.resource://com.netease.nim.demo/raw/msg";
options.statusBarNotificationConfig = config;
@@ -411,6 +416,9 @@ public class XChatApplication extends Application {
} else if (customAttachment instanceof OpenSignInAttachment) {
return getContentFromOpenSignIn(customAttachment);
}
else if (customAttachment.getFirst() == CUSTOM_MSG_PUSH_NOTIFIFICATION){
return getContentRoomInvite(customAttachment);
}
}
// 采用SDK默认文案
return "收到一条消息";
@@ -424,6 +432,8 @@ public class XChatApplication extends Application {
return message.getFromNick();
} else if (customAttachment instanceof OpenSignInAttachment) {
return getContentFromOpenSignIn(customAttachment);
} else if (customAttachment instanceof RoomInviteFansAttachment){
return getContentRoomInvite(customAttachment);
}
}
// 采用SDK默认文案
@@ -444,6 +454,20 @@ public class XChatApplication extends Application {
return result;
}
private String getContentRoomInvite(CustomAttachment attachment) {
String result = null;
if (attachment instanceof RoomInviteFansAttachment) {
RoomInviteFansInfo roomInviteFansInfo = ((RoomInviteFansAttachment) attachment).getRoomInviteFansInfo();
if (roomInviteFansInfo != null) {
result = roomInviteFansInfo.getPushTitle();
}
}
if (TextUtils.isEmpty(result)) {
result = "收到一条消息";
}
return result;
}
@Override
public String makeRevokeMsgTip(String s, IMMessage imMessage) {
return null;

View File

@@ -105,7 +105,9 @@ public class MicroViewAdapter extends BaseMicroViewAdapter {
@Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, final int position) {
RoomQueueInfo roomQueueInfo = AvRoomDataManager.get().getRoomQueueMemberInfoByMicPosition(position - 1);
if (roomQueueInfo == null) return;
if (roomQueueInfo == null) {
return;
}
NormalMicroViewHolder holder = (NormalMicroViewHolder) viewHolder;
holder.bind(roomQueueInfo, position - 1);
}

View File

@@ -92,7 +92,11 @@ import static com.yizhuan.xchat_android_core.Constants.DEBUG_MAX_UID;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MESS_HEAD_NOBLE;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MESS_SUB_OPENNOBLE;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MESS_SUB_RENEWNOBLE;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_PUSH_NOTIFIFICATION;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_RED_PACKAGE;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_SUB_PUSH_NOTIFICATION_IN_CHAT_ROOM;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_SUB_PUSH_NOTIFICATION_IN_DYNAMIC_MSG;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_SUB_PUSH_NOTIFICATION_IN_ROOM;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_SUB_RED_PACKAGE_RECEIVE_ALL_DIAMOND;
@@ -974,6 +978,25 @@ public abstract class BaseMvpActivity<V extends IMvpBaseView, P extends Abstract
}
}
}
// case CUSTOM_MSG_PUSH_NOTIFIFICATION:
// switch (baseProtocol.getSecond()){
// case CUSTOM_MSG_SUB_PUSH_NOTIFICATION_IN_ROOM:
//
// break;
//
// case CUSTOM_MSG_SUB_PUSH_NOTIFICATION_IN_CHAT_ROOM:
//
// break;
//
// case CUSTOM_MSG_SUB_PUSH_NOTIFICATION_IN_DYNAMIC_MSG:
//
// break;
//
// default:
// break;
// }
// break;
default:
break;
}

View File

@@ -93,6 +93,7 @@ import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUS
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_IM_GAME;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_MODULE_HALL;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_PUBLIC_CHAT_HALL;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_PUSH_NOTIFIFICATION;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_RED_PACKAGE;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_SHARE_FAMILY;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_SHARE_ROOM;
@@ -321,6 +322,12 @@ public class RecentListFragment extends BaseFragment {
}
}
/**
* 定义消息收到后显示的文案
* @param recent
* @param attachment 消息附件对象
* @return
*/
@Override
public String getDigestOfAttachment(RecentContact recent, MsgAttachment attachment) {
if (attachment instanceof CustomAttachment) {
@@ -406,6 +413,9 @@ public class RecentListFragment extends BaseFragment {
}else if (customAttachment.getFirst() == CUSTOM_MSG_RED_PACKAGE){
return "[您收到一个全服红包]";
}
// else if (customAttachment.getFirst() == CUSTOM_MSG_PUSH_NOTIFIFICATION){
// return null;//"[您收到一条邀请信息]";
// }
} else if (attachment instanceof AudioAttachment) {
return "[语音]";
}

View File

@@ -1,11 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#EAE5FC" />
<corners android:radius="19dp" />
</shape>

View File

@@ -2,7 +2,7 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#EAE5FC" />
<solid android:color="#DBDBDB" />
<corners android:radius="22dp" />

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#DBDBDB" />
<corners android:radius="22dp" />
</shape>

View File

@@ -63,23 +63,30 @@ public class RoomInviteFansActivity extends BaseActivity {
@SuppressLint("CheckResult")
public void init() {
if (AvRoomDataManager.get().mCurrentRoomInfo == null){
return;
}
getInviteFans();
}
@SuppressLint("CheckResult")
private void getInviteFans(){
if (AvRoomDataManager.get().mCurrentRoomInfo == null){
return;
}
RoomInviteFansModel.INSTANCE.getRoomInviteFans(AvRoomDataManager.get().mCurrentRoomInfo.getUid())
.doOnError(throwable -> LogUtil.print(throwable.getMessage()))
.subscribe(info -> {
tvInviteFansCount.setText(Html.fromHtml("确认邀请后会给收藏该房间的"+"<font color=#7154EE font-size=12dp>"+info.getFansNum()+"</font>"+"位用户发送提醒"));
tvInviteFansTimes.setText(Html.fromHtml("今日剩余"+"<font color=#7662FE font-size=18dp>"+info.getInviteTimes()+"</font>"+""));
tvInviteFansConfirm.setBackground(getResources().getDrawable(R.drawable.bg_common_confirm_normal_22r));
if (info.getInviteInterval() > 0){
tvInviteFansConfirm.setClickable(false);
startCountDownTimer(info.getInviteInterval());
}else {
if (info.getInviteTimes() <= 0){
tvInviteFansConfirm.setBackground(getResources().getDrawable(R.drawable.bg_common_cancel_22r));
tvInviteFansConfirm.setText("今日次数已用完");
return;
}
tvInviteFansConfirm.setClickable(true);
tvInviteFansConfirm.setText("确认邀请");
tvInviteFansConfirm.setOnClickListener(v -> {
@@ -129,7 +136,7 @@ public class RoomInviteFansActivity extends BaseActivity {
private void startCountDownTimer(long timeSecond) {
stopCountDownTimer();
timer = new InViteFansTimer(tvInviteFansConfirm,timeSecond*1000, 1000);
timer = new InViteFansTimer(this,tvInviteFansConfirm,timeSecond*1000, 1000);
timer.start();
}

View File

@@ -1,10 +1,13 @@
package com.yizhuan.tutu.room_chat.utils;
import android.content.Context;
import android.os.CountDownTimer;
import android.text.Html;
import android.view.View;
import android.widget.TextView;
import com.yizhuan.erban.R;
/**
* Created by zhouxiangfeng on 2017/5/2.
@@ -12,6 +15,7 @@ import android.widget.TextView;
public class InViteFansTimer extends CountDownTimer {
private TextView tvInvite;
private Context mContext;
/**
* @param tvInvite
@@ -21,9 +25,10 @@ public class InViteFansTimer extends CountDownTimer {
* @param countDownInterval The interval along the way to receiver
* {@link #onTick(long)} callbacks.
*/
public InViteFansTimer(TextView tvInvite, long millisInFuture, long countDownInterval) {
public InViteFansTimer(Context context,TextView tvInvite, long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
this.tvInvite = tvInvite;
this.mContext = context;
}
@Override
@@ -34,12 +39,14 @@ public class InViteFansTimer extends CountDownTimer {
@Override
public void onFinish() {
tvInvite.setBackground(mContext.getResources().getDrawable(R.drawable.bg_common_confirm_normal_22r));
tvInvite.setText(Html.fromHtml("确认邀请"));
tvInvite.setClickable(true);//重新获得点击
}
private String inviteInterval(int timeSecond){
tvInvite.setBackground(mContext.getResources().getDrawable(R.drawable.bg_common_cancel_22r));
return (timeSecond / 60) + "" + (timeSecond % 60) + "秒后可邀请";
}

View File

@@ -83,6 +83,8 @@ import com.yizhuan.xchat_android_core.im.custom.bean.NobleAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.RoomBoxPrizeAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.RoomGiftValueAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.RoomInfoAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.RoomInviteFansAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.RoomInviteFansInfo;
import com.yizhuan.xchat_android_core.im.custom.bean.RoomTipAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.RouterType;
import com.yizhuan.xchat_android_core.im.custom.bean.SysMsgAttachment;
@@ -308,15 +310,17 @@ public final class IMNetEaseManager {
model = AvRoomModel.get();
}
/**
* 推送通知,无论在前台后台都能收到
*/
private void registerMessageFilter() {
NIMClient.getService(MsgService.class)
.registerIMMessageFilter(message -> {
if (message.getMsgType() == MsgTypeEnum.custom) {
CustomAttachment customAttachment = (CustomAttachment) message.getAttachment();
int second = customAttachment.getSecond();
switch (customAttachment.getFirst()) {
case CustomAttachment.CUSTOM_MSG_HEADER_TYPE_LUCKY_MONEY:
switch (second) {
switch (customAttachment.getSecond()) {
case CustomAttachment.CUSTOM_MSG_SUB_TYPE_RECEIVE_LUCKY_MONEY:
LuckyMoneyTipsAttachment luckyMoneyAttachment = (LuckyMoneyTipsAttachment) message.getAttachment();
LuckyMoneyInfo luckyMoneyInfo = luckyMoneyAttachment.getLuckyMoneyInfo();
@@ -330,6 +334,16 @@ public final class IMNetEaseManager {
break;
}
break;
//邀请粉丝
// case CustomAttachment.CUSTOM_MSG_PUSH_NOTIFIFICATION:
// switch (customAttachment.getSecond()){
// case CustomAttachment.CUSTOM_MSG_SUB_PUSH_NOTIFICATION_IN_ROOM:
// RoomInviteFansAttachment roomInviteFansAttachment = (RoomInviteFansAttachment) message.getAttachment();
// RoomInviteFansInfo inviteFansInfo = roomInviteFansAttachment.getRoomInviteFansInfo();
// return true;
// }
// break;
}
} else if (message.getMsgType() == MsgTypeEnum.notification) {
NotificationAttachment notificationAttachment = (NotificationAttachment) message.getAttachment();

View File

@@ -488,6 +488,16 @@ public class CustomAttachParser implements MsgAttachmentParser {
}
break;
case CustomAttachment.CUSTOM_MSG_PUSH_NOTIFIFICATION:
switch (second){
case CustomAttachment.CUSTOM_MSG_SUB_PUSH_NOTIFICATION_IN_ROOM:
attachment = new RoomInviteFansAttachment(second);
break;
default:
break;
}
break;
default:
break;
}

View File

@@ -346,9 +346,14 @@ public class CustomAttachment implements MsgAttachment {
//红包消息
public static final int CUSTOM_MSG_RED_PACKAGE = 60;
public static final int CUSTOM_MSG_SUB_RED_PACKAGE_RECEIVE_ROOM_DIAMOND = 602;
public static final int CUSTOM_MSG_SUB_RED_PACKAGE_RECEIVE_ALL_DIAMOND = 604;
public static final int CUSTOM_MSG_SUB_RED_PACKAGE_RECEIVE_ALL_DIAMOND = 604;//全服红包
public static final int CUSTOM_MSG_SUB_RED_PACKAGE_RECEIVE_ROOM_MSG = 605;
//推送消息
public static final int CUSTOM_MSG_PUSH_NOTIFIFICATION = 70;
public static final int CUSTOM_MSG_SUB_PUSH_NOTIFICATION_IN_ROOM = 701;// 推送进入房间
public static final int CUSTOM_MSG_SUB_PUSH_NOTIFICATION_IN_CHAT_ROOM = 702;// 推送进入聊天页
public static final int CUSTOM_MSG_SUB_PUSH_NOTIFICATION_IN_DYNAMIC_MSG = 703;// 推送进入动态消息
public CustomAttachment() {

View File

@@ -0,0 +1,33 @@
package com.yizhuan.xchat_android_core.im.custom.bean;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.yizhuan.xchat_android_core.redpackage.RedPackageNotifyInfo;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* Created by MadisonRong on 17/06/2018.
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class RoomInviteFansAttachment extends CustomAttachment {
private RoomInviteFansInfo roomInviteFansInfo;
public RoomInviteFansAttachment(int second) {
super(CUSTOM_MSG_PUSH_NOTIFIFICATION, second);
}
@Override
protected void parseData(JSONObject data) {
roomInviteFansInfo = new Gson().fromJson(data.toJSONString(), RoomInviteFansInfo.class);
}
@Override
protected JSONObject packData() {
String jsonStr = new Gson().toJson(roomInviteFansInfo);
return JSONObject.parseObject(jsonStr);
}
}

View File

@@ -0,0 +1,25 @@
package com.yizhuan.xchat_android_core.im.custom.bean;
import java.io.Serializable;
import lombok.Data;
@Data
public class RoomInviteFansInfo implements Serializable {
private String title;
private String content;
private JumpValue data;
private int skiptype;
private String pushTitle;
@Data
public class JumpValue implements Serializable{
private long roomUid;
}
}

View File

@@ -21,5 +21,5 @@ with_jenkins=false
#\u6253\u652F\u6301x86\u7684\u6A21\u62DF\u5668\u5305\u4F7F\u7528
ndk_abi_filters=arm
version_name=1.2.1
version_code=121
version_name=1.2.2
version_code=122