|
|
|
## 邀请卡组件
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 版本历史
|
|
|
|
|
|
|
|
| 版本号 | 更新时间 | 更新描述 |
|
|
|
|
| ------ | ---------- | -------- |
|
|
|
|
| 1.0.1 | 2022.6.15 | 组件上线 |
|
|
|
|
| 1.0.2 | 2022.11.24 | 优化UI |
|
|
|
|
| | | |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 组件引入
|
|
|
|
|
|
|
|
注意:所有使用互动组件必须要引入basemodule库,最新版本见 [互动组件对接文档](互动组件/互动组件对接文档)
|
|
|
|
|
|
|
|
项目根目录build.gradle引入:
|
|
|
|
|
|
|
|
```groovy
|
|
|
|
repositories {
|
|
|
|
maven { url 'http://nexus-app.bokecc.com/repository/sdk-group/' }
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
module的build.gradle引入:
|
|
|
|
|
|
|
|
```java
|
|
|
|
dependencies {
|
|
|
|
api ('com.bokecc:basemodule:x.x.x')
|
|
|
|
api ('com.bokecc.module:invitationcardmodule:x.x.x')
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Application的onCreate方法中,调用`DWLiveEngine.init`初始化dwlivesdk后,添加代码:
|
|
|
|
|
|
|
|
```java
|
|
|
|
InvitationCardInteractSDK.getInstance().init(app);
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 1. 组件描述
|
|
|
|
|
|
|
|
邀请卡组件是基于基础组件库扩展的组件服务,包括展示邀请卡,获取排行榜等功能,为业务方提供邀请卡能力。邀请卡组件包含管理器和基于管理器实现的UI界面,接入方可基于管理器对外API实现完全自定义UI的邀请卡,也可直接集成组件SDK提供的UI。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 2. 组件架构
|
|
|
|
|
|
|
|
#### 2.1 组件架构图
|
|
|
|
|
|
|
|
![image-20220506100931572](组件架构图.png)
|
|
|
|
|
|
|
|
#### 2.2 核心对外API
|
|
|
|
|
|
|
|
IInvitationCardManager内部唯一实现类为InvitationCardManagerImpl
|
|
|
|
|
|
|
|
| 作用 | API |
|
|
|
|
| -------------- | ------------------------------------------------------------ |
|
|
|
|
| 初始化 | init(BaseInvitationCardListener listener, String userId, String roomId, String interactToken, String originUrl, String avatarUrl, Context context) |
|
|
|
|
| 获取邀请卡列表 | getCardList(IBaseCallBack<List<InvitationCardDataBean>> callBack) |
|
|
|
|
| 获取邀请卡配置 | getCardConfig(IBaseCallBack<InvitationCardConfigBean> callBack) |
|
|
|
|
| 获取短链接 | getShortLink(String originUrl, IBaseCallBack<String> callBack) |
|
|
|
|
| 获取排行榜 | getCardRankList(IBaseCallBack<List<InvitationCardRankBean>> callBack) |
|
|
|
|
| 重连 | reConnect() |
|
|
|
|
| 释放 | release() |
|
|
|
|
|
|
|
|
API接口代码
|
|
|
|
|
|
|
|
```java
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#### 2.3 数据参数定义
|
|
|
|
|
|
|
|
数据类参数说明
|
|
|
|
|
|
|
|
```java
|
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 3. 组件接入
|
|
|
|
|
|
|
|
#### 3.1 使用组件提供UI
|
|
|
|
|
|
|
|
邀请卡ViewGroup为InvitationCardMainLayout
|
|
|
|
|
|
|
|
1. 登录业务SDK(云直播等)
|
|
|
|
|
|
|
|
2. xml中添加InvitationCardMainLayout
|
|
|
|
|
|
|
|
```xml
|
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
|
|
|
<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>
|
|
|
|
```
|
|
|
|
|
|
|
|
4. 初始化组件
|
|
|
|
|
|
|
|
1. 获取token-初始化组件需要传递参数token,可以通过业务SDK(云直播等)提供的对外API获取token
|
|
|
|
|
|
|
|
2. 使用业务SDK提供的配置信息初始化组件SDK
|
|
|
|
|
|
|
|
代码示例(以云直播为例):
|
|
|
|
|
|
|
|
|
|
|
|
```java
|
|
|
|
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>() {
|
|
|
|
@Override
|
|
|
|
public void onError(String error) {
|
|
|
|
Toast.makeText(LivePlayActivity.this, "获取组件token失败", Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(final String token) {
|
|
|
|
invitationCard.setListener(new InvitationCardMainLayout.IInvitationCardListener() {
|
|
|
|
@Override
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClose() {
|
|
|
|
invitationCard.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onInitSuccess() {
|
|
|
|
isInvitationCardInit = true;
|
|
|
|
invitationCard.getRankList(new IBaseCallBack<List<InvitationCardRankBean>>() {
|
|
|
|
@Override
|
|
|
|
public void onSuccess(List<InvitationCardRankBean> invitationCardRankBeans) {
|
|
|
|
//设置排行榜数据
|
|
|
|
mMoreFunctionLayout.setInvitationRankData(invitationCardRankBeans,false);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
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("")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
5. 销毁组件
|
|
|
|
|
|
|
|
```java
|
|
|
|
@Override
|
|
|
|
protected void onDestroy() {
|
|
|
|
super.onDestroy();
|
|
|
|
if (invitationCard!=null){
|
|
|
|
invitationCard.release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#### 3.2 使用组件管理器+自定义UI
|
|
|
|
|
|
|
|
邀请卡管理器实现类为InvitationCardManagerImpl,对外方法参照IInvitationCardManager,UI可以参考InvitationCardBaseLayout以及其子类InvitationCardMainLayout实现
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 4. 混淆配置
|
|
|
|
|
|
|
|
混淆配置
|
|
|
|
|
|
|
|
```
|
|
|
|
-keep class com.bokecc.**{*;}
|
|
|
|
-keep interface com.bokecc.**{*;}
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 5. 组件库依赖
|
|
|
|
|
|
|
|
```groovy
|
|
|
|
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'
|
|
|
|
``` |
|
|
|
\ No newline at end of file |