1c41cb6d2Sopenharmony_ci/**
2c41cb6d2Sopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3c41cb6d2Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4c41cb6d2Sopenharmony_ci * you may not use this file except in compliance with the License.
5c41cb6d2Sopenharmony_ci * You may obtain a copy of the License at
6c41cb6d2Sopenharmony_ci *
7c41cb6d2Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8c41cb6d2Sopenharmony_ci *
9c41cb6d2Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10c41cb6d2Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11c41cb6d2Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12c41cb6d2Sopenharmony_ci * See the License for the specific language governing permissions and
13c41cb6d2Sopenharmony_ci * limitations under the License.
14c41cb6d2Sopenharmony_ci */
15c41cb6d2Sopenharmony_ci
16c41cb6d2Sopenharmony_ciimport ComponentConfig from './ComponentConfig';
17c41cb6d2Sopenharmony_ciimport ConfigData from '../../../../../utils/src/main/ets/default/baseUtil/ConfigData';
18c41cb6d2Sopenharmony_ci
19c41cb6d2Sopenharmony_ci/**
20c41cb6d2Sopenharmony_ci * item custom component
21c41cb6d2Sopenharmony_ci */
22c41cb6d2Sopenharmony_ci@Component
23c41cb6d2Sopenharmony_ciexport default struct EntryComponent {
24c41cb6d2Sopenharmony_ci  @State isShow: Boolean = true;
25c41cb6d2Sopenharmony_ci  @State settingIcon: string = "";
26c41cb6d2Sopenharmony_ci  @State endTextIsShow: Boolean = true;
27c41cb6d2Sopenharmony_ci  @State settingSummary: string = '';
28c41cb6d2Sopenharmony_ci  @State settingValue: string = "";
29c41cb6d2Sopenharmony_ci  @State settingArrow: string = '';
30c41cb6d2Sopenharmony_ci  @State settingArrowStyle: string = "";
31c41cb6d2Sopenharmony_ci  @State titleFontColor: Resource = $r('sys.color.ohos_id_color_text_primary');
32c41cb6d2Sopenharmony_ci  @State isTouched: boolean = false;
33c41cb6d2Sopenharmony_ci  private settingTitle: string | Resource = '';
34c41cb6d2Sopenharmony_ci  private settingUri: string = '';
35c41cb6d2Sopenharmony_ci  private isEnabled: boolean = true;
36c41cb6d2Sopenharmony_ci  private onArrowClick?: () => void;
37c41cb6d2Sopenharmony_ci  private heights ? = $r('app.float.wh_value_70');
38c41cb6d2Sopenharmony_ci  private image_wh ? = $r('app.float.wh_value_50');
39c41cb6d2Sopenharmony_ci  private fontSize ? = $r('sys.float.ohos_id_text_size_body1');
40c41cb6d2Sopenharmony_ci  private valueFontSize ? = $r('sys.float.ohos_id_text_size_body2');
41c41cb6d2Sopenharmony_ci
42c41cb6d2Sopenharmony_ci  build() {
43c41cb6d2Sopenharmony_ci    Row() {
44c41cb6d2Sopenharmony_ci      Row() {
45c41cb6d2Sopenharmony_ci        Image(this.settingIcon)
46c41cb6d2Sopenharmony_ci          .width(this.image_wh as Length)
47c41cb6d2Sopenharmony_ci          .height(this.image_wh as Length)
48c41cb6d2Sopenharmony_ci          .margin({ right: $r('app.float.wh_10') })
49c41cb6d2Sopenharmony_ci          .visibility('' === this.settingIcon ? Visibility.None : Visibility.Visible)
50c41cb6d2Sopenharmony_ci          .objectFit(ImageFit.Contain)
51c41cb6d2Sopenharmony_ci          .fillColor($r("sys.color.ohos_id_color_primary"))
52c41cb6d2Sopenharmony_ci        Column() {
53c41cb6d2Sopenharmony_ci          Text(this.settingTitle)
54c41cb6d2Sopenharmony_ci            .fontColor(this.isEnabled ? this.titleFontColor : $r("sys.color.ohos_id_color_primary"))
55c41cb6d2Sopenharmony_ci            .fontSize(this.fontSize as (number | string | Resource))
56c41cb6d2Sopenharmony_ci            .textAlign(TextAlign.Start)
57c41cb6d2Sopenharmony_ci            .maxLines(ComponentConfig.MAX_LINES_3)
58c41cb6d2Sopenharmony_ci            .textOverflow({ overflow: TextOverflow.Ellipsis })
59c41cb6d2Sopenharmony_ci            .fontWeight(500)
60c41cb6d2Sopenharmony_ci          Row() {
61c41cb6d2Sopenharmony_ci            Text($r('app.string.version'))
62c41cb6d2Sopenharmony_ci              .fontColor($r('sys.color.ohos_id_color_text_secondary'))
63c41cb6d2Sopenharmony_ci              .fontSize($r('sys.float.ohos_id_text_size_body2'))
64c41cb6d2Sopenharmony_ci              .textAlign(TextAlign.Start)
65c41cb6d2Sopenharmony_ci              .maxLines(ComponentConfig.MAX_LINES_1)
66c41cb6d2Sopenharmony_ci              .textOverflow({ overflow: TextOverflow.Ellipsis })
67c41cb6d2Sopenharmony_ci              .visibility('pages/applicationInfo' === this.settingUri ? Visibility.Visible : Visibility.None)
68c41cb6d2Sopenharmony_ci              .margin({ top: $r('sys.float.ohos_id_text_margin_vertical') });
69c41cb6d2Sopenharmony_ci
70c41cb6d2Sopenharmony_ci            Text(this.settingSummary)
71c41cb6d2Sopenharmony_ci              .fontColor($r('sys.color.ohos_id_color_text_secondary'))
72c41cb6d2Sopenharmony_ci              .fontSize($r('sys.float.ohos_id_text_size_body2'))
73c41cb6d2Sopenharmony_ci              .fontWeight('sans-serif')
74c41cb6d2Sopenharmony_ci              .textAlign(TextAlign.Start)
75c41cb6d2Sopenharmony_ci              .maxLines(ComponentConfig.MAX_LINES_1)
76c41cb6d2Sopenharmony_ci              .textOverflow({ overflow: TextOverflow.Ellipsis })
77c41cb6d2Sopenharmony_ci              .visibility('' === this.settingSummary || undefined === this.settingSummary ? Visibility.None : Visibility.Visible)
78c41cb6d2Sopenharmony_ci              .margin({ top: $r('sys.float.ohos_id_text_margin_vertical') });
79c41cb6d2Sopenharmony_ci          }
80c41cb6d2Sopenharmony_ci        }
81c41cb6d2Sopenharmony_ci        .alignItems(HorizontalAlign.Start);
82c41cb6d2Sopenharmony_ci      }
83c41cb6d2Sopenharmony_ci      .flexShrink(0)
84c41cb6d2Sopenharmony_ci      .alignItems(VerticalAlign.Center)
85c41cb6d2Sopenharmony_ci      .align(Alignment.Start)
86c41cb6d2Sopenharmony_ci      .layoutWeight(ConfigData.LAYOUT_WEIGHT_1)
87c41cb6d2Sopenharmony_ci
88c41cb6d2Sopenharmony_ci      Row() {
89c41cb6d2Sopenharmony_ci        Text(this.settingValue)
90c41cb6d2Sopenharmony_ci          .fontSize(this.valueFontSize as (number | string | Resource))
91c41cb6d2Sopenharmony_ci          .fontColor($r("sys.color.ohos_id_color_primary"))
92c41cb6d2Sopenharmony_ci          .opacity($r('sys.float.ohos_id_alpha_content_secondary'))
93c41cb6d2Sopenharmony_ci          .fontWeight('HwChinese-medium')
94c41cb6d2Sopenharmony_ci          .height($r('app.float.wh_value_40'))
95c41cb6d2Sopenharmony_ci          .margin({ left: $r('sys.float.ohos_id_elements_margin_horizontal_l'), right: $r('app.float.wh_value_4') })
96c41cb6d2Sopenharmony_ci          .align(Alignment.End);
97c41cb6d2Sopenharmony_ci
98c41cb6d2Sopenharmony_ci        if (!this.settingArrowStyle && this.settingArrow) {
99c41cb6d2Sopenharmony_ci          Image(this.settingArrow)
100c41cb6d2Sopenharmony_ci            .visibility('' === this.settingArrow ? Visibility.None : Visibility.Visible)
101c41cb6d2Sopenharmony_ci            .width($r("app.float.wh_value_12"))
102c41cb6d2Sopenharmony_ci            .height($r("app.float.wh_value_24"))
103c41cb6d2Sopenharmony_ci            .margin({ right: $r('app.float.wh_value_8') })
104c41cb6d2Sopenharmony_ci            .fillColor($r("sys.color.ohos_id_color_primary"))
105c41cb6d2Sopenharmony_ci            .opacity($r("app.float.opacity_0_2"))
106c41cb6d2Sopenharmony_ci        } else if (this.settingArrow) {
107c41cb6d2Sopenharmony_ci          Image(this.settingArrow)
108c41cb6d2Sopenharmony_ci            .visibility('' === this.settingArrow ? Visibility.None : Visibility.Visible)
109c41cb6d2Sopenharmony_ci            .fillColor($r("sys.color.ohos_id_color_primary"))
110c41cb6d2Sopenharmony_ci            .width($r('app.float.wh_value_24'))
111c41cb6d2Sopenharmony_ci            .height($r('app.float.wh_value_24'))
112c41cb6d2Sopenharmony_ci            .margin({ right: $r('app.float.wh_value_12') })
113c41cb6d2Sopenharmony_ci            .borderRadius($r("sys.float.ohos_id_corner_radius_default_l"))
114c41cb6d2Sopenharmony_ci            .onClick(this.onArrowClick as ((event?: ClickEvent) => void))
115c41cb6d2Sopenharmony_ci
116c41cb6d2Sopenharmony_ci        }
117c41cb6d2Sopenharmony_ci      }
118c41cb6d2Sopenharmony_ci      .alignItems(VerticalAlign.Center)
119c41cb6d2Sopenharmony_ci      .align(Alignment.End);
120c41cb6d2Sopenharmony_ci    }
121c41cb6d2Sopenharmony_ci    .opacity(this.isEnabled ? 1 : $r('sys.float.ohos_id_alpha_disabled'))
122c41cb6d2Sopenharmony_ci    .height(this.heights as Length)
123c41cb6d2Sopenharmony_ci    .width(ComponentConfig.WH_100_100)
124c41cb6d2Sopenharmony_ci    .padding({ left: $r('sys.float.ohos_id_card_margin_start') })
125c41cb6d2Sopenharmony_ci    .borderRadius($r("sys.float.ohos_id_corner_radius_default_l"))
126c41cb6d2Sopenharmony_ci    .linearGradient((this.isEnabled && this.isTouched) ? {
127c41cb6d2Sopenharmony_ci      angle: 90,
128c41cb6d2Sopenharmony_ci      direction: GradientDirection.Right,
129c41cb6d2Sopenharmony_ci      colors: [[$r("app.color.DCEAF9"), 0.0], [$r("app.color.FAFAFA"), 1.0]]
130c41cb6d2Sopenharmony_ci    } : {
131c41cb6d2Sopenharmony_ci      angle: 90,
132c41cb6d2Sopenharmony_ci      direction: GradientDirection.Right,
133c41cb6d2Sopenharmony_ci      colors: [[$r("sys.color.ohos_id_color_foreground_contrary"), 1], [$r("sys.color.ohos_id_color_foreground_contrary"), 1]]
134c41cb6d2Sopenharmony_ci    })
135c41cb6d2Sopenharmony_ci    .alignItems(VerticalAlign.Center)
136c41cb6d2Sopenharmony_ci    .onTouch((event?: TouchEvent) => {
137c41cb6d2Sopenharmony_ci      if (event?.type === TouchType.Down) {
138c41cb6d2Sopenharmony_ci        this.isTouched = true;
139c41cb6d2Sopenharmony_ci      }
140c41cb6d2Sopenharmony_ci      if (event?.type === TouchType.Up) {
141c41cb6d2Sopenharmony_ci        this.isTouched = false;
142c41cb6d2Sopenharmony_ci      }
143c41cb6d2Sopenharmony_ci    })
144c41cb6d2Sopenharmony_ci  }
145c41cb6d2Sopenharmony_ci}