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