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 */ 15import BasicDataSource from './BasicDataSource'; 16import { HiLog } from '../../../../../../common/src/main/ets/util/HiLog'; 17import { ArrayUtil } from '../../../../../../common/src/main/ets/util/ArrayUtil'; 18 19const TAG = "BatchSelectRecentSource"; 20 21export default class BatchSelectRecentSource extends BasicDataSource { 22 private callLogs: { [key: string]: any }[] = []; 23 24 public totalCount(): number { 25 return this.callLogs.length; 26 } 27 28 public getData(index: number): any { 29 HiLog.i(TAG, "getData index is " + JSON.stringify(index)); 30 if (ArrayUtil.isEmpty(this.callLogs) || index >= this.callLogs.length) { 31 HiLog.i(TAG, "getData calllog is empty"); 32 return null; 33 } else { 34 let showDivifer: boolean = !ArrayUtil.isEmpty(this.callLogs) && (index != (this.callLogs.length - 1)); 35 36 return { 37 showDivifer: showDivifer, 38 index: index, 39 calllog: this.callLogs[index] 40 }; 41 } 42 } 43 44 public refresh(callLogTemp: any[]) { 45 HiLog.i(TAG, ' refresh!'); 46 this.callLogs = callLogTemp; 47 this.notifyDataReload(); 48 } 49 50 public refreshSpecificOne(index: number, checked: boolean) { 51 this.callLogs[index].checked = checked; 52 this.notifyDataChange(index); 53 } 54}