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 */ 15import { promptShowToast } from '../model/Prompt' 16import display from '@ohos.display' 17 18@CustomDialog 19export struct RenameDialog { 20 @State title: string = '' 21 @State displayWidth: number = undefined 22 private suffix: string 23 private disPlayType: string 24 private setRename: (newName: string) => void 25 private controller: CustomDialogController 26 async aboutToAppear() { 27 this.suffix = this.title.substring(this.title.lastIndexOf('.')) 28 let abilityDisplay = await display.getDefaultDisplay() 29 this.displayWidth = abilityDisplay.width 30 } 31 build() { 32 Column() { 33 Text(`${this.disPlayType}`) 34 .fontSize(20) 35 .fontColor(this.displayWidth > 2500 ? '#FFFFFF' : '#000000') 36 .width(this.displayWidth > 2500 ? 280 : 328) 37 .fontWeight(FontWeight.Medium) 38 .height(22) 39 40 TextInput({ placeholder: 'input name', text: this.title.substring(this.title.lastIndexOf('.'), 0) }) 41 .type(InputType.Normal) 42 .fontWeight(FontWeight.Regular) 43 .maxLength(18) 44 .fontSize(16) 45 .width(this.displayWidth > 2500 ? 310 : 350) 46 .margin({ top: 10 }) 47 .backgroundColor(this.displayWidth > 2500 ? '#1C1D1F' : '#FFFFFF') 48 .fontColor(this.displayWidth > 2500 ? Color.White : Color.Black) 49 .onChange((value: string) => { 50 this.title = value + this.suffix 51 }) 52 Text() 53 .width(this.displayWidth > 2500 ? 270 : 320) 54 .height(1) 55 .backgroundColor(this.displayWidth > 2500 ? '#8F8F8F' : '#cccccc') 56 Row() { 57 Button() { 58 Text($r('app.string.index_cel')).fontColor(this.displayWidth > 2500 ? '#5291FF' : '#254FF7').fontSize(17) 59 }.layoutWeight(5).backgroundColor(this.displayWidth > 2500 ? '#1C1D1F' : '#FFFFFF').onClick(() => { 60 promptShowToast($r('app.string.index_celOk')) 61 this.controller.close() 62 }) 63 64 Text().width(1).height(30).backgroundColor(this.displayWidth > 2500 ? '#8F8F8F' : '#cccccc') 65 Button() { 66 Text($r('app.string.index_sure')).fontColor(this.displayWidth > 2500 ? '#5291FF' : '#254FF7').fontSize(17) 67 }.layoutWeight(5).backgroundColor(this.displayWidth > 2500 ? '#1C1D1F' : '#FFFFFF').onClick(() => { 68 if (this.title == this.suffix) { 69 promptShowToast($r('app.string.renameDialog_inputName')) 70 return 71 } 72 this.setRename(this.title) 73 promptShowToast($r('app.string.renameDialog_inputNameOk')) 74 this.controller.close() 75 }) 76 }.justifyContent(FlexAlign.SpaceAround).width('100%').margin({ top: '5%' }) 77 } 78 .width(this.displayWidth > 2500 ? '26%' : '80%') 79 .padding('3%') 80 .borderRadius(24) 81 .backgroundColor(this.displayWidth > 2500 ? '#1C1D1F' : '#FFFFFF') 82 } 83}