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 16export class CommentDataModel { 17 constructor(public name: string | Resource, public comment: string | Resource) { 18 this.name = name; 19 this.comment = comment 20 } 21} 22 23export class LiveInfoDataModel { 24 constructor(public uri: string | Resource, public name: string | Resource, public peopleNum: string | Resource, public commentList: Array<CommentDataModel>) { 25 this.uri = uri; 26 this.name = name; 27 this.peopleNum = peopleNum; 28 this.commentList = commentList 29 } 30} 31 32// LazyForEach的模型 33class BasicDataSource implements IDataSource { 34 private listeners: DataChangeListener[] = [] 35 36 public totalCount(): number { 37 return 0 38 } 39 40 public getData(index: number): any { 41 return undefined 42 } 43 44 registerDataChangeListener(listener: DataChangeListener): void { 45 if (this.listeners.indexOf(listener) < 0) { 46 this.listeners.push(listener) 47 } 48 } 49 50 unregisterDataChangeListener(listener: DataChangeListener): void { 51 const pos = this.listeners.indexOf(listener); 52 if (pos >= 0) { 53 this.listeners.splice(pos, 1) 54 } 55 } 56 57 notifyDataReload(): void { 58 this.listeners.forEach(listener => { 59 listener.onDataReloaded() 60 }) 61 } 62 63 notifyDataAdd(index: number): void { 64 this.listeners.forEach(listener => { 65 listener.onDataAdded(index) 66 }) 67 } 68 69 notifyDataChange(index: number): void { 70 this.listeners.forEach(listener => { 71 listener.onDataChanged(index) 72 }) 73 } 74} 75 76export class MyDataSource extends BasicDataSource { 77 public dataArray: string[] = [] 78 79 constructor(ele) { 80 super() 81 for (var index = 0;index < ele.length; index++) { 82 this.dataArray.push(ele[index]) 83 } 84 } 85 86 public totalCount(): number { 87 return this.dataArray.length 88 } 89 90 public getData(index: number): any { 91 return this.dataArray[index] 92 } 93 94 public addData(index: number, data: string): void { 95 this.dataArray.splice(index, 0) 96 this.notifyDataAdd(index) 97 } 98} 99