199da06d0Sopenharmony_ci/** 299da06d0Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 399da06d0Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 499da06d0Sopenharmony_ci * you may not use this file except in compliance with the License. 599da06d0Sopenharmony_ci * You may obtain a copy of the License at 699da06d0Sopenharmony_ci * 799da06d0Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 899da06d0Sopenharmony_ci * 999da06d0Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1099da06d0Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1199da06d0Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1299da06d0Sopenharmony_ci * See the License for the specific language governing permissions and 1399da06d0Sopenharmony_ci * limitations under the License. 1499da06d0Sopenharmony_ci */ 1599da06d0Sopenharmony_ci 1699da06d0Sopenharmony_ci/** 1799da06d0Sopenharmony_ci * @file: Header information display component 1899da06d0Sopenharmony_ci */ 1999da06d0Sopenharmony_ciimport LogUtils from '../utils/LogUtils'; 2099da06d0Sopenharmony_ciimport CallStateConst from '../constant/CallStateConst'; 2199da06d0Sopenharmony_ciimport Utils from '../utils/utils' 2299da06d0Sopenharmony_ciimport CallList from './CallList' 2399da06d0Sopenharmony_ciimport callStateConst from '../constant/CallStateConst'; 2499da06d0Sopenharmony_ciimport CallUtils from '../utils/CallUtils' 2599da06d0Sopenharmony_ciimport DefaultCallData from '../struct/TypeUtils' 2699da06d0Sopenharmony_ciimport CallListStruct from '../struct/CallListStruct' 2799da06d0Sopenharmony_ciimport CallTimeListStruct from '../struct/CallTimeListStruct' 2899da06d0Sopenharmony_ci 2999da06d0Sopenharmony_ciconst TAG = 'MultiContactCard'; 3099da06d0Sopenharmony_ci 3199da06d0Sopenharmony_ci@Component 3299da06d0Sopenharmony_ciexport default struct MultiContactCard { 3399da06d0Sopenharmony_ci @State callStateText: string = ''; 3499da06d0Sopenharmony_ci @State dialing: string = '.'; 3599da06d0Sopenharmony_ci @Prop isShowKeyboard: boolean; 3699da06d0Sopenharmony_ci @Link callList: Array<CallListStruct>; 3799da06d0Sopenharmony_ci @Link callData: DefaultCallData; 3899da06d0Sopenharmony_ci @Link incomingData: DefaultCallData; 3999da06d0Sopenharmony_ci @StorageLink('TextInput') textInput: string = ''; 4099da06d0Sopenharmony_ci @StorageLink('TextInputValue') textInputValue: string = ''; 4199da06d0Sopenharmony_ci @StorageLink('CallTimeList') callTimeList: Array<CallTimeListStruct> = []; 4299da06d0Sopenharmony_ci @StorageLink('AccountNumber') accountNumber: string = ''; 4399da06d0Sopenharmony_ci @StorageLink('IsEmergencyPhoneNumber') isEmergencyPhoneNumber: boolean = false; 4499da06d0Sopenharmony_ci @StorageLink('hasSimCard1') hasSimCard1: boolean = false; 4599da06d0Sopenharmony_ci @StorageLink('hasSimCard2') hasSimCard2: boolean = false; 4699da06d0Sopenharmony_ci @State multiContactName: string = ''; 4799da06d0Sopenharmony_ci @State multiContactNumber: string = ''; 4899da06d0Sopenharmony_ci private mUtils: Utils; 4999da06d0Sopenharmony_ci private timer; 5099da06d0Sopenharmony_ci private emergency = $r('app.string.emergency'); 5199da06d0Sopenharmony_ci 5299da06d0Sopenharmony_ci public aboutToAppear(): void { 5399da06d0Sopenharmony_ci LogUtils.i(TAG, 'aboutToAppear'); 5499da06d0Sopenharmony_ci this.mUtils = Utils.getInstance(); 5599da06d0Sopenharmony_ci this.timer = setInterval(() => { 5699da06d0Sopenharmony_ci if (this.dialing === '...') { 5799da06d0Sopenharmony_ci this.dialing = ''; 5899da06d0Sopenharmony_ci } 5999da06d0Sopenharmony_ci this.dialing += '.'; 6099da06d0Sopenharmony_ci }, 500) 6199da06d0Sopenharmony_ci if (this.callData.callState === 3) { 6299da06d0Sopenharmony_ci clearInterval(this.timer) 6399da06d0Sopenharmony_ci } 6499da06d0Sopenharmony_ci 6599da06d0Sopenharmony_ci if (this.callData.callState === 4 || this.callData.callState === 5) { 6699da06d0Sopenharmony_ci CallUtils.hasSimeCard(0); 6799da06d0Sopenharmony_ci CallUtils.hasSimeCard(1); 6899da06d0Sopenharmony_ci } 6999da06d0Sopenharmony_ci } 7099da06d0Sopenharmony_ci 7199da06d0Sopenharmony_ci private isShowSim() { 7299da06d0Sopenharmony_ci return (this.callData.callState === CallStateConst.callStateObj.CALL_STATUS_WAITING || this.callData.callState === 7399da06d0Sopenharmony_ci CallStateConst.callStateObj.CALL_STATUS_INCOMING) && this.hasSimCard1 && this.hasSimCard2; 7499da06d0Sopenharmony_ci } 7599da06d0Sopenharmony_ci 7699da06d0Sopenharmony_ci getInComingCallState() { 7799da06d0Sopenharmony_ci if (this.callList.length > 1) { 7899da06d0Sopenharmony_ci let incomingState = false; 7999da06d0Sopenharmony_ci this.callList.forEach((v) => { 8099da06d0Sopenharmony_ci if (v.callState === CallStateConst.callStateObj.CALL_STATUS_WAITING || v.callState === 8199da06d0Sopenharmony_ci CallStateConst.callStateObj.CALL_STATUS_INCOMING) { 8299da06d0Sopenharmony_ci this.incomingData = v; 8399da06d0Sopenharmony_ci this.multiContactName = v.contactName; 8499da06d0Sopenharmony_ci this.multiContactNumber = v.accountNumber; 8599da06d0Sopenharmony_ci incomingState = true; 8699da06d0Sopenharmony_ci } 8799da06d0Sopenharmony_ci }); 8899da06d0Sopenharmony_ci LogUtils.i(TAG, 'getInComingCallState incomingState:' + JSON.stringify(incomingState)); 8999da06d0Sopenharmony_ci return incomingState; 9099da06d0Sopenharmony_ci } else { 9199da06d0Sopenharmony_ci return this.callData.callState; 9299da06d0Sopenharmony_ci } 9399da06d0Sopenharmony_ci } 9499da06d0Sopenharmony_ci 9599da06d0Sopenharmony_ci build() { 9699da06d0Sopenharmony_ci GridRow({ columns: { sm: 4, md: 8, lg: 12 }, gutter: 24 }) { 9799da06d0Sopenharmony_ci GridCol({ span: { sm: 4, md: 6, lg: 6 }, offset: { md: 1, lg: 3 } }) { 9899da06d0Sopenharmony_ci Column() { 9999da06d0Sopenharmony_ci if (!(this.isShowKeyboard && this.textInput.length != 0)) { 10099da06d0Sopenharmony_ci CallList({ 10199da06d0Sopenharmony_ci callList: $callList, 10299da06d0Sopenharmony_ci callData: $callData 10399da06d0Sopenharmony_ci }) 10499da06d0Sopenharmony_ci 10599da06d0Sopenharmony_ci if (this.getInComingCallState()) { 10699da06d0Sopenharmony_ci Column() { 10799da06d0Sopenharmony_ci if (!this.isShowKeyboard || this.isShowKeyboard && this.textInput.length === 0) { 10899da06d0Sopenharmony_ci Text(this.isEmergencyPhoneNumber ? this.emergency : this.multiContactName ? this.multiContactName : 10999da06d0Sopenharmony_ci this.multiContactNumber) 11099da06d0Sopenharmony_ci .fontSize(30) 11199da06d0Sopenharmony_ci .height(40) 11299da06d0Sopenharmony_ci .lineHeight(40) 11399da06d0Sopenharmony_ci .fontWeight(FontWeight.Medium) 11499da06d0Sopenharmony_ci .fontColor('#FFFFFF') 11599da06d0Sopenharmony_ci .margin({ bottom: 8 }) 11699da06d0Sopenharmony_ci 11799da06d0Sopenharmony_ci Text((this.multiContactName || this.isEmergencyPhoneNumber) ? this.multiContactNumber : '') 11899da06d0Sopenharmony_ci .fontSize(14) 11999da06d0Sopenharmony_ci .height(19) 12099da06d0Sopenharmony_ci .lineHeight(19) 12199da06d0Sopenharmony_ci .fontColor('#FFFFFF') 12299da06d0Sopenharmony_ci .opacity(0.60) 12399da06d0Sopenharmony_ci .visibility((this.multiContactName || this.isEmergencyPhoneNumber) && !this.isShowKeyboard ? 12499da06d0Sopenharmony_ci Visibility.Visible : Visibility.None) 12599da06d0Sopenharmony_ci } 12699da06d0Sopenharmony_ci } 12799da06d0Sopenharmony_ci .margin({ top: 56 }) 12899da06d0Sopenharmony_ci 12999da06d0Sopenharmony_ci if (this.isShowSim()) { 13099da06d0Sopenharmony_ci Image(this.callData.accountId == 1 ? $r('app.media.ic_public_phone_sim2') : 13199da06d0Sopenharmony_ci $r('app.media.ic_public_phone_sim1')) 13299da06d0Sopenharmony_ci .margin({ right: 4 }) 13399da06d0Sopenharmony_ci .width(12) 13499da06d0Sopenharmony_ci .height(12) 13599da06d0Sopenharmony_ci .opacity(0.6) 13699da06d0Sopenharmony_ci } 13799da06d0Sopenharmony_ci } 13899da06d0Sopenharmony_ci 13999da06d0Sopenharmony_ci 14099da06d0Sopenharmony_ci } else if (this.isShowKeyboard && this.textInput.length != 0) { 14199da06d0Sopenharmony_ci Scroll() { 14299da06d0Sopenharmony_ci Text(this.textInputValue) 14399da06d0Sopenharmony_ci .height(40) 14499da06d0Sopenharmony_ci .fontSize(30) 14599da06d0Sopenharmony_ci .lineHeight(40) 14699da06d0Sopenharmony_ci .fontWeight(FontWeight.Medium) 14799da06d0Sopenharmony_ci .margin({ bottom: 8 }) 14899da06d0Sopenharmony_ci .fontColor('#FFFFFF') 14999da06d0Sopenharmony_ci .onTouch((event: TouchEvent) => { 15099da06d0Sopenharmony_ci if (event.type === TouchType.Move) { 15199da06d0Sopenharmony_ci this.textInputValue = this.textInput 15299da06d0Sopenharmony_ci } 15399da06d0Sopenharmony_ci }) 15499da06d0Sopenharmony_ci } 15599da06d0Sopenharmony_ci .scrollable(ScrollDirection.Horizontal) 15699da06d0Sopenharmony_ci .scrollBar(BarState.Off) 15799da06d0Sopenharmony_ci .width('100%') 15899da06d0Sopenharmony_ci } 15999da06d0Sopenharmony_ci } 16099da06d0Sopenharmony_ci } 16199da06d0Sopenharmony_ci } 16299da06d0Sopenharmony_ci .margin({ left: 24, right: 24 }) 16399da06d0Sopenharmony_ci } 16499da06d0Sopenharmony_ci}