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