Toggle navigation
Toggle navigation
This project
Loading...
Sign in
developOne
/
harmonyPool
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
xugenyuan
2024-08-06 20:31:30 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
934fdcb608ffc721050d47498692ba33a1db1260
934fdcb6
1 parent
6cf7f2a9
ref |> 华为分享增加标题和描述部分
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
90 additions
and
45 deletions
sight_harmony/commons/wdShareBase/src/main/ets/Constant.ets
sight_harmony/commons/wdShareBase/src/main/ets/System/WDSystemShare.ets
sight_harmony/commons/wdShareBase/src/main/ets/WDShareBase.ets
sight_harmony/commons/wdShareBase/src/main/ets/WDShareInterface.ets
sight_harmony/features/wdShare/src/main/ets/WDShare.ets
sight_harmony/features/wdShare/src/main/resources/base/media/test_share_poster.png
sight_harmony/products/phone/oh-package.json5
sight_harmony/products/phone/src/main/ets/startupmanager/StartupManager.ets
sight_harmony/commons/wdShareBase/src/main/ets/Constant.ets
View file @
934fdcb
...
...
@@ -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
}
...
...
sight_harmony/commons/wdShareBase/src/main/ets/System/WDSystemShare.ets
View file @
934fdcb
...
...
@@ -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) {
...
...
sight_harmony/commons/wdShareBase/src/main/ets/WDShareBase.ets
View file @
934fdcb
...
...
@@ -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
}
...
...
sight_harmony/commons/wdShareBase/src/main/ets/WDShareInterface.ets
View file @
934fdcb
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>
...
...
sight_harmony/features/wdShare/src/main/ets/WDShare.ets
View file @
934fdcb
...
...
@@ -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"),
}
})
}
...
...
sight_harmony/features/wdShare/src/main/resources/base/media/test_share_poster.png
0 → 100644
View file @
934fdcb
1.6 MB
sight_harmony/products/phone/oh-package.json5
View file @
934fdcb
...
...
@@ -21,6 +21,7 @@
"wdTracking"
:
"file:../../features/wdTracking"
,
"wdPlayer"
:
"file:../../features/wdPlayer"
,
"wdShare"
:
"file:../../features/wdShare"
,
"wdShareBase"
:
"file:../../commons/wdShareBase"
,
"wdDetailPlayLive"
:
"file:../../features/wdDetailPlayLive"
}
}
...
...
sight_harmony/products/phone/src/main/ets/startupmanager/StartupManager.ets
View file @
934fdcb
...
...
@@ -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() {
}
...
...
Please
register
or
login
to post a comment