Merge lp:~dgadomski/ubuntu-rssreader-app/relative-time-formatting into lp:~ubuntu-shorts-dev/ubuntu-rssreader-app/trunk
- relative-time-formatting
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Joey Chan |
Approved revision: | 22 |
Merged at revision: | 25 |
Proposed branch: | lp:~dgadomski/ubuntu-rssreader-app/relative-time-formatting |
Merge into: | lp:~ubuntu-shorts-dev/ubuntu-rssreader-app/trunk |
Diff against target: |
520 lines (+116/-74) 10 files modified
ArticleFullImg.qml (+4/-3) ArticleOneImgA.qml (+4/-3) ArticleOneImgB.qml (+4/-3) ArticleTextA.qml (+4/-3) ArticleTextB.qml (+4/-3) ArticleTwoImgA.qml (+4/-3) ListColumnDelegate.qml (+2/-2) ListColumnView.qml (+1/-1) addDelegate.js (+19/-19) dateutils.js (+70/-34) |
To merge this branch: | bzr merge lp:~dgadomski/ubuntu-rssreader-app/relative-time-formatting |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ubuntu Phone Apps Jenkins Bot | continuous-integration | Approve | |
Ubuntu Shorts Developers | Pending | ||
Joey Chan | Pending | ||
David Planella | Pending | ||
Review via email: mp+176435@code.launchpad.net |
Commit message
Improved relative time formatting utility.
Description of the change
This is my second approach to provide a more generic and flexible relative time formatting utility. This one incorporates an array of formatters which may be adjusted when needed.
There are 2 new formats added 'borrowed' from the calculator app: displaying that something happened yesterday ("Yesterday at %1") or within a week from now (by using the weekday name).
I have tested this version and it works just fine with gettext (all strings are extracted correctly for translations).
Unfortunately, since i18n is a QML context property (confirmed in Ubuntu UI toolkit source code: http://
I believe in this form it can be easily reused in ubuntu-
Roman Shchekin (mrqtros) wrote : | # |
- 22. By Dariusz Gadomski
-
Merge with trunk.
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) : | # |
Joey Chan (qqworini) wrote : | # |
Hi Dariusz,
We gonna make some changes to the database, one of the major change is, store time value in Integer, not text like before, in order to "order" articles by time value.
So, I want to ask u to separate the "formatRelative
1. one is convert the original time value to an Integer which is seconds from 1970-01-01 00:00
2. convert the "seconds" Integer to current output
Hope u have time to help :)
Thanks
Joey
Dariusz Gadomski (dgadomski) wrote : | # |
Hi Joey,
I have changed the implementation to suit your needs:
https:/
I hope this is what you expected.
Regards,
Dariusz
Preview Diff
1 | === modified file 'ArticleFullImg.qml' | |||
2 | --- ArticleFullImg.qml 2013-07-09 16:08:27 +0000 | |||
3 | +++ ArticleFullImg.qml 2013-07-26 15:25:31 +0000 | |||
4 | @@ -1,12 +1,13 @@ | |||
5 | 1 | import QtQuick 2.0 | 1 | import QtQuick 2.0 |
6 | 2 | import Ubuntu.Components 0.1 | 2 | import Ubuntu.Components 0.1 |
7 | 3 | import Ubuntu.Components.ListItems 0.1 as ListItem | 3 | import Ubuntu.Components.ListItems 0.1 as ListItem |
8 | 4 | import "./dateutils.js" as DateUtils | ||
9 | 4 | 5 | ||
10 | 5 | Column { | 6 | Column { |
11 | 6 | width: units.gu(26) | 7 | width: units.gu(26) |
12 | 7 | height: units.gu(20) | 8 | height: units.gu(20) |
13 | 8 | // anchors.fill: parent | 9 | // anchors.fill: parent |
15 | 9 | property string rss_title: "" | 10 | property variant rss_item |
16 | 10 | property variant imageArray: [] | 11 | property variant imageArray: [] |
17 | 11 | property variant rss_model | 12 | property variant rss_model |
18 | 12 | property int model_index | 13 | property int model_index |
19 | @@ -42,7 +43,7 @@ | |||
20 | 42 | Label | 43 | Label |
21 | 43 | { | 44 | { |
22 | 44 | id: label_title | 45 | id: label_title |
24 | 45 | text: rss_title | 46 | text: rss_item.title |
25 | 46 | anchors.bottom: parent.bottom | 47 | anchors.bottom: parent.bottom |
26 | 47 | anchors.bottomMargin: units.gu(1) | 48 | anchors.bottomMargin: units.gu(1) |
27 | 48 | anchors.horizontalCenter: parent.horizontalCenter | 49 | anchors.horizontalCenter: parent.horizontalCenter |
28 | @@ -67,7 +68,7 @@ | |||
29 | 67 | Label | 68 | Label |
30 | 68 | { | 69 | { |
31 | 69 | id: label_time | 70 | id: label_time |
33 | 70 | text: "13 minutes ago" | 71 | text: DateUtils.formatRelativeTime(i18n, rss_item.pubdate) |
34 | 71 | color: "black" | 72 | color: "black" |
35 | 72 | fontSize: "medium" | 73 | fontSize: "medium" |
36 | 73 | } | 74 | } |
37 | 74 | 75 | ||
38 | === modified file 'ArticleOneImgA.qml' | |||
39 | --- ArticleOneImgA.qml 2013-07-05 13:59:01 +0000 | |||
40 | +++ ArticleOneImgA.qml 2013-07-26 15:25:31 +0000 | |||
41 | @@ -1,13 +1,14 @@ | |||
42 | 1 | import QtQuick 2.0 | 1 | import QtQuick 2.0 |
43 | 2 | import Ubuntu.Components 0.1 | 2 | import Ubuntu.Components 0.1 |
44 | 3 | import Ubuntu.Components.ListItems 0.1 as ListItem | 3 | import Ubuntu.Components.ListItems 0.1 as ListItem |
45 | 4 | import "./dateutils.js" as DateUtils | ||
46 | 4 | 5 | ||
47 | 5 | Column { | 6 | Column { |
48 | 6 | id: delegate_item | 7 | id: delegate_item |
49 | 7 | width: units.gu(34) | 8 | width: units.gu(34) |
50 | 8 | // height: units.gu(16) | 9 | // height: units.gu(16) |
51 | 9 | // anchors.fill: parent | 10 | // anchors.fill: parent |
53 | 10 | property string rss_title: "" | 11 | property variant rss_item |
54 | 11 | property variant imageArray: [] | 12 | property variant imageArray: [] |
55 | 12 | property variant rss_model | 13 | property variant rss_model |
56 | 13 | property int model_index | 14 | property int model_index |
57 | @@ -21,7 +22,7 @@ | |||
58 | 21 | Label | 22 | Label |
59 | 22 | { | 23 | { |
60 | 23 | id: label_title | 24 | id: label_title |
62 | 24 | text: rss_title | 25 | text: rss_item.title |
63 | 25 | // anchors.horizontalCenter: parent.horizontalCenter | 26 | // anchors.horizontalCenter: parent.horizontalCenter |
64 | 26 | width: units.gu(14) | 27 | width: units.gu(14) |
65 | 27 | wrapMode: Text.WrapAtWordBoundaryOrAnywhere | 28 | wrapMode: Text.WrapAtWordBoundaryOrAnywhere |
66 | @@ -72,7 +73,7 @@ | |||
67 | 72 | Label | 73 | Label |
68 | 73 | { | 74 | { |
69 | 74 | id: label_time | 75 | id: label_time |
71 | 75 | text: "13 minutes ago" | 76 | text: DateUtils.formatRelativeTime(i18n, rss_item.pubdate) |
72 | 76 | color: "black" | 77 | color: "black" |
73 | 77 | fontSize: "medium" | 78 | fontSize: "medium" |
74 | 78 | horizontalAlignment: Text.AlignRight | 79 | horizontalAlignment: Text.AlignRight |
75 | 79 | 80 | ||
76 | === modified file 'ArticleOneImgB.qml' | |||
77 | --- ArticleOneImgB.qml 2013-07-05 13:59:01 +0000 | |||
78 | +++ ArticleOneImgB.qml 2013-07-26 15:25:31 +0000 | |||
79 | @@ -1,13 +1,14 @@ | |||
80 | 1 | import QtQuick 2.0 | 1 | import QtQuick 2.0 |
81 | 2 | import Ubuntu.Components 0.1 | 2 | import Ubuntu.Components 0.1 |
82 | 3 | import Ubuntu.Components.ListItems 0.1 as ListItem | 3 | import Ubuntu.Components.ListItems 0.1 as ListItem |
83 | 4 | import "./dateutils.js" as DateUtils | ||
84 | 4 | 5 | ||
85 | 5 | Column { | 6 | Column { |
86 | 6 | id: delegate_item | 7 | id: delegate_item |
87 | 7 | width: units.gu(34) | 8 | width: units.gu(34) |
88 | 8 | // height: units.gu(16) | 9 | // height: units.gu(16) |
89 | 9 | // anchors.fill: parent | 10 | // anchors.fill: parent |
91 | 10 | property string rss_title: "" | 11 | property variant rss_item |
92 | 11 | property variant imageArray: [] | 12 | property variant imageArray: [] |
93 | 12 | property variant rss_model | 13 | property variant rss_model |
94 | 13 | property int model_index | 14 | property int model_index |
95 | @@ -59,7 +60,7 @@ | |||
96 | 59 | Label | 60 | Label |
97 | 60 | { | 61 | { |
98 | 61 | id: label_title | 62 | id: label_title |
100 | 62 | text: rss_title | 63 | text: rss_item.title |
101 | 63 | // anchors.horizontalCenter: parent.horizontalCenter | 64 | // anchors.horizontalCenter: parent.horizontalCenter |
102 | 64 | width: units.gu(14) | 65 | width: units.gu(14) |
103 | 65 | wrapMode: Text.WrapAtWordBoundaryOrAnywhere | 66 | wrapMode: Text.WrapAtWordBoundaryOrAnywhere |
104 | @@ -91,7 +92,7 @@ | |||
105 | 91 | Label | 92 | Label |
106 | 92 | { | 93 | { |
107 | 93 | id: label_time | 94 | id: label_time |
109 | 94 | text: "13 minutes ago" | 95 | text: DateUtils.formatRelativeTime(i18n, rss_item.pubdate) |
110 | 95 | color: "black" | 96 | color: "black" |
111 | 96 | fontSize: "medium" | 97 | fontSize: "medium" |
112 | 97 | } | 98 | } |
113 | 98 | 99 | ||
114 | === modified file 'ArticleTextA.qml' | |||
115 | --- ArticleTextA.qml 2013-07-05 13:59:01 +0000 | |||
116 | +++ ArticleTextA.qml 2013-07-26 15:25:31 +0000 | |||
117 | @@ -1,12 +1,13 @@ | |||
118 | 1 | import QtQuick 2.0 | 1 | import QtQuick 2.0 |
119 | 2 | import Ubuntu.Components 0.1 | 2 | import Ubuntu.Components 0.1 |
120 | 3 | import Ubuntu.Components.ListItems 0.1 as ListItem | 3 | import Ubuntu.Components.ListItems 0.1 as ListItem |
121 | 4 | import "./dateutils.js" as DateUtils | ||
122 | 4 | 5 | ||
123 | 5 | Column { | 6 | Column { |
124 | 6 | width: units.gu(30) | 7 | width: units.gu(30) |
125 | 7 | // height: units.gu(15) | 8 | // height: units.gu(15) |
126 | 8 | // anchors.fill: parent | 9 | // anchors.fill: parent |
128 | 9 | property string rss_title: "" | 10 | property variant rss_item |
129 | 10 | property variant imageArray: [] | 11 | property variant imageArray: [] |
130 | 11 | property variant rss_model | 12 | property variant rss_model |
131 | 12 | property int model_index | 13 | property int model_index |
132 | @@ -19,7 +20,7 @@ | |||
133 | 19 | Label | 20 | Label |
134 | 20 | { | 21 | { |
135 | 21 | id: label_title | 22 | id: label_title |
137 | 22 | text: rss_title | 23 | text: rss_item.title |
138 | 23 | // anchors.horizontalCenter: parent.horizontalCenter | 24 | // anchors.horizontalCenter: parent.horizontalCenter |
139 | 24 | width: units.gu(30) | 25 | width: units.gu(30) |
140 | 25 | wrapMode: Text.WrapAtWordBoundaryOrAnywhere | 26 | wrapMode: Text.WrapAtWordBoundaryOrAnywhere |
141 | @@ -42,7 +43,7 @@ | |||
142 | 42 | Label | 43 | Label |
143 | 43 | { | 44 | { |
144 | 44 | id: label_time | 45 | id: label_time |
146 | 45 | text: "13 minutes ago" | 46 | text: DateUtils.formatRelativeTime(i18n, rss_item.pubdate) |
147 | 46 | color: "black" | 47 | color: "black" |
148 | 47 | fontSize: "medium" | 48 | fontSize: "medium" |
149 | 48 | width: parent.width | 49 | width: parent.width |
150 | 49 | 50 | ||
151 | === modified file 'ArticleTextB.qml' | |||
152 | --- ArticleTextB.qml 2013-07-05 13:59:01 +0000 | |||
153 | +++ ArticleTextB.qml 2013-07-26 15:25:31 +0000 | |||
154 | @@ -1,12 +1,13 @@ | |||
155 | 1 | import QtQuick 2.0 | 1 | import QtQuick 2.0 |
156 | 2 | import Ubuntu.Components 0.1 | 2 | import Ubuntu.Components 0.1 |
157 | 3 | import Ubuntu.Components.ListItems 0.1 as ListItem | 3 | import Ubuntu.Components.ListItems 0.1 as ListItem |
158 | 4 | import "./dateutils.js" as DateUtils | ||
159 | 4 | 5 | ||
160 | 5 | Column { | 6 | Column { |
161 | 6 | width: units.gu(30) | 7 | width: units.gu(30) |
162 | 7 | // height: units.gu(15) | 8 | // height: units.gu(15) |
163 | 8 | // anchors.fill: parent | 9 | // anchors.fill: parent |
165 | 9 | property string rss_title: "" | 10 | property variant rss_item |
166 | 10 | property variant imageArray: [] | 11 | property variant imageArray: [] |
167 | 11 | property variant rss_model | 12 | property variant rss_model |
168 | 12 | property int model_index | 13 | property int model_index |
169 | @@ -19,7 +20,7 @@ | |||
170 | 19 | Label | 20 | Label |
171 | 20 | { | 21 | { |
172 | 21 | id: label_title | 22 | id: label_title |
174 | 22 | text: rss_title | 23 | text: rss_item.title |
175 | 23 | // anchors.horizontalCenter: parent.horizontalCenter | 24 | // anchors.horizontalCenter: parent.horizontalCenter |
176 | 24 | width: units.gu(30) | 25 | width: units.gu(30) |
177 | 25 | wrapMode: Text.WrapAtWordBoundaryOrAnywhere | 26 | wrapMode: Text.WrapAtWordBoundaryOrAnywhere |
178 | @@ -43,7 +44,7 @@ | |||
179 | 43 | Label | 44 | Label |
180 | 44 | { | 45 | { |
181 | 45 | id: label_time | 46 | id: label_time |
183 | 46 | text: "13 minutes ago" | 47 | text: DateUtils.formatRelativeTime(i18n, rss_item.pubdate) |
184 | 47 | color: "black" | 48 | color: "black" |
185 | 48 | fontSize: "medium" | 49 | fontSize: "medium" |
186 | 49 | horizontalAlignment: Text.AlignRight | 50 | horizontalAlignment: Text.AlignRight |
187 | 50 | 51 | ||
188 | === modified file 'ArticleTwoImgA.qml' | |||
189 | --- ArticleTwoImgA.qml 2013-07-05 13:59:01 +0000 | |||
190 | +++ ArticleTwoImgA.qml 2013-07-26 15:25:31 +0000 | |||
191 | @@ -1,13 +1,14 @@ | |||
192 | 1 | import QtQuick 2.0 | 1 | import QtQuick 2.0 |
193 | 2 | import Ubuntu.Components 0.1 | 2 | import Ubuntu.Components 0.1 |
194 | 3 | import Ubuntu.Components.ListItems 0.1 as ListItem | 3 | import Ubuntu.Components.ListItems 0.1 as ListItem |
195 | 4 | import "./dateutils.js" as DateUtils | ||
196 | 4 | 5 | ||
197 | 5 | Column { | 6 | Column { |
198 | 6 | id: delegate_item | 7 | id: delegate_item |
199 | 7 | width: units.gu(34) | 8 | width: units.gu(34) |
200 | 8 | // height: units.gu(30) | 9 | // height: units.gu(30) |
201 | 9 | // anchors.fill: parent | 10 | // anchors.fill: parent |
203 | 10 | property string rss_title: "" | 11 | property variant rss_item |
204 | 11 | property variant imageArray: [] | 12 | property variant imageArray: [] |
205 | 12 | property variant rss_model | 13 | property variant rss_model |
206 | 13 | property int model_index | 14 | property int model_index |
207 | @@ -21,7 +22,7 @@ | |||
208 | 21 | Label | 22 | Label |
209 | 22 | { | 23 | { |
210 | 23 | id: label_title | 24 | id: label_title |
212 | 24 | text: rss_title | 25 | text: rss_item.title |
213 | 25 | // anchors.horizontalCenter: parent.horizontalCenter | 26 | // anchors.horizontalCenter: parent.horizontalCenter |
214 | 26 | width: units.gu(14) | 27 | width: units.gu(14) |
215 | 27 | wrapMode: Text.WrapAtWordBoundaryOrAnywhere | 28 | wrapMode: Text.WrapAtWordBoundaryOrAnywhere |
216 | @@ -78,7 +79,7 @@ | |||
217 | 78 | Label | 79 | Label |
218 | 79 | { | 80 | { |
219 | 80 | id: label_time | 81 | id: label_time |
221 | 81 | text: "13 minutes ago" | 82 | text: DateUtils.formatRelativeTime(i18n, rss_item.pubdate) |
222 | 82 | color: "black" | 83 | color: "black" |
223 | 83 | fontSize: "medium" | 84 | fontSize: "medium" |
224 | 84 | } | 85 | } |
225 | 85 | 86 | ||
226 | === modified file 'ListColumnDelegate.qml' | |||
227 | --- ListColumnDelegate.qml 2013-07-13 18:28:20 +0000 | |||
228 | +++ ListColumnDelegate.qml 2013-07-26 15:25:31 +0000 | |||
229 | @@ -20,10 +20,10 @@ | |||
230 | 20 | property real childrenMaxWidth: 0 | 20 | property real childrenMaxWidth: 0 |
231 | 21 | property int modelIndex | 21 | property int modelIndex |
232 | 22 | 22 | ||
234 | 23 | function addItem(rss_title, rss_description, model, index) | 23 | function addItem(rss_item, rss_description, model, index) |
235 | 24 | { | 24 | { |
236 | 25 | // console.log("delegate height: ", rss_item_delegate.height) ; | 25 | // console.log("delegate height: ", rss_item_delegate.height) ; |
238 | 26 | var newD = AddD.addDelegate(rss_title, ImgS.separate(rss_description), model, index); | 26 | var newD = AddD.addDelegate(rss_item, ImgS.separate(rss_description), model, index); |
239 | 27 | getChildrenRect() ; | 27 | getChildrenRect() ; |
240 | 28 | rss_item_delegate.width = childrenMaxWidth ; | 28 | rss_item_delegate.width = childrenMaxWidth ; |
241 | 29 | //console.log("childrenSumHeight, column.height: ", childrenSumHeight, rss_item_delegate.height) | 29 | //console.log("childrenSumHeight, column.height: ", childrenSumHeight, rss_item_delegate.height) |
242 | 30 | 30 | ||
243 | === modified file 'ListColumnView.qml' | |||
244 | --- ListColumnView.qml 2013-07-13 18:28:20 +0000 | |||
245 | +++ ListColumnView.qml 2013-07-26 15:25:31 +0000 | |||
246 | @@ -104,7 +104,7 @@ | |||
247 | 104 | // model++ ; | 104 | // model++ ; |
248 | 105 | // currentIndex = model - 1 ; | 105 | // currentIndex = model - 1 ; |
249 | 106 | // console.log("model index: ", i) | 106 | // console.log("model index: ", i) |
251 | 107 | while (!currentItem.addItem(tempmodel.get(i).title, tempmodel.get(i).description, tempmodel, i)) | 107 | while (!currentItem.addItem(tempmodel.get(i), tempmodel.get(i).description, tempmodel, i)) |
252 | 108 | { | 108 | { |
253 | 109 | // model++ ; | 109 | // model++ ; |
254 | 110 | column_model.append( { "nothing": "nothing" } ) ; | 110 | column_model.append( { "nothing": "nothing" } ) ; |
255 | 111 | 111 | ||
256 | === modified file 'addDelegate.js' | |||
257 | --- addDelegate.js 2013-07-05 13:59:01 +0000 | |||
258 | +++ addDelegate.js 2013-07-26 15:25:31 +0000 | |||
259 | @@ -4,7 +4,7 @@ | |||
260 | 4 | //var mob_component; | 4 | //var mob_component; |
261 | 5 | //var mob_sprite; | 5 | //var mob_sprite; |
262 | 6 | 6 | ||
264 | 7 | function addDelegate(rss_title, imageArray, model, index) | 7 | function addDelegate(rss_item, imageArray, model, index) |
265 | 8 | { | 8 | { |
266 | 9 | // console.log("add delegate start") | 9 | // console.log("add delegate start") |
267 | 10 | // component = undefined ; | 10 | // component = undefined ; |
268 | @@ -23,18 +23,18 @@ | |||
269 | 23 | // component = Qt.createComponent("./ArticledelegateOneImgB.qml"); | 23 | // component = Qt.createComponent("./ArticledelegateOneImgB.qml"); |
270 | 24 | // sprite = component.createObject(rss_item_delegate, {"rss_title": rss_title, "imageArray": imageArray}); | 24 | // sprite = component.createObject(rss_item_delegate, {"rss_title": rss_title, "imageArray": imageArray}); |
271 | 25 | // console.log("delegate BBBBB") | 25 | // console.log("delegate BBBBB") |
273 | 26 | newD = delegateOneImgA (rss_title, imageArray, model, index) | 26 | newD = delegateOneImgA (rss_item, imageArray, model, index) |
274 | 27 | } | 27 | } |
275 | 28 | else if (rand > 70) | 28 | else if (rand > 70) |
276 | 29 | { | 29 | { |
277 | 30 | // component = Qt.createComponent("./ArticledelegateOneImgA.qml"); | 30 | // component = Qt.createComponent("./ArticledelegateOneImgA.qml"); |
278 | 31 | // sprite = component.createObject(rss_item_delegate, {"rss_title": rss_title, "imageArray": imageArray}); | 31 | // sprite = component.createObject(rss_item_delegate, {"rss_title": rss_title, "imageArray": imageArray}); |
279 | 32 | // console.log("delegate AAAAA") | 32 | // console.log("delegate AAAAA") |
281 | 33 | newD = delegateOneImgB (rss_title, imageArray, model, index) | 33 | newD = delegateOneImgB (rss_item, imageArray, model, index) |
282 | 34 | } | 34 | } |
283 | 35 | else | 35 | else |
284 | 36 | { | 36 | { |
286 | 37 | newD = delegateFullImg (rss_title, imageArray, model, index) | 37 | newD = delegateFullImg (rss_item, imageArray, model, index) |
287 | 38 | } | 38 | } |
288 | 39 | 39 | ||
289 | 40 | } | 40 | } |
290 | @@ -42,16 +42,16 @@ | |||
291 | 42 | { | 42 | { |
292 | 43 | if (rand > 50) | 43 | if (rand > 50) |
293 | 44 | { | 44 | { |
295 | 45 | newD = delegateTextA (rss_title/*, imageArray*/, model, index) ; | 45 | newD = delegateTextA (rss_item/*, imageArray*/, model, index) ; |
296 | 46 | } | 46 | } |
297 | 47 | else | 47 | else |
298 | 48 | { | 48 | { |
300 | 49 | newD = delegateTextB (rss_title/*, imageArray*/, model, index) ; | 49 | newD = delegateTextB (rss_item/*, imageArray*/, model, index) ; |
301 | 50 | } | 50 | } |
302 | 51 | } | 51 | } |
303 | 52 | else | 52 | else |
304 | 53 | { | 53 | { |
306 | 54 | newD = delegateTwoImgA (rss_title, imageArray, model, index) | 54 | newD = delegateTwoImgA (rss_item, imageArray, model, index) |
307 | 55 | } | 55 | } |
308 | 56 | 56 | ||
309 | 57 | // else if (imageArray == undefined ) | 57 | // else if (imageArray == undefined ) |
310 | @@ -79,12 +79,12 @@ | |||
311 | 79 | return newD ; | 79 | return newD ; |
312 | 80 | } | 80 | } |
313 | 81 | 81 | ||
315 | 82 | function delegateOneImgA (rss_title, imageArray, model, index) | 82 | function delegateOneImgA (rss_item, imageArray, model, index) |
316 | 83 | { | 83 | { |
317 | 84 | var component; | 84 | var component; |
318 | 85 | var sprite; | 85 | var sprite; |
319 | 86 | component = Qt.createComponent("./ArticleOneImgA.qml"); | 86 | component = Qt.createComponent("./ArticleOneImgA.qml"); |
321 | 87 | sprite = component.createObject(rss_item_delegate, {"rss_title": rss_title, "imageArray": imageArray, "rss_model": model, "model_index": index}); | 87 | sprite = component.createObject(rss_item_delegate, {"rss_item": rss_item, "imageArray": imageArray, "rss_model": model, "model_index": index}); |
322 | 88 | // console.log("delegate AAAAA") | 88 | // console.log("delegate AAAAA") |
323 | 89 | 89 | ||
324 | 90 | if (sprite == null) { | 90 | if (sprite == null) { |
325 | @@ -95,12 +95,12 @@ | |||
326 | 95 | return sprite | 95 | return sprite |
327 | 96 | } | 96 | } |
328 | 97 | 97 | ||
330 | 98 | function delegateOneImgB (rss_title, imageArray, model, index) | 98 | function delegateOneImgB (rss_item, imageArray, model, index) |
331 | 99 | { | 99 | { |
332 | 100 | var component; | 100 | var component; |
333 | 101 | var sprite; | 101 | var sprite; |
334 | 102 | component = Qt.createComponent("./ArticleOneImgB.qml"); | 102 | component = Qt.createComponent("./ArticleOneImgB.qml"); |
336 | 103 | sprite = component.createObject(rss_item_delegate, {"rss_title": rss_title, "imageArray": imageArray, "rss_model": model, "model_index": index}); | 103 | sprite = component.createObject(rss_item_delegate, {"rss_item": rss_item, "imageArray": imageArray, "rss_model": model, "model_index": index}); |
337 | 104 | // console.log("delegate BBBBB") | 104 | // console.log("delegate BBBBB") |
338 | 105 | 105 | ||
339 | 106 | if (sprite == null) { | 106 | if (sprite == null) { |
340 | @@ -111,12 +111,12 @@ | |||
341 | 111 | return sprite | 111 | return sprite |
342 | 112 | } | 112 | } |
343 | 113 | 113 | ||
345 | 114 | function delegateTextA (rss_title, model, index) | 114 | function delegateTextA (rss_item, model, index) |
346 | 115 | { | 115 | { |
347 | 116 | var component; | 116 | var component; |
348 | 117 | var sprite; | 117 | var sprite; |
349 | 118 | component = Qt.createComponent("./ArticleTextA.qml"); | 118 | component = Qt.createComponent("./ArticleTextA.qml"); |
351 | 119 | sprite = component.createObject(rss_item_delegate, {"rss_title": rss_title, "rss_model": model, "model_index": index}); | 119 | sprite = component.createObject(rss_item_delegate, {"rss_item": rss_item, "rss_model": model, "model_index": index}); |
352 | 120 | // console.log("delegate CCCCC") | 120 | // console.log("delegate CCCCC") |
353 | 121 | 121 | ||
354 | 122 | if (sprite == null) { | 122 | if (sprite == null) { |
355 | @@ -127,12 +127,12 @@ | |||
356 | 127 | return sprite | 127 | return sprite |
357 | 128 | } | 128 | } |
358 | 129 | 129 | ||
360 | 130 | function delegateTextB (rss_title, model, index) | 130 | function delegateTextB (rss_item, model, index) |
361 | 131 | { | 131 | { |
362 | 132 | var component; | 132 | var component; |
363 | 133 | var sprite; | 133 | var sprite; |
364 | 134 | component = Qt.createComponent("./ArticleTextB.qml"); | 134 | component = Qt.createComponent("./ArticleTextB.qml"); |
366 | 135 | sprite = component.createObject(rss_item_delegate, {"rss_title": rss_title, "rss_model": model, "model_index": index}); | 135 | sprite = component.createObject(rss_item_delegate, {"rss_item": rss_item, "rss_model": model, "model_index": index}); |
367 | 136 | // console.log("delegate CCCCC") | 136 | // console.log("delegate CCCCC") |
368 | 137 | 137 | ||
369 | 138 | if (sprite == null) { | 138 | if (sprite == null) { |
370 | @@ -143,12 +143,12 @@ | |||
371 | 143 | return sprite | 143 | return sprite |
372 | 144 | } | 144 | } |
373 | 145 | 145 | ||
375 | 146 | function delegateFullImg (rss_title, imageArray, model, index) | 146 | function delegateFullImg (rss_item, imageArray, model, index) |
376 | 147 | { | 147 | { |
377 | 148 | var component; | 148 | var component; |
378 | 149 | var sprite; | 149 | var sprite; |
379 | 150 | component = Qt.createComponent("./ArticleFullImg.qml"); | 150 | component = Qt.createComponent("./ArticleFullImg.qml"); |
381 | 151 | sprite = component.createObject(rss_item_delegate, {"rss_title": rss_title, "imageArray": imageArray, "rss_model": model, "model_index": index}); | 151 | sprite = component.createObject(rss_item_delegate, {"rss_item": rss_item, "imageArray": imageArray, "rss_model": model, "model_index": index}); |
382 | 152 | // console.log("delegate DDDDD") | 152 | // console.log("delegate DDDDD") |
383 | 153 | 153 | ||
384 | 154 | if (sprite == null) { | 154 | if (sprite == null) { |
385 | @@ -159,12 +159,12 @@ | |||
386 | 159 | return sprite | 159 | return sprite |
387 | 160 | } | 160 | } |
388 | 161 | 161 | ||
390 | 162 | function delegateTwoImgA (rss_title, imageArray, model, index) | 162 | function delegateTwoImgA (rss_item, imageArray, model, index) |
391 | 163 | { | 163 | { |
392 | 164 | var component; | 164 | var component; |
393 | 165 | var sprite; | 165 | var sprite; |
394 | 166 | component = Qt.createComponent("./ArticleTwoImgA.qml"); | 166 | component = Qt.createComponent("./ArticleTwoImgA.qml"); |
396 | 167 | sprite = component.createObject(rss_item_delegate, {"rss_title": rss_title, "imageArray": imageArray, "rss_model": model, "model_index": index}); | 167 | sprite = component.createObject(rss_item_delegate, {"rss_item": rss_item, "imageArray": imageArray, "rss_model": model, "model_index": index}); |
397 | 168 | 168 | ||
398 | 169 | if (sprite == null) { | 169 | if (sprite == null) { |
399 | 170 | // Error Handling | 170 | // Error Handling |
400 | 171 | 171 | ||
401 | === modified file 'dateutils.js' | |||
402 | --- dateutils.js 2013-07-21 12:49:09 +0000 | |||
403 | +++ dateutils.js 2013-07-26 15:25:31 +0000 | |||
404 | @@ -18,46 +18,82 @@ | |||
405 | 18 | 18 | ||
406 | 19 | .pragma library | 19 | .pragma library |
407 | 20 | 20 | ||
424 | 21 | var SECONDS_LIMIT = 60 * 1000; | 21 | var SECONDS_LIMIT = 60 * 1000; // used as reference |
425 | 22 | var MINUTES_LIMIT = 60 * SECONDS_LIMIT; | 22 | var MINUTES_LIMIT = 60 * SECONDS_LIMIT; // print minutes up to 1h |
426 | 23 | var HOURS_LIMIT = 24 * MINUTES_LIMIT; | 23 | var HOURS_LIMIT = 12 * MINUTES_LIMIT; // print hours up to 12h |
427 | 24 | var DAYS_LIMIT = 30 * HOURS_LIMIT; | 24 | var DAY_LIMIT = 24 * MINUTES_LIMIT; // print '<val> days ago' up to 30 days back |
428 | 25 | 25 | var DAYS_LIMIT = 30 * DAY_LIMIT; // print '<val> days ago' up to 30 days back | |
413 | 26 | // TODO: handle i18n | ||
414 | 27 | var FORMAT_LIMITS = [ | ||
415 | 28 | { "limit": SECONDS_LIMIT, "formats": ["%0 second ago", "%0 seconds ago"] }, | ||
416 | 29 | { "limit": MINUTES_LIMIT, "formats": ["%0 minute ago", "%0 minutes ago"] }, | ||
417 | 30 | { "limit": HOURS_LIMIT, "formats": ["%0 hour ago", "%0 hours ago"] }, | ||
418 | 31 | { "limit": DAYS_LIMIT, "formats": ["%0 day ago", "%0 days ago"] }, | ||
419 | 32 | ] | ||
420 | 33 | |||
421 | 34 | // fallback if none of the above formats matched | ||
422 | 35 | // TODO: handle i18n | ||
423 | 36 | var DEFAULT_DATE_FORMAT = "MMM Do" | ||
429 | 37 | 26 | ||
430 | 38 | function parseDate(dateAsStr) { | 27 | function parseDate(dateAsStr) { |
432 | 39 | return Date.parse(dateAsStr); | 28 | return new Date(dateAsStr); |
433 | 40 | } | 29 | } |
434 | 41 | 30 | ||
436 | 42 | function formatPostTime(dateAsStr, i18n) { | 31 | function formatRelativeTime(i18n, dateAsStr) { |
437 | 32 | // fallback if none of the other formatters matched | ||
438 | 33 | function defaultFallbackFormat(then) { | ||
439 | 34 | return Qt.formatDateTime(then, i18n.tr("MMMM d")) | ||
440 | 35 | } | ||
441 | 36 | |||
442 | 37 | // Simple matches all diffs < limit, formats using the format function. | ||
443 | 38 | function SimpleFormatter(limit, format) { | ||
444 | 39 | this.matches = function (now, then, diff) { return diff < limit } | ||
445 | 40 | this.format = format | ||
446 | 41 | } | ||
447 | 42 | |||
448 | 43 | // Matches yesterday date | ||
449 | 44 | function YesterdayFormatter() { | ||
450 | 45 | this.matches = function (now, then, diff) { | ||
451 | 46 | return diff < DAY_LIMIT && now.getDate() !== then.getDate(); | ||
452 | 47 | } | ||
453 | 48 | this.format = function (now, then, diff) { | ||
454 | 49 | return i18n.tr("Yesterday at %1").arg( | ||
455 | 50 | Qt.formatDateTime(then, i18n.tr("h:mm AP"))) | ||
456 | 51 | } | ||
457 | 52 | } | ||
458 | 53 | |||
459 | 54 | // Matches up to 7 days ago (formats date as a weekday + time) | ||
460 | 55 | function WeekFormatter() { | ||
461 | 56 | this.matches = function (now, then, diff) { | ||
462 | 57 | return diff < 7 * DAY_LIMIT | ||
463 | 58 | } | ||
464 | 59 | this.format = function (now, then, diff) { | ||
465 | 60 | return Qt.formatDateTime(then, i18n.tr("ddd, h:mm AP")); | ||
466 | 61 | } | ||
467 | 62 | } | ||
468 | 63 | |||
469 | 64 | // An array of formatting object processed from 0 up to a matching object. | ||
470 | 65 | // If none of the object matches a default fallback formatter will be used. | ||
471 | 66 | var FORMATTERS = [ | ||
472 | 67 | new SimpleFormatter(SECONDS_LIMIT, function (now, then, diff) { return i18n.tr("A few seconds ago...") }), | ||
473 | 68 | new SimpleFormatter(MINUTES_LIMIT, function (now, then, diff) { | ||
474 | 69 | var val = Math.floor(diff / SECONDS_LIMIT) | ||
475 | 70 | return i18n.tr("%1 minute ago", "%1 minutes ago", val).arg(val) | ||
476 | 71 | }), | ||
477 | 72 | new SimpleFormatter(HOURS_LIMIT, function (now, then, diff) { | ||
478 | 73 | var val = Math.floor(diff / MINUTES_LIMIT) | ||
479 | 74 | return i18n.tr("%1 hour ago", "%1 hours ago", val).arg(val) | ||
480 | 75 | }), | ||
481 | 76 | new YesterdayFormatter(), | ||
482 | 77 | new WeekFormatter(), | ||
483 | 78 | new SimpleFormatter(DAYS_LIMIT, function (now, then, diff) { | ||
484 | 79 | var val = Math.floor(diff / DAY_LIMIT) | ||
485 | 80 | return i18n.tr("%1 day ago", "%1 days ago", val).arg(val) | ||
486 | 81 | }) | ||
487 | 82 | ] | ||
488 | 83 | |||
489 | 84 | function formatDiff(now, then, diff) { | ||
490 | 85 | for (var i=0; i<FORMATTERS.length; ++i) { | ||
491 | 86 | var formatter = FORMATTERS[i] | ||
492 | 87 | if (formatter.matches(now, then, diff)) { | ||
493 | 88 | return formatter.format(now, then, diff) | ||
494 | 89 | } | ||
495 | 90 | } | ||
496 | 91 | return defaultFallbackFormat(then) | ||
497 | 92 | } | ||
498 | 93 | |||
499 | 43 | var now = new Date(); | 94 | var now = new Date(); |
500 | 44 | var then = parseDate(dateAsStr); | 95 | var then = parseDate(dateAsStr); |
501 | 45 | var diff = now - then; | 96 | var diff = now - then; |
504 | 46 | var formattedDiff = formatDiff(diff, then, i18n); | 97 | var formattedDiff = formatDiff(now, then, diff); |
503 | 47 | console.log("DDD DIFF", diff, formattedDiff) | ||
505 | 48 | return formattedDiff; | 98 | return formattedDiff; |
506 | 49 | } | 99 | } |
507 | 50 | |||
508 | 51 | function formatDiff(diff, then, i18n) { | ||
509 | 52 | for (var i=0; i<FORMAT_LIMITS.length; ++i) { | ||
510 | 53 | var limit = FORMAT_LIMITS[i].limit; | ||
511 | 54 | if (diff < limit) { | ||
512 | 55 | // use previous limit to calculate number of current units | ||
513 | 56 | // e.g. to calculate hours divide by MINUTES_LIMIT | ||
514 | 57 | // (because MINUTES_LIMIT is 1 hours) etc. | ||
515 | 58 | var val = Math.floor(diff / (i > 1 ? FORMAT_LIMITS[i-1].limit : SECONDS_LIMIT)) | ||
516 | 59 | return i18n.tr(FORMAT_LIMITS[i].formats[0], FORMAT_LIMITS[i].formats[1], val).arg(val) | ||
517 | 60 | } | ||
518 | 61 | } | ||
519 | 62 | return then.toString(i18n.tr(DEFAULT_DATE_FORMAT)) | ||
520 | 63 | } |
Looks like all is ok, w8 while guys will review your code too :)