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: User list component 18 */ 19 20import CallStateConst from '../constant/CallStateConst'; 21import CallServiceProxy from '../../model/CallServiceProxy'; 22import LogUtils from '../utils/LogUtils'; 23import GlobalThisHelper from '../utils/GlobalThisHelper' 24import Constants from '../utils/Constants' 25 26const TAG = "CallList"; 27 28@Component 29export default struct CallList { 30 @Link callList: Array<any>; 31 @Link callData: any; 32 @StorageLink("CallTimeList") callTimeList: any = []; 33 34 private mCallStateConst: CallStateConst; 35 private mCallServiceProxy: CallServiceProxy; 36 37 public aboutToAppear(): void { 38 LogUtils.i(TAG, "aboutToAppear"); 39 this.mCallStateConst = new CallStateConst(); 40 this.mCallServiceProxy = CallServiceProxy.getInstance(); 41 } 42 43 /** 44 * Three-way call list 45 * 46 * @return {boolean} - Three-way call list 47 */ 48 getCallList() { 49 let arr = this.callList.map((item) => { 50 const obj = {}; 51 return Object.assign({}, { 52 ...obj, 53 ...item 54 }); 55 }); 56 return arr.filter((v) => v.callState !== CallStateConst.CALL_STATUS_WAITING); 57 } 58 59 /** 60 * Phone number display 61 * 62 * @return {string} Phone number 63 */ 64 public getContactName(item) { 65 return (item.contactName ? item.contactName : item.accountNumber) || $r('app.string.unknownNumber'); 66 } 67 68 /** 69 * Phone number display 70 * 71 * @return {string} Phone number 72 */ 73 public getCallTime(item) { 74 let callTimeObj = this.callTimeList.find((o) => o.callId === item.callId); 75 return callTimeObj ? callTimeObj.callTime : null; 76 } 77 78 /** 79 * Call status 80 * 81 * @return {number} - callState 82 */ 83 private callState() { 84 return this.callData.callState; 85 } 86 87 /** 88 * Hang up call 89 * 90 * @param {number} callId - callId 91 */ 92 public onHangUp(callId) { 93 LogUtils.i(TAG, "onHangUp : " + callId); 94 this.mCallServiceProxy.hangUpCall(callId); 95 if (this.callList.length === 1) { 96 GlobalThisHelper.get<any>(Constants.GLOBALTHIS_CONTEXT)?.terminateSelf().then((data) => { 97 LogUtils.i(TAG, "onHangUp terminateSelfCallBack"); 98 }); 99 } 100 } 101 102 /** 103 * UnHold call 104 * 105 * @param {number} callId - callId 106 */ 107 public onUnHold(callId) { 108 LogUtils.i(TAG, "onUnHold : " + callId); 109 110 this.getCallList().forEach((item) => { 111 if (item.callState === CallStateConst.CALL_STATUS_HOLDING) { 112 this.mCallServiceProxy.unHoldCall(item.callId); 113 return; 114 } 115 }); 116 } 117 118 build() { 119 Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) { 120 List() { 121 ForEach(this.getCallList(), (item) => { 122 ListItem() { 123 Column() { 124 Row() { 125 Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { 126 Text(this.getContactName(item)) 127 .fontColor('#FFFFFF') 128 .fontSize(16) 129 .height(21) 130 .lineHeight(19) 131 132 Row() { 133 if (item.callState === CallStateConst.callStateObj.CALL_STATUS_ACTIVE) { 134 Text(this.getCallTime(item)) 135 .fontSize(14) 136 .fontColor('#FFFFFF') 137 .height(19) 138 .lineHeight(19) 139 .opacity(0.60) 140 } else { 141 Text(CallStateConst.callStateTextMap[item.callState]) 142 .fontSize(14) 143 .fontColor('#FFFFFF') 144 .height(19) 145 .lineHeight(19) 146 .opacity(0.60) 147 } 148 149 if (this.callState() === CallStateConst.callStateObj.CALL_STATUS_WAITING 150 || this.callState() === CallStateConst.callStateObj.CALL_STATUS_INCOMING) { 151 Image($r("app.media.ic_hangup_list")) 152 .width(30) 153 .height(30) 154 .onClick(() => { 155 this.onHangUp(item.callId); 156 }) 157 .margin({ left: 16 }) 158 } 159 } 160 } 161 } 162 .onClick(() => { 163 this.onUnHold(item.callId); 164 }) 165 .height(64) 166 } 167 } 168 }) 169 } 170 .divider({ strokeWidth: 1, color: $r('app.color.divider_calllist') }) 171 .margin({ left: 24, right: 24 }) 172 .width("100%") 173 .listDirection(Axis.Vertical) 174 Divider() 175 .color($r('app.color.divider_calllist')) 176 .strokeWidth(1) 177 } 178 .height(128) 179 180 } 181}