• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * Copyright (c) 2021-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 Router from '@system.router';
17import deviceInfo from '@ohos.deviceInfo';
18import parameter from '@ohos.systemparameter';
19import FeatureAbility from '@ohos.ability.featureAbility';
20import WifiModel from '../model/wifiImpl/WifiModel';
21import BluetoothModel from '../model/bluetoothImpl/BluetoothModel';
22import SettingListModel from '../model/settingListImpl/SettingListModel';
23import LogUtil from '../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil';
24import ConfigData from '../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData';
25import ResourceUtil from '../../../../../../common/search/src/main/ets/default/common/ResourceUtil';
26import {SettingItemComponent} from '../../../../../../common/component/src/main/ets/default/settingItemComponent';
27import GlobalResourceManager from '../../../../../../common/utils/src/main/ets/default/baseUtil/GlobalResourceManager';
28import { VpnTypeModel } from '../model/vpnImpl/VpnTypeModel';
29
30const deviceTypeInfo = deviceInfo.deviceType;
31
32@Extend(ListItem) function settingListItemFancy() {
33  .width(ConfigData.WH_100_100)
34  .borderRadius($r("app.float.radius_16"))
35  .backgroundColor($r("sys.color.ohos_id_color_foreground_contrary"))
36  .padding($r('app.float.distance_4'))
37}
38
39@Extend(List) function settingListItemDividerFancy() {
40  .divider({
41    strokeWidth: $r('app.float.divider_wh'),
42    color: $r('sys.color.ohos_id_color_list_separator'),
43    startMargin: $r('app.float.wh_value_48'),
44    endMargin: $r('app.float.wh_value_8')
45  })
46}
47
48/**
49 * setting home page
50 */
51@Entry
52@Component
53struct SettingList {
54  @State placeholder: string= ''; // for search
55  @State placeholderSize: string = '22';
56  @State listSpaces: string = '12vp';
57  @State isPhone: boolean = false;
58  @StorageLink('bluetoothIsOn') bluetoothIsOn: boolean = false;
59
60  @Builder NavigationTitle() {
61    Column() {
62      Text($r('app.string.settings'))
63        .width(ConfigData.WH_100_100)
64        .height($r('app.float.wh_value_56'))
65        .fontColor($r("sys.color.ohos_id_color_text_primary"))
66        .fontSize($r('app.float.font_30'))
67        .fontWeight(FontWeight.Medium)
68    }
69  }
70
71  build() {
72    Column() {
73      GridContainer({ gutter: ConfigData.GRID_CONTAINER_GUTTER_24, margin: ConfigData.GRID_CONTAINER_MARGIN_24 }) {
74        Column() {
75          if (this.isPhone) {
76            Navigation() {
77              EntryComponent({ listSpaces: this.listSpaces, isPhone: this.isPhone })
78            }
79            .title(this.NavigationTitle)
80            .titleMode(NavigationTitleMode.Free)
81            .hideTitleBar(false)
82            .hideBackButton(true)
83          } else {
84            EntryComponent({ listSpaces: this.listSpaces })
85          }
86        }
87        .useSizeType({
88          xs: { span: 2, offset: 0 },
89          sm: { span: 4, offset: 0 },
90          md: { span: 6, offset: 1 },
91          lg: { span: 8, offset: 2 }
92        })
93      }
94      .width(ConfigData.WH_100_100)
95      .height(ConfigData.WH_100_100)
96    }
97    .backgroundColor($r("sys.color.ohos_id_color_sub_background"))
98    .width(ConfigData.WH_100_100)
99    .height(ConfigData.WH_100_100)
100  }
101
102  aboutToAppear() {
103    LogUtil.info('CCCC settings SettingList aboutToAppear enter');
104    ResourceUtil.getString($r("app.string.searchHint")).then(value => this.placeholder = value);// for search
105    ResourceUtil.getString($r("app.float.search_placeholder_font")).then(value => this.placeholderSize = value);
106    ResourceUtil.getString($r('app.float.distance_12')).then(value => this.listSpaces = value);
107
108    let nYear = GlobalResourceManager.getStringByResource($r('app.string.year'));
109    nYear.then(resp => AppStorage.SetOrCreate(ConfigData.DATE_AND_TIME_YEAR, resp));
110
111    let nMonth = GlobalResourceManager.getStringByResource($r('app.string.month'));
112    nMonth.then(resp => AppStorage.SetOrCreate(ConfigData.DATE_AND_TIME_MONTH, resp));
113
114    let nDay = GlobalResourceManager.getStringByResource($r('app.string.day'));
115    nDay.then(resp => AppStorage.SetOrCreate(ConfigData.DATE_AND_TIME_DAY, resp));
116
117    if (deviceTypeInfo === 'phone') {
118      this.isPhone = true;
119    } else {
120      this.isPhone = false;
121    }
122    LogUtil.info('CCCC settings SettingList aboutToAppear end');
123  }
124}
125
126@Component
127struct EntryComponent {
128  @StorageLink('wifiStatus') @Watch("wifiStatusChange") wifiStatus: boolean = WifiModel.isWiFiActive();
129  @StorageLink('bluetoothIsOn') @Watch("bluetoothIsOnChange") bluetoothIsOn: boolean = false;
130  @StorageLink("wifiStatusInfo") wifiStatusInfo: Resource = WifiModel.isWiFiActive() ? $r("app.string.enabled") : $r("app.string.disabled");
131  @StorageLink("bluetoothStatusInfo") bluetoothStatusInfo: Resource = $r("app.string.disabled");
132  @StorageLink("endTextEmpty") endTextEmpty: Resource = $r("app.string.endTextEmpty");
133  private nfcInfo: boolean = false;
134  private listSpaces: string = '12vp';
135  private isPhone: boolean = false;
136  private info: string = 'false';
137
138  wifiStatusChange() {
139    AppStorage.SetOrCreate("wifiStatusInfo", this.wifiStatus ? $r("app.string.enabled") : $r("app.string.disabled"))
140  }
141
142  bluetoothIsOnChange() {
143    AppStorage.SetOrCreate("bluetoothStatusInfo", this.bluetoothIsOn ? $r("app.string.enabled") : $r("app.string.disabled"))
144  }
145
146  aboutToAppear() {
147    LogUtil.info('CCCC settings SettingList EntryComponent aboutToAppear in');
148    SettingListModel.registerObserver();
149    this.bluetoothIsOn = BluetoothModel.isStateOn();
150    BluetoothModel.subscribeStateChange((isOn: boolean) => {
151      AppStorage.SetOrCreate('bluetoothIsOn', isOn);
152    });
153
154    this.info = parameter.getSync("const.SystemCapability.Communication.NFC.Core" ,"false");
155    LogUtil.info('CCCC settings SettingList EntryComponent aboutToAppear out');
156  }
157
158  aboutToDisappear(){
159    BluetoothModel.unsubscribeStateChange();
160  }
161
162  build() {
163    Column() {
164      if (!this.isPhone) {
165        Text($r('app.string.settings'))
166          .height($r("app.float.wh_value_56"))
167          .fontColor($r("sys.color.ohos_id_color_text_primary"))
168          .fontSize($r("app.float.font_30"))
169          .lineHeight($r("app.float.lineHeight_41"))
170          .fontWeight(FontWeight.Bold)
171          .fontFamily('HarmonyHeiTi')
172          .textAlign(TextAlign.Start)
173          .width(ConfigData.WH_100_100)
174          .padding({
175            left: $r('app.float.distance_12'),
176            top: $r('app.float.distance_7'),
177            bottom: $r('app.float.distance_8')
178          })
179      }
180
181      List({ space: this.listSpaces }) {
182        // search
183        ListItem() {
184          Row() {
185            Image($r("app.media.ic_search"))
186              .width($r('app.float.wh_value_18'))
187              .height($r('app.float.wh_value_18'))
188              .objectFit(ImageFit.Contain)
189              .margin({
190                left: $r("app.float.distance_11"),
191                top: $r('app.float.distance_11'),
192                bottom: $r('app.float.distance_11')
193              });
194
195            Text($r("app.string.searchHint"))
196              .fontSize($r("app.float.font_16"))
197              .lineHeight($r("app.float.lineHeight_21"))
198              .fontWeight(FontWeight.Regular)
199              .fontFamily('HarmonyHeiTi')
200              .fontColor($r("sys.color.ohos_id_color_text_secondary"))
201              .align(Alignment.Start)
202              .margin({
203                left: $r("app.float.distance_6"),
204                top: $r('app.float.distance_9'),
205                bottom: $r('app.float.distance_9')
206              });
207          }
208          .border({
209            width: $r('app.float.wh_value_1_5'),
210            color: $r("sys.color.ohos_id_color_fourth"),
211            radius: $r('app.float.wh_value_20')
212          })
213          .height($r("app.float.wh_value_40"))
214          .width(ConfigData.WH_100_100)
215          .alignItems(VerticalAlign.Center)
216          .backgroundColor($r("sys.color.ohos_id_color_foreground_contrary"));
217        }
218        .height($r("app.float.wh_value_56"))
219        .padding({ top: $r("app.float.wh_value_8"), bottom: $r("app.float.wh_value_8") })
220        .width(ConfigData.WH_100_100)
221        .onClick(() => {
222          LogUtil.info('On click the search editText.');
223          Router.push({
224            uri: 'pages/searchPage'
225          })
226        })
227
228        ListItem() {
229          List() {
230            ListItem(){
231              // WLAN
232              SettingItemComponent({
233                targetPage: "pages/wifi",
234                settingTitle: $r("app.string.wifiTab"),
235                settingEndText: $wifiStatusInfo,
236                settingIcon: "/res/image/wlan.svg",
237              })
238            }
239
240            ListItem(){
241              // blueTooth
242              SettingItemComponent({
243                targetPage: "pages/bluetooth",
244                settingTitle: $r("app.string.bluetoothTab"),
245                settingEndText: $bluetoothStatusInfo,
246                settingIcon: "/res/image/blueTooth.svg",
247              })
248            }
249
250            ListItem(){
251              // mobileData
252              SettingItemComponent({
253                targetPage: "pages/mobileNetwork",
254                settingTitle: $r("app.string.mobileNetwork"),
255                settingEndText:$endTextEmpty,
256                settingIcon: "/res/image/mobileData.svg",
257              })
258            }
259
260            if (this.info === 'true' || VpnTypeModel.getInstance().isSupportVpn()) {
261              ListItem() {
262                // moreConnections
263                SettingItemComponent({
264                  targetPage: "pages/moreConnections",
265                  settingTitle: $r("app.string.moreConnectionsTab"),
266                  settingEndText: $endTextEmpty,
267                  settingIcon: "/res/image/ic_settings_more_connections.svg",
268                })
269              }
270            }
271          }
272          .settingListItemDividerFancy()
273        }
274        .settingListItemFancy()
275
276        ListItem() {
277          // displayAndBrightness
278          SettingItemComponent({
279            targetPage: "pages/screenAndBrightness",
280            settingTitle: $r("app.string.brightnessTab"),
281            settingEndText:$endTextEmpty,
282            settingIcon: "/res/image/displayAndBrightness.svg",
283          })
284        }
285        .settingListItemFancy()
286
287        ListItem() {
288          // volumeControl
289          SettingItemComponent({
290            targetPage: "pages/volumeControl",
291            settingTitle: $r("app.string.volumeControlTab"),
292            settingEndText:$endTextEmpty,
293            settingIcon: "/res/image/volume.svg",
294          })
295        }
296        .settingListItemFancy()
297
298        ListItem() {
299          List() {
300            ListItem(){
301              // biometricsAndPassword
302              SettingItemComponent({
303                targetPage: "pages/passwordSetting",
304                settingTitle: $r("app.string.biometricsAndPassword"),
305                settingEndText:$endTextEmpty,
306                settingIcon: "/res/image/biometricsAndPassword.svg",
307              })
308            }
309
310            ListItem(){
311              // application
312              SettingItemComponent({
313                targetPage: "pages/application",
314                settingTitle: $r("app.string.applyTab"),
315                settingEndText:$endTextEmpty,
316                settingIcon: "/res/image/application.svg",
317              })
318            }
319
320            ListItem(){
321              // storage
322              SettingItemComponent({
323                targetPage: "pages/storage",
324                settingTitle: $r("app.string.storageTab"),
325                settingEndText:$endTextEmpty,
326                settingIcon: "/res/image/storage.svg",
327              })
328            }
329
330            ListItem(){
331              // privacy
332              SettingItemComponent({
333                targetPage: "pages/privacy",
334                settingTitle: $r("app.string.privacy"),
335                settingEndText:$endTextEmpty,
336                settingIcon: "/res/image/privacy.svg",
337              })
338            }
339          }
340          .settingListItemDividerFancy()
341        }
342        .settingListItemFancy()
343
344        ListItem() {
345          // accessibility
346          SettingItemComponent({
347            targetPage: "pages/accessibility",
348            settingTitle: $r("app.string.accessibility"),
349            settingEndText:$endTextEmpty,
350            settingIcon: "/res/image/ic_accessibility.svg",
351          })
352        }
353        .settingListItemFancy()
354
355        ListItem() {
356          List() {
357            ListItem(){
358              // usersAccounts
359              SettingItemComponent({
360                targetPage: "pages/usersAccounts",
361                settingTitle: $r("app.string.usersAccountsTab"),
362                settingEndText:$endTextEmpty,
363                settingIcon: "/res/image/userAccounts.svg",
364              })
365            }
366
367            ListItem(){
368              // system
369              SettingItemComponent({
370                targetPage: "pages/system/homePage",
371                settingTitle: $r("app.string.systemTab"),
372                settingEndText:$endTextEmpty,
373                settingIcon: "/res/image/system.svg",
374              })
375            }
376
377            ListItem(){
378              // aboutDevice
379              SettingItemComponent({
380                targetPage: "pages/aboutDevice",
381                settingTitle: $r("app.string.aboutTab"),
382                settingEndText:$endTextEmpty,
383                settingIcon: "/res/image/aboutDevice.svg",
384              })
385            }
386          }
387          .settingListItemDividerFancy()
388        }
389        .settingListItemFancy()
390      }
391      .scrollBar(BarState.Off)
392      .flexShrink(1)
393      .width(ConfigData.WH_100_100)
394      .alignSelf(ItemAlign.Start);
395    }
396    .width(ConfigData.WH_100_100)
397    .height(ConfigData.WH_100_100)
398  }
399}