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 BasicDataSource from './BasicDataSource'; 17import { HiLog } from '../../../../../../common/src/main/ets/util/HiLog'; 18import { ArrayUtil } from '../../../../../../common/src/main/ets/util/ArrayUtil'; 19 20const TAG = "DetailCallLogDataSource"; 21 22export default class DetailCallLogDataSource extends BasicDataSource { 23 private detailCallLogList: object[] = []; 24 25 public totalCount(): number { 26 return this.detailCallLogList.length; 27 } 28 29 public getData(index: number): any { 30 HiLog.i(TAG, "getData index is %s" + index); 31 if (ArrayUtil.isEmpty(this.detailCallLogList) || index >= this.detailCallLogList.length) { 32 HiLog.i(TAG, "getData detailCallLogList is empty"); 33 return null; 34 } else { 35 let callLog = this.detailCallLogList[index]; 36 let showTitle = false; 37 if (index == 0) { 38 showTitle = true; 39 } 40 let item = { 41 callLog: callLog, 42 showTitle: showTitle 43 } 44 return item; 45 } 46 } 47 48 public refresh(callLog) { 49 HiLog.i(TAG, ' refresh!'); 50 this.detailCallLogList = callLog; 51 this.notifyDataReload(); 52 } 53}