1/* 2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { ScreenManager } from '../model/common/ScreenManager'; 17import { Constants } from '../model/common/Constants'; 18import { Log } from '../utils/Log'; 19 20const IMAGE_SCREEN_RATIO = 0.8 21const TAG: string = 'common_NoPhotoIndexComponent'; 22 23@Component 24export struct NoPhotoIndexComponent { 25 index: number = 0; 26 hasBarSpace: boolean = false; 27 28 // set an initial value temporarily, later change to 0. 29 @State imageSize: number = 0; 30 private reSizeFunc = (): void => this.reSizeLayout(); 31 32 aboutToAppear(): void { 33 Log.info(TAG, 'aboutToAppear'); 34 ScreenManager.getInstance().on(ScreenManager.ON_WIN_SIZE_CHANGED, this.reSizeFunc); 35 this.updateImageSize(); 36 } 37 38 reSizeLayout() { 39 this.updateImageSize(); 40 } 41 42 aboutToDisappear(): void { 43 Log.info(TAG, 'aboutToDisappear'); 44 ScreenManager.getInstance().off(ScreenManager.ON_WIN_SIZE_CHANGED, this.reSizeFunc); 45 } 46 47 updateImageSize() { 48 let winWidth = ScreenManager.getInstance().getWinWidth(); 49 let winHeightHalf = ScreenManager.getInstance().getWinHeight() / 2; 50 this.imageSize = 51 (winWidth < winHeightHalf) ? (winWidth * IMAGE_SCREEN_RATIO) : (winHeightHalf * IMAGE_SCREEN_RATIO) 52 Log.info(TAG, `window size: ${winWidth}, ${winHeightHalf} ,size = ${this.imageSize} index:${this.index}`); 53 } 54 55 build() { 56 Row() { 57 Column() { 58 Image((this.index == Constants.TIMELINE_PAGE_INDEX) ? $r('app.media.photo_empty') : $r('app.media.album_empty')) 59 .height(this.imageSize) 60 .width(this.imageSize) 61 .margin({ 62 bottom: $r('app.float.image_margin_horizontal'), 63 }) 64 .key('EmptyPhotoOrAlbumIco') 65 .onError(() => { 66 Log.info(TAG, `image show error index:${this.index}`); 67 }) 68 if (Constants.DISTRIBUTED_ALBUM_PAGE_INDEX == this.index) { 69 Text($r('app.string.no_distributed_photo_head_title_album')) 70 .fontSize($r('sys.float.ohos_id_text_size_headline8')) 71 .fontFamily($r('app.string.id_text_font_family_regular')) 72 .fontColor($r('sys.color.ohos_id_color_text_primary')) 73 .margin({ 74 left: $r('app.float.max_padding_start'), 75 right: $r('app.float.max_padding_start'), 76 bottom: $r('sys.float.ohos_id_text_paragraph_margin_s'), 77 }) 78 .key('EmptyPhotoOrAlbumText') 79 } else { 80 Text((this.index == Constants.TIMELINE_PAGE_INDEX) ? $r('app.string.no_photo_head_title_timeline') 81 : $r('app.string.no_photo_head_title_album')) 82 .fontSize($r('sys.float.ohos_id_text_size_headline8')) 83 .fontFamily($r('app.string.id_text_font_family_medium')) 84 .fontColor($r('sys.color.ohos_id_color_text_primary')) 85 .margin({ 86 left: $r('app.float.max_padding_start'), 87 right: $r('app.float.max_padding_start'), 88 bottom: $r('sys.float.ohos_id_text_paragraph_margin_s'), 89 }) 90 .key('EmptyPhotoOrAlbumHeadTitle') 91 Text((this.index == Constants.TIMELINE_PAGE_INDEX) ? $r('app.string.no_photo_sub_title_timeline') 92 : $r('app.string.no_photo_sub_title_album')) 93 .fontSize($r('sys.float.ohos_id_text_size_body2')) 94 .fontFamily($r('app.string.id_text_font_family_regular')) 95 .fontColor($r('sys.color.ohos_id_color_text_secondary')) 96 .margin({ 97 left: $r('app.float.max_padding_start'), 98 right: $r('app.float.max_padding_start'), 99 bottom: $r('sys.float.ohos_id_text_paragraph_margin_s'), 100 }) 101 .key('EmptyPhotoOrAlbumSubTitle') 102 } 103 } 104 .width('100%') 105 .margin({ top: this.hasBarSpace ? $r('app.float.appbar_none_img_height') : $r('app.float.appbar_zero_height') }) 106 } 107 .width('100%') 108 .height('100%') 109 .alignItems(VerticalAlign.Top) 110 .justifyContent(FlexAlign.Start) 111 } 112}