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, Log } from '@ohos/common'; 17import { ToolBar } from '@ohos/common/CommonComponents'; 18 19const TAG: string = 'browser_PhotoGridPageToolBar'; 20 21@Component 22export struct PhotoGridPageToolBar { 23 @Consume @Watch('updateToolbar') isSelectedMode: boolean; 24 @Consume @Watch('updateToolbar') isAllSelected: boolean; 25 @Link @Watch('updateToolbar') totalSelectedCount: number; 26 @Provide selectedCount: number = 0; 27 @Consume isEmpty: boolean; 28 isRecycleAlbum: boolean = false; 29 onMenuClicked: Function = (): void => {}; 30 isDistributedAlbum: boolean = false; 31 @Provide toolMenuList: Action[] = []; 32 @Consume hidePopup: boolean; 33 34 aboutToAppear(): void { 35 Log.info(TAG, 'aboutToAppear'); 36 this.updateToolbar(); 37 } 38 39 build() { 40 ToolBar({ 41 onMenuClicked: this.onMenuClicked 42 }) 43 } 44 45 private updateToolbar(): void { 46 Log.info(TAG, 'updateToolbar'); 47 this.selectedCount = this.totalSelectedCount; 48 if (this.isSelectedMode) { 49 this.toolMenuList = []; 50 if (this.isRecycleAlbum) { 51 this.toolMenuList.push(Boolean(this.selectedCount) ? Action.RECOVER : Action.RECOVER_INVALID, 52 Boolean(this.selectedCount) ? Action.DELETE : Action.DELETE_INVALID, 53 this.isAllSelected ? Action.DESELECT_ALL : Action.SELECT_ALL); 54 } else if (this.isDistributedAlbum) { 55 this.toolMenuList.push(this.isAllSelected ? Action.DESELECT_ALL : Action.SELECT_ALL, 56 Boolean(this.selectedCount) ? Action.DOWNLOAD : Action.DOWNLOAD_INVALID); 57 } else { 58 this.toolMenuList.push( 59 this.isAllSelected ? Action.DESELECT_ALL : Action.SELECT_ALL, 60 Boolean(this.selectedCount) ? Action.DELETE : Action.DELETE_INVALID, Action.MORE); 61 } 62 } else { 63 if (this.isRecycleAlbum) { 64 this.toolMenuList = []; 65 this.toolMenuList.push(this.isEmpty ? Action.CLEAR_RECYCLE_INVALID : Action.CLEAR_RECYCLE); 66 } 67 } 68 } 69}