xugenyuan

ref |> 华为分享增加标题和描述部分

... ... @@ -39,6 +39,7 @@ export interface ShareContentLink {
desc?: string
link: string
icon?: string
posterImg?: Resource
deeplink: string // 根据内容详情,生成的深度链接 如:rmrbapp://rmrb.app/openwith?type=article&subType=h5_template_article&contentId=30000762651&relId=500000038702&skipType=1&relType=1
}
... ...
... ... @@ -7,19 +7,20 @@ import { common } from '@kit.AbilityKit';
import { systemShare } from '@kit.ShareKit';
import { uniformTypeDescriptor as utd } from '@kit.ArkData';
import { JSON } from '@kit.ArkTS';
import { image } from '@kit.ImageKit';
import { WDShareBase } from '../WDShareBase';
const TAG = "WDSystemShare"
export class WDSystemShare implements WDShareInterface {
shareContent(scene: ShareScene, content: ShareContent, contentType: ShareContentType): Promise<string> {
shareContent(scene: ShareScene, content: ShareContent, contentType: ShareContentType, context?: common.UIAbilityContext): Promise<string> {
return new Promise((resolve, fail) => {
return new Promise(async (resolve, fail) => {
try {
let data = this.getShareData(content, contentType)
let data = await this.getShareData(content, contentType, context)
let controller: systemShare.ShareController = new systemShare.ShareController(data);
let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext
controller.on('dismiss', () => {
... ... @@ -31,51 +32,78 @@ export class WDSystemShare implements WDShareInterface {
selectionMode: systemShare.SelectionMode.SINGLE
});
console.log("分享控制器调用完成")
console.log(TAG, "分享控制器调用完成")
} catch (e) {
console.log(TAG, "异常1" + JSON.stringify(e))
fail(e)
}
})
}
getShareData(content: ShareContent, contentType: ShareContentType) : systemShare.SharedData {
if (contentType === ShareContentType.PrueText) {
let prueText = content as ShareContentText
console.log("分享纯文本")
return new systemShare.SharedData({
utd: utd.UniformDataType.PLAIN_TEXT,
content: prueText.text
});
}
if (contentType === ShareContentType.ImageAndText) {
let imageAndText = content as ShareContentImageAndText
console.log("分享图片和文本")
let data: systemShare.SharedData = new systemShare.SharedData({
utd: utd.UniformDataType.PLAIN_TEXT,
content: imageAndText.title
});
data.addRecord({
utd: utd.UniformDataType.PNG,
uri: imageAndText.imgURI // 这里必须为本地连接
});
return data
}
console.log("分享链接和文本")
let link = content as ShareContentLink
let data: systemShare.SharedData = new systemShare.SharedData({
utd: utd.UniformDataType.PLAIN_TEXT,
content: link.title
});
let shareLink = this.generateShareLink(link)
console.log("分享 shareLink ==> " + shareLink)
data.addRecord({
utd: utd.UniformDataType.HYPERLINK,
// uri: link.link // SDK 设计 不能传这里
content: link.link
});
return data
getShareData(content: ShareContent, contentType: ShareContentType, context?: common.UIAbilityContext) : Promise<systemShare.SharedData> {
return new Promise((resolve, fail) => {
if (contentType === ShareContentType.PrueText) {
let prueText = content as ShareContentText
console.log(TAG, "分享纯文本")
resolve(new systemShare.SharedData({
utd: utd.UniformDataType.PLAIN_TEXT,
content: prueText.text
}))
return;
}
if (contentType === ShareContentType.ImageAndText) {
let imageAndText = content as ShareContentImageAndText
console.log(TAG, "分享图片和文本")
let data: systemShare.SharedData = new systemShare.SharedData({
utd: utd.UniformDataType.PLAIN_TEXT,
content: imageAndText.title
});
data.addRecord({
utd: utd.UniformDataType.PNG,
uri: imageAndText.imgURI // 这里必须为本地连接
});
resolve(data)
return
}
console.log(TAG, "分享链接和文本")
let link = content as ShareContentLink
let posterImg: Uint8Array | undefined = undefined
let shareLink = this.generateShareLink(link)
console.log("TAG, 分享 shareLink ==> " + shareLink)
if (!context || !link.posterImg) {
let data: systemShare.SharedData = new systemShare.SharedData({
utd: utd.UniformDataType.HYPERLINK,
// uri: link.link // SDK 设计 不能传这里
content: link.link,
title: link.title,
description: link.desc,
thumbnail: posterImg
});
resolve(data)
return
}
context.resourceManager.getMediaContent(link.posterImg)
.then((posterImg) => {
let data: systemShare.SharedData = new systemShare.SharedData({
utd: utd.UniformDataType.HYPERLINK,
// uri: link.link // SDK 设计 不能传这里
content: link.link,
title: link.title,
description: link.desc,
thumbnail: posterImg
});
resolve(data)
})
.catch((e: Error) => {
console.log(TAG, "异常" + JSON.stringify(e))
fail(e)
})
})
}
generateShareLink(shareContent: ShareContentLink) {
... ...
... ... @@ -2,6 +2,7 @@ import { ShareContent, ShareContentType, ShareScene, ShareType } from './Constan
import { HashMap } from '@kit.ArkTS'
import { WDShareInterface } from './WDShareInterface'
import { WDSystemShare } from './System/WDSystemShare'
import { common } from '@kit.AbilityKit'
export interface WDShareObject {
to: ShareType,
... ... @@ -12,6 +13,8 @@ export interface WDShareObject {
export class WDShareBase {
public gotContextFunc?: () => common.UIAbilityContext
private static instance?: WDShareBase
static getInstance() : WDShareBase {
if (!WDShareBase.instance) {
... ... @@ -30,7 +33,8 @@ export class WDShareBase {
share(obj: WDShareObject) : null | Promise<string> {
let shareHandler: WDShareInterface = this.handles.get(obj.to)
if (shareHandler) {
return shareHandler.shareContent(obj.scene, obj.obj, obj.type)
let context = this.gotContextFunc && this.gotContextFunc()
return shareHandler.shareContent(obj.scene, obj.obj, obj.type, context)
}
return null
}
... ...
import { ShareContent, ShareContentType, ShareScene } from './Constant'
import { AsyncCallback } from '@kit.BasicServicesKit'
import { common } from '@kit.AbilityKit'
export interface WDShareInterface {
// shareContent(scene:ShareScene, content: ShareContent, callback: AsyncCallback<void>): void
shareContent(scene:ShareScene, content: ShareContent, contentType: ShareContentType): Promise<string>
shareContent(scene:ShareScene, content: ShareContent, contentType: ShareContentType, context?: common.UIAbilityContext): Promise<string>
... ...
... ... @@ -22,6 +22,7 @@ export class WDShare {
desc: content.shareInfo.shareSummary,
link: content.shareInfo.shareUrl,
deeplink:AppInnerLinkGenerator.generateDeepLinkWithConent(content),
// posterImg:$r("app.media.test_share_poster"),
}
})
}
... ...
... ... @@ -21,6 +21,7 @@
"wdTracking": "file:../../features/wdTracking",
"wdPlayer": "file:../../features/wdPlayer",
"wdShare": "file:../../features/wdShare",
"wdShareBase": "file:../../commons/wdShareBase",
"wdDetailPlayLive": "file:../../features/wdDetailPlayLive"
}
}
... ...
... ... @@ -24,6 +24,7 @@ import { LiveRoomManager } from 'wdDetailPlayLive/Index'
import { initGlobalPlayerSettings } from 'wdPlayer/src/main/ets/utils/GlobalSetting'
import { BackgroundAudioController } from 'wdPlayer/Index'
import { SpConstants } from 'wdConstant'
import { WDShareBase } from 'wdShareBase/Index';
const TAG = "[StartupManager]"
... ... @@ -126,6 +127,8 @@ export class StartupManager {
this.initLiveChatRoom()
this.initBackgroundAudioTask()
this.initShare()
Logger.debug(TAG, "App 必要初始化完成")
}
... ... @@ -233,6 +236,12 @@ export class StartupManager {
}
}
private initShare() {
WDShareBase.getInstance().gotContextFunc = () => {
return StartupManager.sharedInstance().context!
}
}
private initThirdPlatformSDK() {
}
... ...