• 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 Constants from '../common/constant';
17import GlobalContext from '../common/GlobalContext';
18import { directionStatus } from '../common/utils';
19import common from '@ohos.app.ability.common';
20
21const TAG = "[DLPManager_PermStat]";
22
23class Content_ {
24  label: Resource | undefined = undefined
25  value: boolean = false
26}
27
28class TitleContent {
29  title: Resource | undefined = undefined
30  content: Content_[] = []
31}
32
33@Entry
34@Component
35struct PermissionStatus {
36  @State directionStatus: number = 0;
37  @State authPerm: number = Constants.PP_IMAGE_PAD;
38  @State authPermFlag: boolean = false;
39  @State accountId: string = '';
40  private array1: TitleContent[] = [
41    {
42      title: ($r('app.string.perm_list_title_read_only')),
43      content: [
44        {
45          label: ($r('app.string.perm_list_title_read_only')), value: true
46        }
47      ]
48    },
49    {
50      title: ($r('app.string.header_title_edit')),
51      content: [
52        {
53          label: ($r('app.string.save')), value: false
54        },
55        {
56          label: ($r('app.string.save_as')), value: false
57        },
58        {
59          label: ($r('app.string.header_title_edit_content')), value: false
60        },
61        {
62          label: ($r('app.string.screenshot')), value: false
63        },
64        {
65          label: ($r('app.string.share_the_screen')), value: false
66        },
67        {
68          label: ($r('app.string.screen_recording')), value: false
69        },
70        {
71          label: ($r('app.string.duplicate')), value: false
72        },
73      ]
74    },
75    {
76      title: ($r('app.string.perm_list_title_full_control')),
77      content: [
78        {
79          label: ($r('app.string.print')), value: false
80        },
81        {
82          label: ($r('app.string.export')), value: false
83        },
84        {
85          label: ($r('app.string.modifying_the_permissions_of_a_document')), value: false
86        },
87      ]
88    }
89  ];
90  private array2: TitleContent[] = [
91    {
92      title: ($r('app.string.perm_list_title_read_only')),
93      content: [
94        {
95          label: ($r('app.string.perm_list_title_read_only')), value: true
96        }
97      ]
98    },
99    {
100      title: ($r('app.string.header_title_edit')),
101      content: [
102        {
103          label: ($r('app.string.save')), value: true
104        },
105        {
106          label: ($r('app.string.save_as')), value: true
107        },
108        {
109          label: ($r('app.string.header_title_edit_content')), value: true
110        },
111        {
112          label: ($r('app.string.screenshot')), value: true
113        },
114        {
115          label: ($r('app.string.share_the_screen')), value: true
116        },
117        {
118          label: ($r('app.string.screen_recording')), value: true
119        },
120        {
121          label: ($r('app.string.duplicate')), value: true
122        },
123      ]
124    },
125    {
126      title: ($r('app.string.perm_list_title_full_control')),
127      content: [
128        {
129          label: ($r('app.string.print')), value: false
130        },
131        {
132          label: ($r('app.string.export')), value: false
133        },
134        {
135          label: ($r('app.string.modifying_the_permissions_of_a_document')), value: false
136        },
137      ]
138    }
139  ];
140
141  aboutToAppear() {
142    console.info(TAG, 'aboutToAppear');
143    this.authPerm = AppStorage.Get('authPerm') ?? 1;
144    this.accountId = AppStorage.Get('contactAccount') ?? '';
145    this.directionStatus = (GlobalContext
146      .load('context') as common.UIAbilityContext).config.direction ?? -1;
147    directionStatus((counter) => {
148      this.directionStatus = counter;
149    })
150  }
151
152  @Builder itemHead(text?: string | Resource) {
153    Text(text)
154      .fontSize($r('sys.float.ohos_id_text_size_body2'))
155      .width(Constants.HEADER_COLUMN_WIDTH)
156      .height(Constants.HEADER_COLUMN_HEIGHT_READONLY)
157      .fontColor($r('sys.color.ohos_id_color_text_secondary'))
158  }
159
160  build() {
161    GridRow({
162      columns: {
163        xs: Constants.XS_COLUMNS,
164        sm: Constants.SM_COLUMNS,
165        md: Constants.MD_COLUMNS,
166        lg: Constants.LG_COLUMNS
167      },
168      gutter: Constants.DIALOG_GUTTER
169    }) {
170      GridCol({
171        span: {
172          xs: Constants.XS_SPAN,
173          sm: Constants.SM_SPAN,
174          md: Constants.SM_SPAN,
175          lg: Constants.SM_SPAN
176        },
177        offset: {
178          xs: Constants.XS_OFFSET,
179          sm: Constants.SM_OFFSET,
180          md: Constants.LG_OFFSET,
181          lg: Constants.SM_SPAN
182        }
183      }) {
184        Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center,
185          direction: FlexDirection.Column }) {
186          Flex({ alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
187            Column() {
188              Row() {
189                Text($r('app.string.header_title'))
190                  .fontWeight(FontWeight.Medium)
191                  .fontFamily($r('app.string.typeface'))
192                  .fontColor($r('sys.color.ohos_id_color_text_primary'))
193                  .fontSize(Constants.HEADER_TEXT_FRONT_SIZE)
194                  .lineHeight(Constants.HEADER_TEXT_LINE_HEIGHT)
195                  .width(Constants.HEADER_TEXT_WIDTH)
196                  .align(Alignment.Start)
197              }
198              .width(Constants.HEADER_COLUMN_WIDTH)
199              .height(Constants.HEADER_COLUMN_HEIGHT)
200              .padding({
201                left: Constants.HEADER_COLUMN_PADDING_LEFT,
202                right: Constants.HEADER_COLUMN_PADDING_RIGHT
203              })
204
205              Scroll() {
206                Column() {
207                  Row() {
208                    Text(this.authPerm === Constants.FOOTER_OPACITY_ONE ? $r('app.string.permission_status_readOnly') : $r('app.string.permission_status_title'))
209                      .fontWeight(FontWeight.Regular)
210                      .fontColor($r('sys.color.ohos_id_color_text_secondary'))
211                      .fontSize($r('sys.float.ohos_id_text_size_body1'))
212                      .width(Constants.HEADER_TEXT_WIDTH)
213                      .align(Alignment.Start)
214                  }
215                  .width(Constants.HEADER_COLUMN_WIDTH)
216                  .margin({ bottom: Constants.DU_LINE_MARGIN_TOP2 })
217
218                  List() {
219                    ForEach(this.authPerm === Constants.FOOTER_OPACITY_ONE ? this.array1 : this.array2, (item: TitleContent) => {
220                      ListItemGroup({ header: this.itemHead(item.title) }) {
221                        ForEach(item.content, (item: Content_) => {
222                          ListItem() {
223                            Row() {
224                              Text(item.label)
225                                .width(Constants.ENCRYPTION_PERMISSION_STATUS_IMAGE)
226                                .height(Constants.HEADER_COLUMN_HEIGHT_READONLY)
227                                .fontSize($r('sys.float.ohos_id_text_size_body1'))
228                                .textAlign(TextAlign.Start)
229                                .fontWeight(FontWeight.Medium)
230                              Image(item.value ? $r('app.media.ok') : $r('app.media.cancel'))
231                                .width(Constants.PP_IMAGE_WIDTH)
232                                .height(Constants.PP_IMAGE_HEIGHT)
233                                .fillColor($r('sys.color.ohos_id_color_text_primary'))
234                                .opacity(Constants.ENCRYPTION_STATUS_VALUE_COLOR)
235                            }
236                          }
237                        }, (item: Content_) => JSON.stringify(item))
238                      }
239                      .divider({
240                        strokeWidth: Constants.FOOTER_OPACITY_ONE,
241                        color: $r('app.color.encryption_divider_color')
242                      })
243                    })
244                  }
245                }
246              }.constraintSize({
247                maxHeight: this.directionStatus === 0 ? Constants.CHANGE_MAX_HEIGHT : Constants.ENCRYPTION_SUCCESS_MAX_HEIGHT
248              })
249              .padding({
250                left: Constants.HEADER_COLUMN_PADDING_LEFT,
251                right: Constants.HEADER_COLUMN_PADDING_RIGHT
252              })
253
254              Row() {
255                Text($r('app.string.apply_for_the_permission'))
256                  .fontFamily($r('app.string.typeface'))
257                  .fontColor($r('sys.color.ohos_id_color_text_secondary'))
258                  .fontSize($r('sys.float.ohos_id_text_size_body1'))
259                  .align(Alignment.Start)
260                  .fontWeight(FontWeight.Regular)
261                Text(this.accountId)
262                  .fontFamily($r('app.string.typeface'))
263                  .fontColor($r('sys.color.ohos_id_color_text_secondary'))
264                  .fontSize($r('sys.float.ohos_id_text_size_body1'))
265                  .fontWeight(FontWeight.Regular)
266              }
267              .width(Constants.HEADER_COLUMN_WIDTH)
268              .margin({ top: Constants.DA_MARGIN_TOP, bottom: Constants.DU_LINE_MARGIN_TOP2 })
269              .padding({
270                left: Constants.HEADER_COLUMN_PADDING_LEFT,
271                right: Constants.HEADER_COLUMN_PADDING_RIGHT
272              })
273
274              Row() {
275                Button($r('app.string.da_buttion'), { type: ButtonType.Capsule, stateEffect: true })
276                  .backgroundColor($r('app.color.base_button_color'))
277                  .fontColor($r('app.color.encryption_cancel'))
278                  .width(Constants.ENCRYPTION_PERMISSION_STATUS_WIDTH)
279                  .height(Constants.FOOTER_BUTTON_HEIGHT)
280                  .onClick(() => {
281                    (GlobalContext.load('context') as common.UIAbilityContext).terminateSelf()
282                  })
283              }
284              .justifyContent(FlexAlign.Center)
285              .padding({
286                top: Constants.FOOTER_ROW_PAD_LEFT,
287                bottom: Constants.HEADER_COLUMN_PADDING_BOTTOM,
288                left: Constants.FOOTER_ROW_PAD_LEFT,
289                right: Constants.FOOTER_ROW_PAD_RIGHT
290              })
291            }
292            .width(Constants.HEADER_COLUMN_WIDTH)
293            .backgroundColor($r('app.color.da_button_color'))
294            .borderRadius(Constants.INDEX_BORDER_RADIUS)
295          }
296        }
297      }
298    }
299  }
300}
301