1/* 2 * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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 { ActionBarProp } from '../common/ActionBarProp'; 18import { ActionBarMode, ActionBarSelectionMode } from './ActionBarMode'; 19import { screenManager } from '../common/ScreenManager'; 20import { MediaConstants } from '../constants/MediaConstants'; 21 22export class PhotoGridBarModel { 23 private albumId: string = ''; 24 25 setAlbumId(albumId: string): void { 26 this.albumId = albumId; 27 } 28 29 createActionBar(title: Object, isSelectedMode: boolean, selectedCount: number, 30 isAllSelected: boolean, isEmpty: boolean): ActionBarProp { 31 let actionBarProp: ActionBarProp = new ActionBarProp(); 32 let isHorizontal = screenManager.isHorizontal() 33 if (isHorizontal) { 34 this.updateHorizontalActionBar(actionBarProp, title, isSelectedMode, selectedCount, isAllSelected, isEmpty); 35 } else { 36 this.updateVerticalActionBar(actionBarProp, title, isSelectedMode); 37 } 38 return actionBarProp; 39 } 40 41 updateActionBar(actionBarProp: ActionBarProp, title: Object, isSelectedMode: boolean, 42 selectedCount: number, isAllSelected: boolean, isEmpty: boolean): void { 43 let isHorizontal = screenManager.isHorizontal() 44 if (isHorizontal) { 45 this.updateHorizontalActionBar(actionBarProp, title, isSelectedMode, selectedCount, isAllSelected, isEmpty); 46 } else { 47 this.updateVerticalActionBar(actionBarProp, title, isSelectedMode); 48 } 49 } 50 51 private updateHorizontalActionBar(actionBarProp: ActionBarProp, title: Object, isSelectedMode: boolean, 52 selectedCount: number, isAllSelected: boolean, isEmpty: boolean): ActionBarProp { 53 actionBarProp 54 .setLeftAction(Action.BACK) 55 .setTitle(title) 56 .setMode(ActionBarMode.STANDARD_MODE); 57 let menuList: Action[] = this.getMenuList(isSelectedMode, selectedCount, isAllSelected, isEmpty); 58 if (isSelectedMode) { 59 actionBarProp 60 .setLeftAction(Action.CANCEL) 61 .setMode(ActionBarMode.SELECTION_MODE) 62 .setSelectionMode(ActionBarSelectionMode.MULTI); 63 } else { 64 if (!MediaConstants.ALBUM_DISABLE_NEW_LIST.has(this.albumId)) { 65 menuList.push(Action.NEW); 66 } 67 } 68 actionBarProp.setMenuList(menuList); 69 return actionBarProp; 70 } 71 72 private updateVerticalActionBar(actionBarProp: ActionBarProp, title: Object, isSelectedMode: boolean): ActionBarProp { 73 let menuList: Action[] = []; 74 75 if (!MediaConstants.ALBUM_DISABLE_NEW_LIST.has(this.albumId)) { 76 menuList.push(Action.NEW); 77 } 78 79 actionBarProp 80 .setLeftAction(Action.BACK) 81 .setTitle(title) 82 .setMenuList(menuList) 83 .setMode(ActionBarMode.STANDARD_MODE); 84 if (isSelectedMode) { 85 menuList = []; 86 actionBarProp 87 .setLeftAction(Action.CANCEL) 88 .setMenuList(menuList) 89 .setMode(ActionBarMode.SELECTION_MODE) 90 .setSelectionMode(ActionBarSelectionMode.MULTI); 91 } 92 93 return actionBarProp; 94 } 95 96 getMenuList(isSelectedMode: boolean, selectedCount: number, isAllSelected: boolean, isEmpty: boolean): Action[] { 97 let menuList: Action[] = []; 98 if (isSelectedMode) { 99 if (this.albumId === MediaConstants.ALBUM_ID_RECYCLE) { 100 menuList.push((new Boolean(selectedCount)) ? Action.RECOVER : Action.RECOVER_INVALID); 101 menuList.push((new Boolean(selectedCount)) ? Action.DELETE : Action.DELETE_INVALID); 102 menuList.push(isAllSelected ? Action.DESELECT_ALL : Action.SELECT_ALL); 103 } else { 104 menuList.push(isAllSelected ? Action.DESELECT_ALL : Action.SELECT_ALL); 105 menuList.push((new Boolean(selectedCount)) ? Action.DELETE : Action.DELETE_INVALID, Action.MORE); 106 } 107 } else { 108 if (this.albumId === MediaConstants.ALBUM_ID_RECYCLE && !isEmpty) { 109 menuList.push(Action.CLEAR_RECYCLE); 110 } 111 } 112 return menuList; 113 } 114} 115