This repository has been archived by the owner on May 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utopian-stats.b4a
290 lines (253 loc) · 9.67 KB
/
utopian-stats.b4a
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
Build1=Default,eu.dimitrisp.utopianstats
File1=main.bal
File2=pending.bal
File3=reviewed.bal
FileGroup1=Default Group
FileGroup2=Default Group
FileGroup3=Default Group
Group=Default Group
IconFile=
Library1=core
Library2=okhttputils2
Library3=json
Library4=picasso
Library5=reflection
ManifestCode='This code will be applied to the manifest file during compilation.~\n~'You do not need to modify it in most cases.~\n~'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136~\n~AddManifestText(~\n~<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="26"/>~\n~<supports-screens android:largeScreens="true" ~\n~ android:normalScreens="true" ~\n~ android:smallScreens="true" ~\n~ android:anyDensity="true"/>)~\n~SetApplicationAttribute(android:icon, "@drawable/icon")~\n~SetApplicationAttribute(android:label, "$LABEL$")~\n~CreateResourceFromFile(Macro, Themes.DarkTheme)~\n~'End of default text.~\n~
NumberOfFiles=3
NumberOfLibraries=5
NumberOfModules=0
Version=8.5
@EndOfDesignText@
#Region Project Attributes
#ApplicationLabel: Utopian Stats
#VersionCode: 1
#VersionName: autoconf
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: portrait
#CanInstallToExternalStorage: True
#End Region
#Region Activity Attributes
#FullScreen: True
#IncludeTitle: False
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private svPending As ScrollView
Private btnRefresh As Button
Private TabHost1 As TabHost
Private svUpvote As ScrollView
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("main")
SetupUi
btnRefresh_Click
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub JobDone(Job As HttpJob)
If Job.Success Then
If Job.JobName = "getunreviewed" Then
svPending.Invalidate
' Map svPending to Panel0
Dim Panel0 As Panel
Panel0 = svPending.Panel
Panel0.Color=Colors.Gray
' Will be used to modify each entry's visual
Dim PanelTop, Label2Top, PanelTop, PanelHeight As Int
PanelTop=0
' Initiate JSON parser
Dim parser As JSONParser
parser.Initialize(Job.GetString)
Dim root As List = parser.NextArray
For Each colroot As Map In root
' Variables are self-explained by their names
'Dim total_comments As Int = colroot.Get("total_comments")
'Dim valid_age As String = colroot.Get("valid_age")
Dim author As String = colroot.Get("author")
Dim created As String = colroot.Get("created")
Dim moderator As String = colroot.Get("moderator")
'Dim comment_url As String = colroot.Get("comment_url")
'Dim utopian_vote As Int = colroot.Get("utopian_vote")
'Dim voted_on As String = colroot.Get("voted_on")
'Dim repository As String = colroot.Get("repository")
Dim title As String = colroot.Get("title")
Dim url As String = colroot.Get("url")
'Dim score As Int = colroot.Get("score")
'Dim review_date As String = colroot.Get("review_date")
'Dim total_votes As Int = colroot.Get("total_votes")
'Dim is_vipo As String = colroot.Get("is_vipo")
'Dim total_payout As Double = colroot.Get("total_payout")
'Dim review_status As String = colroot.Get("review_status")
'Dim beneficiaries_set As String = colroot.Get("beneficiaries_set")
Dim category As String = colroot.Get("category")
'Dim staff_picked As String = colroot.Get("staff_picked")
'Dim voting_weight As Double = colroot.Get("voting_weight")
'Dim picked_by As String = colroot.Get("picked_by")
'Dim status As String = colroot.Get("status")
Dim cuttitle As String ' To be used for shorting the title
Dim ShortDate,UnderReview,DateArray() As String ' Date & Review variables
Dim AuthorImage As ImageView
Dim PicassoHandler As Picasso
Dim ReviewColor As String
If title.Length > 30 Then
cuttitle = title.SubString2(0,30).Trim & "..."
Else
cuttitle = title
End If
If moderator = "" Then
UnderReview = "No"
ReviewColor = Colors.Red
Else
UnderReview = moderator
ReviewColor = Colors.Green
End If
DateArray = Regex.Split(" ", created)
ShortDate = DateArray(0)
Dim Panel1 As Panel ' To be added inside the ScrollView Panel.
Panel1.Initialize("")
Panel1.Color=Colors.Black
PanelHeight = 74dip
Label2Top=40dip
Panel0.AddView(Panel1,0,PanelTop,svPending.Width,PanelHeight)
Dim Label1, Label2, Label3 As Label
Label1.Initialize("Label1")
Panel1.AddView(Label1,80dip,5dip,Panel0.Width-80dip,30dip)
Label1.Color=Colors.Black
Label1.TextColor = Colors.White
Label1.Tag=url
Label1.Text=cuttitle & " by " & author
Label2.Initialize("")
Panel1.AddView(Label2,80dip,Label2Top,Panel0.Width-80dip,30dip)
Label2.TextSize=14
Label2.Tag="lblDetails"
Label2.Text="D: " & ShortDate & " - C: " & category & " - R: " & UnderReview
Label2.TextSize=14
Label3.Initialize("")
Panel1.AddView(Label3, Panel1.Width-2dip, 0dip, 2dip, PanelHeight)
Label3.Color = ReviewColor
AuthorImage.Initialize("")
Panel1.AddView(AuthorImage,5dip,5dip,65dip,65dip)
PicassoHandler.Initialize
PicassoHandler.LoadUrl("https://cdn.steemitimages.com/u/"&author&"/avatar").IntoImageView(AuthorImage)
PanelTop=PanelTop+PanelHeight+1dip
Next
Panel0.Height=PanelTop
Dim Job As HttpJob
Job.Initialize("getreviewed", Me)
Job.Download("https://utopian.rocks/api/posts?status=pending")
Else If Job.JobName = "getreviewed" Then
svUpvote.Invalidate
' Map svUpvote to Panel2
Dim Panel2 As Panel
Panel2 = svUpvote.Panel
Panel2.Color=Colors.Gray
' Will be used to modify each entry's visual
Dim PanelTop2, Label2Top2, PanelHeight2 As Int
PanelTop2=0
' Initiate JSON parser
Dim parser As JSONParser
parser.Initialize(Job.GetString)
Dim root As List = parser.NextArray
For Each colroot As Map In root
'Dim total_comments As Int = colroot.Get("total_comments")
Dim valid_age As String = colroot.Get("valid_age")
Dim author As String = colroot.Get("author")
Dim created As String = colroot.Get("created")
Dim moderator As String = colroot.Get("moderator")
'Dim comment_url As String = colroot.Get("comment_url")
'Dim utopian_vote As Int = colroot.Get("utopian_vote")
'Dim voted_on As String = colroot.Get("voted_on")
'Dim repository As String = colroot.Get("repository")
Dim title As String = colroot.Get("title")
Dim url As String = colroot.Get("url")
Dim score As Double = colroot.Get("score")
'Dim review_date As String = colroot.Get("review_date")
'Dim total_votes As Int = colroot.Get("total_votes")
'Dim is_vipo As String = colroot.Get("is_vipo")
'Dim total_payout As Double = colroot.Get("total_payout")
'Dim review_status As String = colroot.Get("review_status")
'Dim beneficiaries_set As String = colroot.Get("beneficiaries_set")
Dim category As String = colroot.Get("category")
'Dim staff_picked As String = colroot.Get("staff_picked")
'Dim voting_weight As Double = colroot.Get("voting_weight")
'Dim picked_by As String = colroot.Get("picked_by")
'Dim status As String = colroot.Get("status")
Dim cuttitle As String ' To be used for shorting the title
Dim ShortDate,DateArray() As String ' Date & Review variables
Dim AuthorImage As ImageView
Dim PicassoHandler As Picasso
Dim ReviewColor As String
If title.Length > 30 Then
cuttitle = title.SubString2(0,30).Trim & "..."
Else
cuttitle = title
End If
If valid_age = "true" Then
ReviewColor = Colors.Green
Else
ReviewColor = Colors.Red
End If
DateArray = Regex.Split(" ", created)
ShortDate = DateArray(0)
Dim Panel1 As Panel ' To be added inside the ScrollView Panel.
Panel1.Initialize("")
Panel1.Color=Colors.Black
PanelHeight2 = 74dip
Label2Top2=40dip
Panel2.AddView(Panel1,0,PanelTop2,svUpvote.Width,PanelHeight2)
Dim Label1, Label2, Label3 As Label
Label1.Initialize("Label1")
Panel1.AddView(Label1,80dip,5dip,Panel2.Width-80dip,30dip)
Label1.Color=Colors.Black
Label1.TextColor = Colors.White
Label1.Tag=url
Label1.Text=cuttitle & " by " & author
Label2.Initialize("")
Panel1.AddView(Label2,80dip,Label2Top2,Panel2.Width-80dip,30dip)
Label2.TextSize=14
Label2.Tag="lblDetails"
Label2.Text="S: " & score & " - C: " & category & " - R: " & moderator
Label2.TextSize=14
Label3.Initialize("")
Panel1.AddView(Label3, Panel1.Width-2dip, 0dip, 2dip, PanelHeight2)
Label3.Color = ReviewColor
AuthorImage.Initialize("")
Panel1.AddView(AuthorImage,5dip,5dip,65dip,65dip)
PicassoHandler.Initialize
PicassoHandler.LoadUrl("https://cdn.steemitimages.com/u/"&author&"/avatar").IntoImageView(AuthorImage)
PanelTop2=PanelTop2+PanelHeight2+1dip
Next
Panel2.Height=PanelTop2
ProgressDialogHide
End If
Else
Log( Job.ErrorMessage)
End If
Job.Release
End Sub
Sub btnRefresh_Click
Dim job As HttpJob
ProgressDialogShow2("Fetching details, please wait...",False)
job.Initialize("getunreviewed", Me)
job.Download("https://utopian.rocks/api/posts?status=unreviewed")
End Sub
Sub Label1_Click
Dim lbSend As Label
lbSend = Sender
Dim i As Intent
i.Initialize(i.ACTION_VIEW, lbSend.tag)
StartActivity(i)
End Sub
Sub SetupUi
TabHost1.AddTab("Unreviewed", "pending.bal")
TabHost1.AddTab("Pending Vote", "reviewed.bal")
End Sub
Sub TabHost1_TabChanged
End Sub