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 { Constants } from '../constants//Constants'; 17import { Broadcast } from '@ohos/base/src/main/ets/utils/Broadcast'; 18import broadcastManager from '@ohos/base/src/main/ets/manager/BroadcastManager'; 19import screenManager from '@ohos/base/src/main/ets/manager/ScreenManager'; 20 21@CustomDialog 22export struct SettingDialog { 23 private broadCast: Broadcast = broadcastManager.getBroadcast(); 24 @StorageLink('form_playback_interval') time: number = AppStorage.Get(Constants.FROM_PLAYBACK_INTERVAL); 25 @StorageLink('leftBlank') leftBlank: [number, number, number, number] = [0, 0, 0, 0]; 26 @StorageLink('isHorizontal') isHorizontal: boolean = screenManager.isHorizontal(); 27 @StorageLink('isSidebar') isSidebar: boolean = screenManager.isSidebar(); 28 controller: CustomDialogController; 29 private settings = [ 30 { title: $r('app.string.fa_play_interval_time_30'), value: '30', checked: false }, 31 { title: $r('app.string.fa_play_interval_time_60'), value: '60', checked: false }, 32 { title: $r('app.string.fa_play_interval_time_90'), value: '90', checked: false } 33 ]; 34 35 aboutToAppear() { 36 this.settings.forEach((item) => { 37 if (this.time == parseInt(item.value)) { 38 item.checked = true; 39 } else { 40 item.checked = false; 41 } 42 }) 43 } 44 45 build() { 46 Column() { 47 Row() { 48 Text($r('app.string.fa_select_time')) 49 .fontSize($r('sys.float.ohos_id_text_size_headline7')) 50 .fontFamily($r('app.string.id_text_font_family_regular')) 51 .fontColor($r('sys.color.ohos_id_color_text_primary')) 52 .fontWeight(FontWeight.Medium) 53 }.alignItems(VerticalAlign.Center) 54 .height($r('app.float.dialog_title_height')) 55 56 List() { 57 ForEach(this.settings, (item, index) => { 58 ListItem() { 59 Column() { 60 Row() { 61 Text(item.title) 62 .fontSize($r('sys.float.ohos_id_text_size_button1')) 63 .fontColor($r('app.color.black')) 64 .width('50%') 65 Flex({ 66 direction: FlexDirection.Row, 67 justifyContent: FlexAlign.End, 68 alignItems: ItemAlign.Start 69 }) { 70 Radio({ group: 'timeGroup', value: item.value }) 71 .checked(item.checked) 72 .onChange((checked: boolean) => { 73 item.checked = checked; 74 if (checked) { 75 this.broadCast.emit(Constants.FROM_PLAYBACK_INTERVAL, [parseInt(item.value)]); 76 this.controller.close(); 77 } 78 }) 79 } 80 .width('50%') 81 } 82 .width('100%') 83 84 if (index != this.settings.length - 1) { 85 Divider().width('100%').color($r('sys.color.ohos_id_color_list_separator')) 86 } 87 }.width('100%') 88 } 89 }) 90 } 91 .margin({ bottom: $r('sys.float.ohos_id_text_paragraph_margin_s') }) 92 93 Button() { 94 Text($r('app.string.no')) 95 .fontSize($r('sys.float.ohos_id_text_size_button1')) 96 .fontColor($r('app.color.color_control_highlight')) 97 .fontWeight(FontWeight.Medium) 98 .textAlign(TextAlign.Center) 99 } 100 .backgroundColor($r('app.color.transparent')) 101 .height($r('app.float.details_dialog_button_height')) 102 .width('100%') 103 .margin({ bottom: $r('sys.float.ohos_id_text_paragraph_margin_s') }) 104 .onClick(() => { 105 this.controller.close(); 106 }) 107 } 108 .padding({ left: $r('app.float.dialog_content_margin'), right: $r('app.float.dialog_content_margin') }) 109 .width(screenManager.getColumnsWidth(4)) 110 .alignItems(HorizontalAlign.Start) 111 .borderRadius($r('app.float.dialog_border_radius')) 112 .backgroundColor($r('app.color.white')) 113 .margin({ 114 right: $r('app.float.dialog_content_margin'), 115 left: $r('app.float.dialog_content_margin'), 116 bottom: this.isHorizontal || this.isSidebar ? 0 : Constants.DIALOG_BOTTOM_OFFSET + px2vp(this.leftBlank[3]) 117 }) 118 } 119}