diff --git a/commons/base/src/main/ets/utils/DisplayUtil.ets b/commons/base/src/main/ets/utils/DisplayUtil.ets index 19a6d6cfd484be0973fc54b6ec55615f8780099c..b0fd76257966c9496f0493a39dd0598b437bddb3 100644 --- a/commons/base/src/main/ets/utils/DisplayUtil.ets +++ b/commons/base/src/main/ets/utils/DisplayUtil.ets @@ -17,12 +17,14 @@ import { display } from '@kit.ArkUI'; export class DisplayUtil { static getFoldCreaseRegion(): void { - if (display.isFoldable()) { - let foldRegion: display.FoldCreaseRegion = display.getCurrentFoldCreaseRegion(); - let rect: display.Rect = foldRegion.creaseRects[0]; - // Height of the avoidance area in the upper half screen and height of the avoidance area. - let creaseRegion: number[] = [px2vp(rect.top), px2vp(rect.height)]; - AppStorage.setOrCreate('creaseRegion', creaseRegion); + if(canIUse('SystemCapability.Window.SessionManager')) { + if (display.isFoldable()) { + let foldRegion: display.FoldCreaseRegion = display.getCurrentFoldCreaseRegion(); + let rect: display.Rect = foldRegion.creaseRects[0]; + // Height of the avoidance area in the upper half screen and height of the avoidance area. + let creaseRegion: number[] = [px2vp(rect.top), px2vp(rect.height)]; + AppStorage.setOrCreate('creaseRegion', creaseRegion); + } } } } \ No newline at end of file diff --git a/commons/base/src/main/ets/utils/WindowUtil.ets b/commons/base/src/main/ets/utils/WindowUtil.ets index 2547b96ff12ab0adf01369e374c87d3fbc06e429..a659c245802d05f46c70c9cddd32c75bea62ffdf 100644 --- a/commons/base/src/main/ets/utils/WindowUtil.ets +++ b/commons/base/src/main/ets/utils/WindowUtil.ets @@ -94,28 +94,32 @@ export class WindowUtil { } maximize(): void { - if (this.mainWindowClass!.getWindowStatus() === window.WindowStatusType.FLOATING) { - this.mainWindowClass!.maximize() - .then(() => { - hilog.info(0x0000, 'testTag', '%{public}s', `Succeed in maximizing the window.`); - }) - .catch((err: BusinessError) => { - hilog.error(0x0000, 'testTag', `Failed to maximize the window. Code: ${err.code}, message: ${err.message}`, - JSON.stringify(err) ?? ''); - }); + if(canIUse('SystemCapability.Window.SessionManager')){ + if (this.mainWindowClass!.getWindowStatus() === window.WindowStatusType.FLOATING) { + this.mainWindowClass!.maximize() + .then(() => { + hilog.info(0x0000, 'testTag', '%{public}s', `Succeed in maximizing the window.`); + }) + .catch((err: BusinessError) => { + hilog.error(0x0000, 'testTag', `Failed to maximize the window. Code: ${err.code}, message: ${err.message}`, + JSON.stringify(err) ?? ''); + }); + } } } recover(): void { - if (this.mainWindowClass!.getWindowStatus() === window.WindowStatusType.FULL_SCREEN) { - this.mainWindowClass!.recover() - .then(() => { - hilog.info(0x0000, 'testTag', '%{public}s', `Succeed in rovering the window.`); - }) - .catch((err: BusinessError) => { - hilog.error(0x0000, 'testTag', `Failed to rover the window. Code: ${err.code}, message: ${err.message}`, - JSON.stringify(err) ?? ''); - }); + if(canIUse('SystemCapability.Window.SessionManager')){ + if (this.mainWindowClass!.getWindowStatus() === window.WindowStatusType.FULL_SCREEN) { + this.mainWindowClass!.recover() + .then(() => { + hilog.info(0x0000, 'testTag', '%{public}s', `Succeed in rovering the window.`); + }) + .catch((err: BusinessError) => { + hilog.error(0x0000, 'testTag', `Failed to rover the window. Code: ${err.code}, message: ${err.message}`, + JSON.stringify(err) ?? ''); + }); + } } } diff --git a/features/home/src/main/ets/view/BannerView.ets b/features/home/src/main/ets/view/BannerView.ets index 9981a4acfa1354ef9621e7a2ab3296946a3bdeea..9a27b6344e65679516652c581987fd4161a02e1b 100644 --- a/features/home/src/main/ets/view/BannerView.ets +++ b/features/home/src/main/ets/view/BannerView.ets @@ -298,9 +298,9 @@ export struct BannerView { @Component struct BannerText { - private banner: Banner = new BannerViewModel().getBannerList()[0]; - private currentWidthBreakpoint: string = BreakpointConstants.BREAKPOINT_LG; - private index: number = 0; + public banner: Banner = new BannerViewModel().getBannerList()[0]; + public currentWidthBreakpoint: string = BreakpointConstants.BREAKPOINT_LG; + public index: number = 0; build() { Stack() { diff --git a/features/home/src/main/ets/view/CommonView.ets b/features/home/src/main/ets/view/CommonView.ets index 1f922e8bdc1b3b1e5d54368db7946d66449a7fa6..1e490b6a9addd04505b8a47aa48ce99c9d83e945 100644 --- a/features/home/src/main/ets/view/CommonView.ets +++ b/features/home/src/main/ets/view/CommonView.ets @@ -18,7 +18,7 @@ import { HomeConstants } from '../constants/HomeConstants'; @Component export struct VideoImgRating { - private rating: string = ''; + public rating: string = ''; build() { Row() { @@ -46,7 +46,7 @@ export struct VideoImgRating { export struct VideoTitle { @StorageLink('currentWidthBreakpoint') currentWidthBreakpoint: string = BreakpointConstants.BREAKPOINT_LG; @StorageLink('currentTopIndex') currentTopIndex: number = 0; - private title: ResourceStr = ''; + public title: ResourceStr = ''; build() { Text(this.title) @@ -64,7 +64,7 @@ export struct VideoTitle { export struct VideoContent { @StorageLink('currentWidthBreakpoint') currentWidthBreakpoint: string = BreakpointConstants.BREAKPOINT_LG; @StorageLink('currentTopIndex') currentTopIndex: number = 0; - private content: ResourceStr = ''; + public content: ResourceStr = ''; build() { Text(this.content) @@ -83,7 +83,7 @@ export struct VideoContent { export struct SubtitleComponent { @StorageLink('currentWidthBreakpoint') currentWidthBreakpoint: string = BreakpointConstants.BREAKPOINT_LG; @StorageLink('currentTopIndex') currentTopIndex: number = 0; - private title: ResourceStr = ''; + public title: ResourceStr = ''; build() { Text(this.title) @@ -102,8 +102,8 @@ export struct SubtitleComponent { @Component export struct VideoImgComponent { - private imgSrc?: Resource; - private index: number = 0; + public imgSrc?: Resource; + public index: number = 0; build() { Image(this.imgSrc ? this.imgSrc : '') diff --git a/features/videoDetail/src/main/ets/view/AllComments.ets b/features/videoDetail/src/main/ets/view/AllComments.ets index 762078e3e0781817851e291176094e518b004983..d1f67b0cf18bc7b8f2cfde60f635fe91f21253cf 100644 --- a/features/videoDetail/src/main/ets/view/AllComments.ets +++ b/features/videoDetail/src/main/ets/view/AllComments.ets @@ -133,7 +133,7 @@ export struct AllComments { @Component struct IconImage { - private image: Resource | null = null; + public image: Resource | null = null; build() { Image(this.image) diff --git a/features/videoDetail/src/main/ets/view/RelatedList.ets b/features/videoDetail/src/main/ets/view/RelatedList.ets index 2988ad0f95745a84140c88221c8f7dea770ca8b0..2414a72af8244a40bd2c415d8bd11b7177130d2d 100644 --- a/features/videoDetail/src/main/ets/view/RelatedList.ets +++ b/features/videoDetail/src/main/ets/view/RelatedList.ets @@ -27,7 +27,7 @@ export struct RelatedList { @State commentImgWidth: string = DetailConstants.INITIAL_COMMENT_IMAGE_WIDTH; @Link relatedVideoHeight: number; @Link videoHeight: number; - private screenHeight: number = 0; + public screenHeight: number = 0; private relatedVideoList: RelatedVideo[] = new RelatedVideoViewModel().getRelatedVideoList(); private peripheralVideoList: RelatedVideo[] = new RelatedVideoViewModel().getPeripheralVideoList(); private episodes: string[] = DetailConstants.EPISODES_LIST; diff --git a/features/videoDetail/src/main/ets/view/SideEpisodes.ets b/features/videoDetail/src/main/ets/view/SideEpisodes.ets index 754806555edadc8823597bf6ac30ffe5fc662210..96ea6683185332ba29faa73201eacc9799528cd2 100644 --- a/features/videoDetail/src/main/ets/view/SideEpisodes.ets +++ b/features/videoDetail/src/main/ets/view/SideEpisodes.ets @@ -96,7 +96,7 @@ export struct SideEpisodes { @Component struct SideTitleText { - private content: ResourceStr = ''; + public content: ResourceStr = ''; build() { Text(this.content) diff --git a/features/videoDetail/src/main/ets/view/VideoDetail.ets b/features/videoDetail/src/main/ets/view/VideoDetail.ets index 3ad89e54805737eb59601d8d8a298c82746dc6db..4ad557af5002d5e32923f1192c46faac8bb63ee9 100644 --- a/features/videoDetail/src/main/ets/view/VideoDetail.ets +++ b/features/videoDetail/src/main/ets/view/VideoDetail.ets @@ -16,8 +16,16 @@ import { KeyCode } from '@kit.InputKit'; import { deviceInfo } from '@kit.BasicServicesKit'; import { display, window } from '@kit.ArkUI'; -import { AvPlayerUtil, DeviceScreen, Logger, WindowUtil, BreakpointConstants, CommonConstants, DisplayUtil, - VideoNavPathStack } from '@ohos/commons'; +import { + AvPlayerUtil, + DeviceScreen, + Logger, + WindowUtil, + BreakpointConstants, + CommonConstants, + DisplayUtil, + VideoNavPathStack +} from '@ohos/commons'; import { SelfComment } from './SelfComment'; import { AllComments } from './AllComments'; import { VideoDetailView } from './VideoDetailView'; @@ -37,7 +45,7 @@ export struct VideoDetail { @State relatedVideoHeight: number = DetailConstants.INITIAL_RELATED_VIDEO_HEIGHT; @State videoHeight: number = DetailConstants.INITIAL_VIDEO_HEIGHT; private avPlayerUtil?: AvPlayerUtil = AvPlayerUtil.getInstance(); - private screenHeight: number = 0; + public screenHeight: number = 0; private windowUtil?: WindowUtil = WindowUtil.getInstance(); private mainWindow?: window.Window; private onWindowSizeChange: (windowSize: window.Size) => void = (windowSize: window.Size) => { @@ -45,20 +53,18 @@ export struct VideoDetail { return; } if (((this.currentWidthBreakpoint === BreakpointConstants.BREAKPOINT_MD && this.currentHeightBreakpoint !== - BreakpointConstants.BREAKPOINT_SM) || this.currentWidthBreakpoint === BreakpointConstants.BREAKPOINT_LG) && + BreakpointConstants.BREAKPOINT_SM) || this.currentWidthBreakpoint === BreakpointConstants.BREAKPOINT_LG) && !this.isHalfFolded) { this.windowUtil?.setMainWindowOrientation(window.Orientation.AUTO_ROTATION_RESTRICTED); - } - else if (this.currentWidthBreakpoint === BreakpointConstants.BREAKPOINT_MD && this.currentHeightBreakpoint === - BreakpointConstants.BREAKPOINT_SM) { + } else if (this.currentWidthBreakpoint === BreakpointConstants.BREAKPOINT_MD && this.currentHeightBreakpoint === + BreakpointConstants.BREAKPOINT_SM) { if (this.isFullScreen) { this.windowUtil?.setMainWindowOrientation(window.Orientation.AUTO_ROTATION_LANDSCAPE_RESTRICTED); } else { this.windowUtil?.setMainWindowOrientation(window.Orientation.PORTRAIT); } - } - else if (this.currentWidthBreakpoint === BreakpointConstants.BREAKPOINT_SM && this.currentHeightBreakpoint === - BreakpointConstants.BREAKPOINT_LG) { + } else if (this.currentWidthBreakpoint === BreakpointConstants.BREAKPOINT_SM && this.currentHeightBreakpoint === + BreakpointConstants.BREAKPOINT_LG) { if (this.isFullScreen) { this.windowUtil?.setMainWindowOrientation(window.Orientation.AUTO_ROTATION_LANDSCAPE_RESTRICTED); } else { @@ -66,30 +72,32 @@ export struct VideoDetail { } } }; + private onHalfFoldedChange(): void { if (this.isHalfFolded) { this.windowUtil?.setMainWindowOrientation(window.Orientation.AUTO_ROTATION_LANDSCAPE_RESTRICTED); } else { if (this.currentWidthBreakpoint === BreakpointConstants.BREAKPOINT_MD && this.currentHeightBreakpoint === - BreakpointConstants.BREAKPOINT_MD) { + BreakpointConstants.BREAKPOINT_MD) { this.windowUtil?.setMainWindowOrientation(window.Orientation.AUTO_ROTATION_RESTRICTED); } } } + private onFullScreenChange(): void { if (((this.currentWidthBreakpoint === BreakpointConstants.BREAKPOINT_MD && this.currentHeightBreakpoint !== - BreakpointConstants.BREAKPOINT_SM) || this.currentWidthBreakpoint === BreakpointConstants.BREAKPOINT_LG) && + BreakpointConstants.BREAKPOINT_SM) || this.currentWidthBreakpoint === BreakpointConstants.BREAKPOINT_LG) && !this.isHalfFolded) { this.windowUtil?.setMainWindowOrientation(window.Orientation.AUTO_ROTATION_RESTRICTED); } else if (this.currentWidthBreakpoint === BreakpointConstants.BREAKPOINT_SM && this.currentHeightBreakpoint === - BreakpointConstants.BREAKPOINT_LG) { + BreakpointConstants.BREAKPOINT_LG) { if (this.isFullScreen) { this.windowUtil?.setMainWindowOrientation(window.Orientation.AUTO_ROTATION_LANDSCAPE_RESTRICTED); } else { this.windowUtil?.setMainWindowOrientation(window.Orientation.PORTRAIT); } } else if (this.currentWidthBreakpoint === BreakpointConstants.BREAKPOINT_MD && this.currentHeightBreakpoint === - BreakpointConstants.BREAKPOINT_SM && !this.isFullScreen) { + BreakpointConstants.BREAKPOINT_SM && !this.isFullScreen) { this.windowUtil?.setMainWindowOrientation(window.Orientation.PORTRAIT); } if (deviceInfo.deviceType !== CommonConstants.DEVICE_TYPE) { @@ -163,12 +171,14 @@ export struct VideoDetail { .onAreaChange((newValue: Area) => { if (newValue.width !== 0) { 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 - - DetailConstants.SIDE_BAR_MIN_WIDTH_NUMBER) * (DetailConstants.COMMENT_IMAGE_MAX_HEIGHT_NUMBER - + DetailConstants.SIDE_BAR_MIN_WIDTH_NUMBER) / + (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 - - DetailConstants.SIDE_BAR_MIN_WIDTH_NUMBER) * (DetailConstants.COMMENT_IMAGE_MAX_WIDTH_NUMBER - + DetailConstants.SIDE_BAR_MIN_WIDTH_NUMBER) / + (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); this.commentImgWidth = JSON.stringify(width); @@ -184,12 +194,13 @@ export struct VideoDetail { .layoutWeight(1) SelfComment() .visibility(this.currentWidthBreakpoint === BreakpointConstants.BREAKPOINT_LG || this.isFullScreen ? - Visibility.None : Visibility.Visible) + Visibility.None : Visibility.Visible) } .height(CommonConstants.FULL_PERCENT) .width(CommonConstants.FULL_PERCENT) } - .showSideBar(this.currentWidthBreakpoint === BreakpointConstants.BREAKPOINT_LG && !this.isFullScreen ? true : false) + .showSideBar(this.currentWidthBreakpoint === BreakpointConstants.BREAKPOINT_LG && !this.isFullScreen ? true : + false) .showControlButton(false) .autoHide(false) .sideBarPosition(SideBarPosition.End) @@ -217,8 +228,10 @@ export struct VideoDetail { if (this.avplayerState !== CommonConstants.AV_PLAYER_PLAYING_STATE) { this.avPlayerUtil!.playerStateControl(); } - if (this.currentWidthBreakpoint === BreakpointConstants.BREAKPOINT_MD && display.isFoldable()) { - this.isHalfFolded = false; + if (canIUse('SystemCapability.Window.SessionManager')) { + if (this.currentWidthBreakpoint === BreakpointConstants.BREAKPOINT_MD && display.isFoldable()) { + this.isHalfFolded = false; + } } }) .onKeyEvent((event?: KeyEvent) => { diff --git a/features/videoDetail/src/main/ets/view/VideoDetailView.ets b/features/videoDetail/src/main/ets/view/VideoDetailView.ets index 4115eca1bfd7e99866d4279513fa88670b451021..d71d4ad51f9824d3766faf5e16452102ad1e3245 100644 --- a/features/videoDetail/src/main/ets/view/VideoDetailView.ets +++ b/features/videoDetail/src/main/ets/view/VideoDetailView.ets @@ -32,10 +32,16 @@ export struct VideoDetailView { @Link relatedVideoHeight: number; @Link videoHeight: number; @State isShowingSideBar: boolean = false; - @State foldStatus: display.FoldStatus = display.getFoldStatus(); - private screenHeight: number = 0; + @State foldStatus: display.FoldStatus | undefined = undefined + public screenHeight: number = 0; private scroller: Scroller = new Scroller(); + aboutToAppear(): void { + if(canIUse('SystemCapability.Window.SessionManager')){ + this.foldStatus = display.getFoldStatus(); + } + } + build() { Scroll(this.scroller) { Column() { @@ -51,7 +57,7 @@ export struct VideoDetailView { .height(this.creaseRegion[1]) .width(CommonConstants.FULL_PERCENT) .visibility(this.isHalfFolded && this.isShowingSideBar && this.isFullScreen ? Visibility.Visible : - Visibility.None) + Visibility.None) FooterEpisodes({ isShowingSideBar: this.isShowingSideBar, @@ -134,7 +140,7 @@ export struct VideoDetailView { // Percentage of screen height by sliding. let offsetPercent = (Math.abs(offset) * DetailConstants.TEN) / this.screenHeight; this.relatedVideoHeight = (this.relatedVideoHeight + offsetPercent * DetailConstants.RELATED_LIST_HEIGHT) > - DetailConstants.RELATED_LIST_HEIGHT ? DetailConstants.RELATED_LIST_HEIGHT : (this.relatedVideoHeight + + DetailConstants.RELATED_LIST_HEIGHT ? DetailConstants.RELATED_LIST_HEIGHT : (this.relatedVideoHeight + offsetPercent * DetailConstants.RELATED_LIST_HEIGHT); } else { Logger.info(`No specific function`); diff --git a/features/videoDetail/src/main/ets/view/VideoPlayer.ets b/features/videoDetail/src/main/ets/view/VideoPlayer.ets index 0948b00311664dec59357b7936698fd9a625ebec..6dc2d3c3004a6b78a95ea0be737fb3f8a196390f 100644 --- a/features/videoDetail/src/main/ets/view/VideoPlayer.ets +++ b/features/videoDetail/src/main/ets/view/VideoPlayer.ets @@ -38,27 +38,33 @@ export struct VideoPlayer { private xComponentController: XComponentController = new XComponentController(); private onFoldStatusChange: Callback = (data: display.FoldStatus) => { this.foldStatus = data; - if (data === display.FoldStatus.FOLD_STATUS_HALF_FOLDED) { - let orientation: display.Orientation = display.getDefaultDisplaySync().orientation; - if (orientation === display.Orientation.LANDSCAPE || orientation === display.Orientation.LANDSCAPE_INVERTED) { - this.isHalfFolded = true; - // Full-screen playback. - if (!this.isFullScreen) { - this.isFullScreen = true; + if (canIUse('SystemCapability.Window.SessionManager')) { + if (data === display.FoldStatus.FOLD_STATUS_HALF_FOLDED) { + let orientation: display.Orientation = display.getDefaultDisplaySync().orientation; + if (orientation === display.Orientation.LANDSCAPE || orientation === display.Orientation.LANDSCAPE_INVERTED) { + this.isHalfFolded = true; + // Full-screen playback. + if (!this.isFullScreen) { + this.isFullScreen = true; + } } + } else { + this.isHalfFolded = false; } - } else { - this.isHalfFolded = false; } }; aboutToAppear(): void { this.avPlayerUtil = AvPlayerUtil.getInstance(); - display.on('foldStatusChange', this.onFoldStatusChange); + if (canIUse('SystemCapability.Window.SessionManager')) { + display.on('foldStatusChange', this.onFoldStatusChange); + } } aboutToDisappear(): void { - display.off('foldStatusChange'); + if (canIUse('SystemCapability.Window.SessionManager')) { + display.off('foldStatusChange'); + } } build() { @@ -150,7 +156,7 @@ export struct VideoPlayer { .margin({ top: this.currentWidthBreakpoint === BreakpointConstants.BREAKPOINT_SM ? '0' : $r('app.float.icon_row_top'), bottom: this.currentWidthBreakpoint === BreakpointConstants.BREAKPOINT_SM ? - $r('app.float.icon_row_bottom_sm') : $r('app.float.icon_row_bottom') + $r('app.float.icon_row_bottom_sm') : $r('app.float.icon_row_bottom') }) Blank() @@ -165,9 +171,9 @@ export struct VideoPlayer { } .margin({ top: this.currentWidthBreakpoint === BreakpointConstants.BREAKPOINT_SM ? $r('app.float.button_row_top_sm') : - $r('app.float.button_row_top'), + $r('app.float.button_row_top'), bottom: this.currentWidthBreakpoint === BreakpointConstants.BREAKPOINT_SM ? - $r('app.float.button_row_bottom_sm') : $r('app.float.button_row_bottom') + $r('app.float.button_row_bottom_sm') : $r('app.float.button_row_bottom') }) } .height($r('app.float.icon_button_row_height')) @@ -243,7 +249,7 @@ export struct VideoPlayer { .width($r('app.float.back_size')) .position({ x: this.currentWidthBreakpoint === BreakpointConstants.BREAKPOINT_LG ? $r('app.float.back_position_x') : - $r('app.float.back_position_x_lg'), + $r('app.float.back_position_x_lg'), y: $r('app.float.back_position_y') }) .fillColor(Color.White) @@ -269,7 +275,7 @@ export struct VideoPlayer { @Component struct ImgIcon { - private img?: Resource; + public img?: Resource; build() { Image(this.img ? this.img : '') @@ -281,7 +287,7 @@ struct ImgIcon { @Component struct TextButton { - private content: ResourceStr = ''; + public content: ResourceStr = ''; build() { Text(this.content)