• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 { ItemDataSource } from '../common/ItemDataSource';
17import { MenuContext } from './MenuContext';
18import { BatchDeleteMenuOperation } from './BatchDeleteMenuOperation';
19import { Log } from '../utils/Log';
20import { BroadcastConstants } from '../constants/BroadcastConstants';
21
22const TAG = 'ClearRecycleMenuOperation';
23
24export class ClearRecycleMenuOperation extends BatchDeleteMenuOperation {
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      //@ts-ignore
41      this.count = dataSource.getItems().length;
42    }
43    if (this.count <= 0) {
44      Log.warn(TAG, 'count <= 0, return');
45      return;
46    }
47
48    this.confirmCallback = (): void => this.confirmCallbackBindImpl();
49    this.cancelCallback = (): void => this.cancelCallbackBindImpl();
50
51    this.menuContext.broadCast.emit(BroadcastConstants.SHOW_DELETE_DIALOG, [$r('app.string.recycleAlbum_clear_message'), $r('app.string.dialog_clear'), this.confirmCallback, this.cancelCallback]);
52  }
53
54  confirmCallback(): void {
55    this.confirmCallbackBindImpl();
56  }
57
58  protected confirmCallbackBindImpl(): void {
59    Log.info(TAG, 'Clear Recycle confirm');
60    // 1. Variable initialization
61    this.onOperationEnd = this.menuContext.onOperationEnd;
62
63    // 2. onDeleteStart exit selection mode
64    let onOperationStart: Function = this.menuContext.onOperationStart;
65    if (onOperationStart != null) onOperationStart();
66
67    this.menuContext.broadCast.emit(BroadcastConstants.DELETE_PROGRESS_DIALOG,
68      [$r('app.string.action_delete'), this.count]);
69
70    // 3. selectManager gets the URI of the data and starts processing deletion in the callback
71    let dataSource: ItemDataSource = this.menuContext.dataSource;
72    if (dataSource == null) {
73      this.items = this.menuContext.items;
74    } else {
75      //@ts-ignore
76      this.items = dataSource.getItems();
77    }
78    this.processOperation();
79  }
80}
81