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 { 17 Action, 18 ActionBarMode, 19 ActionBarProp, 20 ActionBarSelectionMode, 21 Constants, 22 Log, 23 ScreenManager 24} from '@ohos/common'; 25import { ActionBar } from '@ohos/common/CommonComponents'; 26 27const TAG: string = 'browser_AlbumSelectActionBar'; 28 29@Component 30export struct AlbumSelectActionBar { 31 @StorageLink('isHorizontal') @Watch('createActionBar') isHorizontal: boolean 32 = ScreenManager.getInstance().isHorizontal(); 33 @StorageLink('isSidebar') isSidebar: boolean = ScreenManager.getInstance().isSidebar(); 34 @State actionBarProp: ActionBarProp = new ActionBarProp(); 35 @Link @Watch('createActionBar') totalSelectedCount: number; 36 @Provide selectedCount: number = 0; 37 onMenuClicked: Function = (): void => {}; 38 @Link @Watch('updateMenu') menuList: Action[]; 39 @Provide moreMenuList: Action[] = new Array<Action>(); 40 @Provide hidePopup: boolean = false; 41 42 aboutToAppear(): void { 43 this.createActionBar(); 44 } 45 46 build() { 47 Column() { 48 ActionBar({ 49 actionBarProp: $actionBarProp, 50 onMenuClicked: this.onMenuClicked, 51 isNeedPlaceholder: false 52 }) 53 } 54 .padding({ 55 top: this.isHorizontal ? Constants.NUMBER_0 : $r('app.float.album_set_page_action_bar_padding_top') 56 }) 57 } 58 59 private updateMenu() { 60 this.moreMenuList = this.menuList; 61 } 62 63 private createActionBar(): void { 64 this.selectedCount = this.totalSelectedCount; 65 let menuList: Array<Action> = new Array<Action>(); 66 let actionBarProp: ActionBarProp = new ActionBarProp(); 67 menuList.push(Boolean(this.totalSelectedCount) ? Action.OK : Action.OK_DISABLE); 68 actionBarProp 69 .setLeftAction(Action.CANCEL) 70 .setMode(ActionBarMode.SELECTION_MODE) 71 .setSelectionMode(ActionBarSelectionMode.MULTI) 72 .setMenuList(menuList); 73 this.actionBarProp = actionBarProp; 74 } 75}