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 { ContactVo } from './ContactVo'; 17import { HiLog } from '../../../../../../common/src/main/ets/util/HiLog'; 18import { ArrayUtil } from '../../../../../../common/src/main/ets/util/ArrayUtil'; 19 20const TAG = 'BatchSelectContactSource'; 21 22export default class BatchSelectContactSource extends BasicDataSource { 23 private contactList: ContactVo[] = []; 24 25 public totalCount(): number { 26 return this.contactList.length; 27 } 28 29 public getData(index: number): any { 30 if (ArrayUtil.isEmpty(this.contactList) || index >= this.contactList.length) { 31 HiLog.i(TAG, 'getData contactlist is empty'); 32 return null; 33 } else { 34 let contact: ContactVo = this.contactList[index]; 35 let preContact: ContactVo = this.contactList[index - 1]; 36 let showIndex: boolean = (index == 0 || !(contact.namePrefix === preContact.namePrefix)); 37 let showDivifer: boolean = false; 38 if (index < this.contactList.length - 1) { 39 let nextContact: any = this.contactList[index + 1]; 40 showDivifer = (contact.namePrefix === nextContact.namePrefix); 41 } else { 42 showDivifer = false; 43 } 44 return { 45 showIndex: showIndex, 46 showDivifer: showDivifer, 47 contact: contact, 48 index: index 49 }; 50 } 51 } 52 53 public refresh(contactList: ContactVo[]) { 54 HiLog.i(TAG, ' refresh!'); 55 this.contactList = contactList; 56 this.notifyDataReload(); 57 } 58}