diff --git a/features/longList/src/main/ets/longlistability/LongListAbility.ets b/features/longList/src/main/ets/longlistability/LongListAbility.ets index ad058eab2ed07c8fa10d7e194ed905d3613c367c..c4156dcb2e706be6057f4df48851939a72e3cf25 100644 --- a/features/longList/src/main/ets/longlistability/LongListAbility.ets +++ b/features/longList/src/main/ets/longlistability/LongListAbility.ets @@ -29,39 +29,59 @@ class ContinueData { } export default class LongListAbility extends UIAbility { + // [Start continue_restore] continueRestore(want: Want) { if (!want.parameters || !want.parameters.distributedSessionId) { + console.error('missing sessionId'); return; } + // 2.1 调用create()接口创建并得到一个分布式数据对象实例 let continueData: ContinueData = new ContinueData(undefined,undefined); let dataObject = distributedDataObject.create(this.context, continueData); + + // 2.2 注册恢复状态监听。收到状态为'restored'的回调通知时,表示接收端分布式数据对象已恢复发起端保存过来的数据(有资产数据时,对应的文件也迁移过来了) dataObject.on('status', (sessionId: string, networkId: string, status: string) => { if (status === 'restored') { + // 收到'restored'的状态通知表示已恢复发起端保存的数据 AppStorage.setOrCreate('continueIndex', dataObject['continueIndex']); AppStorage.setOrCreate('currentOffset', dataObject['currentOffset']); AppStorage.setOrCreate('continueEntry', true); - AppStorage.setOrCreate('setCurrentOffset', true); + AppStorage.setOrCreate('setcurrentOffset', true); } }); + + // 2.3 从want.parameters中获取发起端放入的sessionId,调用setSessionId接口设置同步的sessionId let sessionId = want.parameters.distributedSessionId as string; dataObject.setSessionId(sessionId); this.context.restoreWindowStage(new LocalStorage()); } + // [End continue_restore] + // [Start on_continue] async onContinue(wantParam: Record): Promise { + // 1.1 调用create()接口创建并得到一个分布式数据对象实例 + // continueData是一个object,可以用来存储需要接续的数据 let continueIndex = AppStorage.get('continueIndex') as number; let currentOffset = AppStorage.get('currentOffset') as number; let continueData: ContinueData = new ContinueData(continueIndex, currentOffset); let dataObject = distributedDataObject.create(this.context, continueData); + + // 1.2 调用genSessionId()接口创建一个sessionId,调用setSessionId()接口设置同步的sessionId,并将这个sessionId放入wantParam let sessionId = distributedDataObject.genSessionId(); + console.log(`gen sessionId: ${sessionId}`); dataObject.setSessionId(sessionId); wantParam.distributedSessionId = sessionId; + + // 1.3 从wantParam获取接收端设备networkId,使用这个networkId调用save接口保存数据到接收端 let deviceId = wantParam.targetDevice as string; + console.log(`get deviceId: ${deviceId}`); dataObject.save(deviceId); return AbilityConstant.OnContinueResult.AGREE; } + // [End on_continue] + // [Start on_create] onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { hilog.info(0x0000, 'EntryAbility', '%{public}s', 'Ability onCreate'); if (launchParam.launchReason === AbilityConstant.LaunchReason.CONTINUATION) { @@ -78,6 +98,7 @@ export default class LongListAbility extends UIAbility { } } } + // [End on_create] onDestroy(): void { hilog.info(0x0000, 'EntryAbility', '%{public}s', 'Ability onDestroy'); diff --git a/features/longList/src/main/ets/pages/Index.ets b/features/longList/src/main/ets/pages/Index.ets index d183dd1b783764d9aae43a38e15b77521f6cc1b6..846b59451851aedb7f27293884c154355eb1599f 100644 --- a/features/longList/src/main/ets/pages/Index.ets +++ b/features/longList/src/main/ets/pages/Index.ets @@ -60,13 +60,13 @@ struct Index { this.indexPage = HomeConstants.INDEX_PAGE_EN; } this.pageInfos.pushPath({ name: this.indexPage }, false); - this.windowsHeight = px2vp(display.getDefaultDisplaySync().height); + this.windowsHeight = this.getUIContext().px2vp(display.getDefaultDisplaySync().height); this.breakpointSystem.register(); - window.getLastWindow(getContext()).then(win => { + window.getLastWindow(this.getUIContext().getHostContext()).then(win => { win.setWindowLayoutFullScreen(true); let area = win.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM); let height = area.topRect.height; - let vpHeight = px2vp(height); + let vpHeight = this.getUIContext().px2vp(height); AppStorage.setOrCreate('topHeight', vpHeight); }); } diff --git a/features/longList/src/main/ets/view/HomeContent.ets b/features/longList/src/main/ets/view/HomeContent.ets index ebd56f356fb46df52581f8b1bfa799a1d6e4f393..35d1df19003a4a743f7e864bddda7478eb103a3a 100644 --- a/features/longList/src/main/ets/view/HomeContent.ets +++ b/features/longList/src/main/ets/view/HomeContent.ets @@ -106,13 +106,14 @@ export struct HomeContent { aboutToAppear(): void { this.listenNetworkEvent(true); } - + // [Start on_did_build] onDidBuild(): void { if(this.setCurrentOffset){ this.scroller.scrollTo({xOffset:0, yOffset:this.currentOffset}); this.setCurrentOffset = false; } } + // [End on_did_build] build() { Column() { Row(){ @@ -148,7 +149,9 @@ export struct HomeContent { }) SearchBarView(); Column() { + // [Start scroll_water_flow_view] Scroll(this.scroller) { + // [StartExclude scroll_water_flow_view] if (this.netConnectState === NetConnectionState.SUCCEED_STATE) { Column() { FunctionView({ freshFlag: this.freshFlag }); @@ -180,11 +183,13 @@ export struct HomeContent { } this.currentOffset = this.scroller.currentOffset().yOffset; }) + // [EndExclude scroll_water_flow_view] .onDidScroll((xOffset: number, yOffset: number, scrollState: ScrollState)=>{ if(!this.setCurrentOffset){ this.currentOffset = this.scroller.currentOffset().yOffset; } }) + // [End scroll_water_flow_view] .onDisAppear(()=>{ this.currentOffset = this.scroller.currentOffset().yOffset; }) diff --git a/features/longList/src/main/ets/view/WaterFlowLivingView.ets b/features/longList/src/main/ets/view/WaterFlowLivingView.ets index bffc3449184ad07dbcffd8aff28dcba7707227ec..c8877ffd52cc23e691f14878eeba60bd62b6d039 100644 --- a/features/longList/src/main/ets/view/WaterFlowLivingView.ets +++ b/features/longList/src/main/ets/view/WaterFlowLivingView.ets @@ -90,8 +90,10 @@ export struct WaterFlowLivingView { } }) .onAppear(() => { - let videoPos = componentUtils.getRectangleById(CommonConstants.WATER_FLOW_LIVING_STRUCT_ID + this.itemIndex); - if (px2vp(videoPos.windowOffset.y) + px2vp(videoPos.size.height) < this.windowsHeight) { + let videoPos = + componentUtils.getRectangleById(CommonConstants.WATER_FLOW_LIVING_STRUCT_ID + this.itemIndex); + if (this.getUIContext().px2vp(videoPos.windowOffset.y) + this.getUIContext().px2vp(videoPos.size.height) < + this.windowsHeight) { setTimeout(() => { this.videoController.start(); }, 1000); diff --git a/features/longList/src/main/ets/view/WaterFlowView.ets b/features/longList/src/main/ets/view/WaterFlowView.ets index b708005c79609b52d7f995fd2610572586a89cfb..4dd302eb776fb1a53048e47a67b82f4a42762aa6 100644 --- a/features/longList/src/main/ets/view/WaterFlowView.ets +++ b/features/longList/src/main/ets/view/WaterFlowView.ets @@ -90,14 +90,14 @@ export struct WaterFlowView { } updateWaterFlowItemWidth() { - let windowWidth: number = px2vp(display.getDefaultDisplaySync().width); + let windowWidth: number = this.getUIContext().px2vp(display.getDefaultDisplaySync().width); let columns = windowWidth > CommonConstants.CRITICAL_VALUE ? CommonConstants.WATER_FLOW_THREE_COLUMNS : CommonConstants.WATER_FLOW_TWO_COLUMNS; let marginLeft = windowWidth > CommonConstants.CRITICAL_VALUE ? BreakpointConstants.SEARCHBAR_AND_WATER_FLOW_MARGIN_LEFT_MD : BreakpointConstants.SEARCHBAR_AND_WATER_FLOW_MARGIN_LEFT_SM; this.waterFlowItemWidth = - (px2vp(display.getDefaultDisplaySync().width) - marginLeft * 2 - + (this.getUIContext().px2vp(display.getDefaultDisplaySync().width) - marginLeft * 2 - (columns - 1) * CommonConstants.WATER_FLOW_COLUMN_GAP) / columns; } diff --git a/features/longList/src/main/module.json5 b/features/longList/src/main/module.json5 index f4be63708f93c52662777a59aab1027fee8cef4f..016a182e4caac3804bcb35eef5c6d70e23520733 100644 --- a/features/longList/src/main/module.json5 +++ b/features/longList/src/main/module.json5 @@ -1,5 +1,7 @@ +// [Start module_json5] { "module": { + // [StartExclude module_json5] "name": "longList", "type": "feature", "description": "$string:module_desc", @@ -10,8 +12,10 @@ "deliveryWithInstall": true, "installationFree": false, "pages": "$profile:main_pages", + // [EndExclude module_json5] "abilities": [ { + // [StartExclude module_json5] "name": "LongListAbility", "srcEntry": "./ets/longlistability/LongListAbility.ets", "description": "$string:LongListAbility_desc", @@ -20,8 +24,10 @@ "startWindowIcon": "$media:startIcon", "startWindowBackground": "$color:start_window_background", "exported": true, + // [EndExclude module_json5] "continuable": true } ] } -} \ No newline at end of file +} +// [End module_json5] \ No newline at end of file diff --git a/features/video/src/main/ets/videomanager/AvPlayManager.ets b/features/video/src/main/ets/videomanager/AvPlayManager.ets index 3db1e8dcb9a7ce1d23164fe1fed82a566ac805f7..aa1731199969acb9af3032c9185f955caafe16c1 100644 --- a/features/video/src/main/ets/videomanager/AvPlayManager.ets +++ b/features/video/src/main/ets/videomanager/AvPlayManager.ets @@ -130,11 +130,13 @@ export default class AvPlayManage { case 'playing': // After the play interface is successfully invoked, the state machine is reported. this.state = 'playing'; AppStorage.set('videoState', this.state); + // [Start video_seek] if (this.continue) { this.videoSeek(continueTime); this.continue = false; AppStorage.set('continue', false); } + // [End video_seek] let eventDataTrue: emitter.EventData = { data: { 'flag': true @@ -175,9 +177,11 @@ export default class AvPlayManage { } }); // Listening function for reporting time + // [Start time_update] this.avPlayer.on('timeUpdate', (time: number) => { this.currentTime = time; }); + // [End time_update] } getDurationTime(): number { diff --git a/features/web/src/main/ets/pages/IndexPage.ets b/features/web/src/main/ets/pages/IndexPage.ets index 5bcfd0d0e3905a0baf0a5f3b11d09fe2ee72af69..6f4404f338128693bb83559ad12bcad8d688f741 100644 --- a/features/web/src/main/ets/pages/IndexPage.ets +++ b/features/web/src/main/ets/pages/IndexPage.ets @@ -14,7 +14,6 @@ */ import { BusinessError } from '@kit.BasicServicesKit'; -import { router, promptAction } from '@kit.ArkUI'; import { webview } from '@kit.ArkWeb'; import { window } from '@kit.ArkUI'; import { common, Want } from '@kit.AbilityKit'; @@ -65,8 +64,8 @@ struct IndexPage { let type = window.AvoidAreaType.TYPE_SYSTEM; // Get status bar height. let area: window.AvoidArea = windowClass.getWindowAvoidArea(type); - let statusBarHeight = px2vp(area.topRect.height); - let sliderBarHeight = px2vp(area.bottomRect.height); + let statusBarHeight = this.getUIContext().px2vp(area.topRect.height); + let sliderBarHeight = this.getUIContext().px2vp(area.bottomRect.height); this.statusBarHeight = statusBarHeight; this.sliderBarHeight = sliderBarHeight; if (statusBarHeight > 0) { @@ -83,7 +82,7 @@ struct IndexPage { } jumpOrderConfirm(detailStr: string): void { - router.pushUrl({ + this.getUIContext().getRouter().pushUrl({ url: 'pages/OrderConfirmPage', params: { statusBarHeight: this.statusBarHeight, sliderBarHeight: this.sliderBarHeight, detailStr } }); @@ -93,7 +92,9 @@ struct IndexPage { Stack({ alignContent: Alignment.TopStart }) { + // [Start web_on_page_end] Web({ src: this.pageUrl, controller: this.controller }) + // [StartExclude web_on_page_end] .layoutWeight(1) .javaScriptProxy({ object: this.arkTSObj, @@ -102,7 +103,7 @@ struct IndexPage { controller: this.controller }) .onConfirm(() => { - promptAction.showToast({ + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.toast_msg'), duration: CommonConstants.TOAST_DURATION }); @@ -110,10 +111,13 @@ struct IndexPage { }) .width('100%') .height(this.pageUrl.includes('product_list') ? '90%' : '100%') + // [EndExclude web_on_page_end] .onPageEnd(async () => { + // [StartExclude web_on_page_end] this.webCanBack = this.controller.accessBackward(); this.webCanForward = this.controller.accessForward(); this.onPageEnd = true; + // [EndExclude web_on_page_end] if (this.pageUrl.includes('product_list') && this.continueRestore) { this.controller.runJavaScript('javascript:document.getElementById("productList").scrollTop = ' + this.scrollDistance); @@ -123,7 +127,9 @@ struct IndexPage { await this.controller.runJavaScript('javascript:document.getElementById("productList").scrollTop'); this.scrollDistance = Number(result); }) + // [StartExclude web_on_page_end] .zoomAccess(false) + // [EndExclude web_on_page_end] .onTouch(async (event: TouchEvent) => { if (event.type === TouchType.Up) { if (this.pageUrl.includes('product_list')) { @@ -133,6 +139,7 @@ struct IndexPage { } } }) + // [End web_on_page_end] .margin({ top: this.pageUrl.includes('product_detail') ? 0 : 92, }) diff --git a/features/web/src/main/ets/pages/OrderConfirmPage.ets b/features/web/src/main/ets/pages/OrderConfirmPage.ets index fa532c785c701a7ed7938780475f1149cafd6df3..5347576f861c32a442be2be1681a2d687d07f1a5 100644 --- a/features/web/src/main/ets/pages/OrderConfirmPage.ets +++ b/features/web/src/main/ets/pages/OrderConfirmPage.ets @@ -13,7 +13,6 @@ * limitations under the License. */ -import { router, promptAction } from '@kit.ArkUI'; import { CommonConstants } from '../common/constants/CommonConstants'; import ProductModel from '../model/ProductModel'; @@ -28,9 +27,10 @@ function titleStyle() { @Entry @Component struct OrderConfirmPage { - statusBarHeight: number = (router.getParams() as Record)['statusBarHeight']; - sliderBarHeight: number = (router.getParams() as Record)['sliderBarHeight']; - productDetail: ProductModel = JSON.parse((router.getParams() as Record)['detailStr']) as ProductModel; + statusBarHeight: number = (this.getUIContext().getRouter().getParams() as Record)['statusBarHeight']; + sliderBarHeight: number = (this.getUIContext().getRouter().getParams() as Record)['sliderBarHeight']; + productDetail: ProductModel = + JSON.parse((this.getUIContext().getRouter().getParams() as Record)['detailStr']) as ProductModel; build() { Column() { @@ -39,7 +39,7 @@ struct OrderConfirmPage { .width($r('app.float.img_size')) .margin({ left: $r('app.float.md_padding_margin'), right: $r('app.float.lg_padding_margin') }) .onClick(() => { - router.back(); + this.getUIContext().getRouter().back(); }) Text($r('app.string.confirm_order')) .fontSize($r('app.float.font_size_lg')) @@ -194,7 +194,7 @@ struct OrderConfirmPage { colors: [[$r('app.color.button_start'), 0.11], [$r('app.color.button_end'), 0.89]] }) .onClick(() => { - promptAction.showToast({ + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.toast_msg'), duration: CommonConstants.TOAST_DURATION });