100aff185Sopenharmony_ci/* 200aff185Sopenharmony_ci * Copyright (c) 2022-2023 Huawei Device Co., Ltd. 300aff185Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 400aff185Sopenharmony_ci * you may not use this file except in compliance with the License. 500aff185Sopenharmony_ci * You may obtain a copy of the License at 600aff185Sopenharmony_ci * 700aff185Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 800aff185Sopenharmony_ci * 900aff185Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1000aff185Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1100aff185Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1200aff185Sopenharmony_ci * See the License for the specific language governing permissions and 1300aff185Sopenharmony_ci * limitations under the License. 1400aff185Sopenharmony_ci */ 1500aff185Sopenharmony_ci 1600aff185Sopenharmony_ciimport { 1700aff185Sopenharmony_ci Action, 1800aff185Sopenharmony_ci ActionBarMode, 1900aff185Sopenharmony_ci ActionBarProp, 2000aff185Sopenharmony_ci ActionBarSelectionMode, 2100aff185Sopenharmony_ci Constants, 2200aff185Sopenharmony_ci Log, 2300aff185Sopenharmony_ci ScreenManager 2400aff185Sopenharmony_ci} from '@ohos/common'; 2500aff185Sopenharmony_ciimport { ActionBar } from '@ohos/common/CommonComponents'; 2600aff185Sopenharmony_ci 2700aff185Sopenharmony_ciconst TAG: string = 'timeline_TimelinePageActionBar'; 2800aff185Sopenharmony_ci 2900aff185Sopenharmony_ci@Component 3000aff185Sopenharmony_ciexport struct TimelinePageActionBar { 3100aff185Sopenharmony_ci @Consume isEmpty: boolean; 3200aff185Sopenharmony_ci @Consume @Watch('updateActionBarProp') isSelectedMode: boolean; 3300aff185Sopenharmony_ci @Consume @Watch('updateActionBarProp') isAllSelected: boolean; 3400aff185Sopenharmony_ci @Link @Watch('updateActionBarProp') totalSelectedCount: number; 3500aff185Sopenharmony_ci @Provide selectedCount: number = 0; 3600aff185Sopenharmony_ci @Consume @Watch('updatePlaceholderStatus') isShowSideBar: boolean; 3700aff185Sopenharmony_ci onMenuClicked: Function = (): void => {}; 3800aff185Sopenharmony_ci @StorageLink('isHorizontal') @Watch('updateActionBarProp') isHorizontal: boolean = 3900aff185Sopenharmony_ci ScreenManager.getInstance().isHorizontal(); 4000aff185Sopenharmony_ci @StorageLink('isSidebar') isSidebar: boolean = ScreenManager.getInstance().isSidebar(); 4100aff185Sopenharmony_ci @State actionBarProp: ActionBarProp = new ActionBarProp(); 4200aff185Sopenharmony_ci @StorageLink('statusBarHeight') statusBarHeight: number = 0; 4300aff185Sopenharmony_ci @State isNeedPlaceholder: boolean = true; 4400aff185Sopenharmony_ci @Consume moreMenuList: Action[]; 4500aff185Sopenharmony_ci @StorageLink('deviceType') deviceType: string | undefined = AppStorage.get<string>('deviceType'); 4600aff185Sopenharmony_ci private actionBarPaddingTop: number | Resource = 0; 4700aff185Sopenharmony_ci 4800aff185Sopenharmony_ci aboutToAppear(): void { 4900aff185Sopenharmony_ci if (this.deviceType === Constants.PC_DEVICE_TYPE) { 5000aff185Sopenharmony_ci this.actionBarPaddingTop = $r('app.float.album_set_page_action_bar_padding_top'); 5100aff185Sopenharmony_ci } else if (this.deviceType === Constants.PAD_DEVICE_TYPE) { 5200aff185Sopenharmony_ci this.actionBarPaddingTop = 0 5300aff185Sopenharmony_ci } else { 5400aff185Sopenharmony_ci this.actionBarPaddingTop = px2vp(this.statusBarHeight) 5500aff185Sopenharmony_ci } 5600aff185Sopenharmony_ci this.updateActionBarProp(); 5700aff185Sopenharmony_ci this.updatePlaceholderStatus(); 5800aff185Sopenharmony_ci } 5900aff185Sopenharmony_ci 6000aff185Sopenharmony_ci updatePlaceholderStatus(): void { 6100aff185Sopenharmony_ci if (this.deviceType !== Constants.PC_DEVICE_TYPE) { 6200aff185Sopenharmony_ci this.isNeedPlaceholder = false; 6300aff185Sopenharmony_ci } else { 6400aff185Sopenharmony_ci this.isNeedPlaceholder = this.isShowSideBar ? false : true 6500aff185Sopenharmony_ci } 6600aff185Sopenharmony_ci } 6700aff185Sopenharmony_ci 6800aff185Sopenharmony_ci updateActionBarProp(): void { 6900aff185Sopenharmony_ci this.selectedCount = this.totalSelectedCount; 7000aff185Sopenharmony_ci if (this.isHorizontal) { 7100aff185Sopenharmony_ci this.actionBarProp = this.createHorizontalActionBar(); 7200aff185Sopenharmony_ci } else { 7300aff185Sopenharmony_ci this.actionBarProp = this.createActionBar(); 7400aff185Sopenharmony_ci } 7500aff185Sopenharmony_ci } 7600aff185Sopenharmony_ci 7700aff185Sopenharmony_ci build() { 7800aff185Sopenharmony_ci Column() { 7900aff185Sopenharmony_ci ActionBar({ 8000aff185Sopenharmony_ci actionBarProp: $actionBarProp, 8100aff185Sopenharmony_ci onMenuClicked: this.onMenuClicked, 8200aff185Sopenharmony_ci isNeedPlaceholder: this.isNeedPlaceholder 8300aff185Sopenharmony_ci }) 8400aff185Sopenharmony_ci } 8500aff185Sopenharmony_ci .padding({ 8600aff185Sopenharmony_ci top: this.deviceType === Constants.DEFAULT_DEVICE_TYPE ? px2vp(this.statusBarHeight) : this.actionBarPaddingTop 8700aff185Sopenharmony_ci }) 8800aff185Sopenharmony_ci } 8900aff185Sopenharmony_ci 9000aff185Sopenharmony_ci private createHorizontalActionBar(): ActionBarProp { 9100aff185Sopenharmony_ci let menuList: Action[] = []; 9200aff185Sopenharmony_ci let actionBarProp: ActionBarProp = new ActionBarProp(); 9300aff185Sopenharmony_ci if (!this.isEmpty && this.deviceType === Constants.PC_DEVICE_TYPE) { 9400aff185Sopenharmony_ci menuList.push(Action.MULTISELECT); 9500aff185Sopenharmony_ci } 9600aff185Sopenharmony_ci actionBarProp 9700aff185Sopenharmony_ci .setHasTabBar(true) 9800aff185Sopenharmony_ci .setTitle($r('app.string.tab_timeline')) 9900aff185Sopenharmony_ci .setIsHeadTitle(true) 10000aff185Sopenharmony_ci .setMenuList(menuList) 10100aff185Sopenharmony_ci .setBackgroundColor($r('app.color.transparent')) 10200aff185Sopenharmony_ci .setMode(ActionBarMode.STANDARD_MODE); 10300aff185Sopenharmony_ci Log.info(TAG, `createActionBar, isSelectedMode: ${this.isSelectedMode}`); 10400aff185Sopenharmony_ci if (this.isSelectedMode) { 10500aff185Sopenharmony_ci menuList = []; 10600aff185Sopenharmony_ci menuList.push((this.isAllSelected ? Action.DESELECT_ALL : Action.SELECT_ALL), 10700aff185Sopenharmony_ci Boolean(this.selectedCount) ? Action.DELETE : Action.DELETE_INVALID, Action.MORE); 10800aff185Sopenharmony_ci actionBarProp 10900aff185Sopenharmony_ci .setLeftAction(Action.CANCEL) 11000aff185Sopenharmony_ci .setMenuList(menuList) 11100aff185Sopenharmony_ci .setMode(ActionBarMode.SELECTION_MODE) 11200aff185Sopenharmony_ci .setSelectionMode(ActionBarSelectionMode.MULTI); 11300aff185Sopenharmony_ci } 11400aff185Sopenharmony_ci return actionBarProp; 11500aff185Sopenharmony_ci } 11600aff185Sopenharmony_ci 11700aff185Sopenharmony_ci private createActionBar(): ActionBarProp { 11800aff185Sopenharmony_ci let menuList: Action[] = []; 11900aff185Sopenharmony_ci let actionBarProp: ActionBarProp = new ActionBarProp(); 12000aff185Sopenharmony_ci actionBarProp 12100aff185Sopenharmony_ci .setHasTabBar(this.isSidebar) 12200aff185Sopenharmony_ci .setTitle($r('app.string.tab_timeline')) 12300aff185Sopenharmony_ci .setIsHeadTitle(true) 12400aff185Sopenharmony_ci .setMode(ActionBarMode.STANDARD_MODE); 12500aff185Sopenharmony_ci Log.info(TAG, `createActionBar, isSelectedMode: ${this.isSelectedMode}`); 12600aff185Sopenharmony_ci if (this.isSelectedMode) { 12700aff185Sopenharmony_ci actionBarProp 12800aff185Sopenharmony_ci .setLeftAction(Action.CANCEL) 12900aff185Sopenharmony_ci .setMenuList(menuList) 13000aff185Sopenharmony_ci .setMode(ActionBarMode.SELECTION_MODE) 13100aff185Sopenharmony_ci .setSelectionMode(ActionBarSelectionMode.MULTI); 13200aff185Sopenharmony_ci } 13300aff185Sopenharmony_ci return actionBarProp; 13400aff185Sopenharmony_ci } 13500aff185Sopenharmony_ci}