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