• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023-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 router from '@ohos.router';
17import CheckEmptyUtils, { Log } from '@ohos/common';
18import common from '@ohos.app.ability.common';
19import { GlobalThisHelper, GlobalThisStorageKey} from '@ohos/common';
20import { PreferencesKey} from '@ohos/common';
21import PreferencesAdapter from '../Common/Adapter/PreferencesAdapter';
22import {PrivacyStatementDialog} from './PrivacyStatementDialog';
23import {CancelButton} from './component/BaseComponent';
24
25const TAG = 'PrivacyStatementPage';
26
27let storage = LocalStorage.getShared();
28@Entry(storage)
29@Component
30struct PrivacyStatementPage {
31  private readonly PRIVACY_STATEMENT_STORE: string = 'privacyStatementStore';
32  private abilityContext: common.UIAbilityContext | undefined = undefined
33  private dialogController: CustomDialogController = new CustomDialogController({
34    builder: PrivacyStatementDialog(),
35    autoCancel: false,
36    customStyle: true,
37  })
38
39  aboutToAppear() {
40    this.abilityContext = GlobalThisHelper.getValue<common.UIAbilityContext>(GlobalThisStorageKey.KEY_MAIN_ABILITY_CONTEXT)
41  }
42
43  build() {
44    Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) {
45      Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) {
46        Column() {
47          Image($r('app.media.logo'))
48            .width($r('app.float.privacy_statement_print_log_width_height'))
49            .height($r("app.float.privacy_statement_print_log_width_height"))
50            .margin({top: $r('app.float.print_log_margin_top')})
51          Text($r('app.string.welcome'))
52            .margin({ top: $r('app.float.privacy_statement_text_relative_img_margin_top')})
53            .fontColor($r('sys.color.ohos_id_color_text_tertiary'))
54            .fontSize($r('sys.float.ohos_id_text_size_over_line'))
55            .fontWeight(FontWeight.Regular)
56            .height($r('app.float.privacy_statement_text_tertiary_height'))
57          Text($r('app.string.MainAbility_label'))
58            .fontSize($r('sys.float.ohos_id_text_size_headline7'))
59            .fontColor($r('sys.color.ohos_id_color_text_primary'))
60            .fontWeight(FontWeight.Bolder)
61            .height($r('app.float.privacy_statement_text_headline_height'))
62            .margin({top: $r('app.float.privacy_statement_text_relative_text_margin_top')})
63          Text($r('app.string.print_slogan'))
64            .fontColor($r('sys.color.ohos_id_color_text_tertiary'))
65            .fontSize($r('sys.float.ohos_id_text_size_over_line'))
66            .fontWeight(FontWeight.Regular)
67            .margin({top: $r('app.float.privacy_statement_text_relative_text_margin_top')})
68            .height($r('app.float.privacy_statement_text_tertiary_height'))
69        }
70
71        Column() {
72          Image($r('app.media.ic_public_shield'))
73            .width($r('app.float.shield_width_height'))
74            .height($r('app.float.shield_width_height'))
75          Text() {
76            ForEach(this.getPrivacyStatementText(), (privacyStatementText: string) => {
77              if (privacyStatementText === this.abilityContext?.resourceManager.getStringByNameSync('location_information') ||
78                privacyStatementText === this.abilityContext?.resourceManager.getStringByNameSync('print_permission_network')) {
79                Span(privacyStatementText).fontWeight(FontWeight.Bolder)
80              } else {
81                Span(privacyStatementText)
82              }
83            })
84            Span($r('app.string.about_privacy_statement_text'))
85              .onClick(() => {
86                router.replaceUrl({
87                  url: 'pages/PrivacyStatementWebPage',
88                  params: {
89                    info: true
90                  }
91                });
92              })
93              .fontColor($r('sys.color.ohos_id_color_text_hyperlink'))
94              .fontSize($r('sys.float.ohos_id_text_size_body3'))
95            Span('、')
96            Span($r('app.string.permissions_notice'))
97              .fontColor($r('sys.color.ohos_id_color_text_hyperlink'))
98              .fontSize($r('sys.float.ohos_id_text_size_body3'))
99              .onClick(() => {
100                this.dialogController.open();
101              })
102            Span('。')
103          }
104          .fontColor($r('sys.color.ohos_id_color_text_primary'))
105          .fontSize($r('sys.float.ohos_id_text_size_body3'))
106          .margin({
107            top: $r('app.float.privacy_statement_text_relative_img_margin_top'),
108            left: $r('app.float.privacy_statement_text_margin_left_right'),
109            right: $r('app.float.privacy_statement_text_margin_left_right')
110          })
111          Row() {
112            CancelButton({
113              cancelLabel: $r('app.string.Cancel'),
114              cancelWidth: $r('app.float.privacy_statement_button_width'),
115              cancelHeight: $r('app.float.privacy_statement_button_height'),
116              cancelClick: () => {
117                this.abilityContext?.terminateSelf();
118              }
119            })
120            .margin({right: $r('app.float.privacy_statement_button_space')})
121            Button($r('app.string.Agree'))
122              .onClick(() => {
123                this.agreePrivacyStatement();
124                router.replaceUrl({url: 'pages/PrintPage', params: storage});
125              })
126              .width($r('app.float.privacy_statement_button_width'))
127              .height($r('app.float.privacy_statement_button_height'))
128          }
129          .margin({
130              top: $r('app.float.privacy_statement_button_to_text_margin_top'),
131              bottom: $r('app.float.privacy_statement_button_margin_bottom'),
132          })
133        }
134      }
135    }
136    .width('100%')
137    .height('100%')
138  }
139
140  async agreePrivacyStatement() {
141    Log.info(TAG, "agreePrivacyStatement");
142    PreferencesAdapter.getInstance().getOrCreatePreferencesSync(this.PRIVACY_STATEMENT_STORE).then((successGet) => {
143      Log.info(TAG, 'agreePrivacyStatement getOrCreatePreferencesSync successGet: ' + successGet);
144      if (successGet) {
145        PreferencesAdapter.getInstance().putValue(PreferencesKey.KEY_PRIVACY_STATEMENT_PREFERENCES, true).then((successPut) => {
146          Log.info(TAG, 'agreePrivacyStatement putValue successPut: ' + successPut);
147          if (successPut) {
148            PreferencesAdapter.getInstance().flush();
149          }
150        })
151      }
152    });
153  }
154
155  private getPrivacyStatementText() : Array<string> {
156    let privacyStatementTextList = new Array<string>();
157    if (CheckEmptyUtils.isEmpty(this.abilityContext)) {
158      Log.warn(TAG, 'getPrivacyStatementText abilityContext is invalid.');
159      return privacyStatementTextList;
160    }
161    let privacyStatementText = this.abilityContext!.resourceManager.getStringByNameSync('privacy_statement_text');
162    let printPermissionNetwork = this.abilityContext!.resourceManager.getStringByNameSync('print_permission_network');
163    let locationInformation = this.abilityContext!.resourceManager.getStringByNameSync('location_information');
164
165    let privacyStatementTexts = privacyStatementText.split(printPermissionNetwork);
166    privacyStatementTextList.push(privacyStatementTexts[0]);
167    privacyStatementTextList.push(printPermissionNetwork);
168    privacyStatementTexts = privacyStatementTexts[1].split(locationInformation);
169    privacyStatementTextList.push(privacyStatementTexts[0]);
170    privacyStatementTextList.push(locationInformation);
171    privacyStatementTextList.push(privacyStatementTexts[1]);
172    return privacyStatementTextList;
173  }
174}