From d667d25e4c7bd64c29d74ded70ecb38bb993fa73 Mon Sep 17 00:00:00 2001 From: Neil Date: Sat, 21 Sep 2024 10:29:31 +0800 Subject: [PATCH 1/2] Optimized --- entry/src/main/ets/constant/Constant.ets | 5 -- .../main/ets/view/SampleUnitAVPlayView.ets | 16 +++---- entry/src/main/ets/view/SampleUnitView.ets | 20 +++----- .../main/ets/viewmodel/BasicDataSource.ets | 46 ++----------------- .../src/main/ets/viewmodel/TitleUnitItem.ets | 6 +-- .../main/resources/base/element/string.json | 20 +++----- .../main/resources/en_US/element/string.json | 12 +++++ .../main/resources/zh_CN/element/string.json | 12 +++++ 8 files changed, 50 insertions(+), 87 deletions(-) diff --git a/entry/src/main/ets/constant/Constant.ets b/entry/src/main/ets/constant/Constant.ets index aca2fa8..f0ab9db 100644 --- a/entry/src/main/ets/constant/Constant.ets +++ b/entry/src/main/ets/constant/Constant.ets @@ -25,11 +25,6 @@ export class CONSTANT { static FULL_SIZE = '100%'; static FIFTY_SIZE = '50%'; static EIGHTY_SIZE = '80%'; - // HZ list - static HZ_ZERO = 0; - static HZ_THIRTY = 30; - static HZ_SIXTY = 60; - static HZ_ONE_HUNDRED_AND_TWENTY = 120; // Rotate 360 static ROTATE = 360; // Add rotate num diff --git a/entry/src/main/ets/view/SampleUnitAVPlayView.ets b/entry/src/main/ets/view/SampleUnitAVPlayView.ets index 3fc029c..2277c66 100644 --- a/entry/src/main/ets/view/SampleUnitAVPlayView.ets +++ b/entry/src/main/ets/view/SampleUnitAVPlayView.ets @@ -46,10 +46,10 @@ export default struct SampleUnitAVPlayView { } display.on('foldStatusChange', () => { - if (display.getFoldStatus() === display.FoldStatus.FOLD_STATUS_EXPANDED) { - this.sliderWidth = px2vp(SURFACE_SIZE); - } else { + if (display.getFoldStatus() === display.FoldStatus.FOLD_STATUS_FOLDED) { this.sliderWidth = X_COMPONENT_WIDTH; + } else { + this.sliderWidth = px2vp(SURFACE_SIZE); } }); } @@ -70,14 +70,12 @@ export default struct SampleUnitAVPlayView { this.avPlayer.surfaceID = this.xComponentController.getXComponentSurfaceId(); }) .onVisibleAreaChange([0.0, 1.0], (isVisible: boolean, currentRatio: number) => { - if (isVisible && currentRatio === 1) { if (this.setTimeInstance) { clearTimeout(this.setTimeInstance) } this.setTimeInstance = setTimeout(() => { if (this.avPlayer && this.avPlayer.surfaceID !== '') { - if (this.currentSurfaceID) { if (this.avPlayer.surfaceID !== this.currentSurfaceID) { } @@ -95,6 +93,8 @@ export default struct SampleUnitAVPlayView { .height(this.xComponentHeight) .width(this.xComponentWidth) + + Slider({ value: this.curTime, min: 0, max: 100 }) .enabled(false) .height(4) @@ -103,7 +103,7 @@ export default struct SampleUnitAVPlayView { .blockColor(Color.Red) .blockSize({ width: 4, height: 4 }) .onVisibleAreaChange([0.0, 1.0], (isVisible: boolean, currentRatio: number) => { - if (isVisible) { + if(isVisible) { animateTo({ duration: DURATION, iterations: -1, @@ -113,10 +113,10 @@ export default struct SampleUnitAVPlayView { max: 120, }, }, () => { - if (this.curTime >= 100) { + if(this.curTime >= 100) { this.curTime = 0; } - for (let i = 0; i < 101; i++) { + for(let i = 0; i< 101; i++) { this.curTime += 1; } }) diff --git a/entry/src/main/ets/view/SampleUnitView.ets b/entry/src/main/ets/view/SampleUnitView.ets index 8252323..0d3a682 100644 --- a/entry/src/main/ets/view/SampleUnitView.ets +++ b/entry/src/main/ets/view/SampleUnitView.ets @@ -30,26 +30,18 @@ const STATIC_MARGIN = 8; const MINI_MARGIN = 4; // All types const TYPE_ENUM = ['av', 'pic', 'video']; -// Font weight +// Font weight. const FONT_WEIGHT = 400; // Border radius const BORDER_RADIUS = 5; -// Title unit item obj -const TITLE_UNIT_ITEM_OBJ = ['华商报', '昨天 19:21', '微博视频号'] -// Button unit item obj -const BUTTON_UNIT_ITEM_OBJ = [5, 18, 53] @Component export default struct SampleUnitView { - type: string = 'av'; - buttonUnit: ButtonUnitItem = - new ButtonUnitItem($r('app.media.share'), BUTTON_UNIT_ITEM_OBJ[0], $r('app.media.like'), BUTTON_UNIT_ITEM_OBJ[1], - $r('app.media.collect'), BUTTON_UNIT_ITEM_OBJ[2]); - areaUnit: TitleUnitItem = - new TitleUnitItem($r('app.media.huaShangBaoPic'), TITLE_UNIT_ITEM_OBJ[0], TITLE_UNIT_ITEM_OBJ[1], - TITLE_UNIT_ITEM_OBJ[2], $r('app.media.honour')); - textContext: string = ''; - imageArray: Resource[] = [$r("app.media.b")]; + @Prop areaUnit: TitleUnitItem; + @Prop buttonUnit: ButtonUnitItem; + @Prop type: string; + @Prop textContext: string; + @Prop imageArray: Resource[]; controller: VideoController = new VideoController(); avPlayer: AVPlayerItem = new AVPlayerItem(); diff --git a/entry/src/main/ets/viewmodel/BasicDataSource.ets b/entry/src/main/ets/viewmodel/BasicDataSource.ets index 20807e9..c56e295 100644 --- a/entry/src/main/ets/viewmodel/BasicDataSource.ets +++ b/entry/src/main/ets/viewmodel/BasicDataSource.ets @@ -25,44 +25,6 @@ export class DataSource { return this.dataSource; } - pushData(): void { - let imageArray1: Resource[] = [$r("app.media.b")]; - let imageArray3: Resource[] = [$r("app.media.a"), $r("app.media.b"), $r("app.media.c")]; - let imageArray4: Resource[] = [$r("app.media.a"), $r("app.media.b"), $r("app.media.c"), $r("app.media.d")]; - let imageArray8: Resource[] = - [$r("app.media.a"), $r("app.media.b"), $r("app.media.c"), $r("app.media.d"), $r("app.media.e"), $r("app.media.f"), - $r("app.media.g"), $r("app.media.h")]; - let imageArray9: Resource[] = - [$r("app.media.a"), $r("app.media.b"), $r("app.media.c"), $r("app.media.d"), $r("app.media.e"), $r("app.media.f"), - $r("app.media.g"), $r("app.media.h"), $r("app.media.i")]; - let buttonUnit: ButtonUnitItem = - new ButtonUnitItem($r('app.media.share'), 5, $r('app.media.like'), 18, $r('app.media.collect'), 53); - let areaUnit: TitleUnitItem = - new TitleUnitItem($r('app.media.avatar'), '小鱼儿', '昨天', '', $r('app.media.honour'),); - let textContext = - '上面的示例中,用户与应用程序的交互触发了文本状态变更,状态变更引起了UI渲染,UI从“Hello World”变更为“Hello ArkUI”。' + - '在声明式UI编程框架中,UI是程序状态的运行结果,用户构建了一个UI模型,其中应用的运行时的状态是参数。当参数改变时,UI作为返回结果,也将进行对应的改变。这些运行时的状态变化所带来的UI的重新渲染,在ArkUI中统称为状态管理机制。' + - '自定义组件拥有变量,变量必须被装饰器装饰才可以成为状态变量,状态变量的改变会引起UI的渲染刷新。如果不使用状态变量,UI只能在初始化时渲染,后续将不会再刷新。 下图展示了State和View(UI)之间的关系。'; - this.dataSource.data.push(new SampleUnitItem('video', areaUnit, textContext, buttonUnit, imageArray1, - new VideoController(), new AVPlayerItem())); - this.dataSource.data.push(new SampleUnitItem('pic', areaUnit, textContext, buttonUnit, imageArray3, - new VideoController(), new AVPlayerItem())); - this.dataSource.data.push(new SampleUnitItem('pic', areaUnit, textContext, buttonUnit, imageArray4, - new VideoController(), new AVPlayerItem())); - this.dataSource.data.push(new SampleUnitItem('pic', areaUnit, textContext, buttonUnit, imageArray8, - new VideoController(), new AVPlayerItem())); - this.dataSource.data.push(new SampleUnitItem('pic', areaUnit, textContext, buttonUnit, imageArray9, - new VideoController(), new AVPlayerItem())); - this.dataSource.data.push(new SampleUnitItem('pic', areaUnit, textContext, buttonUnit, imageArray3, - new VideoController(), new AVPlayerItem())); - this.dataSource.data.push(new SampleUnitItem('av', areaUnit, textContext, buttonUnit, imageArray1, - new VideoController(), new AVPlayerItem())); - this.dataSource.data.push(new SampleUnitItem('pic', areaUnit, textContext, buttonUnit, imageArray1, - new VideoController(), new AVPlayerItem())); - this.dataSource.data.push(new SampleUnitItem('pic', areaUnit, textContext, buttonUnit, imageArray3, - new VideoController(), new AVPlayerItem())); - } - clear() { this.dataSource.data = []; } @@ -85,9 +47,11 @@ class BasicDataSource implements IDataSource { let buttonUnit: ButtonUnitItem = new ButtonUnitItem($r('app.media.share'), 5, $r('app.media.like'), 18, $r('app.media.collect'), 53); let areaUnit: TitleUnitItem = - new TitleUnitItem($r('app.media.avatar'), '小鱼儿', '昨天 19:12', '微博视频号', $r('app.media.honour'),); - let textContext = - '亲近大海,领悟海,体会到了海的心声,海自然与你共鸣,无需可以强求,也无需费力搜寻,海,始终都会以潮声与你相亲,以其海色伴你舒适。'; + new TitleUnitItem($r('app.media.avatar'), + getContext(this).resourceManager.getStringSync($r('app.string.show_netname')), + getContext(this).resourceManager.getStringSync($r('app.string.show_time')), + ); + let textContext = getContext(this).resourceManager.getStringSync($r('app.string.show_text')); let data: SampleUnitItem[] = [ new SampleUnitItem('video', areaUnit, textContext, buttonUnit, this.imageArray1, new VideoController(), diff --git a/entry/src/main/ets/viewmodel/TitleUnitItem.ets b/entry/src/main/ets/viewmodel/TitleUnitItem.ets index b46a92e..d24ef93 100644 --- a/entry/src/main/ets/viewmodel/TitleUnitItem.ets +++ b/entry/src/main/ets/viewmodel/TitleUnitItem.ets @@ -17,14 +17,10 @@ export default class TitleUnitItem { public titlePic: Resource; public titleName: string; public titleTime: string; - public titleFrom: string; - public titleHonours: Resource; - constructor(titlePic: Resource, titleName: string, titleTime: string, titleFrom: string, titleHonours: Resource) { + constructor(titlePic: Resource, titleName: string, titleTime: string) { this.titlePic = titlePic; this.titleName = titleName; this.titleTime = titleTime; - this.titleFrom = titleFrom; - this.titleHonours = titleHonours; } } \ No newline at end of file diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json index 4fd9a11..bfe2bef 100644 --- a/entry/src/main/resources/base/element/string.json +++ b/entry/src/main/resources/base/element/string.json @@ -13,24 +13,16 @@ "value": "label" }, { - "name": "width_100", - "value": "100%" + "name": "show_text", + "value": "Close to the sea, understand the sea, experience the voice of the sea, the sea naturally resonates with you, no need to force, no need to search, the sea, will always be with the sound of the tide and you are comfortable with its sea color." }, { - "name": "height_100", - "value": "100%" + "name": "show_netname", + "value": "small fish" }, { - "name": "image_set_size_9_flex_width", - "value": "75%" - }, - { - "name": "image_set_size_4_flex_width", - "value": "50%" - }, - { - "name": "image_toast", - "value": "本图片仅展示,具体业务可自行实现" + "name": "show_time", + "value": "19:12 Yesterday" } ] } \ No newline at end of file diff --git a/entry/src/main/resources/en_US/element/string.json b/entry/src/main/resources/en_US/element/string.json index 21f3c1b..8984ec8 100644 --- a/entry/src/main/resources/en_US/element/string.json +++ b/entry/src/main/resources/en_US/element/string.json @@ -11,6 +11,18 @@ { "name": "EntryAbility_label", "value": "FluentBlog" + }, + { + "name": "show_text", + "value": "Close to the sea, understand the sea, experience the voice of the sea, the sea naturally resonates with you, no need to force, no need to search, the sea, will always be with the sound of the tide and you are comfortable with its sea color." + }, + { + "name": "show_netname", + "value": "small fish" + }, + { + "name": "show_time", + "value": "19:12 Yesterday" } ] } \ No newline at end of file diff --git a/entry/src/main/resources/zh_CN/element/string.json b/entry/src/main/resources/zh_CN/element/string.json index 67dfc50..75866f2 100644 --- a/entry/src/main/resources/zh_CN/element/string.json +++ b/entry/src/main/resources/zh_CN/element/string.json @@ -11,6 +11,18 @@ { "name": "EntryAbility_label", "value": "流畅刷文章" + }, + { + "name": "show_text", + "value": "亲近大海,领悟海,体会到了海的心声,海自然与你共鸣,无需可以强求,也无需费力搜寻,海,始终都会以潮声与你相亲,以其海色伴你舒适。" + }, + { + "name": "show_netname", + "value": "小鱼儿" + }, + { + "name": "show_time", + "value": "昨天 19:12" } ] } \ No newline at end of file -- Gitee From 5db6408534c41d95f147aba5fbcc2ed86c270559 Mon Sep 17 00:00:00 2001 From: Neil Date: Sat, 21 Sep 2024 10:31:47 +0800 Subject: [PATCH 2/2] Optimized --- entry/src/main/ets/view/SampleUnitAVPlayView.ets | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/entry/src/main/ets/view/SampleUnitAVPlayView.ets b/entry/src/main/ets/view/SampleUnitAVPlayView.ets index 2277c66..0bb0eae 100644 --- a/entry/src/main/ets/view/SampleUnitAVPlayView.ets +++ b/entry/src/main/ets/view/SampleUnitAVPlayView.ets @@ -94,7 +94,6 @@ export default struct SampleUnitAVPlayView { .width(this.xComponentWidth) - Slider({ value: this.curTime, min: 0, max: 100 }) .enabled(false) .height(4) @@ -103,7 +102,7 @@ export default struct SampleUnitAVPlayView { .blockColor(Color.Red) .blockSize({ width: 4, height: 4 }) .onVisibleAreaChange([0.0, 1.0], (isVisible: boolean, currentRatio: number) => { - if(isVisible) { + if (isVisible) { animateTo({ duration: DURATION, iterations: -1, @@ -113,10 +112,10 @@ export default struct SampleUnitAVPlayView { max: 120, }, }, () => { - if(this.curTime >= 100) { + if (this.curTime >= 100) { this.curTime = 0; } - for(let i = 0; i< 101; i++) { + for (let i = 0; i < 101; i++) { this.curTime += 1; } }) -- Gitee