1/*
2 * Copyright (c) 2024 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 */
15if (!('finalizeConstruction' in ViewPU.prototype)) {
16  Reflect.set(ViewPU.prototype, 'finalizeConstruction', () => {});
17}
18const TAG = 'AVVolumePanel';
19class AVVolumePanelParameter {
20}
21export class AVVolumePanel extends ViewPU {
22  constructor(p, q, r, s = -1, t = undefined, u) {
23    super(p, r, s, u);
24    if (typeof t === 'function') {
25      this.paramsGenerator_ = t;
26    }
27    this.__volumeLevel = new SynchedPropertySimpleOneWayPU(q.volumeLevel, this, 'volumeLevel');
28    this.__volumeParameter = new SynchedPropertyObjectOneWayPU(q.volumeParameter, this, 'volumeParameter');
29    this.volumeCallback = undefined;
30    this.setInitiallyProvidedValue(q);
31    this.declareWatch('volumeLevel', this.volumeChange);
32    this.finalizeConstruction();
33  }
34  setInitiallyProvidedValue(o) {
35    if (o.volumeLevel === undefined) {
36      this.__volumeLevel.set(0);
37    }
38    if (o.volumeCallback !== undefined) {
39      this.volumeCallback = o.volumeCallback;
40    }
41  }
42  updateStateVars(n) {
43    this.__volumeLevel.reset(n.volumeLevel);
44    this.__volumeParameter.reset(n.volumeParameter);
45  }
46  purgeVariableDependenciesOnElmtId(m) {
47    this.__volumeLevel.purgeDependencyOnElmtId(m);
48    this.__volumeParameter.purgeDependencyOnElmtId(m);
49  }
50  aboutToBeDeleted() {
51    this.__volumeLevel.aboutToBeDeleted();
52    this.__volumeParameter.aboutToBeDeleted();
53    SubscriberManager.Get().delete(this.id__());
54    this.aboutToBeDeletedInternal();
55  }
56  get volumeLevel() {
57    return this.__volumeLevel.get();
58  }
59  set volumeLevel(l) {
60    this.__volumeLevel.set(l);
61  }
62  get volumeParameter() {
63    return this.__volumeParameter.get();
64  }
65  set volumeParameter(k) {
66    this.__volumeParameter.set(k);
67  }
68  volumeChange() {
69    if (this.volumeCallback != null) {
70      console.info(TAG, `volumechange volumeLevel = ` + this.volumeLevel);
71      this.volumeCallback.send({'volume': this.volumeLevel});
72    }
73  }
74  initialRender() {
75    this.observeComponentCreation2((i, j) => {
76      Column.create();
77      Column.size({width: '100%', height: '100%'});
78    }, Column);
79    this.observeComponentCreation2((c, d) => {
80      UIExtensionComponent.create({
81        abilityName: 'AVVolumeExtension',
82        bundleName: 'com.hmos.mediacontroller',
83        parameters: {
84          'volumeParameter': this.volumeParameter,
85          'ability.want.params.uiExtensionType': 'sysPicker/mediaControl',
86        }
87      });
88      UIExtensionComponent.onReceive((h) => {
89        console.info(TAG, `onReceive : ${JSON.stringify(h.state)}`);
90      });
91      UIExtensionComponent.onRemoteReady((g) => {
92        console.info(TAG, `onRemoteReady callback : ${JSON.stringify(g)}`);
93        this.volumeCallback = g;
94      });
95      UIExtensionComponent.size({ width: '100%', height: '100%' });
96    }, UIExtensionComponent);
97    Column.pop();
98  }
99  rerender() {
100    this.updateDirtyElements();
101  }
102}
103export default {AVVolumePanel, AVVolumePanelParameter};
104