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 { getUpdateTimes, Style } from '@ohos/common'; 17 18@Preview 19@CustomDialog 20export default struct UpdateTimeDialog { 21 private controller: CustomDialogController; 22 private updateTimes: string[] = getUpdateTimes(); 23 private handleCancelDialog: () => void; 24 @StorageLink('curBp') curBp: string = 'md'; 25 26 build() { 27 GridRow({ columns: { sm: 4, md: 8, lg: 12 }, 28 gutter: { x: Style.GRID_GUTTER, y: Style.GRID_GUTTER }, 29 breakpoints: { reference: BreakpointsReference.WindowSize } }) { 30 GridCol({ span: 4, offset: { sm: 0, md: 2, lg: 4 } }) { 31 Row() { 32 Column() { 33 Text($r('app.string.update_time')) 34 .width('100%') 35 .fontSize(20) 36 .fontWeight(FontWeight.Medium) 37 .margin({ top: 14 }) 38 List() { 39 ForEach(this.updateTimes, (item, index) => { 40 ListItem() { 41 UpdateTimeItem({ index: index, updateTime: item }) 42 } 43 }, item => item) 44 } 45 .lanes(this.curBp === 'lg' ? 2 : 1) 46 .divider({ strokeWidth: 1 }) 47 .margin({ top: Style.TIME_LIST_MARGIN }) 48 .width('100%') 49 .height(this.calcListHeight()) 50 51 Text($r('app.string.cancel')) 52 .width('100%') 53 .fontSize(16) 54 .fontColor('#0A59F7') 55 .textAlign(TextAlign.Center) 56 .fontWeight(FontWeight.Medium) 57 .margin({ top: 9, bottom: 25 }) 58 .onClick(() => { 59 this.handleCancelDialog() 60 }) 61 } 62 .padding({ left: Style.DIALOG_PADDING, right: Style.DIALOG_PADDING }) 63 .backgroundColor(Color.White) 64 .borderRadius(24) 65 } 66 .height('100%') 67 .alignItems(this.curBp === 'sm' ? VerticalAlign.Bottom : VerticalAlign.Center) 68 .padding({ 69 left: Style.DIALOG_PADDING_OUT, 70 right: Style.DIALOG_PADDING_OUT, 71 bottom: this.curBp === 'sm' ? Style.DIALOG_PADDING_OUT : 0 72 }) 73 } 74 } 75 } 76 77 calcListHeight() { 78 if (this.curBp === 'lg') { 79 return Style.TIME_LIST_HEIGHT * this.updateTimes.length / 2 + Style.TIME_LIST_MARGIN; 80 } else { 81 return Style.TIME_LIST_HEIGHT * this.updateTimes.length + Style.TIME_LIST_MARGIN; 82 } 83 } 84} 85 86@Component 87struct UpdateTimeItem { 88 private index: number = 0; 89 private updateTime: string = ''; 90 @StorageLink('curBp') curBp: string = 'md'; 91 92 build() { 93 Row() { 94 Text(this.updateTime) 95 .fontSize(16) 96 Blank() 97 Radio({ group: 'time', value: this.updateTime }) 98 .width(20) 99 .height(20) 100 } 101 .width('100%') 102 .height(Style.TIME_LIST_HEIGHT) 103 .padding(this.curBp === 'lg' ? (this.index % 2 === 0 ? { right: 10 } : { left: 10 }) : 0) 104 } 105}