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 { Action } from './browserOperation/Action';
17import { ActionBar } from './actionbar/ActionBar';
18import { ActionBarProp } from './browserOperation/ActionBarProp';
19import { ActionBarColorMode, ActionBarMode, ActionBarSelectionMode } from './browserOperation/ActionBarMode';
20import { ScreenManager } from '../model/common/ScreenManager';
21import { Constants } from '../model/common/Constants';
22
23const TAG: string = 'common_ThirdSelectPhotoBrowserActionBar';
24
25@Component
26export struct ThirdSelectPhotoBrowserActionBar {
27  @StorageLink('leftBlank') leftBlank: number[] =
28    [0, ScreenManager.getInstance().getStatusBarHeight(), 0, ScreenManager.getInstance().getNaviBarHeight()];
29  @State isMultiPick: boolean = false;
30  @Consume @Watch('createActionBar') isSelected: boolean;
31  onMenuClicked: Function = (): void => {};
32  @StorageLink('isHorizontal') @Watch('createActionBar') isHorizontal: boolean = ScreenManager.getInstance()
33    .isHorizontal();
34  @State actionBarProp: ActionBarProp = new ActionBarProp();
35  @StorageLink('statusBarHeight') statusBarHeight: number = 0;
36  @Link isShowBar: boolean;
37  @Provide('selectedCount') selectedCount: number = 0;
38  @Link @Watch('onSelectedCountChanged') totalSelectedCount: number;
39  @Provide moreMenuList: Action[] = [];
40  @Provide hidePopup: boolean = false;
41  private title: string | Resource = '';
42  private isThird: boolean = false;
43  @Consume canEdit: boolean;
44
45  aboutToAppear() {
46    this.createActionBar();
47    this.onSelectedCountChanged();
48  }
49
50  build() {
51    Stack({ alignContent: Alignment.TopStart }) {
52      Image($r('app.media.gradientBasePlate')).width(Constants.PERCENT_100)
53        .height(Constants.PERCENT_100).objectFit(ImageFit.Fill)
54      ActionBar({
55        actionBarProp: $actionBarProp,
56        onMenuClicked: this.onMenuClicked,
57        isNeedPlaceholder: false
58      })
59        .padding({
60          top: (this.isHorizontal && !ScreenManager.getInstance().isUIExtensionEnv()) ?
61            $r('app.float.third_selected_actionbar_padding_top') : px2vp(this.statusBarHeight)
62        })
63    }
64    .height(this.isHorizontal ? Constants.ActionBarHeight * Constants.PHOTO_BAR_MULTIPLES_1_5 :
65      Constants.ActionBarHeight * Constants.PHOTO_BAR_MULTIPLES_1_5 +
66      px2vp(this.statusBarHeight))
67    .markAnchor({ x: Constants.PERCENT_0, y: Constants.PERCENT_0 })
68    .position({ x: Constants.PERCENT_0, y: Constants.PERCENT_0 })
69    .visibility(this.isShowBar ? Visibility.Visible : Visibility.Hidden)
70  }
71
72  private onSelectedCountChanged() {
73    this.selectedCount = this.totalSelectedCount;
74  }
75
76  private createActionBar(): void {
77    let actionBarProp: ActionBarProp = new ActionBarProp();
78
79    let menuList: Action[] = [];
80    if (this.canEdit) {
81      menuList.push(Action.EDIT);
82    }
83
84    actionBarProp
85      .setLeftAction(Action.BACK)
86      .setMode(ActionBarMode.SELECTION_MODE)
87      .setSelectionMode(this.isMultiPick ? ActionBarSelectionMode.MULTI : ActionBarSelectionMode.SINGLE)
88      .setColorMode(ActionBarColorMode.TRANSPARENT)
89      .setAlpha(ActionBarProp.PHOTO_BROWSER_ACTIONBAR_ALPHA)
90
91    if (this.isMultiPick && !this.isThird) {
92      menuList.push(this.isSelected ? Action.SELECTED : Action.MATERIAL_SELECT);
93    }
94    actionBarProp.setMenuList(menuList)
95
96    if (this.title) {
97      actionBarProp
98        .setIsNeedTitle(false);
99    }
100    this.actionBarProp = actionBarProp;
101  }
102}