• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 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 './Action';
17import { ActionBar } from '../../../common/view/actionbar/ActionBar';
18import { ActionBarProp } from './ActionBarProp';
19import { ActionBarMode } from './ActionBarMode';
20import screenManager from '@ohos/base/src/main/ets/manager/ScreenManager';
21import { MediaOperationType } from '@ohos/base/src/main/ets/data/MediaOperationType';
22
23@Component
24export struct MediaOperationActionBar {
25    @Consume pageType: string;
26    @Consume @Watch('updateActionBar') loadingFinish: boolean;
27    onMenuClicked: Function;
28    @StorageLink('isHorizontal') isHorizontal: boolean = screenManager.isHorizontal();
29    @State actionBarProp: ActionBarProp = new ActionBarProp();
30
31    updateActionBar(): void {
32        this.actionBarProp = this.createActionBar();
33    }
34
35    private createActionBar(): ActionBarProp {
36        let menuList: Array<Action> = new Array<Action>();
37        let actionBarProp: ActionBarProp = new ActionBarProp();
38        if (this.loadingFinish) {
39            menuList.push(Action.NEW);
40        }
41        actionBarProp
42            .setHasTabBar(false)
43            .setTitle((this.pageType == MediaOperationType.Move) ? $r('app.string.move_to') : $r('app.string.copy_to'))
44            .setMode(ActionBarMode.STANDARD_MODE)
45            .setMenuList(menuList)
46            .setLeftAction(Action.CANCEL);
47        return actionBarProp;
48    }
49
50    aboutToAppear(): void {
51        this.actionBarProp = this.createActionBar();
52    }
53
54    build() {
55        Column() {
56            ActionBar({
57                actionBarProp: $actionBarProp,
58                onMenuClicked: this.onMenuClicked
59            })
60        }
61    }
62}