• 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 */
15
16import { DownloadCancelOperationDialog } from './DownloadCancelOperationDialog';
17import { Constants } from '../../model/common/Constants';
18import { Broadcast } from '@ohos/base/src/main/ets/utils/Broadcast';
19import { BroadcastConstants } from '@ohos/base/src/main/ets/constants/BroadcastConstants';
20import { Log } from '@ohos/base/src/main/ets/utils/Log';
21import { MediaDetails, DetailsDialog } from './DetailsDialog';
22import { MultiSelectDetails, MultiSelectDialog } from './MultiSelectDialog';
23import { DeleteDialog } from './DeleteDialog';
24import type { DialogCallback } from '../../model/common/DialogUtil';
25import { MediaDataItem } from '@ohos/base/src/main/ets/data/MediaDataItem';
26import { CancelOperationDialog, CancelParam } from './CancelOperationDialog';
27import { RenameDialog } from './RenameDialog';
28import { AddNotesDialog } from './AddNotesDialog';
29import { ProgressDialog, ProgressParam } from './ProgressDialog';
30import { DeleteProgressDialog, DeleteProgressParam } from './DeleteProgressDialog';
31import { SaveDialog, SaveDialogCallback } from './SaveDialog';
32import { EditExitDialog, EditExitDialogCallback } from './EditExitDialog';
33import { NewAlbumDialog } from './NewAlbumDialog';
34import { CopyOrMoveDialog, OperateParam } from './CopyOrMoveDialog';
35import { FindSameNameDialog, FindSameNameParam } from './FindSameNameDialog';
36import screenManager from '@ohos/base/src/main/ets/manager/ScreenManager';
37import { SaveImageDialog } from './SaveImageDialog';
38
39const TAG: string = 'CustomDialogView'
40
41@Component
42export struct CustomDialogView {
43    @State isShow: boolean = false;
44    @Provide dialogMessage: Resource = $r('app.string.common_place_holder', String(''));
45    @Provide dialogDeleteMessage: Resource = $r('app.string.common_place_holder', String(''));
46    @Provide progressMessage: Resource = $r('app.string.common_place_holder', String(''));
47    @Provide dialogCallback: DialogCallback = { confirmCallback: null, cancelCallback: null };
48    @Provide saveDialogCallback: SaveDialogCallback = { saveAsNewCallback: null, replaceOriginalCallback: null };
49    @Provide editExitDialogCallback: EditExitDialogCallback = { discardCallback: null };
50    @Consume broadCast: Broadcast;
51    @Provide progressParam: ProgressParam = { cancelFunc: null, operationType: '' };
52    @Provide deleteProgress: number = 0;
53    @Provide deleteProgressParam: DeleteProgressParam = { currentCount: 0, totalCount: 0, message: null, deleteProgress: 0};
54    @Provide cancelParam: CancelParam = { continueFunc: null, cancelFunc: null };
55    @Provide operateParam: OperateParam = { moveFunc: null, copyFunc: null };
56    @Provide findSameNameParam: FindSameNameParam = {
57        sourceFileAsset: null,
58        targetFileAsset: null,
59        replaceFunc: null,
60        skipFunc: null,
61        cancelFunc: null,
62        singlePhoto: null,
63        doSameFunc: null
64    };
65    @Provide cancelMessage: Resource = $r('app.string.common_place_holder', String(''));
66    @Provide renameFileName: string = '';
67    @Provide isDistributedAlbum: boolean = false;
68    @Provide mediaDetails: MediaDetails = {
69        mediaType: 0,
70        height: 0,
71        width: 0,
72        size: 0,
73        path: '',
74        duration: 0,
75        title: '',
76        dateTaken: 0,
77        uri: '',
78        displayName: '',
79        dateModified: 0
80    };
81    @Provide targetMediaDetails: MediaDetails = {
82        mediaType: 0,
83        height: 0,
84        width: 0,
85        size: 0,
86        path: '',
87        duration: 0,
88        title: '',
89        dateTaken: 0,
90        uri: '',
91        displayName: '',
92        dateModified: 0
93    };
94    @Provide multiSelectDetails: MultiSelectDetails = {
95        count: 0,
96        size: 0,
97    };
98    @StorageLink('isHorizontal') isHorizontal: boolean = screenManager.isHorizontal();
99    @StorageLink('isSidebar') isSidebar: boolean = screenManager.isSidebar();
100    dialogController: CustomDialogController;
101    multiSelectDialog: CustomDialogController;
102    deleteDialogController: CustomDialogController;
103    deleteProgressDialogController: CustomDialogController;
104    progressDialogController: CustomDialogController;
105    cancelDialogController: CustomDialogController;
106    renameFileDialogController: CustomDialogController;
107    saveDialogController: CustomDialogController;
108    editExitDialogController: CustomDialogController;
109    addNotesDialogController: CustomDialogController;
110    newAlbumDialogController: CustomDialogController;
111    copyOrMoveDialogController: CustomDialogController;
112    findSameNameDialog: CustomDialogController;
113    downloadCancelOperationDialog: CustomDialogController;
114    saveImageDialogController: CustomDialogController;
115
116    aboutToDisappear(): void {
117        Log.info(TAG, 'aboutToDisappear');
118        delete this.dialogController;
119        this.dialogController = undefined;
120        delete this.multiSelectDialog;
121        this.multiSelectDialog = undefined;
122        delete this.deleteDialogController;
123        this.deleteDialogController = undefined;
124        delete this.deleteProgressDialogController;
125        this.deleteProgressDialogController = undefined;
126        delete this.progressDialogController;
127        this.progressDialogController = undefined;
128        delete this.cancelDialogController;
129        this.cancelDialogController = undefined;
130        delete this.renameFileDialogController;
131        this.renameFileDialogController = undefined;
132        delete this.saveDialogController;
133        this.saveDialogController = undefined;
134        delete this.editExitDialogController;
135        this.editExitDialogController = undefined;
136        delete this.addNotesDialogController;
137        this.addNotesDialogController = undefined;
138        delete this.newAlbumDialogController;
139        this.newAlbumDialogController = undefined;
140        delete this.copyOrMoveDialogController;
141        this.copyOrMoveDialogController = undefined;
142        delete this.findSameNameDialog;
143        this.findSameNameDialog = undefined;
144        delete this.downloadCancelOperationDialog;
145        this.downloadCancelOperationDialog = undefined;
146        delete this.saveImageDialogController;
147        this.saveImageDialogController = undefined;
148    }
149
150    aboutToAppear(): void {
151        Log.info(TAG, 'aboutToAppear');
152        let self = this;
153        this.dialogController = new CustomDialogController({
154            builder: DetailsDialog(),
155            autoCancel: false,
156            alignment: this.isHorizontal || this.isSidebar ? DialogAlignment.Center : DialogAlignment.Bottom,
157            offset: {
158                dx: 0,
159                dy: this.isHorizontal || this.isSidebar ? 0 : $r('app.float.dialog_offset_bottom')
160            },
161            customStyle: true
162        });
163        this.multiSelectDialog = new CustomDialogController({
164            builder: MultiSelectDialog(),
165            autoCancel: false,
166            alignment: this.isHorizontal || this.isSidebar ? DialogAlignment.Center : DialogAlignment.Bottom,
167            offset: {
168                dx: 0,
169                dy: this.isHorizontal || this.isSidebar ? 0 : $r('app.float.dialog_offset_bottom')
170            },
171            customStyle: true
172        });
173        this.deleteDialogController = new CustomDialogController({
174            builder: DeleteDialog(),
175            autoCancel: false,
176            alignment: this.isHorizontal || this.isSidebar ? DialogAlignment.Center : DialogAlignment.Bottom,
177            offset: {
178                dx: 0,
179                dy: this.isHorizontal || this.isSidebar ? 0 : $r('app.float.dialog_offset_bottom')
180            },
181            customStyle: true
182        });
183        this.deleteProgressDialogController = new CustomDialogController({
184            builder: DeleteProgressDialog(),
185            autoCancel: false,
186            alignment: this.isHorizontal || this.isSidebar ? DialogAlignment.Center : DialogAlignment.Bottom,
187            offset: {
188                dx: 0,
189                dy: this.isHorizontal || this.isSidebar ? 0 : $r('app.float.dialog_offset_bottom')
190            },
191            customStyle: true
192        });
193        this.progressDialogController = new CustomDialogController({
194            builder: ProgressDialog(),
195            autoCancel: false,
196            alignment: this.isHorizontal || this.isSidebar ? DialogAlignment.Center : DialogAlignment.Bottom,
197            offset: {
198                dx: 0,
199                dy: this.isHorizontal || this.isSidebar ? 0 : $r('app.float.dialog_offset_bottom')
200            },
201            customStyle: true
202        });
203        this.cancelDialogController = new CustomDialogController({
204            builder: CancelOperationDialog(),
205            autoCancel: false,
206            alignment: this.isHorizontal || this.isSidebar ? DialogAlignment.Center : DialogAlignment.Bottom,
207            offset: {
208                dx: 0,
209                dy: this.isHorizontal || this.isSidebar ? 0 : $r('app.float.dialog_offset_bottom')
210            },
211            customStyle: true
212        });
213        this.renameFileDialogController = new CustomDialogController({
214            builder: RenameDialog(),
215            autoCancel: false,
216            alignment: this.isHorizontal || this.isSidebar ? DialogAlignment.Center : DialogAlignment.Bottom,
217            offset: {
218                dx: 0,
219                dy: this.isHorizontal || this.isSidebar ? 0 : $r('app.float.dialog_offset_bottom')
220            },
221            customStyle: true
222        });
223        this.saveDialogController = new CustomDialogController({
224            builder: SaveDialog(),
225            autoCancel: false,
226            alignment: this.isHorizontal || this.isSidebar ? DialogAlignment.Center : DialogAlignment.Bottom,
227            customStyle: true
228        });
229        this.editExitDialogController = new CustomDialogController({
230            builder: EditExitDialog(),
231            autoCancel: false,
232            alignment: this.isHorizontal || this.isSidebar ? DialogAlignment.Center : DialogAlignment.Bottom,
233            customStyle: true
234        });
235        this.addNotesDialogController = new CustomDialogController({
236            builder: AddNotesDialog(),
237            autoCancel: false,
238            alignment: this.isHorizontal || this.isSidebar ? DialogAlignment.Center : DialogAlignment.Bottom,
239            customStyle: true
240        });
241        this.newAlbumDialogController = new CustomDialogController({
242            builder: NewAlbumDialog(),
243            autoCancel: false,
244            alignment: this.isHorizontal || this.isSidebar ? DialogAlignment.Center : DialogAlignment.Bottom,
245            offset: {
246                dx: 0,
247                dy: this.isHorizontal || this.isSidebar ? 0 : $r('app.float.dialog_offset_bottom')
248            },
249            customStyle: true
250        });
251        this.copyOrMoveDialogController = new CustomDialogController({
252            builder: CopyOrMoveDialog(),
253            autoCancel: false,
254            alignment: this.isHorizontal || this.isSidebar ? DialogAlignment.Center : DialogAlignment.Bottom,
255            offset: {
256                dx: 0,
257                dy: this.isHorizontal || this.isSidebar ? 0 : $r('app.float.dialog_offset_bottom')
258            },
259            customStyle: true
260        });
261        this.findSameNameDialog = new CustomDialogController({
262            builder: FindSameNameDialog(),
263            autoCancel: false,
264            alignment: this.isHorizontal || this.isSidebar ? DialogAlignment.Center : DialogAlignment.Bottom,
265            offset: {
266                dx: 0,
267                dy: this.isHorizontal || this.isSidebar ? 0 : $r('app.float.dialog_offset_bottom')
268            },
269            customStyle: true
270        });
271        this.downloadCancelOperationDialog = new CustomDialogController({
272            builder: DownloadCancelOperationDialog(),
273            autoCancel: false,
274            alignment: this.isHorizontal || this.isSidebar ? DialogAlignment.Center : DialogAlignment.Bottom,
275            offset: {
276                dx: 0,
277                dy: this.isHorizontal || this.isSidebar ? 0 : $r('app.float.dialog_offset_bottom')
278            },
279            customStyle: true
280        });
281        this.saveImageDialogController = new CustomDialogController({
282            builder: SaveImageDialog(),
283            autoCancel: false,
284            alignment: this.isHorizontal || this.isSidebar ? DialogAlignment.Center : DialogAlignment.Bottom,
285            customStyle: true
286        });
287
288        this.broadCast.on(BroadcastConstants.SHOW_DETAIL_DIALOG, (item: MediaDataItem, isDistributed: boolean) => {
289            this.showDetailDialog(item, isDistributed)
290        });
291
292        this.broadCast.on(BroadcastConstants.SHOW_MULTI_SELECT_DIALOG,
293            function (count: number, size: number) {
294                Log.info(TAG, 'SHOW_MULTI_SELECT_DIALOG ');
295                self.multiSelectDetails = {
296                    size: size,
297                    count: count
298                };
299
300                self.multiSelectDialog.open();
301            });
302
303        this.broadCast.on(BroadcastConstants.SHOW_DELETE_DIALOG,
304            function (deleteMessage: Resource, dialogDeleteMessage: Resource, confirmCallback: Function, cancelCallback?: Function) {
305               Log.info(TAG, 'SHOW_DELETE_DIALOG ');
306                self.dialogMessage = deleteMessage;
307                self.dialogDeleteMessage = dialogDeleteMessage;
308                self.dialogCallback = { confirmCallback: confirmCallback, cancelCallback: cancelCallback };
309                self.deleteDialogController.open();
310            });
311        this.broadCast.on(BroadcastConstants.SHOW_RENAME_PHOTO_DIALOG,
312            function (fileName: string, confirmCallback: Function, cancelCallback?: Function) {
313               Log.info(TAG, 'SHOW_RENAME_PHOTO_DIALOG ');
314                self.renameFileName = fileName;
315                self.dialogCallback = { confirmCallback: confirmCallback, cancelCallback: cancelCallback };
316                self.renameFileDialogController.open();
317            });
318
319        this.broadCast.on(BroadcastConstants.SHOW_ADD_NOTES_PHOTO_DIALOG,
320            function (confirmCallback: Function, cancelCallback?: Function) {
321               Log.info(TAG, 'SHOW_ADD_NOTES_PHOTO_DIALOG ');
322                self.dialogCallback = { confirmCallback: confirmCallback, cancelCallback: cancelCallback };
323                self.addNotesDialogController.open();
324            });
325
326        this.broadCast.on(BroadcastConstants.SHOW_PROGRESS_DIALOG,
327            function (message: Resource, operationType: string, cancelFunc?: Function) {
328               Log.info(TAG, 'SHOW_PROGRESS_DIALOG');
329                if (message != null) {
330                    self.progressMessage = message;
331                }
332
333                if (operationType) {
334                    self.progressParam.operationType = operationType;
335                }
336
337                if (cancelFunc) {
338                    self.progressParam.cancelFunc = cancelFunc;
339                }
340
341                self.progressDialogController.open();
342            });
343
344        this.broadCast.on(BroadcastConstants.UPDATE_PROGRESS,
345            function (progress: number, currentCount: number) {
346               Log.info(TAG, `UPDATE_PROGRESS ${progress}, ${currentCount}`);
347                self.deleteProgress = progress;
348                self.deleteProgressParam.deleteProgress = progress;
349                self.deleteProgressParam.currentCount = currentCount;
350                if (progress == Constants.PROGRESS_MAX) {
351                   Log.info(TAG, 'Update progress 100%');
352                    self.progressDialogController.close();
353                    self.deleteProgress = 0;
354                    self.deleteProgressParam.deleteProgress = 0;
355                    self.deleteProgressDialogController.close();
356                    self.deleteProgressParam.currentCount = 0;
357                }
358            });
359
360        this.broadCast.on(BroadcastConstants.CANCEL_OPERATE,
361            function (cancelMessage: Resource, continueFunc: Function, cancelFunc: Function) {
362                self.cancelMessage = cancelMessage;
363                self.cancelParam.continueFunc = continueFunc;
364                self.cancelParam.cancelFunc = cancelFunc;
365               Log.info(TAG, 'CANCEL_OPERATE');
366                self.cancelDialogController.open();
367            });
368
369        this.broadCast.on(BroadcastConstants.DOWNLOAD_CANCEL_OPERATE,
370            function (cancelMessage: Resource, continueFunc: Function, cancelFunc: Function) {
371                self.cancelMessage = cancelMessage;
372                self.cancelParam.continueFunc = continueFunc;
373                self.cancelParam.cancelFunc = cancelFunc;
374               Log.info(TAG, 'DOWNLOAD_CANCEL_OPERATE');
375                self.downloadCancelOperationDialog.open();
376            });
377
378        this.broadCast.on(BroadcastConstants.SHOW_SAVE_PHOTO_DIALOG,
379            function (saveAsNewCallback: Function, replaceOriginalCallback: Function) {
380               Log.info(TAG, 'SHOW_SAVE_PHOTO_DIALOG');
381                self.saveDialogCallback
382                = { saveAsNewCallback: saveAsNewCallback, replaceOriginalCallback: replaceOriginalCallback };
383                self.saveDialogController.open();
384            });
385
386        this.broadCast.on(BroadcastConstants.SHOW_EDIT_EXIT_PHOTO_DIALOG,
387            function (discardCallback: Function) {
388               Log.info(TAG, 'SHOW_EDIT_EXIT_PHOTO_DIALOG');
389                self.editExitDialogCallback = { discardCallback: discardCallback };
390                self.editExitDialogController.open();
391            });
392
393        this.broadCast.on(BroadcastConstants.SHOW_EDIT_SAVE_PROGRESS_DIALOG,
394            function () {
395               Log.info(TAG, 'SHOW_EDIT_SAVE_PROGRESS_DIALOG');
396                self.saveImageDialogController.open();
397            });
398
399        this.broadCast.on(BroadcastConstants.SHOW_NEW_ALBUM_PHOTO_DIALOG,
400            function (fileName: string, confirmCallback: Function, cancelCallback?: Function) {
401               Log.info(TAG, 'SHOW_NEW_ALBUM_PHOTO_DIALOG');
402                self.renameFileName = fileName;
403                self.dialogCallback = { confirmCallback: confirmCallback, cancelCallback: cancelCallback };
404                self.newAlbumDialogController.open();
405            });
406
407        this.broadCast.on(BroadcastConstants.SHOW_COPY_OR_MOVE_DIALOG,
408            function (moveFunc: Function, copyFunc: Function) {
409               Log.info(TAG, 'SHOW_COPY_OR_MOVE_DIALOG');
410                self.operateParam.moveFunc = moveFunc;
411                self.operateParam.copyFunc = copyFunc;
412                self.copyOrMoveDialogController.open();
413            });
414
415        this.broadCast.on(BroadcastConstants.FIND_SAME_FILE_DIALOG,
416            function (assets: any, count: number, replaceFunc: Function, skipFunc: Function,
417                      cancelFunc: Function, doSameFunc: Function) {
418               Log.info(TAG, 'FIND_SAME_FILE_DIALOG');
419                self.findSameNameParam.sourceFileAsset = assets.sourceAsset;
420                self.findSameNameParam.targetFileAsset = assets.targetAsset;
421                self.findSameNameParam.replaceFunc = replaceFunc;
422                self.findSameNameParam.skipFunc = skipFunc;
423                self.findSameNameParam.cancelFunc = cancelFunc;
424                self.findSameNameParam.singlePhoto = (count == 1);
425                self.findSameNameParam.doSameFunc = doSameFunc;
426                self.findSameNameDialog.open();
427            });
428
429        this.broadCast.on(BroadcastConstants.DELETE_PROGRESS_DIALOG,
430            function (message: Resource, totalCount: number) {
431               Log.info(TAG, 'DELETE_PROGRESS_DIALOG');
432                self.deleteProgressParam.currentCount = 0;
433                self.deleteProgressParam.totalCount = totalCount;
434                self.deleteProgressParam.message = message;
435                self.deleteProgress = 0;
436                self.deleteProgressParam.deleteProgress = 0;
437                self.deleteProgressDialogController.open();
438            });
439    }
440
441    private showDetailDialog(item: MediaDataItem, isDistributed: boolean) {
442        Log.info(TAG, 'SHOW_DETAIL_DIALOG ');
443        item.load(true).then(() => {
444            this.mediaDetails = {
445                mediaType: item.mediaType,
446                height: item.height,
447                width: item.width,
448                size: item.size,
449                path: item.path,
450                duration: item.duration,
451                title: item.title,
452                dateTaken: item.dateTaken,
453                uri: item.uri,
454                displayName: item.displayName,
455                dateModified: item.dateModified
456            };
457            this.isDistributedAlbum = isDistributed;
458            this.dialogController.open();
459        })
460    }
461
462    build() {
463    }
464}