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 photoAccessHelper from '@ohos.file.photoAccessHelper'; 17import { selectManager } from '../common/SelectManager'; 18import { userFileModel } from './UserFileModel'; 19import { Log } from '../utils/Log'; 20import { MediaConstants } from '../constants/MediaConstants'; 21import { UserFileDataItem } from './UserFileDataItem'; 22 23const TAG = 'TrashUserFileDataItem'; 24 25export class TrashUserFileDataItem extends UserFileDataItem { 26 constructor(selections: string, selectionArgs: string[], index: number) { 27 super(selections, selectionArgs, '', index); 28 this.setSelect(false); 29 } 30 31 async loadFileAsset(): Promise<photoAccessHelper.PhotoAsset> { 32 Log.debug(TAG, 'loadFileAsset' + this.uri); 33 return await userFileModel.getMediaItemByUriFromTrash(this.uri); 34 } 35 36 async onRecover(): Promise<boolean> { 37 try { 38 let fileAsset = await this.loadFileAsset(); 39 if (fileAsset == null) { 40 Log.error(TAG, 'onRecover error: cant find file'); 41 return false; 42 } 43 await userFileModel.recover(fileAsset); 44 selectManager.deleteSelect(this.uri); 45 this.status = MediaConstants.TRASHED; 46 return true; 47 } catch (err) { 48 Log.error(TAG, 'onRecover error: ' + JSON.stringify(err)); 49 return false; 50 } 51 } 52 53 async onDelete(): Promise<boolean> { 54 try { 55 let fileAsset = await this.loadFileAsset(); 56 await userFileModel.permanentDelete(fileAsset); 57 selectManager.deleteSelect(this.uri); 58 this.status = MediaConstants.TRASHED; 59 return true; 60 } catch (err) { 61 Log.error(TAG, 'onDelete error: ' + JSON.stringify(err)); 62 return false; 63 } 64 } 65} 66