-
Notifications
You must be signed in to change notification settings - Fork 10
/
send_mail_page.dart
243 lines (230 loc) · 7.83 KB
/
send_mail_page.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
import 'package:byr_mobile_app/customizations/theme_controller.dart';
import 'package:byr_mobile_app/nforum/nforum_service.dart';
import 'package:byr_mobile_app/nforum/nforum_structures.dart';
import 'package:byr_mobile_app/nforum/nforum_text_parser.dart';
import 'package:byr_mobile_app/reusable_components/adaptive_components.dart';
import 'package:byr_mobile_app/reusable_components/byr_app_bar.dart';
import 'package:byr_mobile_app/reusable_components/controller_insert_text.dart';
import 'package:byr_mobile_app/reusable_components/emoticon_panel.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:get/get.dart';
class SendMailPageRouteArg {
final MailModel mail;
final String username;
final bool isReply;
SendMailPageRouteArg({this.mail, this.username, this.isReply = true});
}
class SendMailPage extends StatefulWidget {
final SendMailPageRouteArg arg;
SendMailPage(this.arg);
@override
SendMailPageState createState() => SendMailPageState();
}
class SendMailPageState extends State<SendMailPage> with AutomaticKeepAliveClientMixin {
@override
bool get wantKeepAlive => false;
MailModel _mail;
String _username = "";
String _title = "";
String _content = "";
TextEditingController _userController = new TextEditingController();
TextEditingController _titleController = new TextEditingController();
TextEditingController _contentController = new TextEditingController();
GlobalKey _formKey = new GlobalKey<FormState>();
EmoticonPanel _emoticonPanel;
TextSelection _textSelection;
@override
void initState() {
super.initState();
if (widget.arg.mail != null) {
_mail = widget.arg.mail;
_username = _mail.user.id;
_title = 'Re:' + _mail.title;
_content = NForumTextParser.makeReplyQuote(_username, _mail.content);
} else if (widget.arg.username != null) {
_username = widget.arg.username;
}
_userController.text = _username;
_titleController.text = _title;
_contentController.text = _content;
_contentController.selection = TextSelection(baseOffset: 0, extentOffset: 0);
_emoticonPanel = EmoticonPanel(
config: EmoticonPanelConfig(
{
'backgroundColor': E().otherPagePrimaryColor,
'unselectedBackgroundColor': E().emoticonPanelTopBarTitleUnselectedBackgroundColor,
'selectedBackgroundColor': E().emoticonPanelTopBarTitleSelectedBackgroundColor,
'tabTextColor': E().emoticonPanelTopBarTitleSelectedTextColor,
},
{
'classicsTabTrans': "emoticonTransClassicsTabTrans".tr,
'yoyociciTabTrans': "emoticonTransYoyociciTabTrans".tr,
'tuzkiTabTrans': "emoticonTransTuzkiTabTrans".tr,
'oniontouTabTrans': "emoticonTransOniontouTabTrans".tr,
},
),
onEmoticonTap: (String emoticon) {
_textSelection = controllerInsertText(
controller: _contentController,
insertText: emoticon,
currentSelection: _textSelection,
);
},
);
}
@override
void dispose() {
_userController.dispose();
_titleController.dispose();
_contentController.dispose();
super.dispose();
}
Future<void> _send(context) async {
if ((_formKey.currentState as FormState).validate()) {
AdaptiveComponents.showLoading(
context,
content: "sendingTrans".tr,
);
StatusModel tt = await NForumService.sendMail(
_userController.text,
_titleController.text,
NForumTextParser.stripEmojis(_contentController.text),
);
AdaptiveComponents.hideLoading();
AdaptiveComponents.showToast(
context,
tt.status ? "sendSuccessTrans".tr : "sendFailedTrans".tr,
);
Navigator.of(context).pop();
}
}
Widget _buildContent(BuildContext context) {
return Container(
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 16),
child: Form(
key: _formKey,
autovalidate: true,
child: Column(
children: <Widget>[
TextFormField(
autocorrect: false,
style: TextStyle(
color: E().threadPageContentColor,
),
readOnly: _username != null,
controller: _userController,
decoration: InputDecoration(
labelText: "receiverTrans".tr,
hintText: "loginUsernameTrans".tr,
labelStyle: TextStyle(
color: E().editPagePlaceholderColor,
),
icon: Icon(
Icons.person,
color: E().editPagePlaceholderColor,
),
),
validator: (v) {
return v.trim().length > 0 ? null : "receiverTrans".tr + "nonBlankTrans".tr;
},
),
TextFormField(
style: TextStyle(
color: E().threadPageContentColor,
),
controller: _titleController,
autocorrect: false,
decoration: InputDecoration(
labelText: "titleTrans".tr,
hintText: "smsTrans".tr + "titleTrans".tr,
labelStyle: TextStyle(
color: E().editPagePlaceholderColor,
),
icon: Icon(
Icons.title,
color: E().editPagePlaceholderColor,
),
),
validator: (v) {
return v.trim().length > 0 ? null : "titleTrans".tr + "nonBlankTrans".tr;
},
),
Expanded(
child: TextFormField(
style: TextStyle(
color: E().threadPageContentColor,
),
autofocus: true,
autocorrect: false,
controller: _contentController,
maxLines: null,
keyboardType: TextInputType.multiline,
decoration: InputDecoration(
labelText: "contentTrans".tr,
labelStyle: TextStyle(
color: E().editPagePlaceholderColor,
),
border: OutlineInputBorder(),
hintText: "smsTrans".tr + "contentTrans".tr,
),
validator: (v) {
return v.trim().length > 0 ? null : "contentTrans".tr + "nonBlankTrans".tr;
},
),
),
],
),
),
);
}
@override
Widget build(BuildContext context) {
super.build(context);
return Obx(
() => Scaffold(
appBar: BYRAppBar(
title: Text(
"smsTrans".tr,
),
actions: <Widget>[
FlatButton.icon(
icon: Icon(
Icons.send,
color: E().editPageTopBarButtonColor,
),
onPressed: () {
_send(context);
},
label: Text(
widget.arg.isReply ? "replyTrans".tr : "sendTrans".tr,
style: TextStyle(fontSize: 17, color: E().topBarTitleNormalColor),
),
),
],
),
backgroundColor: E().editPageBackgroundColor,
body: _buildContent(context),
floatingActionButton: FloatingActionButton(
child: Icon(
FontAwesomeIcons.smile,
),
onPressed: () {
_textSelection = _contentController.selection;
showModalBottomSheet(
context: context,
builder: (BuildContext context) {
return _emoticonPanel;
},
).whenComplete(
() {
_contentController.selection = _textSelection;
},
);
},
),
),
);
}
}