• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022-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
16import router from '@ohos.router'
17import { BasicDataSource } from '../common/BasicDataSource'
18import { EMContact } from '../common/MsgBase'
19
20@Entry
21@Component
22export struct FriendsPage {
23  @State friendsListLength: number = 0
24  private friendListData = new FriendListData()
25
26  build() {
27    Column() {
28      Stack({ alignContent: Alignment.Top }) {
29        Column() {
30          List() {
31            ListItem() {
32              Column() {
33                Stack({ alignContent: Alignment.Center }) {
34                  Text($r('app.string.search'))
35                    .fontSize(20)
36                }
37                .backgroundColor(Color.White)
38                .height('50')
39                .width('100%')
40                .margin({ left: 10, right: 10, top: 5, bottom: 5 })
41                .onClick(() => {
42                  router.pushUrl({ url: 'pages/SearchPage' })
43                })
44
45                Column() {
46                  EMContactItemView({ image: $r('app.media.icon_addfriend'), text: $r('app.string.new_friend') })
47                }
48
49                Column() {
50                  EMContactItemView({ image: $r('app.media.icon_group'), text: $r('app.string.group') })
51                }
52
53                Column() {
54                  EMContactItemView({ image: $r('app.media.chat_home'), text: $r('app.string.only_chat') })
55                }
56
57                Column() {
58                  EMContactItemView({ image: $r('app.media.label'), text: $r('app.string.label') })
59                }
60
61                Column() {
62                  EMContactItemView({ image: $r('app.media.public'), text: $r('app.string.official_account') })
63                }
64
65                Column() {
66                  EMContactItemView({ image: $r('app.media.empresa'), text: $r('app.string.enterprise') })
67                }
68
69                Column() {
70                  EMContactItemView({ image: $r('app.media.icon_public'), text: $r('app.string.subscription') })
71                }
72              }
73            }
74
75            LazyForEach(this.friendListData, (msg: EMContact) => {
76              ListItem() {
77                EMContactItemView({ image: msg.userImage, text: msg.userName })
78              }
79              .onClick(() => {
80                router.pushUrl({
81                  url: "pages/ChatDetailPage",
82                  params: { chatImage: msg.userImage, chatName: msg.userName, chatId: msg.userId } })
83              })
84            }, (msg: EMContact) => msg.userId)
85          }
86          .listDirection(Axis.Vertical)
87          .height('100%')
88          .width('100%')
89        }
90      }
91      .width('100%')
92    }
93    .backgroundColor('#e3e3e3')
94    .width('100%')
95    .height('100%')
96  }
97
98  aboutToAppear(): void {
99    this.makeDataLocal()
100  }
101
102  pageTransition() {
103    PageTransitionEnter({ duration: 0 })
104    PageTransitionExit({ duration: 0 })
105  }
106
107  makeDataLocal() {
108    for (let i = 0;i < 1000; i++) {
109      let imageStr = `/resources/images/photo${(i % 50).toString()}.jpg`
110      let temp1 = new EMContact(i.toString(), `朋友${i.toString()}`, imageStr);
111      this.friendListData.pushData(temp1)
112    }
113  }
114}
115
116@Component
117export struct EMContactItemView {
118  private image: string | Resource
119  private text: string | Resource
120
121  build() {
122    Row() {
123      Image(this.image)
124        .width(40)
125        .height(40)
126        .borderRadius(5)
127      Text(this.text)
128        .fontSize(15)
129        .fontColor("#000000")
130        .margin({ left: 10 })
131    }
132    .width('100%')
133    .height(60)
134    .padding({ left: 10, right: 10 })
135    .backgroundColor(Color.White)
136  }
137}
138
139class FriendListData extends BasicDataSource {
140  friendList: Array<EMContact> = []
141
142  public totalCount(): number {
143    return this.friendList.length
144  }
145
146  public getData(index: number): any {
147    return this.friendList[index]
148  }
149
150  public addData(index: number, data: EMContact): void {
151    this.friendList.splice(index, 0, data)
152    this.notifyDataAdd(index)
153  }
154
155  public pushData(data: EMContact): void {
156    this.friendList.push(data)
157    this.notifyDataAdd(this.friendList.length - 1)
158  }
159}