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