-
Notifications
You must be signed in to change notification settings - Fork 1
/
ThreadPage.qml
313 lines (261 loc) · 8.99 KB
/
ThreadPage.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
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
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3
import QtGraphicalEffects 1.0
import NinepunchGlobals 1.0
import "Android"
import "Components"
import "js/fonticons.js" as FontIcons
Page{
property string threadURL: "https://forum.facepunch.com/f/meta/btjnz/Facepunch-API/1/"
property string errorType: ""
property bool useBackButton: false
id: threadPage
BusyIndicatorPage{
id: busyIndicatorPage
state: threadPage.state
errorType: threadPage.errorType
}
PosterInfoPopup{
id:posterInfoPopup
}
RatingsPopup{
id:ratingsPopup
}
ListModel{
id: postListModel
}
ListView {
anchors.fill: parent
model: 1
id: postView
header: Item{
height: parent.width > 768 ? 64 : 0
}
delegate:
Item{
width: parent.width > 768 ? 768 : parent.width
height: childrenRect.height
anchors.horizontalCenter: parent.horizontalCenter
Column{
width: parent.width
id: postContent
topPadding: ( -busyIndicatorPage.busyScale + 1 ) * 200 //Fancy effect on page load
spacing: ( -busyIndicatorPage.busyScale + 1 ) * 200 + ( (parent.width > 512) * 32)
scale: 1 - (( -busyIndicatorPage.busyScale + 1 ) * 0.1)
Repeater{
model: postListModel
delegate: Post{
message: Message
poster: Username
postCountry: Country
ratings: Meta.Votes
}
}
//Infinite scrolling loading indicator
Item{
width: parent.width
height: 128
Column{
anchors.centerIn: parent
BusyIndicator { running: true; anchors.horizontalCenter: parent.horizontalCenter }
Label { text: "Loading next page..." }
}
}
}
}
ScrollBar.vertical: ScrollBar {}
}
//New post button
CircleButton{
id: postbutton
anchors.bottom: parent.bottom
anchors.right: parent.right
anchors.margins: 16
state: tabBar.state
glyph: FontIcons.Ionicons.edit
onClicked: {
tabBar.state = "POSTING";
}
states: [
State { name: "POSTING"
PropertyChanges {
target: postbutton
anchors.bottomMargin: -128
}
},
State { name: "READING"
PropertyChanges {
target: postbutton
anchors.bottomMargin: 16
}
}
]
transitions: [
Transition {
NumberAnimation {
properties: "bottomMargin"
duration: 500
easing.type: Easing.OutElastic
easing.period: 0.9
}
}
]
}
BlurRectangle{
id: postContainer
readonly property int widePostingWidth: 512
readonly property bool isWidePosting: parent.width > widePostingWidth
anchors.horizontalCenter: parent.horizontalCenter
width: isWidePosting ? widePostingWidth : parent.width
height: (postTextContainer.height + 16) * (tabBar.height / tabBar.implicitHeight)
element: postView
visible: height > 10
onWidthChanged: tabBar.visible = !isWidePosting
clip: true
//Hack
Rectangle{
width: parent.width
height: 48
visible: postContainer.isWidePosting
color: Qt.rgba(Globals.overlayColor.r,Globals.overlayColor.g,Globals.overlayColor.b,0.5)
}
Column{
id:postTextContainer
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
anchors.margins: 16
anchors.topMargin: postContainer.isWidePosting ? 0 : 8
//Wideposting header
Item{
width: parent.width
height: 48
visible: postContainer.isWidePosting
PostToolButton {
onClicked: {
tabBar.state = "READING";
}
glyph: FontIcons.Ionicons.android_arrow_back
useTheme: true
anchors.left: parent.left
}
GlyphButton {
glyph: FontIcons.Ionicons.android_send
useTheme: true
anchors.right: parent.right
}
}
TextArea {
id: postTextArea
placeholderText: qsTr("Comment reply")
width: parent.width
height: contentHeight < 100 - 24 ? 100 : contentHeight > 256 ? 256 + 24 : contentHeight + 24 //fixme
wrapMode: TextEdit.WrapAtWordBoundaryOrAnywhere
textFormat: TextEdit.RichText
selectByMouse: true
background: Rectangle{
height: 2
anchors.bottom: parent.bottom;
color: parent.focus ? Globals.secondaryColor : "gray"
}
textMargin: 0
color: Globals.isDarkMode ? "white" : "black"
//textColor: Global.isDarkMode ? "white" : "black"
}
//Wideposting footer
Item{
width: parent.width
height: 32
visible: postContainer.isWidePosting
RowLayout{
width: 256
PostToolButton {
glyph: FontIcons.Ionicons.quote
useTheme: true
}
PostToolButton {
glyph: FontIcons.Ionicons.ios_photos
useTheme: true
}
PostToolButton {
glyph: FontIcons.Ionicons.android_film
useTheme: true
}
PostToolButton {
glyph: FontIcons.Ionicons.android_attach
useTheme: true
}
}
}
}
y: postView.height - height - (isWidePosting * 32) //Hack but needed to avoid further hacks with the blurring
}
footer: PostTabBar{
id: tabBar
}
Component.onCompleted: {
loadThread();
}
function loadThread(){
threadPage.state = "loading";
busyIndicatorPage.busyScale = 0;
//console.log( threadURL + "?json=1");
var jsonurl = threadURL + "?json=1";
//console.log(jsonurl);
getData( jsonurl , parseJSON );
}
function getData(url, callback) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange=function() {
//console.log("XmlHTTP Status: " + xmlhttp.status);
if (xmlhttp.readyState == XMLHttpRequest.DONE )
{
switch(xmlhttp.status){
case 0: //No connection(?)
throwError("errorNoConnection");
break;
case 200: //Successful loading
threadPage.state = "finishedLoading";
parseJSON(xmlhttp.responseText);
console.log("finished");
break;
case 400:
throwError("badRequest");
break;
case 403:
throwError("errorForbidden");
break;
case 404:
throwError("errorThreadNotFound");
break;
case 503:
throwError("errorUnauthorised");
break;
default: //Unhandled
throwError("errorUnknown");
break;
}
}
}
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
function parseJSON( json ){
var threadContent = JSON.parse( json )
console.log( threadContent );
console.log( threadContent.Thread.Name )
threadPage.title = threadContent.Thread.Name;
threadContent.Posts.forEach(function(post) {
//console.log( JSON.stringify(element) );
var userName = post.Username;
var message = JSON.parse(post.Message);
postListModel.append( post );
});
}
function throwError(errorType){
threadPage.state = "error";
threadPage.errorType = errorType;
threadPage.title = errorType;
}
}