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