• 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
16/**
17 * @file: Header information display component
18 */
19import LogUtils from '../utils/LogUtils';
20import callStateConst from '../constant/CallStateConst';
21import Utils from '../utils/utils'
22import CallUtils from '../utils/CallUtils'
23
24const TAG = "contactCard";
25
26@Component
27export default struct ContactCard {
28  @State callStateText: string = '';
29  @State dialing: string = '.';
30  @Prop isShowKeyboard: boolean;
31  @Link callList: Array<any>;
32  @Link callData: any;
33  @StorageLink("TextInput") textInput: string = '';
34  @StorageLink("TextInputValue") textInputValue: string = '';
35  @StorageLink("CallTimeList") callTimeList: any = [];
36  @StorageLink("AccountNumber") accountNumber: string = '';
37  @StorageLink("IsEmergencyPhoneNumber") isEmergencyPhoneNumber: boolean = false;
38  @StorageLink("hasSimCard1") hasSimCard1: boolean = false;
39  @StorageLink("hasSimCard2") hasSimCard2: boolean = false;
40  private mUtils: Utils;
41  private timer;
42  private emergency = $r('app.string.emergency');
43
44  public aboutToAppear(): void {
45    LogUtils.i(TAG, "aboutToAppear");
46    this.mUtils = Utils.getInstance();
47    this.timer = setInterval(() => {
48      if (this.dialing === '...') {
49        this.dialing = '';
50      }
51      this.dialing += '.';
52    }, 500)
53    if (this.callData.callState === 3) {
54      clearInterval(this.timer)
55    }
56    if (this.callData.callState === 4) {
57      CallUtils.hasSimeCard(0);
58      CallUtils.hasSimeCard(1);
59    }
60  }
61
62  /**
63   * Determine whether to display the call list or the input box
64   *
65   * @return {boolean} - return success true fail false
66   */
67  private isShowCard() {
68    return this.callList.length === 1 || (this.callList.length > 1 && this.callList.some((v) =>
69    v.callState === callStateConst.CALL_STATUS_WAITING));
70  }
71
72  /**
73   * Call status
74   *
75   * @return {number} - Call status
76   */
77  public callState() {
78    return this.callData.callState;
79  }
80
81  /**
82   * Whether to display the time
83   *
84   * @return {boolean} - return success true fail false
85   */
86  private isShowTime() {
87    return this.callState() === callStateConst.CALL_STATUS_ACTIVE && this.callList.length === 1;
88  }
89
90  private isShowSim() {
91    return this.callState() === callStateConst.CALL_STATUS_INCOMING && this.hasSimCard1 && this.hasSimCard2;
92  }
93
94  build() {
95    GridRow({ columns: { sm: 4, md: 8, lg: 12 }, gutter: 24 }) {
96      GridCol({ span: { sm: 4, md: 6, lg: 6 }, offset: { md: 1, lg: 3 } }) {
97        Column() {
98          if (!this.isShowKeyboard) {
99            Image($r("app.media.ic_public_avatar"))
100              .width(110)
101              .height(110)
102              .borderRadius(55)
103              .margin({ bottom: 18 })
104          }
105
106          if (this.isShowKeyboard && this.textInput.length === 0) {
107            Text(this.callData.contactName ? this.callData.contactName : this.callData.accountNumber)
108              .fontSize(30)
109              .height(40)
110              .lineHeight(40)
111              .fontWeight(FontWeight.Medium)
112              .fontColor('#FFFFFF')
113              .margin({ bottom: 8 })
114              .maxLines(1)
115              .textOverflow({ overflow: TextOverflow.Ellipsis })
116          } else if (!this.isShowKeyboard) {
117            Text(this.isEmergencyPhoneNumber ? this.emergency : this.callData.contactName ? this.callData.contactName : this.callData.accountNumber)
118              .fontSize(30)
119              .height(40)
120              .lineHeight(40)
121              .fontWeight(FontWeight.Medium)
122              .fontColor('#FFFFFF')
123              .margin({ bottom: 8 })
124              .maxLines(1)
125              .textOverflow({ overflow: TextOverflow.Ellipsis })
126          } else if (this.isShowKeyboard && this.textInput.length != 0) {
127            Scroll() {
128              Text(this.textInputValue)
129                .height(40)
130                .fontSize(30)
131                .lineHeight(40)
132                .fontWeight(FontWeight.Medium)
133                .margin({ bottom: 8 })
134                .fontColor('#FFFFFF')
135                .onTouch((event: TouchEvent) => {
136                  if (event.type === TouchType.Move) {
137                    this.textInputValue = this.textInput
138                  }
139                })
140            }
141            .scrollable(ScrollDirection.Horizontal)
142            .scrollBar(BarState.Off)
143            .width('100%')
144          }
145
146          Row() {
147            if (!this.isShowKeyboard || this.isShowKeyboard && this.textInput.length === 0) {
148              Text((this.callData.contactName || this.isEmergencyPhoneNumber) ? this.callData.accountNumber : '')
149                .fontSize(14)
150                .height(19)
151                .lineHeight(16)
152                .fontColor('#FFFFFF')
153                .margin({ bottom: 8 })
154                .visibility((this.callData.contactName || this.isEmergencyPhoneNumber) && !this.isShowKeyboard ? Visibility.Visible : Visibility.None)
155            }
156          }
157
158          if (this.callData.callState === 1) {
159            Row() {
160              Text($r("app.string.callHold"))
161                .fontSize(14)
162                .height(19)
163                .lineHeight(19)
164                .fontColor('#FFFFFF')
165                .fontWeight(FontWeight.Medium)
166            }
167          }
168
169          if (this.callData.callState === 2) {
170            Row() {
171              Text($r("app.string.dialing"))
172                .fontSize(14)
173                .height(19)
174                .lineHeight(16)
175                .fontColor('#FFFFFF')
176                .align(Alignment.Start)
177
178              Text(this.dialing)
179                .fontColor('#FFFFFF')
180            }
181            .width(60)
182          }
183
184          if (this.callData.callState === 3) {
185            Text($r("app.string.partyIsRinging"))
186              .fontSize(14)
187              .height(19)
188              .lineHeight(16)
189              .fontColor('#FFFFFF')
190          }
191
192          if (this.isShowSim()) {
193            Image(this.callData.accountId == 1 ? $r("app.media.ic_public_phone_sim2") : $r("app.media.ic_public_phone_sim1"))
194              .margin({ right: 4 })
195              .width(12)
196              .height(12)
197              .opacity(0.6)
198          }
199
200          if (this.isShowTime()) {
201            Row() {
202              if (this.callData.callType === 1) {
203                Image($r("app.media.ic_public_phone_HD"))
204                  .margin({ right: 4 })
205                  .width(12)
206                  .height(12)
207                  .opacity(0.6)
208              }
209
210              Text(this.callTimeList[0]?.callTime)
211                .fontSize(14)
212                .height(19)
213                .lineHeight(19)
214                .fontColor('#FFFFFF')
215            }
216          }
217        }
218      }
219    }
220    .margin({ left: 24, right: 24 })
221  }
222}