diff --git a/commons/base/src/main/ets/utils/AvPlayerUtil.ets b/commons/base/src/main/ets/utils/AvPlayerUtil.ets index dd4d00b884ff4b168ba11dcaba08cc31cfbc8199..becd2f1e353bb909f98ace07e793ae38e37a0a20 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 c87a3e83f4c479d23d43c98c7811726e15d59e58..7d854299ea2b47aaad8e6831a29162cb2602be72 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 ef24674a87aa03a9ee9d1974aa912b4a167b3e22..b5372002f36cee6755e539c6d67f6733dcb08b55 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 8894cfb8ab396d7c2610bc03b811f6b5b44818fb..56965126e55b8b218d5e5411e2d8b0032551b4b3 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 67784760e031db97d5e19aa60ab6185c6f16c6d7..64f0271b885ff576f8fa2a7e7c91179cb1a6fb16 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 32e7b341263f39cf924bb9486b2ff78d996fa61c..54bac78d158e692f6eb9de31fee50abc3fe45da1 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 d0a0a31af2a092a42b6d39ff418cf66e8a5474c8..6e9df84ce1191367ff89b205c9210cc9c72dc166 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 74942f95d2174927df802b5a922a36ea5dd5d559..53c6890dd527e88c2446bc21229a0884e6822a56 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); }