• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 ReceiveController from "./receiveController"
16import ConversationController from "../../pages/conversation/conversationController"
17import HiLog from "../../utils/HiLog";
18
19const TAG = "Receive";
20@Component
21export struct Receive {
22    @State mReceiveController: ReceiveController = ReceiveController.getInstance();
23    @Link mConversationController: ConversationController;
24
25    aboutToAppear() {
26        this.mReceiveController.onInit((receiverData) => {
27            this.mConversationController.setReceiveContactValue(receiverData)
28        })
29    }
30
31    aboutToDisappear() {
32        HiLog.i(TAG,"aboutToDisappear")
33        this.mReceiveController.onBackPress();
34    }
35
36    build() {
37        Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Start }) {
38            Flex({ alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
39                Flex({ alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
40                    Text($r("app.string.putAddresser"))
41                        .maxLines(1)
42                        .lineHeight($r("app.float.addressee_line_height"))
43                        .fontSize($r("app.float.addressee_font_size"))
44                        .fontColor($r("sys.color.ohos_id_color_text_secondary"))
45                        .fontWeight(FontWeight.Regular)
46                        .fontFamily("HarmonyHeiTi")
47                        .flexShrink(0)
48                    Flex({ wrap: FlexWrap.NoWrap, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Start }) {
49                        // If a contact is selected
50                        if (this.mReceiveController.isInputStatus) {
51                            if (this.mReceiveController.selectContacts.length > 0) {
52                                ForEach(this.mReceiveController.selectContacts, (item, index) => {
53                                    Row() {
54                                        if (item.contactName == "" || item.contactName == null) {
55                                            Text(item.telephoneFormat)
56                                                .textAlign(TextAlign.Center)
57                                                .maxLines(1)
58                                                .textOverflow({ overflow: TextOverflow.Ellipsis })
59                                                .fontSize(12)
60                                                .flexShrink(1)
61                                        }
62                                        if (item.contactName != "" && item.contactName != null) {
63                                            Text(item.contactName)
64                                                .textAlign(TextAlign.Center)
65                                                .maxLines(1)
66                                                .textOverflow({ overflow: TextOverflow.Ellipsis })
67                                                .fontSize(12)
68                                                .flexShrink(1)
69                                        }
70                                        if (item.select) {
71                                            Image($rawfile("icon/ic_public_cancel.svg"))
72                                                .width(16)
73                                                .height(16)
74                                                .flexShrink(1)
75                                        }
76                                    }
77                                    .padding({ left: 8, right: 8 })
78                                    .margin(8)
79                                    .backgroundColor($r("sys.color.ohos_id_color_component_normal"))
80                                    .borderRadius(24)
81                                    .height(28)
82                                    .alignItems(VerticalAlign.Center)
83                                    .constraintSize({ maxWidth: item.select ? 244 : 228 ,minWidth: 68})
84                                    .onClick(() => {
85                                        this.mReceiveController.nameClick(index, (receiverData) => {
86                                            this.mConversationController.setReceiveContactValue(receiverData);
87                                        })
88                                    })
89                                }, item => JSON.stringify(item))
90                            }
91                            Flex() {
92                                TextArea({ text: this.mReceiveController.myText })
93                                    .caretColor($r("sys.color.ohos_id_color_focused_outline"))
94                                    .placeholderColor($r("sys.color.ohos_id_color_text_hint"))
95                                    .backgroundColor($r("sys.color.ohos_id_color_background_transparent"))
96                                    .focusable(true)
97                                    .flexShrink(1)
98                                    .onChange((value) => {
99                                        this.mReceiveController.searchChange(value, (receiverData) => {
100                                            this.mConversationController.setReceiveContactValue(receiverData);
101                                        });
102                                    })
103                                    .onBlur(() => {
104                                        this.mReceiveController.checkReceive((receiverData) => {
105                                            this.mConversationController.setReceiveContactValue(receiverData);
106                                        });
107                                    })
108                                    .onFocus(() => {
109                                        this.mReceiveController.myContactFocus();
110                                    })
111                            }
112                            .flexShrink(1)
113                            .constraintSize({ maxHeight: 120 })
114                        }
115                        else {
116                            Text(this.mReceiveController.strSelectContact)
117                                .fontColor($r("sys.color.ohos_id_color_text_primary_activated"))
118                                .textAlign(TextAlign.Center)
119                                .fontSize(16)
120                                .lineHeight(22)
121                                .maxLines(1)
122                                .textAlign(TextAlign.Start)
123                                .textOverflow({ overflow: TextOverflow.Ellipsis })
124                                .width("100%")
125                                .padding({ top: 12, bottom: 12 })
126                                .onClick(() => {
127                                    this.mReceiveController.myContactClick();
128                                })
129                        }
130                    }
131                    .flexShrink(1)
132                }
133                .flexBasis("auto")
134                .flexShrink(1)
135
136                // Contact icon on the right
137                Image($rawfile("icon/ic_about.svg"))
138                    .width(24)
139                    .height(24)
140                    .onClick(() => {
141                        // The page for selecting a contact is displayed.
142                        this.mReceiveController.clickToContacts(receiverData => {
143                            this.mConversationController.setReceiveContactValue(receiverData);
144                        })
145                    })
146
147            }
148            .constraintSize({ minHeight: 56, maxHeight:200 })
149            .backgroundColor($r("sys.color.ohos_id_color_background"))
150            .borderRadius($r("app.float.settings_items_radius"))
151            .padding({ left: 12, right: 12 })
152
153            Column() {
154                // Indicates whether to display the recent contact list.
155                if (this.mReceiveController.isShowSearch && this.mReceiveController.contacts.length > 0) {
156                    //                    Flex({ alignItems: ItemAlign.Center, justifyContent: FlexAlign.Start }) {
157                    //                        Text("最近联系人")
158                    //                            .fontSize(16)
159                    //                            .fontColor($r("sys.color.ohos_id_color_text_tertiary"))
160                    //                            .fontWeight(FontWeight.Regular)
161                    //                    }
162                    //                    .height(48)
163                    // List area
164                    List({ space: 0, initialIndex: 0 }) {
165                        ForEach(this.mReceiveController.contacts, (item, index) => {
166                            ListItem() {
167                                Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) {
168                                    Image($rawfile("icon/ic_user_portrait.svg"))
169                                        .objectFit(ImageFit.Fill)
170                                        .width("40vp")
171                                        .height("40vp")
172                                        .clip(new Circle({ width: "40vp", height: "40vp" }))
173                                        .backgroundColor($r("app.color.ic_user_head_color"))
174                                        .onClick(() => {
175                                            this.mReceiveController.titleBarAvatar(index)
176                                        })
177
178                                    Flex({
179                                        direction: FlexDirection.Column,
180                                        justifyContent: FlexAlign.Center,
181                                        alignItems: ItemAlign.Start
182                                    }) {
183                                        if (item.contactName != '' || item.contactName != null) {
184                                            Text(item.contactName)
185                                                .fontSize(16)
186                                                .fontColor($r("sys.color.ohos_id_color_text_primary"))
187                                                .maxLines(1)
188                                                .fontWeight(FontWeight.Medium)
189                                                .textOverflow({ overflow: TextOverflow.Ellipsis })
190                                        }
191                                        Text(item.telephoneFormat)
192                                            .fontColor($r("sys.color.ohos_id_color_text_tertiary"))
193                                            .fontSize(14)
194                                            .maxLines(1)
195                                            .margin({ top: 4 })
196                                            .textOverflow({ overflow: TextOverflow.Ellipsis })
197                                    }
198                                    .layoutWeight(1)
199                                    .margin({ left: 12 })
200                                    .onClick(() => {
201                                        this.mReceiveController.addContact(index, (receiverData) => {
202                                            this.mConversationController.setReceiveContactValue(receiverData);
203                                        })
204                                    })
205                                }
206                                .width('100%')
207                                .height(64)
208                            }
209                        }, item => JSON.stringify(item))
210                    }
211                    .listDirection(Axis.Vertical) // Arrange Direction
212                    .edgeEffect(EdgeEffect.Spring) // Sliding to the edge has no effect
213                    .divider({
214                        strokeWidth: 1,
215                        color: $r("sys.color.ohos_id_color_list_separator"),
216                        startMargin: 52,
217                        endMargin: 0
218                    }) // Demarcation line between each row
219                }
220            }.padding({ left: 12, right: 12, bottom: 56 })
221        }
222        .width("100%")
223        .padding({ left: 12, right: 12 })
224    }
225}