42
|
1 |
// ////////////////////////////////////////////////////////////////////////////
|
|
2 |
// Symbian Foundation Example Code
|
|
3 |
//
|
|
4 |
// This software is in the public domain. No copyright is claimed, and you
|
|
5 |
// may use it for any purpose without license from the Symbian Foundation.
|
|
6 |
// No warranty for any purpose is expressed or implied by the authors or
|
|
7 |
// the Symbian Foundation.
|
|
8 |
// ////////////////////////////////////////////////////////////////////////////
|
|
9 |
|
|
10 |
// Feed presentation classes
|
|
11 |
|
|
12 |
// Abstract class used to create controls to represent feed entries.
|
|
13 |
function FeedPresenter(rssreader){
|
|
14 |
if (rssreader) {
|
|
15 |
this.init(rssreader);
|
|
16 |
}
|
|
17 |
}
|
|
18 |
|
|
19 |
// FeedPresenter "Constructor"
|
|
20 |
FeedPresenter.prototype.init = function(rssreader){
|
|
21 |
this.rssreader = rssreader;
|
|
22 |
}
|
|
23 |
|
|
24 |
// Create a control that represents this item and add it to
|
|
25 |
// parent rss reader
|
|
26 |
FeedPresenter.prototype.show = function(item){
|
|
27 |
}
|
|
28 |
|
|
29 |
// Create and add controls to be shown before items list.
|
|
30 |
FeedPresenter.prototype.addPreambleItems = function(){
|
|
31 |
}
|
|
32 |
|
|
33 |
// Create and add controls to be shown before items list.
|
|
34 |
FeedPresenter.prototype.addFooterItems = function(){
|
|
35 |
}
|
|
36 |
|
|
37 |
// No items returned, show "No messages"
|
|
38 |
FeedPresenter.prototype.showNoItems = function(){
|
|
39 |
var label = new Label(null, null, "No messages");
|
|
40 |
this.rssreader.addControl(label);
|
|
41 |
}
|
|
42 |
|
|
43 |
// Implementation of FeedPresenter that shows feed in a
|
|
44 |
// ContentPanel
|
|
45 |
function HtmlFeedPresenter(rssreader) {
|
|
46 |
if (rssreader) {
|
|
47 |
this.init(rssreader);
|
|
48 |
}
|
|
49 |
this.expanded = false;
|
|
50 |
}
|
|
51 |
|
|
52 |
// HtmlFeedPresenter is a subclass of FeedPresenter
|
|
53 |
HtmlFeedPresenter.prototype = new FeedPresenter(null);
|
|
54 |
|
|
55 |
// HtmlFeedPresenter "constructor"
|
|
56 |
HtmlFeedPresenter.prototype.init = function(rssreader) {
|
|
57 |
FeedPresenter.prototype.init.call(this, rssreader);
|
|
58 |
}
|
|
59 |
|
|
60 |
// Create a control that represents this item and add it to
|
|
61 |
// parent rss reader
|
|
62 |
HtmlFeedPresenter.prototype.show = function(item) {
|
|
63 |
// get a feed item control from the pool or create one and
|
|
64 |
// place it in the pool if there aren't enough feed item controls
|
|
65 |
var feedItemControl = new ContentPanel(null, null, null, true);
|
|
66 |
|
|
67 |
// initialize feed item control
|
|
68 |
feedItemControl.setCaption(item.title);
|
|
69 |
feedItemControl.setContent(this.getContentHTMLForFeedItem(item));
|
|
70 |
feedItemControl.setExpanded(this.expanded);
|
|
71 |
|
|
72 |
// add the feed item control to the main view
|
|
73 |
this.rssreader.feedItemControls.push(feedItemControl);
|
|
74 |
this.rssreader.addControl(feedItemControl);
|
|
75 |
}
|
|
76 |
|
|
77 |
// Returns the content HTML for a feed item.
|
|
78 |
HtmlFeedPresenter.prototype.getContentHTMLForFeedItem = function (item){
|
|
79 |
var buf = "";
|
|
80 |
|
|
81 |
// item date
|
|
82 |
if (item.date != null) {
|
|
83 |
buf += "<div class=\"FeedItemDate\">" ;
|
|
84 |
if ( item.author != null ) {
|
|
85 |
buf += item.author + ", ";
|
|
86 |
}
|
|
87 |
buf += item.date + "</div>";
|
|
88 |
}
|
|
89 |
|
|
90 |
// item description
|
|
91 |
if (item.description != null) {
|
|
92 |
buf += "<div class=\"FeedItemDescription\">" + item.description + "</div>";
|
|
93 |
}
|
|
94 |
|
|
95 |
if (item.url != null) {
|
|
96 |
// blogs
|
|
97 |
buf += "<div class=\"FeedItemLink\">";
|
|
98 |
// buf += "<a href=\"JavaScript:void(0)\" onclick=\"openURL('" + item.title + "', '" + item.url + "'); return false;\">";
|
|
99 |
buf += "<a href=\"JavaScript:void(0)\" onclick=\"openURL('" + item.url + "'); return false;\">";
|
|
100 |
buf += "Read more...";
|
|
101 |
buf += "</a>";
|
|
102 |
buf += "</div>";
|
|
103 |
}
|
|
104 |
|
|
105 |
return buf;
|
|
106 |
}
|
|
107 |
|
|
108 |
|
|
109 |
// Implementation of FeedPresenter that shows feed as a clickable
|
|
110 |
// button that shows feed entry title as label
|
|
111 |
function ButtonFeedPresenter(rssreader) {
|
|
112 |
if (rssreader) {
|
|
113 |
this.init(rssreader);
|
|
114 |
}
|
|
115 |
this.indexCounter = 0;
|
|
116 |
this.items = [];
|
|
117 |
}
|
|
118 |
|
|
119 |
// ButtonFeedPresenter is a subclass of FeedPresenter
|
|
120 |
ButtonFeedPresenter.prototype = new FeedPresenter(null);
|
|
121 |
|
|
122 |
// ButtonFeedPresenter "constructor"
|
|
123 |
ButtonFeedPresenter.prototype.init = function(rssreader) {
|
|
124 |
FeedPresenter.prototype.init.call(this, rssreader);
|
|
125 |
}
|
|
126 |
|
|
127 |
// Create a control that represents this item and add it to
|
|
128 |
// parent rss reader
|
|
129 |
ButtonFeedPresenter.prototype.show = function(item) {
|
|
130 |
this.items[this.indexCounter] = item;
|
|
131 |
// get a feed item control from the pool or create one and
|
|
132 |
// place it in the pool if there aren't enough feed item controls
|
|
133 |
var feedItemControl = new NavigationButton(this.indexCounter, "right.gif", item.title);
|
|
134 |
|
|
135 |
// add button press handler
|
|
136 |
var self = this;
|
|
137 |
feedItemControl.addEventListener("ActionPerformed",
|
|
138 |
function(event) { self.feedClicked(event); } );
|
|
139 |
|
|
140 |
this.indexCounter++;
|
|
141 |
|
|
142 |
// add the feed item control to the main view
|
|
143 |
this.rssreader.feedItemControls.push(feedItemControl);
|
|
144 |
this.rssreader.addControl(feedItemControl);
|
|
145 |
}
|
|
146 |
|
|
147 |
// Handle the button-press
|
|
148 |
ButtonFeedPresenter.prototype.feedClicked = function(event){
|
|
149 |
var clickedButton = event.source;
|
|
150 |
var id = clickedButton.id;
|
|
151 |
var url = this.items[id].url;
|
|
152 |
|
|
153 |
if (url.indexOf("/wiki/index.php")) {
|
|
154 |
// hack for printable wiki pages
|
|
155 |
var articleName = url.replace(wikiBaseUrl + "/", "");
|
|
156 |
url = wikiBaseUrl + "?title=" + articleName + "&action=render";
|
|
157 |
openURL(url);
|
|
158 |
}
|
|
159 |
else {
|
|
160 |
openURL(url);
|
|
161 |
}
|
|
162 |
}
|
|
163 |
|
|
164 |
|