• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 */
15import { TrashMediaDataItem } from '../data/TrashMediaDataItem';
16import { Log } from '../utils/Log';
17import { ItemDataSource } from '../vm/ItemDataSource';
18import { MenuContext } from './MenuContext'
19import { ProcessMenuOperation } from './ProcessMenuOperation';
20import { BroadcastConstants } from '../constants/BroadcastConstants';
21
22const TAG = "BatchRecoverMenuOperation"
23
24export class BatchRecoverMenuOperation extends ProcessMenuOperation {
25    constructor(menuContext: MenuContext) {
26        super(menuContext);
27    }
28
29    doAction(): void {
30        Log.info(TAG, 'delete doAction');
31        if (this.menuContext == null) {
32            Log.warn(TAG, 'menuContext is null, return');
33            return;
34        }
35
36        let dataSource: ItemDataSource = this.menuContext.dataSource;
37        if (dataSource == null) {
38            this.count = this.menuContext.items.length;
39        } else {
40            this.count = dataSource.getSelectedCount();
41        }
42        if (this.count <= 0) {
43            Log.warn(TAG, 'count <= 0, return');
44            return;
45        }
46
47        this.onOperationEnd = this.menuContext.onOperationEnd;
48        let onOperationStart = this.menuContext.onOperationStart;
49        onOperationStart && onOperationStart();
50
51        this.menuContext.broadCast.emit(BroadcastConstants.DELETE_PROGRESS_DIALOG,
52            [$r('app.string.action_recover'), this.count]);
53
54
55        if (dataSource == null) {
56            this.items = this.menuContext.items;
57        } else {
58            this.items = dataSource.getSelectedItems();
59        }
60        this.processOperation();
61    }
62
63    // Delete a batch of data
64    requestOneBatchOperation(): void {
65        let item = this.items[this.currentBatch] as TrashMediaDataItem;
66        item.onRecover().then(() => {
67            this.currentBatch++;
68            this.menuContext.broadCast.emit(BroadcastConstants.UPDATE_PROGRESS, [this.getExpectProgress(), this.currentBatch]);
69            this.cyclicOperation();
70        })
71    }
72}