xugenyuan

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

@@ -39,6 +39,7 @@ export interface ShareContentLink { @@ -39,6 +39,7 @@ export interface ShareContentLink {
39 desc?: string 39 desc?: string
40 link: string 40 link: string
41 icon?: string 41 icon?: string
  42 + posterImg?: Resource
42 deeplink: string // 根据内容详情,生成的深度链接 如:rmrbapp://rmrb.app/openwith?type=article&subType=h5_template_article&contentId=30000762651&relId=500000038702&skipType=1&relType=1 43 deeplink: string // 根据内容详情,生成的深度链接 如:rmrbapp://rmrb.app/openwith?type=article&subType=h5_template_article&contentId=30000762651&relId=500000038702&skipType=1&relType=1
43 44
44 } 45 }
@@ -7,19 +7,20 @@ import { common } from '@kit.AbilityKit'; @@ -7,19 +7,20 @@ import { common } from '@kit.AbilityKit';
7 import { systemShare } from '@kit.ShareKit'; 7 import { systemShare } from '@kit.ShareKit';
8 import { uniformTypeDescriptor as utd } from '@kit.ArkData'; 8 import { uniformTypeDescriptor as utd } from '@kit.ArkData';
9 import { JSON } from '@kit.ArkTS'; 9 import { JSON } from '@kit.ArkTS';
  10 +import { image } from '@kit.ImageKit';
  11 +import { WDShareBase } from '../WDShareBase';
10 12
11 const TAG = "WDSystemShare" 13 const TAG = "WDSystemShare"
12 14
13 export class WDSystemShare implements WDShareInterface { 15 export class WDSystemShare implements WDShareInterface {
14 16
15 - shareContent(scene: ShareScene, content: ShareContent, contentType: ShareContentType): Promise<string> { 17 + shareContent(scene: ShareScene, content: ShareContent, contentType: ShareContentType, context?: common.UIAbilityContext): Promise<string> {
16 18
17 - return new Promise((resolve, fail) => { 19 + return new Promise(async (resolve, fail) => {
18 try { 20 try {
19 21
20 - let data = this.getShareData(content, contentType) 22 + let data = await this.getShareData(content, contentType, context)
21 let controller: systemShare.ShareController = new systemShare.ShareController(data); 23 let controller: systemShare.ShareController = new systemShare.ShareController(data);
22 - let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext  
23 24
24 controller.on('dismiss', () => { 25 controller.on('dismiss', () => {
25 26
@@ -31,26 +32,30 @@ export class WDSystemShare implements WDShareInterface { @@ -31,26 +32,30 @@ export class WDSystemShare implements WDShareInterface {
31 selectionMode: systemShare.SelectionMode.SINGLE 32 selectionMode: systemShare.SelectionMode.SINGLE
32 }); 33 });
33 34
34 - console.log("分享控制器调用完成") 35 + console.log(TAG, "分享控制器调用完成")
35 } catch (e) { 36 } catch (e) {
  37 + console.log(TAG, "异常1" + JSON.stringify(e))
36 fail(e) 38 fail(e)
37 } 39 }
38 }) 40 })
39 } 41 }
40 42
41 - getShareData(content: ShareContent, contentType: ShareContentType) : systemShare.SharedData { 43 + getShareData(content: ShareContent, contentType: ShareContentType, context?: common.UIAbilityContext) : Promise<systemShare.SharedData> {
  44 + return new Promise((resolve, fail) => {
  45 +
42 if (contentType === ShareContentType.PrueText) { 46 if (contentType === ShareContentType.PrueText) {
43 let prueText = content as ShareContentText 47 let prueText = content as ShareContentText
44 - console.log("分享纯文本")  
45 - return new systemShare.SharedData({ 48 + console.log(TAG, "分享纯文本")
  49 + resolve(new systemShare.SharedData({
46 utd: utd.UniformDataType.PLAIN_TEXT, 50 utd: utd.UniformDataType.PLAIN_TEXT,
47 content: prueText.text 51 content: prueText.text
48 - }); 52 + }))
  53 + return;
49 } 54 }
50 55
51 if (contentType === ShareContentType.ImageAndText) { 56 if (contentType === ShareContentType.ImageAndText) {
52 let imageAndText = content as ShareContentImageAndText 57 let imageAndText = content as ShareContentImageAndText
53 - console.log("分享图片和文本") 58 + console.log(TAG, "分享图片和文本")
54 let data: systemShare.SharedData = new systemShare.SharedData({ 59 let data: systemShare.SharedData = new systemShare.SharedData({
55 utd: utd.UniformDataType.PLAIN_TEXT, 60 utd: utd.UniformDataType.PLAIN_TEXT,
56 content: imageAndText.title 61 content: imageAndText.title
@@ -59,23 +64,46 @@ export class WDSystemShare implements WDShareInterface { @@ -59,23 +64,46 @@ export class WDSystemShare implements WDShareInterface {
59 utd: utd.UniformDataType.PNG, 64 utd: utd.UniformDataType.PNG,
60 uri: imageAndText.imgURI // 这里必须为本地连接 65 uri: imageAndText.imgURI // 这里必须为本地连接
61 }); 66 });
62 - return data 67 + resolve(data)
  68 + return
63 } 69 }
64 70
65 - console.log("分享链接和文本") 71 + console.log(TAG, "分享链接和文本")
66 let link = content as ShareContentLink 72 let link = content as ShareContentLink
  73 + let posterImg: Uint8Array | undefined = undefined
  74 + let shareLink = this.generateShareLink(link)
  75 + console.log("TAG, 分享 shareLink ==> " + shareLink)
  76 +
  77 + if (!context || !link.posterImg) {
67 let data: systemShare.SharedData = new systemShare.SharedData({ 78 let data: systemShare.SharedData = new systemShare.SharedData({
68 - utd: utd.UniformDataType.PLAIN_TEXT,  
69 - content: link.title 79 + utd: utd.UniformDataType.HYPERLINK,
  80 + // uri: link.link // SDK 设计 不能传这里
  81 + content: link.link,
  82 + title: link.title,
  83 + description: link.desc,
  84 + thumbnail: posterImg
70 }); 85 });
71 - let shareLink = this.generateShareLink(link)  
72 - console.log("分享 shareLink ==> " + shareLink)  
73 - data.addRecord({ 86 + resolve(data)
  87 + return
  88 + }
  89 +
  90 + context.resourceManager.getMediaContent(link.posterImg)
  91 + .then((posterImg) => {
  92 + let data: systemShare.SharedData = new systemShare.SharedData({
74 utd: utd.UniformDataType.HYPERLINK, 93 utd: utd.UniformDataType.HYPERLINK,
75 // uri: link.link // SDK 设计 不能传这里 94 // uri: link.link // SDK 设计 不能传这里
76 - content: link.link 95 + content: link.link,
  96 + title: link.title,
  97 + description: link.desc,
  98 + thumbnail: posterImg
77 }); 99 });
78 - return data 100 + resolve(data)
  101 + })
  102 + .catch((e: Error) => {
  103 + console.log(TAG, "异常" + JSON.stringify(e))
  104 + fail(e)
  105 + })
  106 + })
79 } 107 }
80 108
81 generateShareLink(shareContent: ShareContentLink) { 109 generateShareLink(shareContent: ShareContentLink) {
@@ -2,6 +2,7 @@ import { ShareContent, ShareContentType, ShareScene, ShareType } from './Constan @@ -2,6 +2,7 @@ import { ShareContent, ShareContentType, ShareScene, ShareType } from './Constan
2 import { HashMap } from '@kit.ArkTS' 2 import { HashMap } from '@kit.ArkTS'
3 import { WDShareInterface } from './WDShareInterface' 3 import { WDShareInterface } from './WDShareInterface'
4 import { WDSystemShare } from './System/WDSystemShare' 4 import { WDSystemShare } from './System/WDSystemShare'
  5 +import { common } from '@kit.AbilityKit'
5 6
6 export interface WDShareObject { 7 export interface WDShareObject {
7 to: ShareType, 8 to: ShareType,
@@ -12,6 +13,8 @@ export interface WDShareObject { @@ -12,6 +13,8 @@ export interface WDShareObject {
12 13
13 export class WDShareBase { 14 export class WDShareBase {
14 15
  16 + public gotContextFunc?: () => common.UIAbilityContext
  17 +
15 private static instance?: WDShareBase 18 private static instance?: WDShareBase
16 static getInstance() : WDShareBase { 19 static getInstance() : WDShareBase {
17 if (!WDShareBase.instance) { 20 if (!WDShareBase.instance) {
@@ -30,7 +33,8 @@ export class WDShareBase { @@ -30,7 +33,8 @@ export class WDShareBase {
30 share(obj: WDShareObject) : null | Promise<string> { 33 share(obj: WDShareObject) : null | Promise<string> {
31 let shareHandler: WDShareInterface = this.handles.get(obj.to) 34 let shareHandler: WDShareInterface = this.handles.get(obj.to)
32 if (shareHandler) { 35 if (shareHandler) {
33 - return shareHandler.shareContent(obj.scene, obj.obj, obj.type) 36 + let context = this.gotContextFunc && this.gotContextFunc()
  37 + return shareHandler.shareContent(obj.scene, obj.obj, obj.type, context)
34 } 38 }
35 return null 39 return null
36 } 40 }
1 import { ShareContent, ShareContentType, ShareScene } from './Constant' 1 import { ShareContent, ShareContentType, ShareScene } from './Constant'
2 import { AsyncCallback } from '@kit.BasicServicesKit' 2 import { AsyncCallback } from '@kit.BasicServicesKit'
  3 +import { common } from '@kit.AbilityKit'
3 4
4 export interface WDShareInterface { 5 export interface WDShareInterface {
5 // shareContent(scene:ShareScene, content: ShareContent, callback: AsyncCallback<void>): void 6 // shareContent(scene:ShareScene, content: ShareContent, callback: AsyncCallback<void>): void
6 - shareContent(scene:ShareScene, content: ShareContent, contentType: ShareContentType): Promise<string> 7 + shareContent(scene:ShareScene, content: ShareContent, contentType: ShareContentType, context?: common.UIAbilityContext): Promise<string>
7 8
8 9
9 10
@@ -22,6 +22,7 @@ export class WDShare { @@ -22,6 +22,7 @@ export class WDShare {
22 desc: content.shareInfo.shareSummary, 22 desc: content.shareInfo.shareSummary,
23 link: content.shareInfo.shareUrl, 23 link: content.shareInfo.shareUrl,
24 deeplink:AppInnerLinkGenerator.generateDeepLinkWithConent(content), 24 deeplink:AppInnerLinkGenerator.generateDeepLinkWithConent(content),
  25 + // posterImg:$r("app.media.test_share_poster"),
25 } 26 }
26 }) 27 })
27 } 28 }
@@ -21,6 +21,7 @@ @@ -21,6 +21,7 @@
21 "wdTracking": "file:../../features/wdTracking", 21 "wdTracking": "file:../../features/wdTracking",
22 "wdPlayer": "file:../../features/wdPlayer", 22 "wdPlayer": "file:../../features/wdPlayer",
23 "wdShare": "file:../../features/wdShare", 23 "wdShare": "file:../../features/wdShare",
  24 + "wdShareBase": "file:../../commons/wdShareBase",
24 "wdDetailPlayLive": "file:../../features/wdDetailPlayLive" 25 "wdDetailPlayLive": "file:../../features/wdDetailPlayLive"
25 } 26 }
26 } 27 }
@@ -24,6 +24,7 @@ import { LiveRoomManager } from 'wdDetailPlayLive/Index' @@ -24,6 +24,7 @@ import { LiveRoomManager } from 'wdDetailPlayLive/Index'
24 import { initGlobalPlayerSettings } from 'wdPlayer/src/main/ets/utils/GlobalSetting' 24 import { initGlobalPlayerSettings } from 'wdPlayer/src/main/ets/utils/GlobalSetting'
25 import { BackgroundAudioController } from 'wdPlayer/Index' 25 import { BackgroundAudioController } from 'wdPlayer/Index'
26 import { SpConstants } from 'wdConstant' 26 import { SpConstants } from 'wdConstant'
  27 +import { WDShareBase } from 'wdShareBase/Index';
27 28
28 const TAG = "[StartupManager]" 29 const TAG = "[StartupManager]"
29 30
@@ -126,6 +127,8 @@ export class StartupManager { @@ -126,6 +127,8 @@ export class StartupManager {
126 this.initLiveChatRoom() 127 this.initLiveChatRoom()
127 128
128 this.initBackgroundAudioTask() 129 this.initBackgroundAudioTask()
  130 +
  131 + this.initShare()
129 Logger.debug(TAG, "App 必要初始化完成") 132 Logger.debug(TAG, "App 必要初始化完成")
130 } 133 }
131 134
@@ -233,6 +236,12 @@ export class StartupManager { @@ -233,6 +236,12 @@ export class StartupManager {
233 } 236 }
234 } 237 }
235 238
  239 + private initShare() {
  240 + WDShareBase.getInstance().gotContextFunc = () => {
  241 + return StartupManager.sharedInstance().context!
  242 + }
  243 + }
  244 +
236 private initThirdPlatformSDK() { 245 private initThirdPlatformSDK() {
237 246
238 } 247 }