邀请卡组件版本历史1. 组件描述2. 组件架构2.1 组件架构图2.2 核心对外API2.3 数据参数定义3. 组件接入3.1 使用组件提供UI3.2 使用组件管理器+自定义UI4. 混淆配置5. 组件库依赖
版本号 | 更新时间 | 更新描述 |
---|---|---|
1.0.1 | 2022.6.15 | 组件上线 |
1.0.2 | 2022.11.24 | 优化UI |
邀请卡组件是基于基础组件库扩展的组件服务,包括展示邀请卡,获取排行榜等功能,为业务方提供邀请卡能力。邀请卡组件包含管理器和基于管理器实现的UI界面,接入方可基于管理器对外API实现完全自定义UI的邀请卡,也可直接集成组件SDK提供的UI。
IInvitationCardManager内部唯一实现类为InvitationCardManagerImpl
作用 | API |
---|---|
初始化 | init(BaseInvitationCardListener listener, String userId, String roomId, String interactToken, String originUrl, String avatarUrl, Context context) |
获取邀请卡列表 | getCardList(IBaseCallBack<List |
获取邀请卡配置 | getCardConfig(IBaseCallBack |
获取短链接 | getShortLink(String originUrl, IBaseCallBack |
获取排行榜 | getCardRankList(IBaseCallBack<List |
重连 | reConnect() |
释放 | release() |
API接口代码
public interface IInvitationCardManager {
/**
* @param listener 监听
* @param userId viewerId
* @param roomId 房间id
* @param interactToken token
*/
void init(BaseInvitationCardListener listener, String userId, String roomId, String interactToken, String originUrl, String avatarUrl, Context context);
/**
* 重连
*/
void reConnect();
/**
* 释放
*/
void release();
/**
* 获取card列表
* @param callBack 回调
*/
void getCardList(IBaseCallBack<List<InvitationCardDataBean>> callBack);
/**
* 获取card配置
* @param callBack 回调
*/
void getCardConfig(IBaseCallBack<InvitationCardConfigBean> callBack);
/**
* 获取短链接
* @param originUrl 链接
* @param callBack 回调
*/
void getShortLink(String originUrl, IBaseCallBack<String> callBack);
/**
* 获取排行榜
* @param callBack 回调
*/
void getCardRankList(IBaseCallBack<List<InvitationCardRankBean>> callBack);
}
数据类参数说明
public class InvitationCardConfigBean {
/**
* 邀请人头像, 0不显示1显示
*/
private int showHead;
/**
* 邀请人昵称, 0不显示1显示
*/
private int showName;
/**
* 时间,0不显示,1显示
*/
private int showTime;
/**
* 排行榜,0不显示,1显示
*/
private int showRank;
/**
* 水印, 0不显示1显示
*/
private int showWatermark;
/**
* 标题, 0不显示,1跟随直播间,2自定义
*/
private int showTitle;
/**
* 描述,0不显示,1跟随直播间,2自定义
*/
private int showDesc;
/**
* 水印内容, 默认, 获得场景视频技术支持
*/
private String watermark = "获得场景视频技术支持";
/**
* 自定义标题
*/
private String title;
/**
* 自定义描述
*/
private String description;
}
邀请卡ViewGroup为InvitationCardMainLayout
登录业务SDK(云直播等)
xml中添加InvitationCardMainLayout
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#eeeeee"
android:orientation="vertical">
<com.bokecc.invitationcard.ui.InvitationCardMainLayout
android:id="@+id/invitation_card"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
初始化组件
获取token-初始化组件需要传递参数token,可以通过业务SDK(云直播等)提供的对外API获取token
使用业务SDK提供的配置信息初始化组件SDK
代码示例(以云直播为例):
private void initInvitationCard() {
invitationCard = findViewById(R.id.invitation_card);
if (DWLiveCoreHandler.getInstance().getInteractionConfigure() != null && DWLiveCoreHandler.getInstance().getInteractionConfigure().getInviteSwitch() > 0) {
String userId = "";
try {
//从登录信息中获取(上个界面传入)
userId = getIntent().getStringExtra("userId");
} catch (Exception e) {
e.printStackTrace();
}
String nickName = "";
try {
//从登录信息中获取(上个界面传入)
nickName = getIntent().getStringExtra("nickName");
} catch (Exception e) {
e.printStackTrace();
}
String roomId = "";
try {
roomId = getIntent().getStringExtra("roomId");
} catch (Exception e) {
e.printStackTrace();
}
String viewerId = "";
try {
viewerId = DWLiveCoreHandler.getInstance().getViewer().getId();
} catch (Exception e) {
e.printStackTrace();
}
String roomTitle = "";
try {
roomTitle = DWLiveCoreHandler.getInstance().getRoomInfo().getName();
} catch (Exception e) {
e.printStackTrace();
}
String roomDesc = "";
try {
roomDesc = DWLiveCoreHandler.getInstance().getRoomInfo().getDesc();
} catch (Exception e) {
e.printStackTrace();
}
String startTime = "";
try {
startTime = DWLiveCoreHandler.getInstance().getRoomInfo().getEstimateStartTime();
//时间格式做一下转换
if (startTime.endsWith(".0")){
startTime = startTime.substring(0,startTime.length()-2);
}
} catch (Exception e) {
e.printStackTrace();
}
final String finalViewerId = viewerId;
final String finalRoomId = roomId;
final String finalRoomTitle = roomTitle;
final String finalRoomDesc = roomDesc;
final String finalStartTime = startTime;
final String finalNickName = nickName;
final String liveLinkUrl = "https://view.csslcloud.net/api/view/index?roomid=" + roomId + "&userid=" +userId;
//获取组件token
DWLive.getInstance().getInteractiveToken(new BaseCallback<String>() {
public void onError(String error) {
Toast.makeText(LivePlayActivity.this, "获取组件token失败", Toast.LENGTH_SHORT).show();
}
public void onSuccess(final String token) {
invitationCard.setListener(new InvitationCardMainLayout.IInvitationCardListener() {
public void onCardLongClick(View view) {
//当前view生成Bitmap,保存的逻辑可以自定义实现
int width = view.getWidth();
int height = view.getHeight();
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
view.draw(canvas);
File file = ImageUtils.save2Album(LivePlayActivity.this, bitmap, Bitmap.CompressFormat.JPEG);
Toast.makeText(LivePlayActivity.this, "已保存至相册", Toast.LENGTH_SHORT).show();
}
public void onClose() {
invitationCard.setVisibility(View.GONE);
}
public void onInitSuccess() {
isInvitationCardInit = true;
invitationCard.getRankList(new IBaseCallBack<List<InvitationCardRankBean>>() {
public void onSuccess(List<InvitationCardRankBean> invitationCardRankBeans) {
//设置排行榜数据
mMoreFunctionLayout.setInvitationRankData(invitationCardRankBeans,false);
}
public void onFailed(int code, String msg) {
}
});
}
});
invitationCard.initialize(
new InvitationCardBaseLayout
.InvitationCardConfig()
.setInteractToken(token)
.setUserId(finalViewerId)
.setRoomId(finalRoomId)
.setOngoingId("")
.setOngoing(false)
//邀请卡内容相关
.setCardLiveTitle(finalRoomTitle)
.setCardLiveTime(finalStartTime)
.setCardLiveDesc(finalRoomDesc)
.setCardNickname(finalNickName)
.setCardQrCodeUrl(liveLinkUrl)
.setCardAvatarUrl("")
);
}
});
}
}
销毁组件
protected void onDestroy() {
super.onDestroy();
if (invitationCard!=null){
invitationCard.release();
}
}
邀请卡管理器实现类为InvitationCardManagerImpl,对外方法参照IInvitationCardManager,UI可以参考InvitationCardBaseLayout以及其子类InvitationCardMainLayout实现
混淆配置
-keep class com.bokecc.**{*;}
-keep interface com.bokecc.**{*;}
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.github.bumptech.glide:glide:3.7.0'
implementation 'com.google.zxing:core:3.3.3'