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 settings from '@ohos.settings' 17 18import { Log } from '../../../utils/Log' 19import SettingListModel from '../../../../../../../../common/src/main/ets/default/featurecommon/settingview/model/SettingListModel' 20import { SettingManager } from '../../../setting/SettingManager' 21import Timer from '../../../setting/settingitem/Timer' 22import AspectRatio from '../../../setting/settingitem/AspectRatio' 23import Resolution from '../../../setting/settingitem/Resolution' 24import getStore from '../../../redux/store'; 25 26let localState = (state) => { 27 return { 28 mode: state.ModeReducer.mode, 29 } 30} 31 32let localDispatcher = (dispatch) => { 33 return {} 34} 35 36 37@Component 38export default struct EntryComponent { 39 private TAG: string = '[EntryComponent]:' 40 @State itemValue: string = '' 41 @State checkedValue: string = '' 42 @State settingAlias: string = '' 43 private getValue: Resource 44 private onChange: Function 45 private settingManager = SettingManager.getInstance() 46 @State state: any = {} 47 48 aboutToAppear(): void { 49 Log.info(`${this.TAG} aboutToAppear calle1d = ${this.settingAlias}`) 50 getStore().connect(localState, localDispatcher)(this.state) 51 try { 52 this.getValue = JSON.parse(JSON.stringify(this.settingManager.getSettingValue(this.settingAlias))) 53 Log.log(`${this.TAG} EntryComponent.getValue=${this.getValue}`) 54 } catch { 55 Log.log(`${this.TAG} catch this.settingAlias=${this.settingAlias}`) 56 if (this.settingAlias === Resolution.ALIAS) { 57 this.getValue = Resolution.DEFAULT_VALUE 58 } else if (this.settingAlias === Timer.ALIAS) { 59 this.getValue = Timer.DEFAULT_VALUE 60 } else { 61 this.getValue = AspectRatio.DEFAULT_VALUE 62 } 63 Log.error(`${this.TAG} catch this.getValue=${this.getValue}`) 64 } 65 } 66 67 build() { 68 Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) { 69 Text(this.itemValue) 70 .fontColor('#E6000000') 71 .fontSize($r("sys.float.ohos_id_text_size_body1")) 72 .fontWeight(FontWeight.Regular) 73 74 Radio({ group: 'settingChildren', value: this.itemValue.toString() }) 75 .width(24) 76 .height(24) 77 .margin({ right: 14 }) 78 .borderColor('#007DFF') 79 .checked(JSON.stringify(this.itemValue) === JSON.stringify(this.getValue)) 80 .enabled(true) 81 .onClick(() => { 82 Log.info(`${this.TAG} onChange settingAlias:${this.settingAlias} itemValue:${this.itemValue}`) 83 this.settingManager.setSettingValue(this.settingAlias, this.itemValue, this.state.mode) 84 this.onChange() 85 }) 86 } 87 .width('100%') 88 } 89}