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_AlbumSetPageActionBar'; 28 29@Component 30export struct AlbumSetPageActionBar { 31 @Consume @Watch('updateActionBar') isAlbumSetSelectedMode: boolean; 32 @Consume('selectedCount') @Watch('updateActionBar') selectedAlbumsCount: number; 33 @Consume isDisableRename: boolean; 34 @Consume isDisableDelete: boolean; 35 @Consume @Watch('updatePlaceholderStatus') isShowSideBar: boolean; 36 @State actionBarProp: ActionBarProp = new ActionBarProp(); 37 @StorageLink('isHorizontal') @Watch('updateActionBar') isHorizontal: boolean 38 = ScreenManager.getInstance().isHorizontal(); 39 @StorageLink('isSidebar') isSidebar: boolean = ScreenManager.getInstance().isSidebar(); 40 @StorageLink('statusBarHeight') statusBarHeight: number = 0; 41 onMenuClicked: Function = (): void => {}; 42 @State isNeedPlaceholder: boolean = true; 43 @Provide moreMenuList: Action[] = new Array<Action>(); 44 @Provide hidePopup: boolean = false; 45 private deviceType: string = ''; 46 private actionBarPaddingTop: number | Resource = 0; 47 48 updatePlaceholderStatus(): void { 49 if (this.deviceType !== Constants.PC_DEVICE_TYPE) { 50 this.isNeedPlaceholder = false; 51 } else { 52 this.isNeedPlaceholder = this.isShowSideBar ? false : true; 53 } 54 } 55 56 updateActionBar(): void { 57 if (this.isHorizontal) { 58 this.actionBarProp = this.createHorizontalActionBar(); 59 } else { 60 this.actionBarProp = this.createActionBar(); 61 } 62 } 63 64 aboutToAppear(): void { 65 this.deviceType = AppStorage.get<string>('deviceType') as string; 66 if (this.deviceType === Constants.PC_DEVICE_TYPE) { 67 this.actionBarPaddingTop = $r('app.float.album_set_page_action_bar_padding_top'); 68 } else if (this.deviceType === Constants.PAD_DEVICE_TYPE) { 69 this.actionBarPaddingTop = 0; 70 } else { 71 this.actionBarPaddingTop = px2vp(this.statusBarHeight); 72 } 73 this.updatePlaceholderStatus(); 74 this.updateActionBar(); 75 } 76 77 build() { 78 Column() { 79 ActionBar({ 80 actionBarProp: $actionBarProp, 81 onMenuClicked: this.onMenuClicked, 82 isNeedPlaceholder: this.isNeedPlaceholder 83 }) 84 } 85 .padding({ 86 top: this.deviceType === Constants.DEFAULT_DEVICE_TYPE ? px2vp(this.statusBarHeight) : this.actionBarPaddingTop 87 }) 88 } 89 90 private createHorizontalActionBar(): ActionBarProp { 91 Log.info(TAG, `createHorizontalActionBar, isAlbumSetSelectedMode: ${this.isAlbumSetSelectedMode}`); 92 93 let menuList: Array<Action> = new Array<Action>(); 94 let actionBarProp: ActionBarProp = new ActionBarProp(); 95 96 actionBarProp 97 .setHasTabBar(this.isSidebar) 98 .setTitle($r('app.string.tab_albums')) 99 .setBackgroundColor($r('app.color.transparent')) 100 .setIsHeadTitle(true); 101 102 if (this.isAlbumSetSelectedMode) { 103 menuList.push( 104 ((!this.isDisableRename && this.selectedAlbumsCount == 1) ? Action.RENAME : Action.RENAME_INVALID), 105 ((!this.isDisableDelete && this.selectedAlbumsCount > 0) ? Action.DELETE : Action.DELETE_INVALID)); 106 actionBarProp 107 .setLeftAction(Action.CANCEL) 108 .setMenuList(menuList) 109 .setMode(ActionBarMode.SELECTION_MODE) 110 .setSelectionMode(ActionBarSelectionMode.MULTI); 111 } else { 112 menuList.push(Action.NEW) 113 const deviceType: string = AppStorage.get('deviceType') as string; 114 if (deviceType === Constants.PC_DEVICE_TYPE) { 115 menuList.push(Action.MULTISELECT) 116 } 117 actionBarProp 118 .setMenuList(menuList) 119 .setMode(ActionBarMode.STANDARD_MODE); 120 } 121 122 return actionBarProp; 123 } 124 125 private createActionBar(): ActionBarProp { 126 Log.info(TAG, `createActionBar, isAlbumSetSelectedMode: ${this.isAlbumSetSelectedMode}`); 127 128 let menuList: Array<Action> = new Array<Action>(); 129 let actionBarProp: ActionBarProp = new ActionBarProp(); 130 131 menuList.push(Action.NEW); 132 133 actionBarProp 134 .setHasTabBar(this.isSidebar) 135 .setTitle($r('app.string.tab_albums')) 136 .setIsHeadTitle(true); 137 138 if (this.isAlbumSetSelectedMode) { 139 actionBarProp 140 .setLeftAction(Action.CANCEL) 141 .setMode(ActionBarMode.SELECTION_MODE) 142 .setSelectionMode(ActionBarSelectionMode.MULTI); 143 } else { 144 actionBarProp 145 .setMenuList(menuList) 146 .setMode(ActionBarMode.STANDARD_MODE); 147 } 148 149 return actionBarProp; 150 } 151}