From d02f2b11f14039c05f00216040a5bc853969a42f Mon Sep 17 00:00:00 2001 From: zhangxCode Date: Wed, 4 Jun 2025 10:17:25 +0800 Subject: [PATCH] =?UTF-8?q?Fix=EF=BC=9A=E8=A7=A3=E5=86=B3=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E6=97=A0=E6=B3=95=E6=92=AD=E6=94=BE=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=9B=E8=A7=A3=E5=86=B3=E5=A4=B4=E9=83=A8=E5=AF=BC=E8=88=AA?= =?UTF-8?q?=E6=8D=A2=E8=A1=8C=E6=A0=B7=E5=BC=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- commons/base/src/main/ets/utils/AvPlayerUtil.ets | 12 ++++++++---- commons/base/src/main/ets/utils/DisplayUtil.ets | 3 +-- features/home/src/main/ets/view/BannerView.ets | 2 +- features/home/src/main/ets/view/HomeHeader.ets | 2 +- features/home/src/main/ets/view/VideoDaily.ets | 4 ++-- .../videoDetail/src/main/ets/view/VideoDetail.ets | 4 ++-- .../src/main/ets/view/VideoDetailChange.ets | 10 +++++----- .../videoDetail/src/main/ets/view/VideoPlayer.ets | 2 +- 8 files changed, 21 insertions(+), 18 deletions(-) diff --git a/commons/base/src/main/ets/utils/AvPlayerUtil.ets b/commons/base/src/main/ets/utils/AvPlayerUtil.ets index dd4d00b..becd2f1 100644 --- a/commons/base/src/main/ets/utils/AvPlayerUtil.ets +++ b/commons/base/src/main/ets/utils/AvPlayerUtil.ets @@ -20,11 +20,11 @@ import { BusinessError } from '@kit.BasicServicesKit'; import Logger from './Logger'; import { CommonConstants } from '../constants/CommonConstants'; -const uiContext: UIContext | undefined = AppStorage.get('uiContext'); +const AppStorageUiContext: UIContext | undefined = AppStorage.get('uiContext'); export class AvPlayerUtil { private avPlayer?: media.AVPlayer; - private context: common.UIAbilityContext = uiContext?.getHostContext() as common.UIAbilityContext; + private context: common.UIAbilityContext = AppStorageUiContext?.getHostContext() as common.UIAbilityContext; private url: resourceManager.RawFileDescriptor | null = null; private surfaceId: string = ''; private sliderBegin: number = 0; @@ -94,9 +94,13 @@ export class AvPlayerUtil { } }; - static getInstance(): AvPlayerUtil | undefined { + constructor(uiContext: UIContext) { + this.context = uiContext.getHostContext() as common.UIAbilityContext; + } + + static getInstance(uiContext: UIContext): AvPlayerUtil | undefined { if (!AppStorage.get('avPlayerUtil')) { - AppStorage.setOrCreate('avPlayerUtil', new AvPlayerUtil()); + AppStorage.setOrCreate('avPlayerUtil', new AvPlayerUtil(uiContext)); } else { Logger.info(`AppStorage does not have avPlayerUtil`); } diff --git a/commons/base/src/main/ets/utils/DisplayUtil.ets b/commons/base/src/main/ets/utils/DisplayUtil.ets index c87a3e8..7d85429 100644 --- a/commons/base/src/main/ets/utils/DisplayUtil.ets +++ b/commons/base/src/main/ets/utils/DisplayUtil.ets @@ -16,10 +16,9 @@ import { display } from '@kit.ArkUI'; // [Start display_util] -const uiContext: UIContext | undefined = AppStorage.get('uiContext'); export class DisplayUtil { - static getFoldCreaseRegion(): void { + static getFoldCreaseRegion(uiContext: UIContext): void { if(canIUse('SystemCapability.Window.SessionManager')) { if (display.isFoldable()) { let foldRegion: display.FoldCreaseRegion = display.getCurrentFoldCreaseRegion(); diff --git a/features/home/src/main/ets/view/BannerView.ets b/features/home/src/main/ets/view/BannerView.ets index ef24674..b537200 100644 --- a/features/home/src/main/ets/view/BannerView.ets +++ b/features/home/src/main/ets/view/BannerView.ets @@ -298,7 +298,7 @@ export struct BannerView { getBannerNewHeight(windowWidth: number): string { // Obtain the window width and subtract the blank parts on both sides. - let result: number = px2vp(windowWidth) - new BreakpointType(32, + let result: number = this.getUIContext().px2vp(windowWidth) - new BreakpointType(32, 48, 64).getValue(this.currentWidthBreakpoint) - 96; // Calculate the width of a single image based on the percent. diff --git a/features/home/src/main/ets/view/HomeHeader.ets b/features/home/src/main/ets/view/HomeHeader.ets index 8894cfb..5696512 100644 --- a/features/home/src/main/ets/view/HomeHeader.ets +++ b/features/home/src/main/ets/view/HomeHeader.ets @@ -61,7 +61,7 @@ export struct HomeHeader { span: { sm: 4, md: 5, - lg: 7 + lg: 5 } }) { this.searchBar() diff --git a/features/home/src/main/ets/view/VideoDaily.ets b/features/home/src/main/ets/view/VideoDaily.ets index 6778476..64f0271 100644 --- a/features/home/src/main/ets/view/VideoDaily.ets +++ b/features/home/src/main/ets/view/VideoDaily.ets @@ -58,8 +58,8 @@ export struct DailyVideo { // [Start dd_windowrect_rect] let windowRect: window.Rect = this.mainWindowClass!.getWindowProperties().windowRect; - let windowWidthVp: number = px2vp(windowRect.width); - let windowHeightVp: number = px2vp(windowRect.height); + let windowWidthVp: number = this.getUIContext().px2vp(windowRect.width); + let windowHeightVp: number = this.getUIContext().px2vp(windowRect.height); let aspectRatio: number = windowHeightVp / windowWidthVp; if (aspectRatio < 1.2 && aspectRatio >= 0.8) { this.mainWindowClass?.setPreferredOrientation(window.Orientation.AUTO_ROTATION_RESTRICTED); diff --git a/features/videoDetail/src/main/ets/view/VideoDetail.ets b/features/videoDetail/src/main/ets/view/VideoDetail.ets index 32e7b34..54bac78 100644 --- a/features/videoDetail/src/main/ets/view/VideoDetail.ets +++ b/features/videoDetail/src/main/ets/view/VideoDetail.ets @@ -48,7 +48,7 @@ export struct VideoDetail { @State commentImgWidth: string = DetailConstants.INITIAL_COMMENT_IMAGE_WIDTH; @State relatedVideoHeight: number = DetailConstants.INITIAL_RELATED_VIDEO_HEIGHT; @State videoHeight: number = DetailConstants.INITIAL_VIDEO_HEIGHT; - private avPlayerUtil?: AvPlayerUtil = AvPlayerUtil.getInstance(); + private avPlayerUtil?: AvPlayerUtil = AvPlayerUtil.getInstance(this.getUIContext()); public screenHeight: number = 0; private windowUtil?: WindowUtil = WindowUtil.getInstance(); private mainWindow?: window.Window; @@ -131,7 +131,7 @@ export struct VideoDetail { aboutToAppear() { // [StartExclude on_window_size_change] - DisplayUtil.getFoldCreaseRegion(); + DisplayUtil.getFoldCreaseRegion(this.getUIContext()); this.screenHeight = DeviceScreen.getDeviceHeight(); // [EndExclude on_window_size_change] this.mainWindow = this.windowUtil!.getMainWindow(); diff --git a/features/videoDetail/src/main/ets/view/VideoDetailChange.ets b/features/videoDetail/src/main/ets/view/VideoDetailChange.ets index d0a0a31..6e9df84 100644 --- a/features/videoDetail/src/main/ets/view/VideoDetailChange.ets +++ b/features/videoDetail/src/main/ets/view/VideoDetailChange.ets @@ -48,7 +48,7 @@ export struct VideoDetail { @State commentImgWidth: string = DetailConstants.INITIAL_COMMENT_IMAGE_WIDTH; @State relatedVideoHeight: number = DetailConstants.INITIAL_RELATED_VIDEO_HEIGHT; @State videoHeight: number = DetailConstants.INITIAL_VIDEO_HEIGHT; - private avPlayerUtil?: AvPlayerUtil = AvPlayerUtil.getInstance(); + private avPlayerUtil?: AvPlayerUtil = AvPlayerUtil.getInstance(this.getUIContext()); public screenHeight: number = 0; private windowUtil?: WindowUtil = WindowUtil.getInstance(); private mainWindow?: window.Window; @@ -128,7 +128,7 @@ export struct VideoDetail { // [End on_full_screen_change] aboutToAppear() { - DisplayUtil.getFoldCreaseRegion(); + DisplayUtil.getFoldCreaseRegion(this.getUIContext()); this.screenHeight = DeviceScreen.getDeviceHeight(); this.mainWindow = this.windowUtil!.getMainWindow(); this.mainWindow?.on('windowSizeChange', this.onWindowSizeChange); @@ -192,12 +192,12 @@ export struct VideoDetail { // Handling when the width of the sidebar changes. let height: number = DetailConstants.COMMENT_IMAGE_MIN_HEIGHT_NUMBER + (Number(newValue.width) - DetailConstants.SIDE_BAR_MIN_WIDTH_NUMBER) / - (px2vp(this.windowWidth) * DetailConstants.COMMENTS_AREA_PERCENT - + (this.getUIContext().px2vp(this.windowWidth) * DetailConstants.COMMENTS_AREA_PERCENT - DetailConstants.SIDE_BAR_MIN_WIDTH_NUMBER) * (DetailConstants.COMMENT_IMAGE_MAX_HEIGHT_NUMBER - DetailConstants.COMMENT_IMAGE_MIN_HEIGHT_NUMBER); let width: number = DetailConstants.COMMENT_IMAGE_MIN_WIDTH_NUMBER + (Number(newValue.width) - DetailConstants.SIDE_BAR_MIN_WIDTH_NUMBER) / - (px2vp(this.windowWidth) * DetailConstants.COMMENTS_AREA_PERCENT - + (this.getUIContext().px2vp(this.windowWidth) * DetailConstants.COMMENTS_AREA_PERCENT - DetailConstants.SIDE_BAR_MIN_WIDTH_NUMBER) * (DetailConstants.COMMENT_IMAGE_MAX_WIDTH_NUMBER - DetailConstants.COMMENT_IMAGE_MIN_WIDTH_NUMBER); this.commentImgHeight = JSON.stringify(height); @@ -227,7 +227,7 @@ export struct VideoDetail { .sideBarPosition(SideBarPosition.End) .sideBarWidth($r('app.float.side_bar_min_width')) .minSideBarWidth($r('app.float.side_bar_min_width')) - .maxSideBarWidth(px2vp(this.windowWidth * DetailConstants.COMMENTS_AREA_PERCENT)) + .maxSideBarWidth(this.getUIContext().px2vp(this.windowWidth * DetailConstants.COMMENTS_AREA_PERCENT)) } .height(CommonConstants.FULL_PERCENT) } diff --git a/features/videoDetail/src/main/ets/view/VideoPlayer.ets b/features/videoDetail/src/main/ets/view/VideoPlayer.ets index 74942f9..53c6890 100644 --- a/features/videoDetail/src/main/ets/view/VideoPlayer.ets +++ b/features/videoDetail/src/main/ets/view/VideoPlayer.ets @@ -55,7 +55,7 @@ export struct VideoPlayer { }; aboutToAppear(): void { - this.avPlayerUtil = AvPlayerUtil.getInstance(); + this.avPlayerUtil = AvPlayerUtil.getInstance(this.getUIContext()); if (canIUse('SystemCapability.Window.SessionManager')) { display.on('foldStatusChange', this.onFoldStatusChange); } -- Gitee