• 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 { TintContentInfo } from '../../../../../../../../common/src/main/ets/default/TintStateManager'
18import CheckEmptyUtils from '../../../../../../../../common/src/main/ets/default/CheckEmptyUtils'
19import ViewModel from '../viewmodel/StatusBarVM'
20import StyleConfigurationCommon, { CommonStyle
21} from '../../../../../../../../common/src/main/ets/default/StyleConfiguration'
22import StyleConfiguration, { IconItemComponentStyle } from '../common/StyleConfiguration'
23import { itemData } from "../../../../../../../../common/src/main/ets/plugindatasource/common/Constants"
24
25const TAG = 'MetaIconItemComponent'
26
27@Component
28export default struct MetaIconItemComponent {
29  @Prop keyId: string
30  @State mItemData: itemData = new itemData()
31  @State mTintContentInfo: TintContentInfo = new TintContentInfo()
32  @State style: IconItemComponentStyle = StyleConfiguration.getIconItemComponentStyle()
33  @State styleCommon: CommonStyle = StyleConfigurationCommon.getCommonStyle()
34
35  aboutToAppear() {
36    Log.showInfo(TAG, `aboutToAppear Start, keyId: ${this.keyId}`);
37    this.linkItemData()
38    this.mTintContentInfo = ViewModel.getPluginTintContentInfo(this.keyId)
39  }
40
41  aboutToDisappear() {
42    Log.showInfo(TAG, `aboutToDisappear`);
43  }
44
45  linkItemData() {
46    this.mItemData = AppStorage.Get('StatusBar_' + this.keyId) as itemData;
47    Log.showInfo(TAG, `linkItemData, mItemData: ${this.keyId} ${this.mItemData.label} ${
48    this.mItemData
49    .iconUrl}`)
50  }
51
52  build() {
53    Row() {
54      if ((this.mItemData.isShowLabel && !CheckEmptyUtils.isEmpty(this.mItemData.label))
55      || (this.mItemData.isShowIcon && !CheckEmptyUtils.isEmpty(this.mItemData.iconUrl))) {
56        Row().width(this.styleCommon.statusBarMarginLeftRight).height('100%')
57      }
58      if (this.mItemData.isShowLabel && !CheckEmptyUtils.isEmpty(this.mItemData.label)) {
59        Text(this.mItemData
60        .label)
61          .fontColor(this.mTintContentInfo.contentColor)
62          .fontSize(this.styleCommon.statusBarFontSize)
63          .textAlign(TextAlign.End)
64      }
65      if (this.mItemData.isShowLabel && !CheckEmptyUtils.isEmpty(this.mItemData.label)) {
66        if (this.mItemData.isShowIcon && !CheckEmptyUtils.isEmpty(this.mItemData.iconUrl)) {
67          Row() {
68          }.height(1).width(this.style.componentSpace)
69        }
70      }
71      if (this.mItemData.isShowIcon && !CheckEmptyUtils.isEmpty(this.mItemData.iconUrl)) {
72        Image(this.mItemData
73        .iconUrl)
74          .width(this.style.iconWidth)
75          .height(this.style.iconHeight)
76          .fillColor(this.mTintContentInfo.contentColor)
77          .objectFit(ImageFit.Contain)
78      }
79      if ((this.mItemData.isShowLabel && !CheckEmptyUtils.isEmpty(this.mItemData.label))
80      || (this.mItemData.isShowIcon && !CheckEmptyUtils.isEmpty(this.mItemData.iconUrl))) {
81        Row().width(this.styleCommon.statusBarMarginLeftRight).height('100%')
82      }
83    }.height('100%')
84  }
85}