1bea4f105Sopenharmony_ci/*
2bea4f105Sopenharmony_ci * Copyright (c) Huawei Technologies Co., Ltd. 2021-2022. All rights reserved.
3bea4f105Sopenharmony_ci */
4bea4f105Sopenharmony_ci
5bea4f105Sopenharmony_ciimport UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession';
6bea4f105Sopenharmony_ciimport common from '@ohos.app.ability.common';
7bea4f105Sopenharmony_ciimport Want from '@ohos.app.ability.Want';
8bea4f105Sopenharmony_ci
9bea4f105Sopenharmony_ciimport { Logger } from '../../common/util/HiLogger'
10bea4f105Sopenharmony_ciimport {  MusicApp } from '../../common/global/globalmodel/GlobalModel';
11bea4f105Sopenharmony_ciimport { createOrGet, globalKeys } from '../../common/global/GlobalThisHelper'
12bea4f105Sopenharmony_ciimport { AudioPickerView } from './AudioPickerView';
13bea4f105Sopenharmony_ci
14bea4f105Sopenharmony_cilet storage = LocalStorage.getShared()
15bea4f105Sopenharmony_ciconst app: MusicApp = createOrGet(MusicApp, globalKeys.app);
16bea4f105Sopenharmony_ciconst logger: Logger = new Logger('AudioPickerExtension')
17bea4f105Sopenharmony_ci
18bea4f105Sopenharmony_ci/**
19bea4f105Sopenharmony_ci * [扩展Ability入口页面文件extension]
20bea4f105Sopenharmony_ci */
21bea4f105Sopenharmony_ci@Entry(storage)
22bea4f105Sopenharmony_ci@Component
23bea4f105Sopenharmony_cistruct AudioPickerExtension {
24bea4f105Sopenharmony_ci  @State isShow: boolean = false
25bea4f105Sopenharmony_ci  private session: UIExtensionContentSession | undefined = storage.get<UIExtensionContentSession>('session');
26bea4f105Sopenharmony_ci  private want: Want | undefined = storage.get<Want>('want');
27bea4f105Sopenharmony_ci  private context = getContext(this) as common.UIAbilityContext;
28bea4f105Sopenharmony_ci
29bea4f105Sopenharmony_ci  aboutToAppear(): void {
30bea4f105Sopenharmony_ci    logger.info('aboutToAppear')
31bea4f105Sopenharmony_ci    app.abilityContext = this.context
32bea4f105Sopenharmony_ci    this.isShow = true
33bea4f105Sopenharmony_ci  }
34bea4f105Sopenharmony_ci
35bea4f105Sopenharmony_ci  aboutToDisappear(): void {
36bea4f105Sopenharmony_ci    storage.clear()
37bea4f105Sopenharmony_ci  }
38bea4f105Sopenharmony_ci
39bea4f105Sopenharmony_ci  /**
40bea4f105Sopenharmony_ci   * 半模态框标题
41bea4f105Sopenharmony_ci   */
42bea4f105Sopenharmony_ci  @Builder
43bea4f105Sopenharmony_ci  titleStyle() {
44bea4f105Sopenharmony_ci    Text($r('app.string.select_audio'))
45bea4f105Sopenharmony_ci      .height(56)
46bea4f105Sopenharmony_ci      .fontSize(20)
47bea4f105Sopenharmony_ci      .fontColor($r('sys.color.ohos_id_color_text_primary'))
48bea4f105Sopenharmony_ci      .fontWeight(FontWeight.Bold)
49bea4f105Sopenharmony_ci  }
50bea4f105Sopenharmony_ci
51bea4f105Sopenharmony_ci  @Builder
52bea4f105Sopenharmony_ci  //装饰器
53bea4f105Sopenharmony_ci  myBuilder() {
54bea4f105Sopenharmony_ci    Column() {
55bea4f105Sopenharmony_ci      AudioPickerView({
56bea4f105Sopenharmony_ci        isShow: $isShow,
57bea4f105Sopenharmony_ci        session: this.session,
58bea4f105Sopenharmony_ci        want: this.want
59bea4f105Sopenharmony_ci      });
60bea4f105Sopenharmony_ci    }
61bea4f105Sopenharmony_ci  }
62bea4f105Sopenharmony_ci
63bea4f105Sopenharmony_ci
64bea4f105Sopenharmony_ci  build() {
65bea4f105Sopenharmony_ci    Row() {
66bea4f105Sopenharmony_ci    }
67bea4f105Sopenharmony_ci    .width('100%')
68bea4f105Sopenharmony_ci    .height('100%')
69bea4f105Sopenharmony_ci    .bindSheet(
70bea4f105Sopenharmony_ci      this.isShow, //是否显示半模态页面
71bea4f105Sopenharmony_ci      this.myBuilder(), //builder:配置半模态页面内容
72bea4f105Sopenharmony_ci      {
73bea4f105Sopenharmony_ci        title: this.titleStyle,
74bea4f105Sopenharmony_ci        height: SheetSize.FIT_CONTENT,
75bea4f105Sopenharmony_ci        dragBar: false, //是否显示控制条,默认显示
76bea4f105Sopenharmony_ci        preferType: SheetType.CENTER,
77bea4f105Sopenharmony_ci        onAppear: () => {
78bea4f105Sopenharmony_ci          logger.info('BindSheet onAppear.') //半模态页面显示回调函数
79bea4f105Sopenharmony_ci        },
80bea4f105Sopenharmony_ci        onDisappear: () => {
81bea4f105Sopenharmony_ci          if (this.session !== undefined) {
82bea4f105Sopenharmony_ci            this.session.sendData({ 'isShowUIExtension': false })
83bea4f105Sopenharmony_ci            this.session.terminateSelf()
84bea4f105Sopenharmony_ci          }
85bea4f105Sopenharmony_ci          logger.info('BindSheet onDisappear.') //半模态页面回退回调函数
86bea4f105Sopenharmony_ci        }
87bea4f105Sopenharmony_ci      })
88bea4f105Sopenharmony_ci  }
89bea4f105Sopenharmony_ci}