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 type { MenuOperation, MenuOperationCallback } from '@ohos/common'; 17import { BroadCastConstants, BrowserOperationFactory, Log, MenuContext } from '@ohos/common'; 18 19const TAG: string = 'browser_AddNotesMenuOperation'; 20 21export class AddNotesMenuOperation implements MenuOperation, MenuOperationCallback { 22 private menuContext: MenuContext; 23 24 constructor(menuContext: MenuContext) { 25 this.menuContext = menuContext; 26 } 27 28 doAction(): void { 29 if (this.menuContext == null) { 30 Log.error(TAG, 'menuContext is null, return'); 31 return; 32 } 33 let mediaItem = this.menuContext.mediaItem; 34 if (mediaItem == null) { 35 Log.error(TAG, 'mediaItem is null, return'); 36 return; 37 } 38 39 this.confirmCallback = this.confirmCallback.bind(this); 40 this.cancelCallback = this.cancelCallback.bind(this); 41 42 this.menuContext.broadCast.emit(BroadCastConstants.SHOW_ADD_NOTES_PHOTO_DIALOG, 43 [this.confirmCallback, this.cancelCallback]); 44 } 45 46 onCompleted(): void { 47 Log.info(TAG, 'Add notes data succeed!'); 48 } 49 50 onError(): void { 51 Log.error(TAG, 'Add notes data failed!'); 52 } 53 54 private async confirmCallback(text: string) { 55 Log.info(TAG, `Add notes confirm new name: ${text}`); 56 let operationImpl = BrowserOperationFactory.getFeature(BrowserOperationFactory.TYPE_PHOTO); 57 let mediaItem = this.menuContext.mediaItem 58 if (mediaItem == null) { 59 Log.error(TAG, 'Add notes is null, return'); 60 return; 61 } 62 } 63 64 private cancelCallback(): void { 65 Log.info(TAG, 'Add notes cancel'); 66 } 67}