-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathArticleListPage.qml
141 lines (119 loc) · 4.25 KB
/
ArticleListPage.qml
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
import QtQuick 2.2
import Ubuntu.Components 1.1
Page {
title: i18n.tr("2buntu Articles")
visible: false
// These will need to be specified when the page is instantiated
property ListModel articleModel
signal articleSelected(int index)
// Progress indicator displayed while articles load for the first time
ActivityIndicator {
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
running: !articleModel.count && articleModel.loading
visible: running
}
// Each list item will be instantiated from this component
Component {
id: articleListDelegate
Item {
width: parent.width
height: childrenRect.height
// Display the author's Gravatar on the left side
UbuntuShape {
id: authorGravatar
anchors {
left: parent.left
top: parent.top
}
radius: 'medium'
// TODO: figure out the optimal size to display
image: Image {
source: 'http://gravatar.com/avatar/' + author.email_hash + '?s=128&d=identicon'
}
}
// Display the title of the article at the top
Text {
id: articleTitle
anchors {
left: authorGravatar.right
leftMargin: units.gu(2)
right: parent.right
top: parent.top
topMargin: units.gu(0.5)
}
color: "#555555"
font.pixelSize: FontUtils.sizeToPixels("large")
elide: Text.ElideRight
text: title
}
// Display the article body at the bottom
Text {
anchors {
left: authorGravatar.right
leftMargin: units.gu(2)
right: parent.right
top: articleTitle.bottom
}
color: "#555555"
font.pixelSize: FontUtils.sizeToPixels("small")
elide: Text.ElideRight
horizontalAlignment: Text.AlignJustify
maximumLineCount: 2
wrapMode: Text.WordWrap
// Attempt to strip out anything looking like an HTML tag from the body...
// It would sure be nice to have a striphtml() method
text: body.replace(/<(?:.|\n)*?>/g, '').replace(/\n+/g, ' ')
textFormat: Text.PlainText
}
// Mouse area to register clicks on articles
MouseArea {
anchors.fill: parent
onClicked: articleSelected(index)
}
}
}
// The list view that actually displays the articles
ListView {
anchors.fill: parent
anchors.margins: units.gu(2)
model: articleModel
delegate: articleListDelegate
spacing: units.gu(3)
// Allow pull-to-refresh
PullToRefresh {
refreshing: articleModel.loading
onRefresh: articleModel.refresh()
}
// Display a button allowing more articles to be loaded
footer: Column {
width: parent.width
visible: articleModel.count
// A nasty hack to work around margin issues with footers
Rectangle {
color: "transparent"
width: parent.width
height: units.gu(3)
}
// Button that is pressed to load more items
Button {
width: parent.width
text: "Load More"
visible: !articleModel.loading
onClicked: articleModel.loadMore()
}
// Indicator shown when more items are loading
Row {
anchors.horizontalCenter: parent.horizontalCenter
spacing: units.gu(2)
visible: articleModel.loading
ActivityIndicator {
running: true
}
Label {
text: "Loading more articles..."
}
}
}
}
}