summaryrefslogtreecommitdiffstats
path: root/qml/components/HomeScreen.qml
blob: 62eab75697c1dd8dd0cf7ad88a250de36118a8fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
**   * Redistributions of source code must retain the above copyright
**     notice, this list of conditions and the following disclaimer.
**   * Redistributions in binary form must reproduce the above copyright
**     notice, this list of conditions and the following disclaimer in
**     the documentation and/or other materials provided with the
**     distribution.
**   * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
**     of its contributors may be used to endorse or promote products derived
**     from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/

import QtQuick 2.2
import QtQuick.Layouts 1.1
import TalkSchedule 1.0

Rectangle {
    id: homeScreenWindow
    height: window.height - header.height
    width: window.width
    objectName: "homeScreen"
    property int usefulItemHeight: Theme.sizes.infoButtonSize + Theme.sizes.homeTitleHeight + Theme.margins.twenty

    property var idx
    property var ids
    property int counter: 0

    function linkForEntity(entity)
    {
        return (entity.url ? entity.url :
               (entity.screen_name ? 'https://twitter.com/' + entity.screen_name :
                                     'https://twitter.com/search?q=%23' + entity.text))
    }

    function textForEntity(entity)
    {
        return (entity.display_url ? entity.display_url :
               (entity.screen_name ? entity.screen_name : entity.text))
    }

    function insertLinks(text, entities)
    {
        if (typeof text !== 'string')
            return "";

        if (!entities)
            return text;

        if (entities.retweeted_status)
            return "";

        var links = []
        entities.urls = entities.media ? entities.urls.concat(entities.media) : entities.urls
        links = entities.urls.concat(entities.hashtags, entities.user_mentions)

        links.sort(function(a, b) { return b.indices[0] - a.indices[0] })

        for (var i = 0; i < links.length; i++) {
            var offset = links[i].url ? 0 : 1
            text = text.substring(0, links[i].indices[0] + offset) +
                '<a href=\"' + linkForEntity(links[i]) + '\">' +
                textForEntity(links[i]) + '</a>' +
                text.substring(links[i].indices[1])
        }

        return text.replace(/\n/g, '<br>');
    }

    Column {
        spacing: 0
        visible: ModelsSingleton.conferenceId !== ""
        anchors.fill: parent
        Item {
            // upcoming
            id: upcomingItem
            width: homeScreenWindow.width
            height: (homeScreenWindow.height - homeScreenWindow.usefulItemHeight)/2

            property string visibleDate: ""
            property string formatDate: "ddd d.MM"

            SortFilterModel {
                id: sortModelNextEvents

                function init()
                {
                    emptyUpcoming.visible = false
                    if (sortModelNextEvents.rowCount() > 0)
                        upcomingItem.visibleDate = Qt.formatDate(sortModelNextEvents.get(0, "start"), upcomingItem.formatDate)
                    if (sortModelNextEvents.rowCount() === 0)
                        emptyUpcoming.visible = true
                }

                sortRole: "start"
                filterRole: "fromNow"
                maximumCount: 7
                model: ModelsSingleton.eventModel
                Component.onCompleted: init()
            }

            Connections {
                target: ModelsSingleton.eventModel
                onDataReady: {
                    sortModelNextEvents.model = ModelsSingleton.eventModel
                    sortModelNextEvents.init()
                }
            }

            Text {
                id: labelUpcoming
                text: Theme.text.upcoming.arg(applicationClient.currentConferenceDetails.title).arg(upcomingItem.visibleDate)
                width: parent.width
                height: Theme.sizes.homeTitleHeight
                z: 1
                font.pointSize: Theme.fonts.seven_pt
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignVCenter
                font.capitalization: Font.AllUppercase
                Rectangle {
                    anchors.fill: parent
                    z: -1
                    color: Theme.colors.smokewhite
                }
                Image {
                    id: reloadUpcoming
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.right: parent.right
                    anchors.rightMargin: Theme.margins.fifteen
                    source: Theme.images.loading
                    sourceSize.height: Theme.sizes.reloadButtonSize
                    sourceSize.width: Theme.sizes.reloadButtonSize
                    MouseArea {
                        anchors.fill: parent
                        onClicked: {
                            rotationUpcoming.running = true
                            homeScreenListView.reloadUpcoming()
                        }
                    }
                    RotationAnimation {
                        id: rotationUpcoming
                        target: reloadUpcoming
                        property: "rotation"
                        running: false
                        duration: 800
                        from: 0
                        to: 360
                    }
                }
            }
            ListView {
                id: homeScreenListView
                anchors.top: labelUpcoming.bottom
                anchors.bottom: parent.bottom
                anchors.right: parent.right
                anchors.left: parent.left
                anchors.margins: Theme.margins.ten
                model: sortModelNextEvents
                clip: true
                function reloadUpcoming() {
                    emptyUpcoming.visible = false
                    if (visible && sortModelNextEvents.rowCount() > 0) {
                        sortModelNextEvents.filter()
                        upcomingItem.visibleDate = Qt.formatDate(sortModelNextEvents.get(0, "start"), upcomingItem.formatDate)
                    }
                    if (sortModelNextEvents.rowCount() === 0)
                        emptyUpcoming.visible = true
                }

                onVisibleChanged: homeScreenListView.reloadUpcoming()
                Text {
                    id: emptyUpcoming
                    visible: false
                    text: Theme.text.endedEvent
                    anchors.centerIn: parent
                    font.pointSize: Theme.fonts.eight_pt
                }
                spacing: Theme.margins.ten
                delegate: RowLayout {
                    id: upcomingEventDelegate
                    width: parent.width
                    visible: Qt.formatDate(start, upcomingItem.formatDate) === upcomingItem.visibleDate
                    height: visible ? Theme.sizes.upcomingEventHeight : 0
                    Rectangle {
                        color: tracks.backgroundColor
                        Layout.fillHeight: true
                        Layout.preferredWidth: Theme.sizes.upcomingEventTimeWidth
                        Text {
                            anchors.fill: parent
                            anchors.leftMargin: Theme.margins.five
                            text: tracks.name
                            font.capitalization: Font.AllUppercase
                            color: Theme.colors.white
                            verticalAlignment: Text.AlignVCenter
                            horizontalAlignment: Text.AlignLeft
                            font.pointSize: Theme.fonts.six_pt
                        }
                    }
                    Rectangle {
                        Layout.fillHeight: true
                        Layout.fillWidth: true
                        color: mouseArea.pressed ? Theme.colors.smokewhite : Theme.colors.white
                        MouseArea {
                            id: mouseArea
                            anchors.fill: parent
                            onClicked: stack.push({
                                                      "item" : Qt.resolvedUrl("Event.qml"),
                                                      "properties" : {"eventId" : id}
                                                  })
                        }
                        ColumnLayout {
                            anchors.fill: parent
                            anchors.leftMargin: Theme.margins.twenty
                            Text {
                                Layout.fillWidth: true
                                text: topic
                                verticalAlignment: Text.AlignVCenter
                                elide: Text.ElideRight
                                font.pointSize: Theme.fonts.seven_pt
                            }
                            Text {
                                Layout.fillWidth: true
                                text: Qt.formatTime(start, Qt.locale().timeFormat(Locale.ShortFormat)) + Theme.text.room_space.arg(location)
                                verticalAlignment: Text.AlignVCenter
                                elide: Text.ElideRight
                                font.pointSize: Theme.fonts.seven_pt
                                color: Theme.colors.gray
                            }
                        }
                    }
                }
            }
        }
        Item {
            // twitter news
            width: window.width
            height: (homeScreenWindow.height - homeScreenWindow.usefulItemHeight)/2

            TweetModel {
                id: tweetModel
            }

            Rectangle {
                id: labelNews
                width: parent.width
                height: Theme.sizes.homeTitleHeight
                color: Theme.colors.smokewhite

                Text {
                    id: labelNewsText
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.horizontalCenter: parent.horizontalCenter

                    text: Theme.text.news
                    font.pointSize: Theme.fonts.seven_pt
                    font.capitalization: Font.AllUppercase
                }

                Image {
                    source: Theme.images.twitter
                    sourceSize.height: labelNewsText.height
                    sourceSize.width: labelNewsText.height
                    anchors.right: labelNewsText.left
                    anchors.rightMargin: Theme.margins.five
                    anchors.verticalCenter: parent.verticalCenter

                    MouseArea {
                        anchors.fill: parent
                        onClicked: Qt.openUrlExternally(Theme.text.twitterLink)
                    }
                }

                Image {
                    id: reloadNews
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.right: parent.right
                    anchors.rightMargin: Theme.margins.fifteen
                    source: Theme.images.loading
                    sourceSize.height: Theme.sizes.reloadButtonSize
                    sourceSize.width: Theme.sizes.reloadButtonSize
                    RotationAnimation {
                        id: rotationNews
                        target: reloadNews
                        property: "rotation"
                        running: false
                        duration: 800
                        from: 0
                        to: 360
                    }
                }
                MouseArea {
                    anchors.fill: reloadNews
                    onClicked: {
                        rotationNews.running = true
                        tweetModel.reload()
                    }
                }
            }

            Text {
                anchors.centerIn: parent
                visible: tweetModel.errorMessage !== ""
                text: tweetModel.errorMessage
            }


            Component {
                id: tweetDelegate

                Rectangle {
                    color: Theme.colors.white
                    height: Math.max(tweetArea.height, Theme.sizes.twitterAvatarSize)
                    width: window.width

                    Image {
                        id: placeHolder
                        anchors.top: parent.top
                        anchors.left: parent.left
                        source: Theme.images.anonymous
                        sourceSize.height: Theme.sizes.twitterAvatarSize
                        sourceSize.width: Theme.sizes.twitterAvatarSize
                        visible: avatar.status != Image.Ready
                    }

                    Image {
                        id: avatar
                        anchors.fill: placeHolder
                        source: model.user.profile_image_url
                        sourceSize.height: Theme.sizes.twitterAvatarSize
                        sourceSize.width: Theme.sizes.twitterAvatarSize

                        MouseArea {
                            anchors.fill: parent
                            onClicked: Qt.openUrlExternally(Theme.text.twitterLink + model.user.screen_name)
                        }
                    }

                    Column {
                        id: tweetArea
                        width: parent.width - placeHolder.width - Theme.margins.twenty
                        height: userName.implicitHeight + tweetContent.implicitHeight
                        anchors.left: placeHolder.right
                        anchors.leftMargin: Theme.margins.ten
                        anchors.rightMargin: Theme.margins.ten

                        Item {
                            width: parent.width
                            height: userName.implicitHeight
                            Text {
                                id: userName
                                anchors.left: parent.left
                                text: model.user.name
                                font.pointSize: Theme.fonts.eight_pt
                                color: Theme.colors.black
                                textFormat: Text.StyledText
                                MouseArea {
                                    anchors.fill: parent
                                    onClicked: Qt.openUrlExternally(Theme.text.twitterLink
                                                                    + model.user.screen_name)
                                }
                            }

                            Text {
                                id: screenName
                                anchors.left: userName.right
                                anchors.leftMargin: Theme.margins.ten
                                anchors.bottom: parent.bottom
                                text: "@" + model.user.screen_name
                                font.pointSize: Theme.fonts.seven_pt
                                color: Theme.colors.gray
                                textFormat: Text.StyledText
                                MouseArea {
                                    anchors.fill: parent
                                    onClicked: Qt.openUrlExternally(Theme.text.twitterLink
                                                                    + model.user.screen_name)
                                }
                            }
                            Text {
                                id: timeStamp
                                anchors.right: parent.right
                                anchors.rightMargin: Theme.margins.ten
                                anchors.bottom: parent.bottom
                                text: getElapsedTime()
                                font.pointSize: Theme.fonts.seven_pt
                                color: Theme.colors.gray
                                textFormat: Text.StyledText
                                MouseArea {
                                    anchors.fill: parent
                                    onClicked: Qt.openUrlExternally(Theme.text.twitterLink
                                                                    + model.user.screen_name
                                                                    + "/status/" + model.id_str)
                                }
                                function getElapsedTime()
                                {
                                    var createdAt = model.created_at.replace(" +0000", "") // UTC
                                    var createdDate = new Date(createdAt)
                                    var now = new Date() // Local
                                    var localOffset = now.getTimezoneOffset() * 60 * 1000
                                    var diff = Math.floor((now - createdDate + localOffset) / 1000); // seconds
                                    if (diff <= 10)
                                        return "Now"
                                    if (diff <= 90)
                                        return "1m"
                                    if (diff <= 3540)
                                        return Math.round(diff / 60) + "m"
                                    if (diff <= 5400)
                                        return "1h"
                                    if (diff <= 87000)
                                        return Math.round(diff / 3600) + "h"
                                    if (diff <= 130000)
                                        return "1 day"
                                    if (diff < 540000)
                                       return Math.round(diff / 86400) + " days"
                                    return Qt.formatDate(createdDate, "d MMM");
                                }
                            }
                        }

                        Text {
                            id: tweetContent
                            width: parent.width
                            text: insertLinks(model.text, model.entities)
                            wrapMode: Text.WordWrap
                            textFormat: Text.RichText
                            font.pointSize: Theme.fonts.seven_pt
                            color: Theme.colors.gray
                            onLinkActivated: Qt.openUrlExternally(link)
                            MouseArea {
                                anchors.fill: parent
                                onClicked: Qt.openUrlExternally(Theme.text.twitterLink
                                                                + model.user.screen_name
                                                                + "/status/" + model.id_str)
                            }
                        }
                    }
                }
            }

            ListView {
                id: listNews
                anchors.top: labelNews.bottom
                anchors.left: parent.left
                anchors.right: parent.right
                anchors.bottom: parent.bottom
                anchors.margins: Theme.margins.ten
                clip: true
                spacing: Theme.margins.twenty
                model: tweetModel.model
                delegate: tweetDelegate
            }
        }
        Item {
            // useful info
            id: usefulItem
            width: window.width
            height: homeScreenWindow.usefulItemHeight
            Text {
                id: labelInfo
                z: 1
                text: Theme.text.info
                width: parent.width
                height: Theme.sizes.homeTitleHeight
                font.pointSize: Theme.fonts.seven_pt
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignVCenter
                font.capitalization: Font.AllUppercase
                Rectangle {
                    anchors.fill: parent
                    z: -1
                    color: Theme.colors.smokewhite
                }
            }
            Row {
                anchors.top: labelInfo.bottom
                anchors.bottom: usefulItem.bottom
                anchors.horizontalCenter: parent.horizontalCenter
                spacing: Theme.margins.thirty
                Image {
                    source: Theme.images.btnFloorMap
                    sourceSize.height: Theme.sizes.infoButtonSize
                    sourceSize.width: Theme.sizes.infoButtonSize
                    anchors.verticalCenter: parent.verticalCenter
                    MouseArea {
                        anchors.fill: parent
                        onClicked: stack.push(Qt.resolvedUrl("Floorplan.qml"))
                    }
                }
                Image {
                    source: Theme.images.btnSchedule
                    sourceSize.height: Theme.sizes.infoButtonSize
                    sourceSize.width: Theme.sizes.infoButtonSize
                    anchors.verticalCenter: parent.verticalCenter
                    MouseArea {
                        anchors.fill: parent
                        onClicked: stack.push(Qt.resolvedUrl("TrackSwitcher.qml"))
                    }
                }
                Image {
                    source: Theme.images.btnToWebsite
                    sourceSize.height: Theme.sizes.infoButtonSize
                    sourceSize.width: Theme.sizes.infoButtonSize
                    anchors.verticalCenter: parent.verticalCenter
                    MouseArea {
                        anchors.fill: parent
                        onClicked: Qt.openUrlExternally(applicationClient.currentConferenceDetails.infopage)
                    }
                }
            }
        }
    }
}