0
|
1 |
///////////////////////////////////////////////////////////////////////////////
|
|
2 |
// RSS Reader from WRTKit examples, modified for Symbian.org
|
|
3 |
|
|
4 |
// RSS reader class
|
|
5 |
|
|
6 |
function RssReader(aFeedName, aFeedUrl, aFeedPresenter, aParent, aResponseParser){
|
|
7 |
this.responseParser = aResponseParser;
|
|
8 |
this.feedUpdateBroker = null;
|
|
9 |
this.feedUpdateBrokerActive = false;
|
|
10 |
this.feedName = aFeedName;
|
|
11 |
this.feedURL = aFeedUrl;
|
|
12 |
this.feedUpdateForced = false;
|
|
13 |
this.feedItemControls = [];
|
|
14 |
this.feedLastModified = 0;
|
|
15 |
this.ignoreContent = false;
|
|
16 |
this.hasData = false;
|
|
17 |
this.startFromItem = 0;
|
|
18 |
this.maxItems = 0;
|
|
19 |
|
|
20 |
var caption = createCaption(aFeedName);
|
|
21 |
|
|
22 |
ListView.prototype.init.call(this, null, caption);
|
|
23 |
this.previousView = aParent;
|
|
24 |
if (aFeedPresenter != null) {
|
|
25 |
this.feedPresenter = aFeedPresenter;
|
|
26 |
this.feedPresenter.init(this);
|
|
27 |
} else {
|
|
28 |
this.feedPresenter = new HtmlFeedPresenter(this);
|
|
29 |
}
|
|
30 |
|
|
31 |
// add pre-amble items (latest posts, new thread, reply etc)
|
|
32 |
this.feedPresenter.addPreambleItems();
|
|
33 |
}
|
|
34 |
|
|
35 |
RssReader.prototype = new ListView(null, null);
|
|
36 |
|
|
37 |
// Callback function that gets called when a feed update has completed.
|
|
38 |
RssReader.prototype.feedUpdateCompleted = function(event){
|
|
39 |
// remove cancel button
|
|
40 |
this.setupSoftKeys();
|
|
41 |
if (event.status == "ok") {
|
|
42 |
// if there aren't any feed items yet, we'll hide the progress dialog
|
|
43 |
|
|
44 |
// check if the feed has updated
|
|
45 |
if (event.lastModified != this.feedLastModified) {
|
|
46 |
// remember the last modified timestamp
|
|
47 |
this.feedLastModified = event.lastModified;
|
|
48 |
|
|
49 |
// feed fetched and parsed successfully
|
|
50 |
this.setFeedItems(event.items);
|
|
51 |
|
|
52 |
// focus the first feed item control
|
|
53 |
// (but only if we are in the main view)
|
|
54 |
if (this.feedItemControls.length > 0 ) {
|
|
55 |
this.feedItemControls[0].setFocused(true);
|
|
56 |
}
|
|
57 |
}
|
|
58 |
uiManager.hideNotification();
|
|
59 |
}
|
|
60 |
else if (event.status != "cancelled") {
|
|
61 |
// show error message
|
2
|
62 |
uiManager.showNotification(3000, "warning", "Error while updating feed!");
|
0
|
63 |
}
|
|
64 |
|
|
65 |
// reset the broker
|
|
66 |
this.feedUpdateBroker = null;
|
|
67 |
this.feedUpdateBrokerActive = false;
|
|
68 |
|
|
69 |
// reset commanded feed update flag
|
|
70 |
this.feedUpdateForced = false;
|
|
71 |
}
|
|
72 |
|
|
73 |
// Removes feed items.
|
|
74 |
RssReader.prototype.removeFeedItems = function (){
|
|
75 |
// remove all current feed items from the main view
|
|
76 |
for (var i = 0; i < this.feedItemControls.length; i++) {
|
|
77 |
this.removeControl(this.feedItemControls[i]);
|
|
78 |
}
|
|
79 |
|
|
80 |
// reset feed item control array
|
|
81 |
this.feedItemControls = [];
|
|
82 |
}
|
|
83 |
|
|
84 |
|
|
85 |
// Sets feed items.
|
|
86 |
RssReader.prototype.setFeedItems = function (items){
|
|
87 |
// start by removing all current feed items
|
|
88 |
this.removeFeedItems();
|
|
89 |
|
|
90 |
if (items.length == 0) {
|
|
91 |
this.feedPresenter.showNoItems();
|
|
92 |
}
|
|
93 |
else {
|
|
94 |
// create new feed items and add them to the main view
|
|
95 |
// use feed item pool to recycle controls
|
|
96 |
for (var i = 0; i < items.length; i++) {
|
|
97 |
var item = items[i];
|
|
98 |
this.feedPresenter.show(item);
|
|
99 |
}
|
|
100 |
|
|
101 |
}
|
|
102 |
this.hasData = true;
|
|
103 |
}
|
|
104 |
|
|
105 |
|
|
106 |
// Update feed
|
|
107 |
RssReader.prototype.update = function(forceFeedUpdate){
|
|
108 |
if ( this.hasData && !forceFeedUpdate ) {
|
|
109 |
return;
|
|
110 |
}
|
|
111 |
this.feedUpdateForced = forceFeedUpdate;
|
|
112 |
|
|
113 |
// check if a feed update has been scheduled, if it's time to update now,
|
|
114 |
// and if there's no update currently in progress and if we're in the main view
|
|
115 |
if ((this.feedURL != null) && (!this.feedUpdateBrokerActive) ) { //&& (uiManager.getView() == this) ) {
|
|
116 |
// fetch the feed from the specified URL
|
|
117 |
this.feedUpdateBrokerActive = true;
|
|
118 |
this.feedUpdateBroker = new FeedUpdateBroker();
|
|
119 |
this.feedUpdateBroker.startFromItem = this.startFromItem;
|
|
120 |
this.feedUpdateBroker.maxItems = this.maxItems;
|
|
121 |
|
|
122 |
if ( this.responseParser != null ) {
|
|
123 |
this.feedUpdateBroker.responseParser = this.responseParser;
|
|
124 |
}
|
|
125 |
this.feedUpdateBroker.ignoreContent = this.ignoreContent;
|
|
126 |
this.feedUpdateBroker.fetchFeed(this.feedURL, this);
|
|
127 |
// allow cancelling
|
|
128 |
if (window.widget) {
|
|
129 |
var self = this;
|
|
130 |
menu.setRightSoftkeyLabel("Cancel", function(){
|
|
131 |
self.feedUpdateBroker.cancel(); self.setupSoftKeys();
|
|
132 |
uiManager.hideNotification();
|
|
133 |
});
|
|
134 |
}
|
|
135 |
uiManager.showNotification(-1, "wait", "Loading feed...", -1);
|
|
136 |
}
|
|
137 |
}
|