• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * Copyright (c) 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 { ArrayUtil } from '../../../../../../common/src/main/ets/util/ArrayUtil';
17import { DataItemType } from '../../../../../../feature/contact/src/main/ets/contract/DataType';
18import StringFormatUtil from '../../util/StringFormatUtil'
19import { Birthday } from '../../../../../../feature/contact/src/main/ets/contract/Birthday';
20
21@Component
22export default struct DetailInfoList {
23  private dataType: DataItemType;
24  private List: string;
25  private hasArrow: boolean;
26
27  build() {
28    Column() {
29      if (!ArrayUtil.isEmpty(JSON.parse(this.List))) {
30        Divider()
31          .color($r("sys.color.ohos_id_color_list_separator"))
32        List() {
33          ForEach(JSON.parse(this.List), (item, index) => {
34            ListItem() {
35              DetailInfoListItem({
36                title: this.dataType == DataItemType.EVENT ? StringFormatUtil.stringFormatDateResource(item.data, item?.type == Birthday.TYPE_LUNARBIRTHDAY) : item.data,
37                content: item.labelName,
38                hasArrow: this.hasArrow,
39              });
40            }
41          }, item => JSON.stringify(item))
42        }
43        .divider({ strokeWidth: $r("app.float.id_divide_width"), color: $r("sys.color.ohos_id_color_list_separator") })
44      }
45    }
46    .width("100%")
47  }
48}
49
50@Component
51struct DetailInfoListItem {
52  private title: string;
53  private content: string;
54  private hasArrow: boolean;
55
56  build() {
57    Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) {
58      Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Start }) {
59        Text(this.title)
60          .fontSize($r("sys.float.ohos_id_text_size_body1"))
61          .fontColor($r("sys.color.ohos_id_color_text_primary"))
62          .fontWeight(FontWeight.Medium)
63          .textOverflow({ overflow: TextOverflow.Ellipsis })
64          .maxLines(2)
65        Text(this.content)
66          .fontSize($r("sys.float.ohos_id_text_size_body2"))
67          .fontColor($r("sys.color.ohos_id_color_text_tertiary"))
68          .fontWeight(FontWeight.Regular)
69          .margin({ top: $r("app.float.id_card_margin_sm") })
70      }
71      .flexShrink(1)
72
73      Row() {
74        Image($r('app.media.ic_arrow_right_grey'))
75          .align(Alignment.Center)
76          .width($r("app.float.id_card_image_xs"))
77          .height($r("app.float.id_card_image_small"))
78          .visibility(this.hasArrow ? Visibility.Visible : Visibility.Hidden)
79          .opacity(0.2)
80      }
81      .flexShrink(0)
82    }
83    .width('100%')
84    .height($r("app.float.id_item_height_max"))
85  }
86}