• 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 { PhoneNumber } from '../../../../../../feature/phonenumber';
17import { CallType } from '../../../../../../feature/call/src/main/ets/entity/CallLog';
18import { HiLog } from '../../../../../../common/src/main/ets/util/HiLog';
19import EnvironmentProp from '../../feature/EnvironmentProp';
20
21const TAG = "ContactDetail-calllog";
22
23/**
24 * Call log
25 */
26@Component
27export default struct CallLogListItem {
28  @State message: { [key: string]: any } = {};
29  @State isEmergencyNum: boolean = false;
30  private imgRes: Resource;
31  @StorageLink("haveMultiSimCard") haveMultiSimCard: boolean = false;
32  @StorageLink("haveSimCard") haveSimCard: boolean = false;
33  @Link private mPresenter: { [key: string]: any };
34  private simImgRes: Resource = $r('app.media.stat_sys_sim1');
35
36  aboutToAppear() {
37    switch (this.message.callType) {
38      case 1:
39        this.imgRes = $r('app.media.ic_contacts_call_in_mini');
40        break;
41      case 2:
42        this.imgRes = $r('app.media.ic_contacts_callout_mini');
43        break;
44      case 3:
45        this.imgRes = $r('app.media.ic_contacts_call_missed_mini');
46        break;
47      case 5:
48        this.imgRes = $r('app.media.ic_contacts_call_rejected_mini');
49        break;
50    }
51    if (this.haveMultiSimCard) {
52      if (this.message.simId == 0) {
53        this.simImgRes = $r('app.media.stat_sys_sim1')
54      } else {
55        this.simImgRes = $r('app.media.stat_sys_sim2')
56      }
57    }
58  }
59
60  build() {
61    Row() {
62      Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Start, }) {
63        Row() {
64          Text(this.message.dateDetail)
65            .fontWeight(FontWeight.Medium)
66            .fontSize($r("sys.float.ohos_id_text_size_body1"))
67            .fontColor($r("sys.color.ohos_id_color_text_primary"))
68          Text(this.message.timeDetail)
69            .fontWeight(FontWeight.Medium)
70            .fontSize($r("sys.float.ohos_id_text_size_body1"))
71            .fontColor($r("sys.color.ohos_id_color_text_primary"))
72        }
73        .height("22vp")
74
75        Row() {
76          Image(this.imgRes)
77            .objectFit(ImageFit.Fill)
78            .width($r("app.float.id_card_image_xs"))
79            .height($r("app.float.id_card_image_xs"))
80            .opacity(0.4)
81          Image(this.simImgRes)
82            .objectFit(ImageFit.Fill)
83            .width($r("app.float.id_card_image_xs"))
84            .height($r("app.float.id_card_image_xs"))
85            .opacity(0.4)
86            .visibility(this.haveMultiSimCard ? Visibility.Visible : Visibility.None)
87          Text(this.message.formatNumber)
88            .fontSize($r("sys.float.ohos_id_text_size_body2"))
89            .fontWeight(FontWeight.Regular)
90            .fontColor(this.message.callType == CallType.MISSED || this.message.callType
91            == CallType.REJECTED ? $r("sys.color.ohos_id_color_handup") : $r("sys.color.ohos_id_color_text_tertiary"))
92            .margin({ left: $r("app.float.id_card_margin_mid") })
93        }
94        .height("19vp")
95        .margin({ top: $r("app.float.id_card_margin_sm") })
96      }
97      .margin({ left: $r("app.float.id_card_margin_max") })
98
99      Blank();
100
101      Row() {
102        Text($r('app.string.Ringing'))
103          .fontWeight(FontWeight.Regular)
104          .fontSize($r("sys.float.ohos_id_text_size_body2"))
105          .fontColor($r("sys.color.ohos_id_color_text_tertiary"))
106          .visibility(this.message.callType == CallType.MISSED ? Visibility.Visible : Visibility.None)
107
108        Text(this.message.talkTime)
109          .fontWeight(FontWeight.Regular)
110          .fontSize($r("sys.float.ohos_id_text_size_body2"))
111          .fontColor($r("sys.color.ohos_id_color_text_tertiary"))
112      }
113      .margin({ right: $r("app.float.id_card_margin_max") })
114      .height("19vp")
115    }
116    .width('100%')
117    .height($r("app.float.id_item_height_max"))
118    .padding({ top: 5, bottom: 5 })
119    .onClick(() => {
120      HiLog.i(TAG, "CallLogListItem onClick:" + JSON.stringify(this.message))
121      if (this.haveMultiSimCard) {
122        PhoneNumber.fromString(this.message.formatNumber).dial({
123          accountId: this.message.simId,
124        });
125      } else {
126        if (!this.haveSimCard) {
127          HiLog.i(TAG, "No SIM card!");
128          //TODO Pop-up window for dialing without a SIM card
129          PhoneNumber.fromString(this.message.formatNumber).isDialEmergencyNum().then((res) => {
130            this.isEmergencyNum = res;
131            if (!this.isEmergencyNum) {
132              HiLog.i(TAG, "Is not Emergency Phone Number!");
133              return;
134            } else {
135              HiLog.i(TAG, "No SIM card, but is Emergency Phone Number");
136              PhoneNumber.fromString(this.message.formatNumber).dial();
137            }
138          })
139        } else {
140          PhoneNumber.fromString(this.message.formatNumber).dial();
141        }
142      }
143    })
144    .gesture(LongPressGesture({ fingers: 1, repeat: false, duration: 500 })
145      .onAction((event: GestureEvent) => {
146      }))
147  }
148}
149