• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 Log from '../../../../../../../../common/src/main/ets/default/Log';
17import EventManager from '../../../../../../../../common/src/main/ets/default/event/EventManager';
18import iconTitleBase from '../../../../../../../../common/src/main/ets/template/iconTitleBase';
19import { ControlComponentData } from '../common/Constants';
20
21const TAG = 'ComplexToggleComponent';
22
23@Component
24export default struct ComplexToggleComponent {
25  @Prop keyId: string;
26  @State mItemData: ControlComponentData = { };
27  @State mStatus: boolean = false;
28  @State mDefaultTitle: string = '';
29
30  aboutToAppear() {
31    Log.showInfo(TAG, `aboutToAppear Start, keyId: ${this.keyId}`);
32    this.linkItemData();
33  }
34
35  aboutToDisappear() {
36    Log.showInfo(TAG, `aboutToDisappear`);
37  }
38
39  linkItemData() {
40    Log.showDebug(TAG, `linkItemData, keyId: ${this.keyId}`);
41    this.mItemData = AppStorage.Get('ControlCenter_' + this.keyId) as ControlComponentData;
42    Log.showDebug(TAG, `linkItemData, mItemData: ${this.keyId} ${this.mItemData.label} ${this.mItemData.iconUrl}`);
43  }
44
45  build() {
46    Column() {
47      iconTitleBase({
48        useTitleStr: true,
49        mTitle: $mDefaultTitle,
50        mTitleStr: this.mItemData
51        .label,
52        useIconStr: true,
53        iconOffStr: this.mItemData
54        .iconUrl,
55        iconOnStr: this.mItemData
56        .iconUrl,
57        changeSwitch: $mStatus,
58        mClickEvent: (): void => this.onIconItemClick(),
59        mLongClickEvent: (): void => this.onIconItemLongPressGesture()
60      })
61    }.width('100%')
62    .height('100%')
63  }
64
65  onIconItemClick() {
66    Log.showDebug(TAG, `onIconItemClick`);
67    if (this.mItemData?.actionData?.clickAction) {
68      EventManager.publish(this.mItemData.actionData.clickAction);
69    }
70  }
71
72  onIconItemLongPressGesture() {
73    Log.showDebug(TAG, `onIconItemLongPressGesture`);
74    if (this.mItemData?.actionData?.longClickAction) {
75      EventManager.publish(this.mItemData.actionData.longClickAction);
76    }
77  }
78}