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 { promptShowToast } from '../model/Prompt' 17import display from '@ohos.display' 18import MediaUtils from '../model/MediaUtils' 19import mediaLibrary from '@ohos.multimedia.mediaLibrary' 20 21@CustomDialog 22export struct DeleteDialog { 23 @State displayWidth: number = undefined 24 private index: number 25 private mediaData: Array<mediaLibrary.FileAsset> = [] 26 private controller: CustomDialogController 27 28 async aboutToAppear() { 29 let abilityDisplay = await display.getDefaultDisplay() 30 this.displayWidth = abilityDisplay.width 31 } 32 33 build() { 34 Column() { 35 Text($r('app.string.index_del')) 36 .fontSize(18) 37 .fontColor(this.displayWidth > 2500 ? Color.White : Color.Black) 38 .margin({ top: 10 }) 39 Row() { 40 Button() { 41 Text($r('app.string.index_cel')) 42 .fontColor(this.displayWidth > 2500 ? '#5291FF' : '#254FF7') 43 .fontSize(17) 44 } 45 .layoutWeight(5) 46 .backgroundColor(this.displayWidth > 2500 ? '#1C1D1F' : '#FFFFFF') 47 .onClick(() => { 48 promptShowToast($r('app.string.index_celOk')) 49 this.controller.close() 50 }) 51 52 Text() 53 .width(1) 54 .height(30) 55 .backgroundColor(this.displayWidth > 2500 ? '#8F8F8F' : '#cccccc') 56 57 Button() { 58 Text($r('app.string.index_sure')) 59 .fontColor(this.displayWidth > 2500 ? '#5291FF' : '#254FF7') 60 .fontSize(17) 61 } 62 .layoutWeight(5) 63 .backgroundColor(this.displayWidth > 2500 ? '#1C1D1F' : '#FFFFFF') 64 .onClick(() => { 65 MediaUtils.deleteFile(this.mediaData[this.index]) 66 this.mediaData.splice(this.index, 1) 67 this.controller.close() 68 promptShowToast($r('app.string.index_deleteOk')) 69 }) 70 } 71 .justifyContent(FlexAlign.SpaceAround) 72 .width('100%') 73 .margin({ top: '5%' }) 74 } 75 .width(this.displayWidth > 2500 ? '26%' : '80%') 76 .padding('3%') 77 .borderRadius(24) 78 .backgroundColor(this.displayWidth > 2500 ? '#1C1D1F' : '#FFFFFF') 79 } 80}