OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of swarmlib; | 5 part of swarmlib; |
6 | 6 |
7 /** | 7 /** |
8 * The top-level class for the UI state. UI state is essentially a "model" from | 8 * The top-level class for the UI state. UI state is essentially a "model" from |
9 * the view's perspective but whose data just describes the UI itself. It | 9 * the view's perspective but whose data just describes the UI itself. It |
10 * contains data like the currently selected story, etc. | 10 * contains data like the currently selected story, etc. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 * Which feed is currently selected (for keyboard shortcuts). | 47 * Which feed is currently selected (for keyboard shortcuts). |
48 */ | 48 */ |
49 BiIterator<Feed> _feedIterator; | 49 BiIterator<Feed> _feedIterator; |
50 | 50 |
51 /** | 51 /** |
52 * Which section is currently selected (for keyboard shortcuts). | 52 * Which section is currently selected (for keyboard shortcuts). |
53 */ | 53 */ |
54 BiIterator<Section> _sectionIterator; | 54 BiIterator<Section> _sectionIterator; |
55 | 55 |
56 SwarmState(this._dataModel) | 56 SwarmState(this._dataModel) |
57 : super(), | 57 : super(), |
58 currentArticle = new ObservableValue<Article>(null), | 58 currentArticle = new ObservableValue<Article>(null), |
59 selectedArticle = new ObservableValue<Article>(null), | 59 selectedArticle = new ObservableValue<Article>(null), |
60 storyMaximized = new ObservableValue<bool>(false), | 60 storyMaximized = new ObservableValue<bool>(false), |
61 storyTextMode = new ObservableValue<bool>(true) { | 61 storyTextMode = new ObservableValue<bool>(true) { |
62 startHistoryTracking(); | 62 startHistoryTracking(); |
63 // TODO(efortuna): consider having this class just hold observable | 63 // TODO(efortuna): consider having this class just hold observable |
64 // currentIndecies instead of iterators with observablevalues.. | 64 // currentIndecies instead of iterators with observablevalues.. |
65 _sectionIterator = new BiIterator<Section>(_dataModel.sections); | 65 _sectionIterator = new BiIterator<Section>(_dataModel.sections); |
66 _feedIterator = new BiIterator<Feed>(_sectionIterator.current.feeds); | 66 _feedIterator = new BiIterator<Feed>(_sectionIterator.current.feeds); |
67 _articleIterator = | 67 _articleIterator = new BiIterator<Article>(_feedIterator.current.articles); |
68 new BiIterator<Article>(_feedIterator.current.articles); | |
69 | 68 |
70 currentArticle.addChangeListener((e) { | 69 currentArticle.addChangeListener((e) { |
71 _articleIterator.jumpToValue(currentArticle.value); | 70 _articleIterator.jumpToValue(currentArticle.value); |
72 }); | 71 }); |
73 } | 72 } |
74 | 73 |
75 /** | 74 /** |
76 * Registers an event to fire on any state change | 75 * Registers an event to fire on any state change |
77 * | 76 * |
78 * TODO(jmesserly): fix this so we don't have to enumerate all of our fields | 77 * TODO(jmesserly): fix this so we don't have to enumerate all of our fields |
(...skipping 13 matching lines...) Expand all Loading... |
92 data['feed'] = currentFeed.id; | 91 data['feed'] = currentFeed.id; |
93 if (currentArticle.value != null) { | 92 if (currentArticle.value != null) { |
94 data['article'] = currentArticle.value.id; | 93 data['article'] = currentArticle.value.id; |
95 } | 94 } |
96 return data; | 95 return data; |
97 } | 96 } |
98 | 97 |
99 void loadFromHistory(Map values) { | 98 void loadFromHistory(Map values) { |
100 // TODO(jimhug): There's a better way of doing this... | 99 // TODO(jimhug): There's a better way of doing this... |
101 if (values['section'] != null) { | 100 if (values['section'] != null) { |
102 _sectionIterator.jumpToValue(_dataModel. | 101 _sectionIterator |
103 findSectionById(values['section'])); | 102 .jumpToValue(_dataModel.findSectionById(values['section'])); |
104 } else { | 103 } else { |
105 _sectionIterator = new BiIterator<Section>(_dataModel.sections); | 104 _sectionIterator = new BiIterator<Section>(_dataModel.sections); |
106 } | 105 } |
107 if (values['feed'] != null && currentSection != null) { | 106 if (values['feed'] != null && currentSection != null) { |
108 _feedIterator.jumpToValue(currentSection.findFeed(values['feed'])); | 107 _feedIterator.jumpToValue(currentSection.findFeed(values['feed'])); |
109 } else { | 108 } else { |
110 _feedIterator = new BiIterator<Feed>(_sectionIterator.current.feeds); | 109 _feedIterator = new BiIterator<Feed>(_sectionIterator.current.feeds); |
111 } | 110 } |
112 if (values['article'] != null && currentFeed != null) { | 111 if (values['article'] != null && currentFeed != null) { |
113 currentArticle.value = currentFeed.findArticle(values['article']); | 112 currentArticle.value = currentFeed.findArticle(values['article']); |
114 _articleIterator.jumpToValue(currentArticle.value); | 113 _articleIterator.jumpToValue(currentArticle.value); |
115 } else { | 114 } else { |
116 _articleIterator = | 115 _articleIterator = |
117 new BiIterator<Article>(_feedIterator.current.articles); | 116 new BiIterator<Article>(_feedIterator.current.articles); |
118 currentArticle.value = null; | 117 currentArticle.value = null; |
119 } | 118 } |
120 | 119 |
121 storyMaximized.value = false; | 120 storyMaximized.value = false; |
122 } | 121 } |
123 | 122 |
124 /** | 123 /** |
125 * Move the currentArticle pointer to the next item in the Feed. | 124 * Move the currentArticle pointer to the next item in the Feed. |
126 */ | 125 */ |
127 void goToNextArticle() { | 126 void goToNextArticle() { |
128 currentArticle.value = _articleIterator.next(); | 127 currentArticle.value = _articleIterator.next(); |
129 selectedArticle.value = _articleIterator.current; | 128 selectedArticle.value = _articleIterator.current; |
130 } | 129 } |
131 | 130 |
132 /** | 131 /** |
133 * Move the currentArticle pointer to the previous item in the Feed. | 132 * Move the currentArticle pointer to the previous item in the Feed. |
134 */ | 133 */ |
135 void goToPreviousArticle() { | 134 void goToPreviousArticle() { |
136 currentArticle.value = _articleIterator.previous(); | 135 currentArticle.value = _articleIterator.previous(); |
137 selectedArticle.value = _articleIterator.current; | 136 selectedArticle.value = _articleIterator.current; |
138 } | 137 } |
(...skipping 13 matching lines...) Expand all Loading... |
152 } | 151 } |
153 | 152 |
154 /** | 153 /** |
155 * Move the pointers for selectedArticle to point to the next | 154 * Move the pointers for selectedArticle to point to the next |
156 * Feed. | 155 * Feed. |
157 */ | 156 */ |
158 void goToNextFeed() { | 157 void goToNextFeed() { |
159 var newFeed = _feedIterator.next(); | 158 var newFeed = _feedIterator.next(); |
160 int oldIndex = _articleIterator.currentIndex.value; | 159 int oldIndex = _articleIterator.currentIndex.value; |
161 | 160 |
162 _articleIterator = new BiIterator<Article>(newFeed.articles, | 161 _articleIterator = new BiIterator<Article>( |
163 _articleIterator.currentIndex.listeners); | 162 newFeed.articles, _articleIterator.currentIndex.listeners); |
164 | 163 |
165 _articleIterator.currentIndex.value = oldIndex; | 164 _articleIterator.currentIndex.value = oldIndex; |
166 selectedArticle.value = _articleIterator.current; | 165 selectedArticle.value = _articleIterator.current; |
167 } | 166 } |
168 | 167 |
169 /** | 168 /** |
170 * Move the pointers for selectedArticle to point to the previous | 169 * Move the pointers for selectedArticle to point to the previous |
171 * DataSource. | 170 * DataSource. |
172 */ | 171 */ |
173 void goToPreviousFeed() { | 172 void goToPreviousFeed() { |
174 var newFeed = _feedIterator.previous(); | 173 var newFeed = _feedIterator.previous(); |
175 int oldIndex = _articleIterator.currentIndex.value; | 174 int oldIndex = _articleIterator.currentIndex.value; |
176 | 175 |
177 _articleIterator = new BiIterator<Article>(newFeed.articles, | 176 _articleIterator = new BiIterator<Article>( |
178 _articleIterator.currentIndex.listeners); | 177 newFeed.articles, _articleIterator.currentIndex.listeners); |
179 _articleIterator.currentIndex.value = oldIndex; | 178 _articleIterator.currentIndex.value = oldIndex; |
180 selectedArticle.value = _articleIterator.current; | 179 selectedArticle.value = _articleIterator.current; |
181 } | 180 } |
182 | 181 |
183 /** | 182 /** |
184 * Move to the next section (page) of feeds in the UI. | 183 * Move to the next section (page) of feeds in the UI. |
185 * @param index the previous index (how far down in a given feed) | 184 * @param index the previous index (how far down in a given feed) |
186 * from the Source we are moving from. | 185 * from the Source we are moving from. |
187 * This method takes sliderMenu in the event that it needs to move | 186 * This method takes sliderMenu in the event that it needs to move |
188 * to a previous section, it can notify the UI to update. | 187 * to a previous section, it can notify the UI to update. |
189 */ | 188 */ |
190 void goToNextSection(SliderMenu sliderMenu) { | 189 void goToNextSection(SliderMenu sliderMenu) { |
191 //TODO(efortuna): move sections? | 190 //TODO(efortuna): move sections? |
192 var oldSection = currentSection; | 191 var oldSection = currentSection; |
193 int oldIndex = _articleIterator.currentIndex.value; | 192 int oldIndex = _articleIterator.currentIndex.value; |
194 sliderMenu.selectNext(true); | 193 sliderMenu.selectNext(true); |
195 // This check prevents our selector from wrapping around when we try to | 194 // This check prevents our selector from wrapping around when we try to |
196 // go to the "next section", but we're already at the last section. | 195 // go to the "next section", but we're already at the last section. |
197 if (oldSection != _sectionIterator.current) { | 196 if (oldSection != _sectionIterator.current) { |
198 _feedIterator = new BiIterator<Feed>(_sectionIterator.current.feeds, | 197 _feedIterator = new BiIterator<Feed>( |
199 _feedIterator.currentIndex.listeners); | 198 _sectionIterator.current.feeds, _feedIterator.currentIndex.listeners); |
200 _articleIterator = | 199 _articleIterator = new BiIterator<Article>(_feedIterator.current.articles, |
201 new BiIterator<Article>(_feedIterator.current.articles, | |
202 _articleIterator.currentIndex.listeners); | 200 _articleIterator.currentIndex.listeners); |
203 _articleIterator.currentIndex.value = oldIndex; | 201 _articleIterator.currentIndex.value = oldIndex; |
204 selectedArticle.value = _articleIterator.current; | 202 selectedArticle.value = _articleIterator.current; |
205 } | 203 } |
206 } | 204 } |
207 | 205 |
208 /** | 206 /** |
209 * Move to the previous section (page) of feeds in the UI. | 207 * Move to the previous section (page) of feeds in the UI. |
210 * @param index the previous index (how far down in a given feed) | 208 * @param index the previous index (how far down in a given feed) |
211 * from the Source we are moving from. | 209 * from the Source we are moving from. |
212 * @param oldSection the original starting section (before the slider | 210 * @param oldSection the original starting section (before the slider |
213 * menu moved) | 211 * menu moved) |
214 * This method takes sliderMenu in the event that it needs to move | 212 * This method takes sliderMenu in the event that it needs to move |
215 * to a previous section, it can notify the UI to update. | 213 * to a previous section, it can notify the UI to update. |
216 */ | 214 */ |
217 void goToPreviousSection(SliderMenu sliderMenu) { | 215 void goToPreviousSection(SliderMenu sliderMenu) { |
218 //TODO(efortuna): don't pass sliderMenu here. Just update in view! | 216 //TODO(efortuna): don't pass sliderMenu here. Just update in view! |
219 var oldSection = currentSection; | 217 var oldSection = currentSection; |
220 int oldIndex = _articleIterator.currentIndex.value; | 218 int oldIndex = _articleIterator.currentIndex.value; |
221 sliderMenu.selectPrevious(true); | 219 sliderMenu.selectPrevious(true); |
222 | 220 |
223 // This check prevents our selector from wrapping around when we try to | 221 // This check prevents our selector from wrapping around when we try to |
224 // go to the "previous section", but we're already at the first section. | 222 // go to the "previous section", but we're already at the first section. |
225 if (oldSection != _sectionIterator.current) { | 223 if (oldSection != _sectionIterator.current) { |
226 _feedIterator = new BiIterator<Feed>(_sectionIterator.current.feeds, | 224 _feedIterator = new BiIterator<Feed>( |
227 _feedIterator.currentIndex.listeners); | 225 _sectionIterator.current.feeds, _feedIterator.currentIndex.listeners); |
228 // Jump to back of feed set if we are moving backwards through sections. | 226 // Jump to back of feed set if we are moving backwards through sections. |
229 _feedIterator.currentIndex.value = _feedIterator.list.length - 1; | 227 _feedIterator.currentIndex.value = _feedIterator.list.length - 1; |
230 _articleIterator = | 228 _articleIterator = new BiIterator<Article>(_feedIterator.current.articles, |
231 new BiIterator<Article>(_feedIterator.current.articles, | |
232 _articleIterator.currentIndex.listeners); | 229 _articleIterator.currentIndex.listeners); |
233 _articleIterator.currentIndex.value = oldIndex; | 230 _articleIterator.currentIndex.value = oldIndex; |
234 selectedArticle.value = _articleIterator.current; | 231 selectedArticle.value = _articleIterator.current; |
235 } | 232 } |
236 } | 233 } |
237 | 234 |
238 /** | 235 /** |
239 * Set the selected story as the current story (for viewing in the larger | 236 * Set the selected story as the current story (for viewing in the larger |
240 * Story View.) | 237 * Story View.) |
241 */ | 238 */ |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 * The user has moved to a new section (page). This can occur either | 277 * The user has moved to a new section (page). This can occur either |
281 * if the user clicked on a section page, or used keyboard shortcuts. | 278 * if the user clicked on a section page, or used keyboard shortcuts. |
282 * The default behavior is to move to the first article in the first | 279 * The default behavior is to move to the first article in the first |
283 * column. The location of the selected item depends on the previous | 280 * column. The location of the selected item depends on the previous |
284 * selected item location if the user used keyboard shortcuts. These | 281 * selected item location if the user used keyboard shortcuts. These |
285 * are manipulated in goToPrevious/NextSection(). | 282 * are manipulated in goToPrevious/NextSection(). |
286 */ | 283 */ |
287 void moveToNewSection(String sectionTitle) { | 284 void moveToNewSection(String sectionTitle) { |
288 _sectionIterator.currentIndex.value = | 285 _sectionIterator.currentIndex.value = |
289 _dataModel.findSectionIndex(sectionTitle); | 286 _dataModel.findSectionIndex(sectionTitle); |
290 _feedIterator = new BiIterator<Feed>(_sectionIterator.current.feeds, | 287 _feedIterator = new BiIterator<Feed>( |
291 _feedIterator.currentIndex.listeners); | 288 _sectionIterator.current.feeds, _feedIterator.currentIndex.listeners); |
292 _articleIterator = | 289 _articleIterator = new BiIterator<Article>(_feedIterator.current.articles, |
293 new BiIterator<Article>(_feedIterator.current.articles, | |
294 _articleIterator.currentIndex.listeners); | 290 _articleIterator.currentIndex.listeners); |
295 } | 291 } |
296 | 292 |
297 Section get currentSection => _sectionIterator.current; | 293 Section get currentSection => _sectionIterator.current; |
298 Feed get currentFeed => _feedIterator.current; | 294 Feed get currentFeed => _feedIterator.current; |
299 } | 295 } |
OLD | NEW |