1// Copyright 2014 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import 'package:flutter/widgets.dart';
6
7import 'email_model.dart';
8
9const String _avatarsLocation = 'reply/avatars';
10
11class EmailStore with ChangeNotifier {
12 static final List<Email> _inbox = <Email>[
13 InboxEmail(
14 id: 1,
15 sender: 'Google Express',
16 time: '15 minutes ago',
17 subject: 'Package shipped!',
18 message:
19 'Cucumber Mask Facial has shipped.\n\n'
20 "Keep an eye out for a package to arrive between this Thursday and next Tuesday. If for any reason you don't receive your package before the end of next week, please reach out to us for details on your shipment.\n\n"
21 'As always, thank you for shopping with us and we hope you love our specially formulated Cucumber Mask!',
22 avatar: '$_avatarsLocation/avatar_express.png',
23 recipients: 'Jeff',
24 ),
25 InboxEmail(
26 id: 2,
27 sender: 'Ali Connors',
28 time: '4 hrs ago',
29 subject: 'Brunch this weekend?',
30 message:
31 "I'll be in your neighborhood doing errands and was hoping to catch you for a coffee this Saturday. If you don't have anything scheduled, it would be great to see you! It feels like its been forever.\n\n"
32 'If we do get a chance to get together, remind me to tell you about Kim. She stopped over at the house to say hey to the kids and told me all about her trip to Mexico.\n\n'
33 'Talk to you soon,\n\n'
34 'Ali',
35 avatar: '$_avatarsLocation/avatar_5.jpg',
36 recipients: 'Jeff',
37 ),
38 InboxEmail(
39 id: 3,
40 sender: 'Allison Trabucco',
41 time: '5 hrs ago',
42 subject: 'Bonjour from Paris',
43 message: 'Here are some great shots from my trip...',
44 avatar: '$_avatarsLocation/avatar_3.jpg',
45 recipients: 'Jeff',
46 containsPictures: true,
47 ),
48 InboxEmail(
49 id: 4,
50 sender: 'Trevor Hansen',
51 time: '9 hrs ago',
52 subject: 'Brazil trip',
53 message:
54 'Thought we might be able to go over some details about our upcoming vacation.\n\n'
55 "I've been doing a bit of research and have come across a few paces in Northern Brazil that I think we should check out. "
56 'One, the north has some of the most predictable wind on the planet. '
57 "I'd love to get out on the ocean and kitesurf for a couple of days if we're going to be anywhere near or around Taiba. "
58 "I hear it's beautiful there and if you're up for it, I'd love to go. Other than that, I haven't spent too much time looking into places along our road trip route. "
59 "I'm assuming we can find places to stay and things to do as we drive and find places we think look interesting. But... I know you're more of a planner, so if you have ideas or places in mind, lets jot some ideas down!\n\n"
60 'Maybe we can jump on the phone later today if you have a second.',
61 avatar: '$_avatarsLocation/avatar_8.jpg',
62 recipients: 'Allison, Kim, Jeff',
63 ),
64 InboxEmail(
65 id: 5,
66 sender: 'Frank Hawkins',
67 time: '10 hrs ago',
68 subject: 'Update to Your Itinerary',
69 avatar: '$_avatarsLocation/avatar_4.jpg',
70 recipients: 'Jeff',
71 ),
72 InboxEmail(
73 id: 6,
74 sender: 'Google Express',
75 time: '12 hrs ago',
76 subject: 'Delivered',
77 message: 'Your shoes should be waiting for you at home!',
78 avatar: '$_avatarsLocation/avatar_express.png',
79 recipients: 'Jeff',
80 ),
81 InboxEmail(
82 id: 7,
83 sender: 'Frank Hawkins',
84 time: '4 hrs ago',
85 subject: 'Your update on the Google Play Store is live!',
86 message:
87 'Your update is now live on the Play Store and available for your alpha users to start testing.\n\n'
88 "Your alpha testers will be automatically notified. If you'd rather send them a link directly, go to your Google Play Console and follow the instructions for obtaining an open alpha testing link.",
89 avatar: '$_avatarsLocation/avatar_4.jpg',
90 recipients: 'Jeff',
91 ),
92 InboxEmail(
93 id: 8,
94 sender: 'Allison Trabucco',
95 time: '6 hrs ago',
96 subject: 'Try a free TrailGo account',
97 message:
98 'Looking for the best hiking trails in your area? TrailGo gets you on the path to the outdoors faster than you can pack a sandwich.\n\n'
99 "Whether you're an experienced hiker or just looking to get outside for the afternoon, there's a segment that suits you.",
100 avatar: '$_avatarsLocation/avatar_3.jpg',
101 recipients: 'Jeff',
102 ),
103 InboxEmail(
104 id: 9,
105 sender: 'Allison Trabucco',
106 time: '4 hrs ago',
107 subject: 'Free money',
108 message:
109 "You've been selected as a winner in our latest raffle! To claim your prize, click on the link.",
110 avatar: '$_avatarsLocation/avatar_3.jpg',
111 recipients: 'Jeff',
112 inboxType: InboxType.spam,
113 ),
114 ];
115
116 static final List<Email> _outbox = <Email>[
117 Email(
118 id: 10,
119 sender: 'Kim Alen',
120 time: '4 hrs ago',
121 subject: 'High school reunion?',
122 message:
123 "Hi friends,\n\nI was at the grocery store on Sunday night.. when I ran into Genie Williams! I almost didn't recognize her afer 20 years!\n\n"
124 "Anyway, it turns out she is on the organizing committee for the high school reunion this fall. I don't know if you were planning on going or not, but she could definitely use our help in trying to track down lots of missing alums. "
125 "If you can make it, we're doing a little phone-tree party at her place next Saturday, hoping that if we can find one person, thee more will...",
126 avatar: '$_avatarsLocation/avatar_7.jpg',
127 recipients: 'Jeff',
128 ),
129 Email(
130 id: 11,
131 sender: 'Sandra Adams',
132 time: '7 hrs ago',
133 subject: 'Recipe to try',
134 message:
135 'Raspberry Pie: We should make this pie recipe tonight! The filling is '
136 'very quick to put together.',
137 avatar: '$_avatarsLocation/avatar_2.jpg',
138 recipients: 'Jeff',
139 ),
140 ];
141
142 static final List<Email> _drafts = <Email>[
143 Email(
144 id: 12,
145 sender: 'Sandra Adams',
146 time: '2 hrs ago',
147 subject: '(No subject)',
148 message:
149 'Hey,\n\n'
150 'Wanted to email and see what you thought of',
151 avatar: '$_avatarsLocation/avatar_2.jpg',
152 recipients: 'Jeff',
153 ),
154 ];
155
156 List<Email> get _allEmails => <Email>[..._inbox, ..._outbox, ..._drafts];
157
158 List<Email> get inboxEmails {
159 return _inbox.where((Email email) {
160 if (email is InboxEmail) {
161 return email.inboxType == InboxType.normal && !trashEmailIds.contains(email.id);
162 }
163 return false;
164 }).toList();
165 }
166
167 List<Email> get spamEmails {
168 return _inbox.where((Email email) {
169 if (email is InboxEmail) {
170 return email.inboxType == InboxType.spam && !trashEmailIds.contains(email.id);
171 }
172 return false;
173 }).toList();
174 }
175
176 Email get currentEmail => _allEmails.firstWhere((Email email) => email.id == _selectedEmailId);
177
178 List<Email> get outboxEmails =>
179 _outbox.where((Email email) => !trashEmailIds.contains(email.id)).toList();
180
181 List<Email> get draftEmails =>
182 _drafts.where((Email email) => !trashEmailIds.contains(email.id)).toList();
183
184 Set<int> starredEmailIds = <int>{};
185
186 bool isEmailStarred(int id) =>
187 _allEmails.any((Email email) => email.id == id && starredEmailIds.contains(id));
188
189 bool get isCurrentEmailStarred => starredEmailIds.contains(currentEmail.id);
190
191 List<Email> get starredEmails {
192 return _allEmails.where((Email email) => starredEmailIds.contains(email.id)).toList();
193 }
194
195 void starEmail(int id) {
196 starredEmailIds.add(id);
197 notifyListeners();
198 }
199
200 void unstarEmail(int id) {
201 starredEmailIds.remove(id);
202 notifyListeners();
203 }
204
205 Set<int> trashEmailIds = <int>{7, 8};
206
207 List<Email> get trashEmails {
208 return _allEmails.where((Email email) => trashEmailIds.contains(email.id)).toList();
209 }
210
211 void deleteEmail(int id) {
212 trashEmailIds.add(id);
213 notifyListeners();
214 }
215
216 int _selectedEmailId = -1;
217
218 int get selectedEmailId => _selectedEmailId;
219
220 set selectedEmailId(int value) {
221 _selectedEmailId = value;
222 notifyListeners();
223 }
224
225 bool get onMailView => _selectedEmailId > -1;
226
227 MailboxPageType _selectedMailboxPage = MailboxPageType.inbox;
228
229 MailboxPageType get selectedMailboxPage => _selectedMailboxPage;
230
231 set selectedMailboxPage(MailboxPageType mailboxPage) {
232 _selectedMailboxPage = mailboxPage;
233 notifyListeners();
234 }
235
236 bool _onSearchPage = false;
237
238 bool get onSearchPage => _onSearchPage;
239
240 set onSearchPage(bool value) {
241 _onSearchPage = value;
242 notifyListeners();
243 }
244}
245