1/* 2 * Copyright (c) 2023 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 deviceInfo from '@ohos.deviceInfo'; 17import { Action } from '@ohos/common/src/main/ets/default/redux/actions/Action'; 18import { EventBusManager } from '@ohos/common/src/main/ets/default/worker/eventbus/EventBusManager'; 19import { Dispatch, getStore, OhCombinedState } from '@ohos/common/src/main/ets/default/redux/store'; 20import { Log } from '@ohos/common/src/main/ets/default/utils/Log'; 21import { SettingManager } from '@ohos/common/src/main/ets/default/setting/SettingManager'; 22import { SettingItem } from '@ohos/common/src/main/ets/default/featurecommon/settingview/phone/SettingItem'; 23import { SettingListModel } from '@ohos/common/src/main/ets/default/featurecommon/settingview/model/SettingListModel'; 24import { SettingGroupItem } from '@ohos/common/src/main/ets/default/featurecommon/settingview/model/SettingData'; 25 26class StateStruct { 27 isCloseFlag: boolean = false; 28 mode: string = ''; 29 zoomRatio: number = 1; 30} 31 32class SettingViewDispatcher { 33 public setDispatch(dispatch: Dispatch) { 34 this.mDispatch = dispatch; 35 } 36 37 public closeDialog(isCloseFlag: boolean): void { 38 this.mDispatch(Action.closeDialog(isCloseFlag)); 39 } 40 41 public hideSettingView(): void { 42 this.mDispatch(Action.showSettingView(false)); 43 } 44 45 public changeXComponentSize(xComponentWidth: number, xComponentHeight: number): void { 46 this.mDispatch(Action.changeXComponentSize(xComponentWidth, xComponentHeight)); 47 } 48 49 public assistiveGridView(isViewShow: number): void { 50 this.mDispatch(Action.assistiveGridView(isViewShow)); 51 } 52 53 public reStartPreview(zoomRatio: number): void { 54 this.mDispatch(Action.reStartPreview(zoomRatio)); 55 } 56 57 private mDispatch: Dispatch = (data) => data; 58} 59 60class SizeStruct { 61 width: number = 0; 62 height: number = 0; 63} 64 65@Component 66export struct SettingView { 67 @State checkNameList: Array<string> = ['4:3', '[16:9] 720p'] 68 @State closeFlag: boolean = false 69 @State tempGutter: number = 12; //列间距 70 @State tempMargin: number = 12; //两侧间距 71 @State settingsList: SettingGroupItem[] = new SettingListModel().getSettingList() 72 @State state: StateStruct = new StateStruct() 73 private TAG: string = '[SettingView]:' 74 private settingManager = SettingManager.getInstance() 75 private mEventBus = EventBusManager.getInstance().getEventBus() 76 private WH_100_100: string = "100%"; 77 private mAction: SettingViewDispatcher = new SettingViewDispatcher(); 78 79 aboutToAppear(): void { 80 Log.info(`${this.TAG} aboutToAppear invoke E`) 81 getStore().subscribe((state: OhCombinedState) => { 82 this.state = { 83 isCloseFlag: state.settingReducer.isCloseFlag, 84 mode: state.modeReducer.mode, 85 zoomRatio: state.zoomReducer.zoomRatio 86 }; 87 }, (dispatch: Dispatch) => { 88 this.mAction.setDispatch(dispatch); 89 }); 90 this.mEventBus.on('AspectRatio', (data: SizeStruct) => this.aspectRatioChange(data)); 91 this.mEventBus.on('Resolution', (data: SizeStruct) => this.resolutionChange(data)); 92 this.mEventBus.on('AssistiveGrid', (data: number) => this.assistiveGridChange(data)); 93 Log.info(`${this.TAG} aboutToAppear invoke X`) 94 } 95 96 aboutToDisappear(): void { 97 Log.info(`${this.TAG} aboutToDisappear E`) 98 this.mEventBus.off('AspectRatio', (data: SizeStruct) => this.aspectRatioChange(data)); 99 this.mEventBus.off('Resolution', (data: SizeStruct) => this.resolutionChange(data)); 100 this.mEventBus.off('AssistiveGrid', (data: number) => this.assistiveGridChange(data)); 101 } 102 103 onBackPress(): boolean { 104 Log.info(`${this.TAG} onBackPress invoke X`) 105 if (this.state.isCloseFlag) { 106 this.closeFlag = !this.closeFlag 107 } else { 108 this.mAction.hideSettingView() 109 } 110 return true; 111 } 112 113 build() { 114 Flex({ direction: FlexDirection.Column }) { 115 Row() { 116 Image($r('app.media.ic_public_back')) 117 .width(24) 118 .height(24) 119 .fillColor($r('app.color.settings_ic_public_back_FFFFFF')) 120 .onClick(() => { 121 this.mAction.hideSettingView() 122 }) 123 Text($r('app.string.settings')) 124 .margin({ left: $r('sys.float.ohos_id_elements_margin_horizontal_l') }) 125 .fontColor($r('app.color.settings_ic_public_back_FFFFFF')) 126 .fontSize($r('sys.float.ohos_id_text_size_headline8')) 127 .fontWeight(FontWeight.Medium) 128 } 129 .padding({ left: 24 }) 130 .width(this.WH_100_100) 131 .height(56) 132 .margin({ top: deviceInfo.deviceType !== 'default' ? 25 : 0 }) 133 134 Scroll() { 135 Column() { 136 GridContainer({ columns: 4, gutter: this.tempGutter, margin: this.tempMargin }) { 137 List() { 138 ForEach(this.settingsList, (item: SettingGroupItem, index: number) => { 139 ListItem() { 140 SettingItem({ 141 settingsList: $settingsList, 142 closeFlag: $closeFlag, 143 item: item, 144 index: index 145 }) 146 } 147 }) 148 } 149 } 150 151 Row() { 152 Button({ type: ButtonType.Normal, stateEffect: true }) { 153 Text($r('app.string.restore_defaults')) 154 .fontSize($r('sys.float.ohos_id_text_size_button1')) 155 .fontColor($r('app.color.font_color_FFFFFF')) 156 .fontWeight(FontWeight.Regular) 157 .textAlign(TextAlign.Center) 158 } 159 .borderRadius(30) 160 .backgroundColor($r('app.color.background_color_333333')) 161 .height(40) 162 .width('52%') 163 .onClick(() => { 164 this.settingManager.restoreValues(this.state.mode) 165 this.mAction.hideSettingView() 166 }) 167 } 168 .margin({ top: $r('sys.float.ohos_id_text_paragraph_margin_l') }) 169 } 170 } 171 .width(this.WH_100_100) 172 .flexShrink(1) 173 .edgeEffect(EdgeEffect.Spring) 174 } 175 .height(this.WH_100_100) 176 .backgroundColor(Color.Black) 177 } 178 179 private aspectRatioChange(xComponentSize: SizeStruct): void { 180 if (this.state.mode != 'VIDEO') { 181 this.mAction.changeXComponentSize(xComponentSize.width, xComponentSize.height) 182 this.mAction.reStartPreview(this.state.zoomRatio) 183 } 184 } 185 186 private resolutionChange(xComponentSize: SizeStruct): void { 187 if (this.state.mode == 'VIDEO') { 188 this.mAction.changeXComponentSize(xComponentSize.width, xComponentSize.height) 189 this.mAction.reStartPreview(this.state.zoomRatio) 190 } 191 } 192 193 private assistiveGridChange(mAssistiveGrid: number): void { 194 this.mAction.assistiveGridView(mAssistiveGrid) 195 } 196}