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 InputMethod from '@ohos.inputMethod';
19import osAccount from '@ohos.account.osAccount';
20import SystemAccountModel, { MAX_LENGTH } from '../model/usersAndAccounts/systemAccountModel';
21import SystemAccountController from '../model/usersAndAccounts/SystemAccountController';
22import LogUtil from '../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil';
23import { TitleText } from '../../../../../../common/component/src/main/ets/default/textComponent';
24import ConfigData from '../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData';
25import HeadComponent from '../../../../../../common/component/src/main/ets/default/headComponent';
26import ResourceUtil from '../../../../../../common/search/src/main/ets/default/common/ResourceUtil';
27import {
28  DialogButtonLayout,
29  DialogButtonLayoutWithState
30} from '../../../../../../common/component/src/main/ets/default/dialogComponent';
31
32const deviceTypeInfo = deviceInfo.deviceType;
33
34class AccountInfo {
35  localId: number = 0;
36  localName: string = '';
37
38  constructor() {
39  }
40}
41
42@Entry
43@Component
44struct MultipleUsers {
45  @StorageLink("isShowAddUser") isShowAddUser: boolean = false;
46  @StorageLink("isShowAddGuest") isShowAddGuest: boolean = false;
47  @StorageLink("systemAccountList") userList: osAccount.OsAccountInfo[] = [];
48  @StorageLink("isShowDelete") isShowDelete: boolean = false;
49  addUserDialogController?: CustomDialogController;
50  waitDialogController?: CustomDialogController;
51
52  handleClickEvent(event: ClickEvent | undefined) {
53    AlertDialog.show({
54      message: $r("app.string.askAddGuest"),
55      primaryButton: {
56        value: $r("app.string.cancel"),
57        action: () => {
58          LogUtil.info("Cancel add guest.");
59        }
60      },
61      secondaryButton: {
62        value: $r("app.string.confirm"),
63        action: () => {
64          LogUtil.info("Confirm add guest user.");
65          if (this.waitDialogController) {
66            this.waitDialogController.open();
67          }
68          SystemAccountController.createQuest((() => {
69            if (this.waitDialogController) {
70              this.waitDialogController.close();
71            }
72          }));
73        }
74      },
75      alignment: deviceTypeInfo === 'phone' || deviceTypeInfo === 'default' ? DialogAlignment.Bottom : DialogAlignment.Center,
76      offset: ({ dx: 0, dy: deviceTypeInfo === 'phone' || deviceTypeInfo === 'default' ? '-24dp' : 0 }),
77      cancel: () => {
78        LogUtil.info("Cancel dialog.");
79      }
80    })
81  }
82
83  build() {
84    Column() {
85      GridContainer({ gutter: ConfigData.GRID_CONTAINER_GUTTER_24, margin: ConfigData.GRID_CONTAINER_MARGIN_24 }) {
86        Column() {
87          Flex({
88            direction: FlexDirection.Column,
89            alignItems: ItemAlign.Center,
90            justifyContent: FlexAlign.SpaceBetween
91          }) {
92            Column() {
93              // head
94              HeadComponent({ headName: $r('app.string.user'), isActive: true });
95
96              // user list
97              List() {
98                ForEach(this.userList, (userItem: osAccount.OsAccountInfo) => {
99                  ListItem() {
100                    UserItem({ user: userItem });
101                  }
102                })
103              }
104              .margin({ top: $r("app.float.distance_14") })
105              .divider({
106                strokeWidth: $r('app.float.divider_wh'),
107                color: $r('sys.color.ohos_id_color_list_separator'),
108                startMargin: $r('app.float.wh_value_20'),
109                endMargin: $r('app.float.wh_value_20')
110              })
111              .borderRadius($r("app.float.radius_24"))
112              .backgroundColor($r("sys.color.ohos_id_color_foreground_contrary"))
113              .visibility(this.userList.length > 0 ? Visibility.Visible : Visibility.None)
114
115              // Add user, shown when is administrator
116              if (this.isShowAddUser) {
117                TitleText({
118                  title: $r("app.string.addUser"),
119                  color: $r("app.color.font_color_007DFF"),
120                  visible: this.isShowAddUser ? Visibility.Visible : Visibility.None,
121                  clickEvent: (event => {
122                    LogUtil.info("Add user.");
123                    if (this.addUserDialogController) {
124                      this.addUserDialogController.open();
125                    }
126                  })
127                })
128              }
129
130              /**
131               * Add guest, shown with conditions:
132               * 1. Current user is administrator
133               * 2. Guest is not created.
134               */
135              if (this.isShowAddGuest) {
136                TitleText({
137                  title: $r("app.string.addGuest"),
138                  color: $r("app.color.font_color_007DFF"),
139                  visible: this.isShowAddGuest ? Visibility.Visible : Visibility.None,
140                  clickEvent: (event: ClickEvent | undefined): void => {
141                    this.handleClickEvent(event);
142                  },
143                })
144              }
145            }
146            .backgroundColor($r("sys.color.ohos_id_color_sub_background"))
147            .height(ConfigData.WH_90_100)
148            .alignItems(HorizontalAlign.Start)
149
150            if (this.isShowDelete) {
151              Column() {
152                Image($r("app.media.ic_delete"))
153                  .height($r("app.float.wh_value_40"))
154                  .width($r("app.float.wh_value_40"))
155                  .fillColor($r("sys.color.ohos_id_color_primary"))
156                  .margin({ top: $r("app.float.wh_value_20"), bottom: $r("app.float.wh_value_10") })
157
158                Text($r("app.string.deleteButton"))
159                  .fontSize($r("app.float.font_20"))
160                  .fontColor($r("app.color.font_color_182431"))
161                  .margin({ bottom: $r("app.float.wh_value_10") })
162              }
163              .width(ConfigData.WH_100_100)
164              .alignItems(HorizontalAlign.Center)
165              .onClick(() => {
166                AlertDialog.show({
167                  message: $r("app.string.deleteUserWarn"),
168                  primaryButton: {
169                    value: $r("app.string.cancel"),
170                    action: () => {
171                      LogUtil.info("Cancel delete user.");
172                    }
173                  },
174                  secondaryButton: {
175                    value: $r("app.string.deleteButton"),
176                    action: () => {
177                      LogUtil.info("Confirm delete user.");
178                      SystemAccountController.removeAccount();
179                    }
180                  },
181                  alignment: deviceTypeInfo === 'phone' || deviceTypeInfo === 'default' ? DialogAlignment.Bottom : DialogAlignment.Center,
182                  offset: ({ dx: 0, dy: deviceTypeInfo === 'phone' || deviceTypeInfo === 'default' ? '-24dp' : 0 })
183                });
184              })
185            }
186          }
187        }
188        .useSizeType({
189          sm: { span: 4, offset: 0 },
190          md: { span: 6, offset: 1 },
191          lg: { span: 8, offset: 2 }
192        })
193      }
194      .width(ConfigData.WH_100_100)
195      .height(ConfigData.WH_100_100)
196    }
197    .backgroundColor($r("sys.color.ohos_id_color_sub_background"))
198    .width(ConfigData.WH_100_100)
199    .height(ConfigData.WH_100_100)
200  }
201
202  onConfirm(localName: string) {
203    LogUtil.info("Open creating wait dialog");
204    if (this.waitDialogController) {
205      this.waitDialogController.open();
206    }
207    SystemAccountController.createSystemAccount(localName, (() => {
208      if (this.waitDialogController) {
209        this.waitDialogController.close();
210      }
211      AlertDialog.show({
212        message: $r("app.string.askSwitchUser"),
213        primaryButton: {
214          value: $r("app.string.cancel"),
215          action: () => {
216            LogUtil.info("Cancel switch to new user.");
217          }
218        },
219        secondaryButton: {
220          value: $r("app.string.switchButton"),
221          action: () => {
222            LogUtil.info("Confirm switch to new user.");
223            SystemAccountController.switchToCreatedAccount();
224          }
225        },
226        alignment: deviceTypeInfo === 'phone' || deviceTypeInfo === 'default' ? DialogAlignment.Bottom : DialogAlignment.Center,
227        offset: ({ dx: 0, dy: deviceTypeInfo === 'phone' || deviceTypeInfo === 'default' ? '-24dp' : 0 }),
228        cancel: () => {
229          LogUtil.info("Cancel dialog.");
230        }
231      })
232    }));
233  }
234
235  onPageShow() {
236    LogUtil.info("Multiple user list about to appear.")
237    this.addUserDialogController = new CustomDialogController({
238      builder: AddUserDialog({
239        controller: this.addUserDialogController,
240        account: new AccountInfo(),
241        confirm: (localName: string): void => {
242          this.onConfirm(localName);
243        },
244      }),
245      alignment: deviceTypeInfo === 'phone' || deviceTypeInfo === 'default' ? DialogAlignment.Bottom : DialogAlignment.Center,
246      offset: ({ dx: 0, dy: deviceTypeInfo === 'phone' || deviceTypeInfo === 'default' ? '-24dp' : 0 }),
247      autoCancel: true
248    });
249    this.waitDialogController = new CustomDialogController({
250      builder: WaitDialog({ controller: this.waitDialogController, content: $r("app.string.isCreatingUser") }),
251      autoCancel: false,
252      alignment: deviceTypeInfo === 'phone' || deviceTypeInfo === 'default' ? DialogAlignment.Bottom : DialogAlignment.Center,
253      offset: ({ dx: 0, dy: deviceTypeInfo === 'phone' || deviceTypeInfo === 'default' ? '-24dp' : 0 }),
254    });
255    SystemAccountController.refreshSystemAccountList();
256    LogUtil.info("after appear.");
257  }
258
259  onPageHide() {
260    this.addUserDialogController = undefined;
261    this.waitDialogController = undefined;
262  }
263
264  aboutToDisappear() {
265    LogUtil.info('multiple user about to disappear.');
266    AppStorage.SetOrCreate("systemAccountList", []);
267  }
268
269  onBackPress() {
270    LogUtil.info('settings MultipleUsers onBackPress');
271  }
272}
273
274@Component
275struct UserItem {
276  @State isTouched: boolean = false;
277  dialogController?: CustomDialogController;
278  private user: osAccount.OsAccountInfo | null = null;
279
280  aboutToAppear(): void {
281    this.dialogController = new CustomDialogController({
282      builder: UserItemDialog({ dialogController: this.dialogController, user: this.user }),
283      autoCancel: false,
284      alignment: deviceTypeInfo === 'phone' || deviceTypeInfo === 'default' ? DialogAlignment.Bottom : DialogAlignment.Center,
285      offset: ({ dx: 0, dy: deviceTypeInfo === 'phone' || deviceTypeInfo === 'default' ? '-24dp' : 0 })
286    });
287  }
288
289  aboutToDisappear(): void {
290    this.dialogController = undefined;
291  }
292
293  build() {
294    Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
295      Row() {
296        Image("/res/image/ic_user_portrait.svg")
297          .width($r("app.float.wh_value_40"))
298          .height($r("app.float.wh_value_40"))
299          .margin({ left: $r("app.float.wh_value_12"), right: $r("app.float.wh_value_12") })
300
301        Column() {
302          Text(this.user?.localName)
303            .fontSize($r("app.float.font_16"))
304            .fontWeight(FontWeight.Medium)
305            .fontSize($r('sys.float.ohos_id_text_size_body1'))
306            .margin({ bottom: $r('sys.float.ohos_id_text_margin_vertical') })
307
308          if (SystemAccountController.isShowIdentity(this.user)) {
309            Text(SystemAccountModel.getIdentityFromMap(this.user?.type))
310              .fontSize($r('sys.float.ohos_id_text_size_body2'))
311              .fontWeight(FontWeight.Regular)
312              .fontColor($r('sys.color.ohos_id_color_text_secondary'))
313          }
314        }
315        .alignItems(HorizontalAlign.Start)
316      }
317
318      Image($r("app.media.ic_settings_arrow"))
319        .width($r("app.float.wh_value_12"))
320        .height($r("app.float.wh_value_24"))
321        .margin({ right: $r("app.float.distance_11") })
322        .fillColor($r("sys.color.ohos_id_color_primary"))
323        .opacity($r("app.float.opacity_0_2"))
324    }
325    .height($r("app.float.wh_value_80"))
326    .onClick((event) => {
327      LogUtil.info("Click the multiple user item.");
328      if (SystemAccountController.isCurrentAdministrator() ||
329        SystemAccountController.isCurrentUser(this.user) && !SystemAccountController.isGuestAccount(this.user)) {
330        if (this.dialogController) {
331          this.dialogController.open();
332        }
333        return;
334      }
335      if (!SystemAccountController.isCurrentQuest() || !SystemAccountController.isGuestAccount(this.user)) {
336        AlertDialog.show({
337          message: $r("app.string.switchUser"),
338          primaryButton: {
339            value: $r("app.string.cancel"),
340            action: () => {
341              LogUtil.info("Cancel switch to user.");
342            }
343          },
344          secondaryButton: {
345            value: $r("app.string.confirm"),
346            action: () => {
347              if (this.user) {
348                SystemAccountController.switchUser(this.user?.localId);
349              }
350            }
351          },
352          alignment: deviceTypeInfo === 'phone' || deviceTypeInfo === 'default' ? DialogAlignment.Bottom : DialogAlignment.Center,
353          offset: ({ dx: 0, dy: deviceTypeInfo === 'phone' || deviceTypeInfo === 'default' ? '-24dp' : 0 })
354        });
355      }
356    })
357    .borderRadius($r('app.float.radius_20'))
358    .linearGradient(this.isTouched ? {
359      angle: 90,
360      direction: GradientDirection.Right,
361      colors: [[$r("app.color.DCEAF9"), 0.0], [$r("app.color.FAFAFA"), 1.0]]
362    } : {
363      angle: 90,
364      direction: GradientDirection.Right,
365      colors: [[$r("sys.color.ohos_id_color_foreground_contrary"), 1], [$r("sys.color.ohos_id_color_foreground_contrary"), 1]]
366    })
367    .onTouch((event?: TouchEvent | undefined) => {
368      if (event?.type === TouchType.Down) {
369        this.isTouched = true;
370      }
371
372      if (event?.type === TouchType.Up) {
373        this.isTouched = false;
374      }
375    });
376  }
377}
378
379// Current user item dialog, allow user to set user name and profile image.
380@CustomDialog
381struct UserItemDialog {
382  private user: osAccount.OsAccountInfo | null = null;
383  private dialogController?: CustomDialogController;
384
385  build() {
386    if (SystemAccountController.isCurrentUser(this.user)) {
387      CurrentDialogBuilder({
388        controller: this.dialogController,
389        user: this.user
390      });
391    } else {
392      UserDialogBuilder({
393        controller: this.dialogController,
394        user: this.user
395      });
396    }
397  }
398}
399
400@Component
401struct CurrentDialogBuilder {
402  private controller: CustomDialogController | null = null;
403  private user: AccountInfo | null = null;
404  private tempName: string = '';
405
406  build() {
407    Column() {
408      Image("/res/image/ic_user_portrait.svg")
409        .width($r("app.float.wh_value_40"))
410        .height($r("app.float.wh_value_40"))
411        .margin({ top: $r("app.float.wh_value_24"), bottom: $r("app.float.wh_value_13") })
412        .onClick((event: ClickEvent | undefined) => {
413          LogUtil.info("Click to modify user image.")
414          let chooseImageDialog = new CustomDialogController({
415            builder: ChooseImageDialog(),
416            alignment: deviceTypeInfo === 'phone' || deviceTypeInfo === 'default' ? DialogAlignment.Bottom : DialogAlignment.Center,
417            offset: ({ dx: 0, dy: deviceTypeInfo === 'phone' || deviceTypeInfo === 'default' ? '-24dp' : 0 })
418          });
419          chooseImageDialog.open();
420        })
421
422      Text($r("app.string.addUserImage"))
423        .fontFamily('HarmonyHeiTi')
424        .fontSize($r("app.float.font_16"))
425        .height($r("app.float.wh_value_22"))
426        .fontColor($r("sys.color.ohos_id_color_primary"))
427        .fontWeight(FontWeight.Medium)
428        .margin({ bottom: $r("app.float.wh_value_8") })
429
430      TextInput({ text: this.user?.localName })
431        .placeholderColor($r("app.color.font_color_182431"))
432        .placeholderFont({
433          size: $r("app.float.font_16"),
434          weight: FontWeight.Regular,
435          style: FontStyle.Normal
436        })
437        .width(ConfigData.WH_100_100)
438        .height($r("app.float.wh_value_48"))
439        .borderRadius($r("app.float.search_input_border_radius"))
440        .maxLength(MAX_LENGTH)
441        .padding({ left: $r("app.float.wh_value_12"), right: $r("app.float.wh_value_12") })
442        .backgroundColor($r('app.color.color_00000000_transparent'))
443        .onChange((value: string) => {
444          LogUtil.info("Set current account name, name: " + value);
445          this.tempName = value;
446        })
447        .onSubmit((enterKey) => {
448          InputMethod.getInputMethodController().stopInput()
449            .then((ret) => {
450              LogUtil.debug(`${ConfigData.TAG}, enterType: ${enterKey}, stopInput: ${ret}`);
451            });
452        })
453
454      Divider()
455        .margin({
456          left: $r("app.float.wh_value_12"),
457          right: $r("app.float.wh_value_12"),
458          bottom: $r("app.float.distance_9")
459        })
460        .color($r("sys.color.ohos_id_color_list_separator"))
461
462      DialogButtonLayout({
463        firstClickEvent: () => {
464          LogUtil.info("Cancel current user modify dialog.");
465          this.controller?.close();
466        },
467        secondClickEvent: () => {
468          LogUtil.info("Confirm current user modify dialog.");
469          this.controller?.close();
470          if (this.user?.localId) {
471            SystemAccountController.setAccountName(this.user.localId, this.tempName);
472          }
473        }
474      })
475    }
476    .padding({ left: $r("app.float.wh_value_12"), right: $r("app.float.wh_value_12") })
477    .borderRadius('24vp')
478    .height('220vp')
479  }
480}
481
482// Current user item dialog, allow user to set user name and profile image.
483@Component
484struct UserDialogBuilder {
485  waitController?: CustomDialogController;
486  private controller: CustomDialogController | null = null;
487  private user: osAccount.OsAccountInfo | null = null;
488
489  aboutToAppear(): void {
490    this.waitController = new CustomDialogController({
491      builder: WaitDialog({
492        controller: this.waitController,
493        content: $r("app.string.isRemoving")
494      }),
495      alignment: deviceTypeInfo === 'phone' || deviceTypeInfo === 'default' ? DialogAlignment.Bottom : DialogAlignment.Center,
496      offset: ({ dx: 0, dy: deviceTypeInfo === 'phone' || deviceTypeInfo === 'default' ? '-24dp' : 0 }),
497      autoCancel: false
498    });
499  }
500
501  aboutToDisappear(): void {
502    this.waitController = undefined;
503  }
504
505  build() {
506    Column() {
507      Text(this.user?.localName)
508        .fontSize($r("app.float.font_20"))
509        .fontWeight(FontWeight.Medium)
510        .fontColor($r("app.color.font_color_182431"))
511        .height($r("app.float.wh_value_56"))
512
513      Text($r("app.string.switchUser"))
514        .fontSize($r("app.float.font_16"))
515        .fontColor($r("app.color.font_color_182431"))
516        .height($r("app.float.wh_value_48"))
517        .width(ConfigData.WH_100_100)
518        .textAlign(TextAlign.Start)
519        .onClick((event) => {
520          this.controller?.close();
521          if (this.user) {
522            SystemAccountController.switchUser(this.user?.localId);
523          }
524        })
525
526      Divider()
527        .color($r("sys.color.ohos_id_color_list_separator"))
528
529      Text($r("app.string.removeUser"))
530        .fontSize($r("app.float.font_16"))
531        .fontColor($r("app.color.font_color_182431"))
532        .height($r("app.float.wh_value_48"))
533        .width(ConfigData.WH_100_100)
534        .textAlign(TextAlign.Start)
535        .onClick(() => {
536          AlertDialog.show({
537            message: $r("app.string.deleteUserWarn"),
538            primaryButton: {
539              value: $r("app.string.cancel"),
540              action: () => {
541                LogUtil.info("Cancel delete user.");
542              }
543            },
544            secondaryButton: {
545              value: $r("app.string.deleteButton"),
546              action: () => {
547                LogUtil.info("Confirm delete user.");
548                if (this.waitController) {
549                  this.waitController.open();
550                }
551                SystemAccountController.removeAccount(this.user?.localId, () => {
552                  if (this.waitController) {
553                    this.waitController.close();
554                  }
555                });
556              }
557            },
558            alignment: deviceTypeInfo === 'phone' || deviceTypeInfo === 'default' ? DialogAlignment.Bottom : DialogAlignment.Center,
559            offset: ({ dx: 0, dy: deviceTypeInfo === 'phone' || deviceTypeInfo === 'default' ? '-24dp' : 0 })
560          });
561          this.controller?.close();
562        })
563
564      Button($r("app.string.cancel"))
565        .fontSize($r("app.float.font_16"))
566        .fontColor($r("app.color.font_color_182431"))
567        .backgroundColor(Color.White)
568        .margin({ top: $r("app.float.wh_value_16"), bottom: $r("app.float.wh_value_16") })
569        .width(ConfigData.WH_100_100)
570        .onClick(() => {
571          LogUtil.info("Cancel user operation dialog.");
572          this.controller?.close();
573        })
574    }
575    .alignItems(HorizontalAlign.Start)
576    .margin({ left: $r("app.float.wh_value_24"), right: $r("app.float.wh_value_24") })
577  }
578}
579
580@CustomDialog
581struct AddUserDialog {
582  @State buttonState: boolean = false;
583  @State hintText: string = '';
584  @State isWarn: boolean = false;
585  private controller?: CustomDialogController;
586  private account: AccountInfo = new AccountInfo();
587
588  build() {
589    Column() {
590      Text($r("app.string.addNewUser"))
591        .fontSize($r("app.float.font_20"))
592        .fontWeight(FontWeight.Medium)
593        .fontColor($r("sys.color.ohos_id_color_primary"))
594        .height($r("app.float.wh_value_56"))
595        .width(ConfigData.WH_100_100)
596        .textAlign(TextAlign.Start)
597        .padding({ right: $r("app.float.wh_value_12"), left: $r("app.float.wh_value_12") })
598
599      Image("/res/image/ic_user_camera.svg")
600        .width($r("app.float.wh_value_40"))
601        .height($r("app.float.wh_value_40"))
602        .margin({ bottom: $r("app.float.wh_value_32") })
603
604      TextInput({ placeholder: this.hintText })
605        .placeholderFont({ size: $r("app.float.font_16") })
606        .placeholderColor($r("app.color.font_color_182431"))
607        .borderRadius($r("app.float.search_input_border_radius"))
608        .maxLength(MAX_LENGTH)
609        .width(ConfigData.WH_100_100)
610        .padding({ left: $r("app.float.wh_value_12"), right: $r("app.float.wh_value_12") })
611        .borderRadius(0)
612        .backgroundColor($r('app.color.color_00000000_transparent'))
613        .onChange((value: string) => {
614          LogUtil.info("Set the user name: " + value);
615          this.account.localName = value;
616          this.isWarn = SystemAccountController.isAlreadyCreated(value);
617          this.buttonState = value != "" && !this.isWarn;
618          LogUtil.info("Set the user name, name: " + this.account.localName);
619        })
620        .onSubmit((enterKey) => {
621          InputMethod.getInputMethodController().stopInput()
622            .then((ret) => {
623              LogUtil.debug(`${ConfigData.TAG}, enterType: ${enterKey}, stopInput: ${ret}`);
624            });
625        })
626
627      Divider()
628        .margin({ right: $r("app.float.wh_value_12"), left: $r("app.float.wh_value_12") })
629        .color($r("sys.color.ohos_id_color_list_separator"))
630
631      if (this.isWarn) {
632        Text($r("app.string.userCreatedWarn"))
633          .fontSize($r("app.float.font_14"))
634          .fontColor($r("sys.color.ohos_id_color_primary"))
635          .width(ConfigData.WH_100_100)
636          .textAlign(TextAlign.Start)
637          .margin({
638            top: $r("app.float.wh_value_8"),
639            bottom: $r("app.float.wh_value_18"),
640            left: $r("app.float.wh_value_12")
641          })
642      } else {
643        Text($r("app.string.addUserDescription"))
644          .fontSize($r("app.float.font_16"))
645          .fontColor($r("app.color.font_color_182431"))
646          .fontWeight(500)
647          .width(ConfigData.WH_100_100)
648          .textAlign(TextAlign.Start)
649          .padding({
650            top: $r("app.float.wh_value_8"),
651            bottom: $r("app.float.distance_9"),
652            left: $r("app.float.wh_value_12")
653          })
654      }
655
656      DialogButtonLayoutWithState({
657        firstClickEvent: () => {
658          LogUtil.info("Cancel add new user.");
659          this.controller?.close();
660        },
661        secondClickEvent: () => {
662          LogUtil.info("Confirm Add new user.");
663          this.controller?.close();
664          this.confirm(this.account.localName);
665        },
666        secondButtonState: this.buttonState
667      })
668    }
669    .borderRadius($r("app.float.wh_value_24"))
670    .height($r("app.float.wh_value_260"))
671    .margin({ left: $r("app.float.wh_value_12"), right: $r("app.float.wh_value_12") })
672  }
673
674  aboutToAppear() {
675    ResourceUtil.getString($r("app.string.nickname"))
676      .then(value => this.hintText = value);
677  }
678
679  private confirm: (localName: string) => void = () => {
680  };
681}
682
683@CustomDialog
684struct ChooseImageDialog {
685  private controller?: CustomDialogController;
686
687  build() {
688    Column() {
689      Text($r("app.string.takePhoto"))
690        .fontSize($r("app.float.font_24"))
691        .fontColor($r("app.color.font_color_182431"))
692        .onClick(() => {
693          router.push({ uri: "" });
694        })
695
696      Text($r("app.string.chooseFromShop"))
697        .fontSize($r("app.float.font_16"))
698        .fontColor($r("app.color.font_color_182431"))
699        .onClick(() => {
700          router.push({ uri: "" })
701        })
702    }
703  }
704}
705
706@CustomDialog
707struct WaitDialog {
708  private controller?: CustomDialogController;
709  private content: string | Resource = '';
710
711  build() {
712    Row() {
713      Text(this.content)
714        .fontSize($r("app.float.font_16"))
715        .fontColor($r("app.color.font_color_182431"))
716        .height($r("app.float.wh_value_48"))
717        .width(ConfigData.WH_100_100)
718        .textAlign(TextAlign.Start)
719        .fontWeight(FontWeight.Medium)
720        .padding({
721          top: $r("app.float.distance_8"),
722          bottom: $r("app.float.distance_8")
723        })
724    }
725    .alignItems(VerticalAlign.Center)
726    .height($r("app.float.wh_value_80"))
727    .padding({
728      left: $r("app.float.distance_24"),
729      right: $r("app.float.distance_24")
730    })
731  }
732}
733