xugenyuan

ref |> 新增华为默认系统分享

Signed-off-by: xugenyuan <xugenyuan@wondertek.com.cn>
Showing 36 changed files with 626 additions and 0 deletions
... ... @@ -244,6 +244,30 @@
]
}
]
},
{
"name": "wdShareBase",
"srcPath": "./commons/wdShareBase",
"targets": [
{
"name": "default",
"applyToProducts": [
"default"
]
}
]
},
{
"name": "wdShare",
"srcPath": "./features/wdShare",
"targets": [
{
"name": "default",
"applyToProducts": [
"default"
]
}
]
}
]
}
\ No newline at end of file
... ...
/node_modules
/oh_modules
/.preview
/build
/.cxx
/.test
\ No newline at end of file
... ...
export { WDShareObject, WDShareBase } from "./src/main/ets/WDShareBase"
export { ShareContent, ShareScene, ShareType } from "./src/main/ets/Constant"
\ No newline at end of file
... ...
{
"apiType": "stageMode",
"buildOption": {
},
"buildOptionSet": [
{
"name": "release",
"arkOptions": {
"obfuscation": {
"ruleOptions": {
"enable": true,
"files": [
"./obfuscation-rules.txt"
]
}
}
},
},
],
"targets": [
{
"name": "default"
}
]
}
\ No newline at end of file
... ...
import { hspTasks } from '@ohos/hvigor-ohos-plugin';
export default {
system: hspTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
plugins:[] /* Custom plugin to extend the functionality of Hvigor. */
}
... ...
# Define project specific obfuscation rules here.
# You can include the obfuscation configuration files in the current module's build-profile.json5.
#
# For more details, see
# https://gitee.com/openharmony/arkcompiler_ets_frontend/blob/master/arkguard/README.md
# Obfuscation options:
# -disable-obfuscation: disable all obfuscations
# -enable-property-obfuscation: obfuscate the property names
# -enable-toplevel-obfuscation: obfuscate the names in the global scope
# -compact: remove unnecessary blank spaces and all line feeds
# -remove-log: remove all console.* statements
# -print-namecache: print the name cache that contains the mapping from the old names to new names
# -apply-namecache: reuse the given cache file
# Keep options:
# -keep-property-name: specifies property names that you want to keep
# -keep-global-name: specifies names that you want to keep in the global scope
\ No newline at end of file
... ...
{
"name": "wdsharebase",
"version": "1.0.0",
"description": "Please describe the basic information.",
"main": "Index.ets",
"author": "",
"license": "Apache-2.0",
"packageType": "InterfaceHar",
"dependencies": {
}
}
\ No newline at end of file
... ...
export const enum ShareType {
System = 0,
WeChat,
QQ,
Weibo,
}
export const enum ShareScene {
System = 0,
WeChatSession,
WeChatTimeline,
QQFriend,
QQZone,
Weibo,
}
export const enum ShareContentType {
PrueText = 1,
ImageAndText,
Link,
}
export interface ShareContentText {
text: string
}
export interface ShareContentImageAndText {
title: string
desc?: string
imgURI: string
}
export interface ShareContentLink {
title: string
desc?: string
link: string
icon?: string
}
export type ShareContent = ShareContentText | ShareContentImageAndText | ShareContentLink
... ...
import { ShareContent, ShareContentImageAndText, ShareContentLink, ShareContentText,
ShareContentType,
ShareScene } from '../Constant';
import { WDShareInterface } from '../WDShareInterface';
import { AsyncCallback } from '@kit.BasicServicesKit';
import { common } from '@kit.AbilityKit';
import { systemShare } from '@kit.ShareKit';
import { uniformTypeDescriptor as utd } from '@kit.ArkData';
export class WDSystemShare implements WDShareInterface {
shareContent(scene: ShareScene, content: ShareContent, contentType: ShareContentType): Promise<string> {
return new Promise((resolve, fail) => {
try {
let controller: systemShare.ShareController = new systemShare.ShareController(this.getShareData(content, contentType));
let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext
controller.on('dismiss', () => {
resolve("dismiss")
});
controller.show(context, {
previewMode: systemShare.SharePreviewMode.DEFAULT,
selectionMode: systemShare.SelectionMode.SINGLE
});
console.log("分享控制器调用完成")
} catch (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
});
data.addRecord({
utd: utd.UniformDataType.HYPERLINK,
uri: link.link
});
return data
}
}
\ No newline at end of file
... ...
import { ShareContent, ShareContentType, ShareScene, ShareType } from './Constant'
import { HashMap } from '@kit.ArkTS'
import { WDShareInterface } from './WDShareInterface'
import { WDSystemShare } from './System/WDSystemShare'
export interface WDShareObject {
to: ShareType,
scene: ShareScene,
type: ShareContentType,
obj: ShareContent
}
export class WDShareBase {
private static instance?: WDShareBase
static getInstance() : WDShareBase {
if (!WDShareBase.instance) {
WDShareBase.instance = new WDShareBase()
WDShareBase.instance.register()
}
return WDShareBase.instance
}
private handles: HashMap<ShareType, WDShareInterface> = new HashMap()
register() {
this.handles.set(ShareType.System, new WDSystemShare())
}
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)
}
return null
}
}
\ No newline at end of file
... ...
import { ShareContent, ShareContentType, ShareScene } from './Constant'
import { AsyncCallback } from '@kit.BasicServicesKit'
export interface WDShareInterface {
// shareContent(scene:ShareScene, content: ShareContent, callback: AsyncCallback<void>): void
shareContent(scene:ShareScene, content: ShareContent, contentType: ShareContentType): Promise<string>
}
\ No newline at end of file
... ...
@Entry
@Component
struct IndexPage {
@State message: string = 'Hello World';
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
... ...
{
"module": {
"name": "wdShareBase",
"type": "shared",
"description": "$string:shared_desc",
"deviceTypes": [
"phone",
"tablet",
"2in1"
],
"deliveryWithInstall": true,
"pages": "$profile:main_pages"
}
}
\ No newline at end of file
... ...
{
"color": [
{
"name": "white",
"value": "#FFFFFF"
}
]
}
\ No newline at end of file
... ...
{
"string": [
{
"name": "shared_desc",
"value": "description"
}
]
}
\ No newline at end of file
... ...
{
"src": [
"pages/IndexPage"
]
}
\ No newline at end of file
... ...
import localUnitTest from './LocalUnit.test';
export default function testsuite() {
localUnitTest();
}
\ No newline at end of file
... ...
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
export default function localUnitTest() {
describe('localUnitTest',() => {
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
beforeAll(() => {
// Presets an action, which is performed only once before all test cases of the test suite start.
// This API supports only one parameter: preset action function.
});
beforeEach(() => {
// Presets an action, which is performed before each unit test case starts.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: preset action function.
});
afterEach(() => {
// Presets a clear action, which is performed after each unit test case ends.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: clear action function.
});
afterAll(() => {
// Presets a clear action, which is performed after all test cases of the test suite end.
// This API supports only one parameter: clear action function.
});
it('assertContain', 0, () => {
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
let a = 'abc';
let b = 'b';
// Defines a variety of assertion methods, which are used to declare expected boolean conditions.
expect(a).assertContain(b);
expect(a).assertEqual(a);
});
});
}
\ No newline at end of file
... ...
... ... @@ -16,5 +16,6 @@
"wdConstant": "file:../../commons/wdConstant",
"wdDetailPlayApi": "file:../../features/wdDetailPlayApi",
// "wdComponent": "file:../../features/wdComponent"
"wdShare": "file:../../features/wdShare"
}
}
... ...
... ... @@ -11,6 +11,7 @@ import { SPHelper, ToastUtils, NumberFormatterUtils } from 'wdKit';
import { WDPlayerController } from 'wdPlayer/Index';
import { WDRouterPage, WDRouterRule } from 'wdRouter/Index';
import { SpConstants } from 'wdConstant/Index'
import { WDShare } from "wdShare"
interface ILikeStyleResp {
url: Resource;
... ... @@ -336,6 +337,8 @@ export struct PlayerRightView {
.aspectRatio(1)
.onClick((event: ClickEvent) => {
ToastUtils.showToast('分享为公共方法,待开发', 1000);
this.share()
})
Text('分享')
.width('100%')
... ... @@ -349,4 +352,9 @@ export struct PlayerRightView {
}
.margin({ bottom: 20 })
}
share() {
WDShare.shareContent(this.contentDetailData)
}
}
\ No newline at end of file
... ...
/node_modules
/oh_modules
/.preview
/build
/.cxx
/.test
\ No newline at end of file
... ...
export { WDShare } from './src/main/ets/WDShare'
... ...
{
"apiType": "stageMode",
"buildOption": {
},
"buildOptionSet": [
{
"name": "release",
"arkOptions": {
"obfuscation": {
"ruleOptions": {
"enable": true,
"files": [
"./obfuscation-rules.txt"
]
}
}
},
},
],
"targets": [
{
"name": "default"
}
]
}
\ No newline at end of file
... ...
import { hspTasks } from '@ohos/hvigor-ohos-plugin';
export default {
system: hspTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
plugins:[] /* Custom plugin to extend the functionality of Hvigor. */
}
... ...
# Define project specific obfuscation rules here.
# You can include the obfuscation configuration files in the current module's build-profile.json5.
#
# For more details, see
# https://gitee.com/openharmony/arkcompiler_ets_frontend/blob/master/arkguard/README.md
# Obfuscation options:
# -disable-obfuscation: disable all obfuscations
# -enable-property-obfuscation: obfuscate the property names
# -enable-toplevel-obfuscation: obfuscate the names in the global scope
# -compact: remove unnecessary blank spaces and all line feeds
# -remove-log: remove all console.* statements
# -print-namecache: print the name cache that contains the mapping from the old names to new names
# -apply-namecache: reuse the given cache file
# Keep options:
# -keep-property-name: specifies property names that you want to keep
# -keep-global-name: specifies names that you want to keep in the global scope
\ No newline at end of file
... ...
{
"meta": {
"stableOrder": true
},
"lockfileVersion": 3,
"ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
"specifiers": {
"@ohos/axios@^2.1.1": "@ohos/axios@2.2.0",
"wdBean@../wdBean": "wdBean@../wdBean",
"wdConstant@../../commons/wdConstant": "wdConstant@../../commons/wdConstant",
"wdKit@../../commons/wdKit": "wdKit@../../commons/wdKit",
"wdNetwork@../../commons/wdNetwork": "wdNetwork@../../commons/wdNetwork",
"wdRouter@../../commons/wdRouter": "wdRouter@../../commons/wdRouter",
"wdShareBase@../../commons/wdShareBase": "wdShareBase@../../commons/wdShareBase"
},
"packages": {
"@ohos/axios@2.2.0": {
"name": "@ohos/axios",
"integrity": "sha512-v1QBWk6DfcN8wUW3D0ieFbHTR1taSI5cOgxp5l6B5cegXuNYhSc8ggKlAIXe6h/14LsfM+NW0ZGfSXcNEIM5yA==",
"resolved": "https://repo.harmonyos.com/ohpm/@ohos/axios/-/axios-2.2.0.har",
"registryType": "ohpm"
},
"wdBean@../wdBean": {
"name": "wdbean",
"resolved": "../wdBean",
"registryType": "local"
},
"wdConstant@../../commons/wdConstant": {
"name": "wdconstant",
"resolved": "../../commons/wdConstant",
"registryType": "local"
},
"wdKit@../../commons/wdKit": {
"name": "wdkit",
"resolved": "../../commons/wdKit",
"registryType": "local"
},
"wdNetwork@../../commons/wdNetwork": {
"name": "wdnetwork",
"resolved": "../../commons/wdNetwork",
"registryType": "local",
"dependencies": {
"wdConstant": "file:../wdConstant",
"wdKit": "file:../wdKit",
"@ohos/axios": "^2.1.1"
}
},
"wdRouter@../../commons/wdRouter": {
"name": "wdrouter",
"resolved": "../../commons/wdRouter",
"registryType": "local",
"dependencies": {
"wdKit": "file:../wdKit",
"wdBean": "file:../../features/wdBean",
"wdNetwork": "file:../../commons/wdNetwork",
"wdConstant": "file:../../commons/wdConstant"
}
},
"wdShareBase@../../commons/wdShareBase": {
"name": "wdsharebase",
"resolved": "../../commons/wdShareBase",
"registryType": "local",
"packageType": "InterfaceHar"
}
}
}
\ No newline at end of file
... ...
{
"name": "wdshare",
"version": "1.0.0",
"description": "Please describe the basic information.",
"main": "Index.ets",
"author": "",
"license": "Apache-2.0",
"packageType": "InterfaceHar",
"dependencies": {
"wdKit": "file:../../commons/wdKit",
"wdBean": "file:../../features/wdBean",
"wdRouter": "file:../../commons/wdRouter",
"wdShareBase": "file:../../commons/wdShareBase"
}
}
\ No newline at end of file
... ...
import { ContentDetailDTO, ContentDTO, PageInfoDTO } from 'wdBean/Index';
import { ShareScene, ShareType, WDShareBase } from 'wdShareBase/Index';
import { ShareContentType } from 'wdShareBase/src/main/ets/Constant';
export class WDShare {
static shareContent(content: ContentDetailDTO, pageName: string ="", pageId: string = "") {
//TODO: 处理分享弹框交互和 海报逻辑
WDShareBase.getInstance().share({
to: ShareType.System,
scene: ShareScene.System,
type: ShareContentType.Link,
obj: {
title: content.shareInfo.shareTitle,
desc: content.shareInfo.shareSummary,
link: content.shareInfo.shareUrl,
}
})
}
static shareProgram(program: ContentDTO, pageName: string ="", pageId: string = "") {
}
static shareSubject(subject: PageInfoDTO) {
}
}
\ No newline at end of file
... ...
@Entry
@Component
struct Index {
@State message: string = 'Hello World';
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
... ...
export function add(a:number, b:number) {
return a + b;
}
\ No newline at end of file
... ...
{
"module": {
"name": "wdShare",
"type": "shared",
"description": "$string:shared_desc",
"deviceTypes": [
"phone",
"tablet",
"2in1"
],
"deliveryWithInstall": true,
"pages": "$profile:main_pages"
}
}
\ No newline at end of file
... ...
{
"color": [
{
"name": "white",
"value": "#FFFFFF"
}
]
}
\ No newline at end of file
... ...
{
"string": [
{
"name": "shared_desc",
"value": "description"
}
]
}
\ No newline at end of file
... ...
import localUnitTest from './LocalUnit.test';
export default function testsuite() {
localUnitTest();
}
\ No newline at end of file
... ...
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
export default function localUnitTest() {
describe('localUnitTest',() => {
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
beforeAll(() => {
// Presets an action, which is performed only once before all test cases of the test suite start.
// This API supports only one parameter: preset action function.
});
beforeEach(() => {
// Presets an action, which is performed before each unit test case starts.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: preset action function.
});
afterEach(() => {
// Presets a clear action, which is performed after each unit test case ends.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: clear action function.
});
afterAll(() => {
// Presets a clear action, which is performed after all test cases of the test suite end.
// This API supports only one parameter: clear action function.
});
it('assertContain', 0, () => {
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
let a = 'abc';
let b = 'b';
// Defines a variety of assertion methods, which are used to declare expected boolean conditions.
expect(a).assertContain(b);
expect(a).assertEqual(a);
});
});
}
\ No newline at end of file
... ...