• 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 TransmitMsgController from "./transmitMsgController";
16import DeviceUtil from "../../utils/DeviceUtil";
17import router from "@system.router";
18import { TransmitMsgDialog } from "../../views/MmsDialogs";
19import WantUtil from "../../utils/WantUtil";
20
21@Entry
22@Component
23export default struct TransmitMsg {
24    @State mTransmitMsgCtrl: TransmitMsgController = TransmitMsgController.getInstance();
25    @State gridColumns: number = DeviceUtil.isTablet() ? 12 : 4;
26    @State gridSizeType: SizeType = DeviceUtil.isTablet() ? SizeType.LG : SizeType.SM;
27    @State gridGutter: string = "24vp";
28    @State gridMargin: string = "24vp";
29    private dialogAlignment: DialogAlignment = DeviceUtil.isTablet() ? DialogAlignment.Center : DialogAlignment.Bottom;
30    private dialogOffset: Offset = DeviceUtil.isTablet() ? { dx: 0, dy: 0 } : { dx: 0, dy: -12 };
31    delDialogController: CustomDialogController = new CustomDialogController({
32        builder: TransmitMsgDialog({
33            cancel: () => {
34
35            },
36            confirm: () => {
37                this.mTransmitMsgCtrl.transmit()
38            },
39            msg: this.mTransmitMsgCtrl.dialogMsg,
40        }),
41        autoCancel: false,
42        alignment: this.dialogAlignment,
43        offset: this.dialogOffset,
44    });
45
46    aboutToAppear() {
47        this.mTransmitMsgCtrl.onInit();
48        this.mTransmitMsgCtrl.onShow();
49    }
50
51    aboutToDisappear() {
52        this.delDialogController = null;
53    }
54
55    onPageShow() {
56        WantUtil.getWant();
57        if(this.mTransmitMsgCtrl.DialogShow){
58            this.delDialogController.open();
59        }
60    }
61
62    onPageHide() {
63    }
64
65    onBackPress() {
66    }
67
68    build() {
69        GridContainer({
70            columns: this.gridColumns,
71            sizeType: this.gridSizeType,
72            gutter: this.gridGutter,
73            margin: this.gridMargin
74        }) {
75            Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Start, alignItems: ItemAlign.Start }) {
76                //Notification information
77                Flex() {
78                    Row() {
79                        Image($rawfile("icon/ic_public_cancel.svg"))
80                            .width(24)
81                            .height(24)
82                            .onClick(() => {
83                                // Click Back to return to the unselected SMS state.
84                                router.back();
85                            })
86                        Text($r("app.string.transmitHeadText"))
87                            .margin({ left: 16 })
88                            .fontSize(20)
89                            .fontColor($r("sys.color.ohos_id_color_text_primary"))
90                            .fontWeight(FontWeight.Bold)
91                    }
92                    .alignItems(VerticalAlign.Center)
93                    .width("100%")
94                    .height(56)
95                }
96
97                //Select Contact
98                Flex(){
99                    Column(){
100                        Row() {
101                            Text($r("app.string.selectContacts"))
102                                .fontSize("16fp")
103                                .fontColor($r("sys.color.ohos_id_color_text_primary"))
104                            Blank()
105                                Image($rawfile("icon/ic_next.svg"))
106                                    .width($r("app.float.settings_item_next_image_width"))
107                                    .height($r("app.float.settings_item_next_image_height"))
108                        }
109                        .width("100%")
110                        .height("100%")
111                        .margin({ left: "4vp" })
112                    }
113                    .layoutWeight(1)
114                    .height("100%")
115                }.height("48vp")
116                .width("100%")
117                .onClick(() => {
118                    //Go to Select Contact
119                    this.mTransmitMsgCtrl.jumpToSelectContacts();
120                })
121
122                //recent
123                Flex() {
124                    Row() {
125                        Text($r("app.string.recently"))
126                            .fontSize("16fp")
127                            .fontColor($r("sys.color.ohos_id_color_text_primary"))
128                    }.height("48vp")
129                }
130                List() {
131                    LazyForEach(this.mTransmitMsgCtrl.transmitMsgDataSource, (item, index) => {
132                        ListItem() {
133                            Row() {
134                                //avatar
135                                if(item.conversation.photoFirstName === '') {
136                                    Image($rawfile("icon/ic_user_portrait.svg"))
137                                        .objectFit(ImageFit.Fill)
138                                        .width("40vp")
139                                        .height("40vp")
140                                        .clip(new Circle({ width: "40vp", height: "40vp" }))
141                                        .backgroundColor(item.conversation.portraitColor)
142                                } else {
143                                    Text(item.conversation.photoFirstName)
144                                        .fontSize("30vp")
145                                        .fontWeight(FontWeight.Bold)
146                                        .fontColor(Color.White)
147                                        .height("40vp")
148                                        .width("40vp")
149                                        .textAlign(TextAlign.Center)
150                                        .clip(new Circle({ width: "40vp", height: "40vp" }))
151                                        .backgroundColor(item.conversation.portraitColor)
152                                }
153                                Text(item.conversation.name !== '' ? item.conversation.name : item.conversation.telephone)
154                                    .fontSize("16vp")
155                                    .fontWeight(FontWeight.Bold)
156                                    .margin({ left: 16 })
157                            }
158                            .width("100%")
159                            .height(64)
160                        }
161                        .onClick( () => {
162                            this.mTransmitMsgCtrl.clickSendMessage(item)
163                            this.delDialogController.open();
164                        })
165                    }, item => item.conversation.threadId.toString())
166                }
167                .divider({
168                    strokeWidth: 1,
169                    startMargin: 56,
170                    endMargin: 0
171                })
172            }.width("100%")
173            .height("100%")
174            .useSizeType({
175                xs: { span: 4, offset: 0 }, sm: { span: 4, offset: 0 },
176                md: { span: 12, offset: 0 }, lg: { span: 12, offset: 0 }
177            })
178        }
179    }
180}