• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 */
15import AdvancedSettingsController from "./advancedSettingsController";
16import DeviceUtil from "../../../utils/DeviceUtil";
17import { MmsSimpleDialog } from "../../../views/MmsDialogs";
18import { MoreMenu } from "../../../views/MmsMenu";
19import router from "@system.router";
20import { SettingItemJump } from "../../../views/SettingItem";
21import WantUtil from "../../../utils/WantUtil";
22import SettingsController from  "../settingsController"
23
24@Entry
25@Component
26struct AdvancedSettings {
27    @StorageLink("AdvancedSettingsController") @Watch("changeSelectState") mAdvancedSettingsCtrl:
28        AdvancedSettingsController = AdvancedSettingsController.getInstance();
29    @StorageLink("SettingsController") @Watch("changeSelectState") mSettingsCtrl:
30        SettingsController = SettingsController.getInstance()
31    private gridColumns: GridRowColumnOption = { sm: 4, md: 8, lg: 12 };
32    private girdSpan: GridColColumnOption = { sm: 4, md: 6, lg: 8 };
33    private gridColOffset: GridColColumnOption = { md: 1, lg: 2 };
34    private gridGutter: string = "12vp";
35    private dialogGridCount: number = 4;
36    dialogAlignment: DialogAlignment = DeviceUtil.isTablet() ? DialogAlignment.Center : DialogAlignment.Bottom;
37    dialogOffset: Offset = DeviceUtil.isTablet() ? { dx: 0, dy: 0 } : { dx: 0, dy: -16 };
38    private restoreDialog = new MmsSimpleDialog({
39        message: $r("app.string.restore_all_default_settings"),
40        primaryButton: {
41            value: $r("app.string.cancel"),
42            action: () => {
43            }
44        },
45        secondaryButton: {
46            value: $r("app.string.restore"),
47            action: () => {
48                this.mAdvancedSettingsCtrl.restoreSettingPageSwitchValue();
49                this.mSettingsCtrl.restoreSettingsPageSwitchValue();
50            }
51        }
52    });
53    @Provide menuItems: Array<any> = [
54        {
55            value: $r("app.string.restore_default_settings"),
56            action: () => {
57                this.restoreDialog.show();
58            },
59            enabled: true
60        }
61    ];
62    @Provide statusTitle: Resource = this.mAdvancedSettingsCtrl.deliveryReportSwitchInText;
63    changeSelectState(){
64        this.statusTitle = this.mAdvancedSettingsCtrl.deliveryReportSwitchInText
65    }
66    deliveryReportsDialogCtrl: CustomDialogController = new CustomDialogController({
67        builder: DeliveryReportsDialog({
68            cancel: () => {
69                this.mAdvancedSettingsCtrl.cancelRestore();
70            },
71            confirm: (isOnOfSms: boolean, isOnOfMms: boolean) => {
72                this.mAdvancedSettingsCtrl.setRestore(isOnOfSms, isOnOfMms);
73            },
74            isOnOfSms: this.mAdvancedSettingsCtrl.checkedValueOfSms,
75            isOnOfMms: this.mAdvancedSettingsCtrl.checkedValueOfMms
76        }),
77        autoCancel: false,
78        alignment: this.dialogAlignment,
79        offset: this.dialogOffset,
80        gridCount: this.dialogGridCount
81    })
82
83    /**
84     * The function executes after a new instance of the custom component is created and before its build function
85     * is executed.
86     * Allows state variables to be changed in the aboutToAppear function, and these changes will take effect in
87     * subsequent executions of the build function.
88     */
89    aboutToAppear() {
90        this.mAdvancedSettingsCtrl.onInit();
91    }
92    /**
93     * Triggers once when this page is displayed. In scenarios such as routing and application access to the foreground
94     * and background, only customized components modified by @Entry take effect.
95     */
96    onPageShow() {
97        this.mAdvancedSettingsCtrl.onShow();
98        WantUtil.getWant();
99    }
100    /**
101     * Triggers once when this page disappears. In scenarios such as routing and application access to the foreground
102     * and background, only customized components modified by @Entry take effect.
103     */
104    onPageHide() {
105    }
106    /**
107     * Function executes before custom component destructor consumption.
108     * Changing state variables in the aboutToDisappear function is not allowed, especially changes to the @Link
109     * variable may cause unstable application behavior.
110     */
111    aboutToDisappear() {
112    }
113    /**
114     * Triggered when a user clicks the back button. Only the customized component modified by @Entry takes effect.
115     * If true is returned, the page processes the return logic and does not route the page.
116     * If false is returned, the default return logic is used.
117     * If no value is returned, the value is treated as false.
118     */
119    onBackPress() {
120    }
121
122    build() {
123        Column() {
124            // Top Device Title
125            Row() {
126                Image($rawfile("icon/ic_message_back.svg"))
127                    .width($r("app.float.icon_side_length_medium"))
128                    .height($r("app.float.icon_side_length_medium"))
129                    .margin({
130                        left: $r("app.float.action_bar_margin_left")
131                    })
132                    .onClick(() => {
133                        router.back()
134                    })
135
136                Row().width($r("app.float.space_16"))
137
138                Text($r("app.string.advanced"))
139                    .fontSize($r("app.float.action_bar_text_size"))
140                    .fontColor(Color.Black)
141                    .fontWeight(FontWeight.Bold)
142
143                Row().width("100%").flexShrink(1)
144
145                Column() {
146                    MoreMenu()
147                }
148                .margin({ right: $r("app.float.action_bar_margin_right") })
149            }
150            .width("100%")
151            .height($r("app.float.action_bar_height"))
152
153            Scroll() {
154                GridRow({ columns: this.gridColumns, gutter: this.gridGutter }) {
155                    GridCol({ span: this.girdSpan, offset: this.gridColOffset }) {
156                        // All settings
157                        Column({ space: 12 }) {
158                            // Setting items of the first group
159                            Column() {
160                                // Delivery Report
161                                SettingItemJump({
162                                    primaryTitle: $r("app.string.delivery_reports"),
163                                    secondaryTitle: $r("app.string.delivery_reports_hint"),
164                                    showBottomDivider: false,
165                                    OnClick: (event?: ClickEvent) => {
166                                        this.deliveryReportsDialogCtrl.open();
167                                    }
168                                })
169                                // Automatically downloading MMs
170                                SettingItemJump({
171                                    primaryTitle: $r("app.string.auto_retrieve_mms"),
172//                                    statusTitle: this.mAdvancedSettingsCtrl.autoRetrieveMmsSwitchInText,
173                                    visibilityShow: Visibility.None,
174                                    OnClick: (event?: ClickEvent) => {
175                                        this.mAdvancedSettingsCtrl.showAutoRetrieveMmsDialog();
176                                    }
177                                })
178                            }
179                            .width("100%")
180                            .padding({
181                                top: $r("app.float.settings_item_padding_top"),
182                                bottom: $r("app.float.settings_item_padding_bottom"),
183                                left: $r("app.float.settings_item_padding_left"),
184                                right: $r("app.float.settings_item_padding_right")
185                            })
186                            .border({
187                                radius: $r("app.float.settings_items_radius"),
188                                color: $r("sys.color.ohos_id_color_text_field_bg")
189                            })
190                            .backgroundColor($r("sys.color.ohos_id_color_text_field_bg"))
191
192                            // Setting items of the second group
193                            Column() {
194                            }
195                            .width("100%")
196                            .padding({
197                                top: $r("app.float.settings_item_padding_top"),
198                                bottom: $r("app.float.settings_item_padding_bottom"),
199                                left: $r("app.float.settings_item_padding_left"),
200                                right: $r("app.float.settings_item_padding_right")
201                            })
202                            .border({
203                                radius: $r("app.float.settings_items_radius"),
204                                color: $r("sys.color.ohos_id_color_text_field_bg")
205                            })
206                            .backgroundColor($r("sys.color.ohos_id_color_text_field_bg"))
207                            .visibility(Visibility.None)
208
209                            // Setting items of the third group
210                            Column() {
211                                // SMSC
212                                SettingItemJump({
213                                    primaryTitle: $r("app.string.sms_center"),
214                                    showBottomDivider: true,
215                                    OnClick: (event?: ClickEvent) => {
216                                        this.mAdvancedSettingsCtrl.jumpToSmsCenterPage(1);
217                                    }
218                                })
219                                // Managing SIM Card Information
220                                SettingItemJump({
221                                    primaryTitle: $r("app.string.manage_sim_card_messages"),
222                                    OnClick: (event?: ClickEvent) => {
223                                        this.mAdvancedSettingsCtrl.jumpToManageSimPage(1);
224                                    }
225                                })
226                            }
227                            .width("100%")
228                            .padding({
229                                top: $r("app.float.settings_item_padding_top"),
230                                bottom: $r("app.float.settings_item_padding_bottom"),
231                                left: $r("app.float.settings_item_padding_left"),
232                                right: $r("app.float.settings_item_padding_right")
233                            })
234                            .border({
235                                radius: $r("app.float.settings_items_radius"),
236                                color: $r("sys.color.ohos_id_color_text_field_bg")
237                            })
238                            .backgroundColor($r("sys.color.ohos_id_color_text_field_bg"))
239                            .visibility(Visibility.None)
240                        }
241                        .margin({
242                            top: $r("app.float.settings_items_margin_top"),
243                            bottom: $r("app.float.settings_items_margin_bottom")
244                        })
245                    }
246                }
247            }
248            .layoutWeight(1)
249            .align(Alignment.Top)
250        }
251        .width("100%")
252        .height("100%")
253        .padding({ left: $r("app.float.page_padding_left"), right: $r("app.float.page_padding_right") })
254        .backgroundColor($r("sys.color.ohos_id_color_sub_background"))
255    }
256}
257
258/**
259 * Delivery report selection box
260 */
261@CustomDialog
262struct DeliveryReportsDialog {
263    controller: CustomDialogController;
264    cancel: () => void;
265    confirm: (isOnOfSms: boolean, isOnOfMms: boolean) => void;
266    private isOnOfSms: boolean = false;
267    private isOnOfMms: boolean = false;
268
269    build() {
270        Column() {
271            Column() {
272                Text($r("app.string.delivery_reports"))
273                    .width("100%")
274                    .height(56)
275                    .textAlign(TextAlign.Start)
276                    .fontSize(20)
277                    .fontColor($r("sys.color.ohos_id_color_foreground"))
278                    .lineHeight(28)
279                    .fontWeight(FontWeight.Medium)
280                    .fontFamily("HarmonyHeiTi")
281                Flex({
282                    direction: FlexDirection.Row,
283                    justifyContent: FlexAlign.SpaceBetween,
284                    alignItems: ItemAlign.Center
285                }) {
286                    Text($r("app.string.sms"))
287                        .fontSize(16)
288                        .fontColor($r("sys.color.ohos_id_color_foreground"))
289                        .lineHeight(22)
290                        .fontWeight(FontWeight.Medium)
291                        .fontFamily("HarmonyHeiTi")
292                    Toggle({ type: ToggleType.Checkbox, isOn: this.isOnOfSms })
293                        .width(20)
294                        .height(20)
295                        .offset({ x: 16, y: 0 })
296                        .selectedColor($r("sys.color.ohos_id_color_activated"))
297                        .onChange((isOn: boolean) => {
298                            this.isOnOfSms = isOn
299                        })
300                }
301                .width("100%")
302                .height(48)
303
304                Divider()
305                    .vertical(false)
306                    .strokeWidth(0.5)
307                    .width("100%")
308                    .color($r("sys.color.ohos_id_color_list_separator"))
309
310                Flex({
311                    direction: FlexDirection.Row,
312                    justifyContent: FlexAlign.SpaceBetween,
313                    alignItems: ItemAlign.Center
314                }) {
315                    Text($r("app.string.mms"))
316                        .fontSize(16)
317                        .fontColor($r("sys.color.ohos_id_color_foreground"))
318                        .lineHeight(22)
319                        .fontWeight(FontWeight.Medium)
320                        .fontFamily("HarmonyHeiTi")
321                    Toggle({ type: ToggleType.Checkbox, isOn: this.isOnOfMms })
322                        .width(20)
323                        .height(20)
324                        .offset({ x: 16, y: 0 })
325                        .selectedColor($r("sys.color.ohos_id_color_activated"))
326                        .onChange((isOn: boolean) => {
327                            this.isOnOfMms = isOn
328                        })
329                }
330                .width("100%")
331                .height(48)
332
333            }
334            .padding({ left: 24, right: 24, bottom: 9 })
335
336            Flex({
337                direction: FlexDirection.Row,
338                justifyContent: FlexAlign.SpaceEvenly,
339                alignItems: ItemAlign.Center
340            }) {
341                Button() {
342                    Text($r("app.string.cancel"))
343                        .textAlign(TextAlign.Center)
344                        .fontSize(16)
345                        .fontColor($r("sys.color.ohos_id_color_activated"))
346                        .fontWeight(FontWeight.Medium)
347                        .fontFamily("HarmonyHeiTi")
348                        .lineHeight(22)
349                }
350                .backgroundColor($r("sys.color.ohos_id_color_background_transparent"))
351                .layoutWeight(1)
352                .height(40)
353                .onClick(() => {
354                    this.controller.close();
355                    this.cancel();
356                })
357
358                Divider().vertical(true).strokeWidth(0.5).height(24).color($r("sys.color.ohos_id_color_list_separator"))
359                Button() {
360                    Text($r("app.string.ok"))
361                        .textAlign(TextAlign.Center)
362                        .fontSize(16)
363                        .fontColor($r("sys.color.ohos_id_color_activated"))
364                        .fontWeight(FontWeight.Medium)
365                        .fontFamily("HarmonyHeiTi")
366                        .lineHeight(22)
367                }
368                .backgroundColor($r("sys.color.ohos_id_color_background_transparent"))
369                .layoutWeight(1)
370                .height(40)
371                .onClick(() => {
372                    this.controller.close();
373                    this.confirm(this.isOnOfSms, this.isOnOfMms);
374                })
375            }
376            .width("100%")
377            .height(56)
378            .padding({ left: 16, right: 16, bottom: 16 })
379        }
380        .width("100%")
381        .borderRadius(16)  // Customdialog need to set borderRadius
382        .backgroundColor($r("sys.color.ohos_id_color_dialog_bg"))
383    }
384}
385