100aff185Sopenharmony_ci/*
200aff185Sopenharmony_ci * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
300aff185Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
400aff185Sopenharmony_ci * you may not use this file except in compliance with the License.
500aff185Sopenharmony_ci * You may obtain a copy of the License at
600aff185Sopenharmony_ci *
700aff185Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
800aff185Sopenharmony_ci *
900aff185Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1000aff185Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1100aff185Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1200aff185Sopenharmony_ci * See the License for the specific language governing permissions and
1300aff185Sopenharmony_ci * limitations under the License.
1400aff185Sopenharmony_ci */
1500aff185Sopenharmony_ci
1600aff185Sopenharmony_ciimport { ScreenManager } from '../model/common/ScreenManager';
1700aff185Sopenharmony_ciimport { Constants } from '../model/common/Constants';
1800aff185Sopenharmony_ciimport { Log } from '../utils/Log';
1900aff185Sopenharmony_ci
2000aff185Sopenharmony_ciconst IMAGE_SCREEN_RATIO = 0.8
2100aff185Sopenharmony_ciconst TAG: string = 'common_NoPhotoIndexComponent';
2200aff185Sopenharmony_ci
2300aff185Sopenharmony_ci@Component
2400aff185Sopenharmony_ciexport struct NoPhotoIndexComponent {
2500aff185Sopenharmony_ci  index: number = 0;
2600aff185Sopenharmony_ci  hasBarSpace: boolean = false;
2700aff185Sopenharmony_ci
2800aff185Sopenharmony_ci  // set an initial value temporarily, later change to 0.
2900aff185Sopenharmony_ci  @State imageSize: number = 0;
3000aff185Sopenharmony_ci  private reSizeFunc = (): void => this.reSizeLayout();
3100aff185Sopenharmony_ci
3200aff185Sopenharmony_ci  aboutToAppear(): void {
3300aff185Sopenharmony_ci    Log.info(TAG, 'aboutToAppear');
3400aff185Sopenharmony_ci    ScreenManager.getInstance().on(ScreenManager.ON_WIN_SIZE_CHANGED, this.reSizeFunc);
3500aff185Sopenharmony_ci    this.updateImageSize();
3600aff185Sopenharmony_ci  }
3700aff185Sopenharmony_ci
3800aff185Sopenharmony_ci    reSizeLayout() {
3900aff185Sopenharmony_ci    this.updateImageSize();
4000aff185Sopenharmony_ci  }
4100aff185Sopenharmony_ci
4200aff185Sopenharmony_ci  aboutToDisappear(): void {
4300aff185Sopenharmony_ci    Log.info(TAG, 'aboutToDisappear');
4400aff185Sopenharmony_ci    ScreenManager.getInstance().off(ScreenManager.ON_WIN_SIZE_CHANGED, this.reSizeFunc);
4500aff185Sopenharmony_ci  }
4600aff185Sopenharmony_ci
4700aff185Sopenharmony_ci  updateImageSize() {
4800aff185Sopenharmony_ci    let winWidth = ScreenManager.getInstance().getWinWidth();
4900aff185Sopenharmony_ci    let winHeightHalf = ScreenManager.getInstance().getWinHeight() / 2;
5000aff185Sopenharmony_ci    this.imageSize =
5100aff185Sopenharmony_ci      (winWidth < winHeightHalf) ? (winWidth * IMAGE_SCREEN_RATIO) : (winHeightHalf * IMAGE_SCREEN_RATIO)
5200aff185Sopenharmony_ci    Log.info(TAG, `window size: ${winWidth}, ${winHeightHalf} ,size = ${this.imageSize} index:${this.index}`);
5300aff185Sopenharmony_ci  }
5400aff185Sopenharmony_ci
5500aff185Sopenharmony_ci  build() {
5600aff185Sopenharmony_ci    Row() {
5700aff185Sopenharmony_ci      Column() {
5800aff185Sopenharmony_ci        Image((this.index == Constants.TIMELINE_PAGE_INDEX) ? $r('app.media.photo_empty') : $r('app.media.album_empty'))
5900aff185Sopenharmony_ci          .height(this.imageSize)
6000aff185Sopenharmony_ci          .width(this.imageSize)
6100aff185Sopenharmony_ci          .margin({
6200aff185Sopenharmony_ci            bottom: $r('app.float.image_margin_horizontal'),
6300aff185Sopenharmony_ci          })
6400aff185Sopenharmony_ci          .key('EmptyPhotoOrAlbumIco')
6500aff185Sopenharmony_ci          .onError(() => {
6600aff185Sopenharmony_ci            Log.info(TAG, `image show error index:${this.index}`);
6700aff185Sopenharmony_ci          })
6800aff185Sopenharmony_ci        if (Constants.DISTRIBUTED_ALBUM_PAGE_INDEX == this.index) {
6900aff185Sopenharmony_ci          Text($r('app.string.no_distributed_photo_head_title_album'))
7000aff185Sopenharmony_ci            .fontSize($r('sys.float.ohos_id_text_size_headline8'))
7100aff185Sopenharmony_ci            .fontFamily($r('app.string.id_text_font_family_regular'))
7200aff185Sopenharmony_ci            .fontColor($r('sys.color.ohos_id_color_text_primary'))
7300aff185Sopenharmony_ci            .margin({
7400aff185Sopenharmony_ci              left: $r('app.float.max_padding_start'),
7500aff185Sopenharmony_ci              right: $r('app.float.max_padding_start'),
7600aff185Sopenharmony_ci              bottom: $r('sys.float.ohos_id_text_paragraph_margin_s'),
7700aff185Sopenharmony_ci            })
7800aff185Sopenharmony_ci            .key('EmptyPhotoOrAlbumText')
7900aff185Sopenharmony_ci        } else {
8000aff185Sopenharmony_ci          Text((this.index == Constants.TIMELINE_PAGE_INDEX) ? $r('app.string.no_photo_head_title_timeline')
8100aff185Sopenharmony_ci                                                             : $r('app.string.no_photo_head_title_album'))
8200aff185Sopenharmony_ci            .fontSize($r('sys.float.ohos_id_text_size_headline8'))
8300aff185Sopenharmony_ci            .fontFamily($r('app.string.id_text_font_family_medium'))
8400aff185Sopenharmony_ci            .fontColor($r('sys.color.ohos_id_color_text_primary'))
8500aff185Sopenharmony_ci            .margin({
8600aff185Sopenharmony_ci              left: $r('app.float.max_padding_start'),
8700aff185Sopenharmony_ci              right: $r('app.float.max_padding_start'),
8800aff185Sopenharmony_ci              bottom: $r('sys.float.ohos_id_text_paragraph_margin_s'),
8900aff185Sopenharmony_ci            })
9000aff185Sopenharmony_ci            .key('EmptyPhotoOrAlbumHeadTitle')
9100aff185Sopenharmony_ci          Text((this.index == Constants.TIMELINE_PAGE_INDEX) ? $r('app.string.no_photo_sub_title_timeline')
9200aff185Sopenharmony_ci                                                             : $r('app.string.no_photo_sub_title_album'))
9300aff185Sopenharmony_ci            .fontSize($r('sys.float.ohos_id_text_size_body2'))
9400aff185Sopenharmony_ci            .fontFamily($r('app.string.id_text_font_family_regular'))
9500aff185Sopenharmony_ci            .fontColor($r('sys.color.ohos_id_color_text_secondary'))
9600aff185Sopenharmony_ci            .margin({
9700aff185Sopenharmony_ci              left: $r('app.float.max_padding_start'),
9800aff185Sopenharmony_ci              right: $r('app.float.max_padding_start'),
9900aff185Sopenharmony_ci              bottom: $r('sys.float.ohos_id_text_paragraph_margin_s'),
10000aff185Sopenharmony_ci            })
10100aff185Sopenharmony_ci            .key('EmptyPhotoOrAlbumSubTitle')
10200aff185Sopenharmony_ci        }
10300aff185Sopenharmony_ci      }
10400aff185Sopenharmony_ci      .width('100%')
10500aff185Sopenharmony_ci      .margin({ top: this.hasBarSpace ? $r('app.float.appbar_none_img_height') : $r('app.float.appbar_zero_height') })
10600aff185Sopenharmony_ci    }
10700aff185Sopenharmony_ci    .width('100%')
10800aff185Sopenharmony_ci    .height('100%')
10900aff185Sopenharmony_ci    .alignItems(VerticalAlign.Top)
11000aff185Sopenharmony_ci    .justifyContent(FlexAlign.Start)
11100aff185Sopenharmony_ci  }
11200aff185Sopenharmony_ci}