1/**
2 * Copyright (c) 2023 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 CallList from './CallList'
23import callStateConst from '../constant/CallStateConst';
24import CallUtils from '../utils/CallUtils'
25import DefaultCallData from '../struct/TypeUtils'
26import CallListStruct from '../struct/CallListStruct'
27import CallTimeListStruct from '../struct/CallTimeListStruct'
28
29const TAG = 'MultiContactCard';
30
31@Component
32export default struct MultiContactCard {
33  @State callStateText: string = '';
34  @State dialing: string = '.';
35  @Prop isShowKeyboard: boolean;
36  @Link callList: Array<CallListStruct>;
37  @Link callData: DefaultCallData;
38  @Link incomingData: DefaultCallData;
39  @StorageLink('TextInput') textInput: string = '';
40  @StorageLink('TextInputValue') textInputValue: string = '';
41  @StorageLink('CallTimeList') callTimeList: Array<CallTimeListStruct> = [];
42  @StorageLink('AccountNumber') accountNumber: string = '';
43  @StorageLink('IsEmergencyPhoneNumber') isEmergencyPhoneNumber: boolean = false;
44  @StorageLink('hasSimCard1') hasSimCard1: boolean = false;
45  @StorageLink('hasSimCard2') hasSimCard2: boolean = false;
46  @State multiContactName: string = '';
47  @State multiContactNumber: string = '';
48  private mUtils: Utils;
49  private timer;
50  private emergency = $r('app.string.emergency');
51
52  public aboutToAppear(): void {
53    LogUtils.i(TAG, 'aboutToAppear');
54    this.mUtils = Utils.getInstance();
55    this.timer = setInterval(() => {
56      if (this.dialing === '...') {
57        this.dialing = '';
58      }
59      this.dialing += '.';
60    }, 500)
61    if (this.callData.callState === 3) {
62      clearInterval(this.timer)
63    }
64
65    if (this.callData.callState === 4 || this.callData.callState === 5) {
66      CallUtils.hasSimeCard(0);
67      CallUtils.hasSimeCard(1);
68    }
69  }
70
71  private isShowSim() {
72    return (this.callData.callState === CallStateConst.callStateObj.CALL_STATUS_WAITING || this.callData.callState ===
73      CallStateConst.callStateObj.CALL_STATUS_INCOMING) && this.hasSimCard1 && this.hasSimCard2;
74  }
75
76  getInComingCallState() {
77    if (this.callList.length > 1) {
78      let incomingState = false;
79      this.callList.forEach((v) => {
80        if (v.callState === CallStateConst.callStateObj.CALL_STATUS_WAITING || v.callState ===
81          CallStateConst.callStateObj.CALL_STATUS_INCOMING) {
82          this.incomingData = v;
83          this.multiContactName = v.contactName;
84          this.multiContactNumber = v.accountNumber;
85          incomingState = true;
86        }
87      });
88      LogUtils.i(TAG, 'getInComingCallState incomingState:' + JSON.stringify(incomingState));
89      return incomingState;
90    } else {
91      return this.callData.callState;
92    }
93  }
94
95  build() {
96    GridRow({ columns: { sm: 4, md: 8, lg: 12 }, gutter: 24 }) {
97      GridCol({ span: { sm: 4, md: 6, lg: 6 }, offset: { md: 1, lg: 3 } }) {
98        Column() {
99          if (!(this.isShowKeyboard && this.textInput.length != 0)) {
100            CallList({
101              callList: $callList,
102              callData: $callData
103            })
104
105            if (this.getInComingCallState()) {
106              Column() {
107                if (!this.isShowKeyboard || this.isShowKeyboard && this.textInput.length === 0) {
108                  Text(this.isEmergencyPhoneNumber ? this.emergency : this.multiContactName ? this.multiContactName :
109                    this.multiContactNumber)
110                    .fontSize(30)
111                    .height(40)
112                    .lineHeight(40)
113                    .fontWeight(FontWeight.Medium)
114                    .fontColor('#FFFFFF')
115                    .margin({ bottom: 8 })
116
117                  Text((this.multiContactName || this.isEmergencyPhoneNumber) ? this.multiContactNumber : '')
118                    .fontSize(14)
119                    .height(19)
120                    .lineHeight(19)
121                    .fontColor('#FFFFFF')
122                    .opacity(0.60)
123                    .visibility((this.multiContactName || this.isEmergencyPhoneNumber) && !this.isShowKeyboard ?
124                      Visibility.Visible : Visibility.None)
125                }
126              }
127              .margin({ top: 56 })
128
129              if (this.isShowSim()) {
130                Image(this.callData.accountId == 1 ? $r('app.media.ic_public_phone_sim2') :
131                  $r('app.media.ic_public_phone_sim1'))
132                  .margin({ right: 4 })
133                  .width(12)
134                  .height(12)
135                  .opacity(0.6)
136              }
137            }
138
139
140          } else if (this.isShowKeyboard && this.textInput.length != 0) {
141            Scroll() {
142              Text(this.textInputValue)
143                .height(40)
144                .fontSize(30)
145                .lineHeight(40)
146                .fontWeight(FontWeight.Medium)
147                .margin({ bottom: 8 })
148                .fontColor('#FFFFFF')
149                .onTouch((event: TouchEvent) => {
150                  if (event.type === TouchType.Move) {
151                    this.textInputValue = this.textInput
152                  }
153                })
154            }
155            .scrollable(ScrollDirection.Horizontal)
156            .scrollBar(BarState.Off)
157            .width('100%')
158          }
159        }
160      }
161    }
162    .margin({ left: 24, right: 24 })
163  }
164}