'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
'Root.LoadLayout("layoutevents")
'load the layout to Root
Drawer.Initialize(Me, "Drawer", Root, 200dip)
Drawer.CenterPanel.LoadLayout("layoutevents")
Drawer.LeftPanel.LoadLayout("Drawer")
HamburgerIcon = xui.LoadBitmapResize(File.DirAssets, "hamburger.png", 32dip, 32dip, True)
logo.Bitmap = LoadBitmap(File.DirAssets, "kasselhuskieslogo.png")
imgsnow.Bitmap = LoadBitmap(File.DirAssets, "event-bg.png")
B4XPages.SetTitle(Me, "Kassel Huskies - Events")
'
clv.Clear
End Sub
Private Sub B4XPage_CloseRequest As ResumableSub
#if B4A
'home button
If Main.ActionBarHomeClicked Then
Drawer.LeftOpen = Not(Drawer.LeftOpen)
Return False
End If
'back key
If Drawer.LeftOpen Then
Drawer.LeftOpen = False
Return False
End If
#end if
Return True
End Sub
Private Sub B4XPage_Disappear
#if B4A
B4XPages.GetManager.ActionBar.RunMethod("setHomeAsUpIndicator", Array(0))
#end if
End Sub
Private Sub B4XPage_Resize (Width As Int, Height As Int)
Drawer.Resize(Width, Height)
End Sub
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
public Sub B4XPage_Appear
#if B4A
Sleep(0)
B4XPages.GetManager.ActionBar.RunMethod("setDisplayHomeAsUpEnabled", Array(True))
Dim bd As BitmapDrawable
bd.Initialize(HamburgerIcon)
B4XPages.GetManager.ActionBar.RunMethod("setHomeAsUpIndicator", Array(bd))
#End If
Log($"${B4XPages.GetManager.MainPage.GetBaseURL}/upcoming-events"$)
'B4XPages.GetManager.MainPage.kvs.Get("access_token")
Log($"Header: "X-Authorization", "Bearer ${B4XPages.GetManager.MainPage.kvs.Get("access_token")}"$)
Dim j2 As HttpJob
j2.Initialize("",Me)
j2.Username = "xxxx"
j2.Password = "cccc"
j2.Download2($"${B4XPages.GetManager.MainPage.GetBaseURL}/upcoming-events"$, Array As String("mimeType", "application/json"))
j2.GetRequest.SetHeader("X-Authorization", "Bearer "&B4XPages.GetManager.MainPage.kvs.Get("access_token"))
Dim elist As List
elist.Initialize
Dim Eventsheute As Int = 0
Wait For(j2)JobDone(job2 As HttpJob)
If job2.Success Then
Dim result As String = job2.GetString
Dim parser As JSONParser
parser.Initialize(result)
Dim jRoot2 As List = parser.NextArray
For Each colj2Root As Map In jRoot2
B4XPages.GetManager.MainPage.kvs.Put("events",colj2Root)
Dim eventId As Int = colj2Root.Get("eventId")
Dim eventName As String = colj2Root.Get("eventName")
Dim HomeTeam As String = ""
Dim RivalTeam As String = ""
Dim eventcomponents() As String
eventcomponents = Regex.Split(" vs ", eventName)
If eventcomponents.Length = 2 Then
HomeTeam = eventcomponents(0)
RivalTeam = eventcomponents(1)
End If
Dim match As Map = colj2Root.Get("match")
Dim teamLogo As String = match.Get("teamLogo")
If File.Exists(File.DirInternal,B4XPages.GetManager.MainPage.GetFilename(teamLogo)) = False Then
Wait For (B4XPages.GetManager.MainPage.DownloadAndSave(teamLogo, File.DirInternal, B4XPages.GetManager.MainPage.GetFilename(teamLogo))) Complete (success As Boolean)
If success Then
Log($"${B4XPages.GetManager.MainPage.GetFilename(teamLogo)} geladen und gespeichert..."$)
End If
End If
Dim homeimg As Bitmap
homeimg.Initialize(File.DirInternal,B4XPages.GetManager.MainPage.GetFilename(teamLogo))
Dim rivalLogo As String = match.Get("rivalLogo")
If File.Exists(File.DirInternal,B4XPages.GetManager.MainPage.GetFilename(rivalLogo)) = False Then
Wait For (B4XPages.GetManager.MainPage.DownloadAndSave(rivalLogo, File.DirInternal, B4XPages.GetManager.MainPage.GetFilename(rivalLogo))) Complete (success As Boolean)
If success Then
Log($"${B4XPages.GetManager.MainPage.GetFilename(rivalLogo)} geladen und gespeichert..."$)
End If
End If
Dim rivalimg As Bitmap
rivalimg.Initialize(File.DirInternal,B4XPages.GetManager.MainPage.GetFilename(rivalLogo))
Dim startDate As String = match.Get("startDate")
'Dim dateOfAvailability As String = colj2Root.Get("dateOfAvailability")
'Dim dateOfVisibility As String = colj2Root.Get("dateOfVisibility")
DateTime.DateFormat = "yyyy-MM-dd'T'HH:mm:ssX"
'DateTime.DateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
'Dim dateAvailable As Long = DateTime.DateParse(startDate)
'Dim dateVisible As Long = DateTime.DateParse(B4XPages.GetManager.MainPage.RemoveMilliseconds(dateOfVisibility))
DateTime.DateFormat = "yyyy-MM-dd'T'HH:mm"
Dim EventDate As Long = DateTime.DateParse(startDate)
DateTime.DateFormat = "dd.MM.yyyy HH:mm"
'Log($"Event-ID =${eventId} Available $Date{dateAvailable}"$)
'Log($"Event-ID =${eventId} Visible $Date{dateVisible}"$)
Log($"Event-ID =${eventId} Match ${match}"$)
Log($"Event-ID =${eventId} eventName ${eventName}"$)
Log($"Event-ID =${eventId} eventdate ${EventDate}"$)
Log($"Event-ID =${eventId} Startdate $Date{EventDate}"$)
Log($"Event-ID =${eventId} TeamLogo ${teamLogo}"$)
Log($"Event-ID =${eventId} RivalLogo ${rivalLogo}"$)
'event.EventDate
Dim event As HuskiesEvent = B4XPages.GetManager.MainPage.CreateHuskiesEvent(eventId, eventName,EventDate,homeimg,rivalimg,HomeTeam,RivalTeam)
elist.Add(event)
DateTime.DateFormat = "dd.MM.yyyy"
'Dim DatumHeute As String = DateTime.Date(DateTime.Now)
Dim Datum As String = DateTime.Date(event.EventDate)
'If Datum = DatumHeute Then
Eventsheute = Eventsheute +1
Dim p As B4XView = xui.CreatePanel("")
p.SetLayoutAnimated(0,0,0,100%x,200dip)
p.LoadLayout("Event")
clv.InsertAt(0,p,200dip,event)
DateTime.DateFormat = "dd.MM.yyyy HH:mm"
Dim Datum As String = DateTime.Date(event.EventDate)
lblDatum.Text = Datum
lblName.Text = eventName
ivHome.SetBitmap(homeimg)
ivRival.SetBitmap(rivalimg)
'End If
Next
elist.SortType("EventDate",True)
If Eventsheute=0 Then
Dim dummy As HuskiesEvent
Dim p As B4XView = xui.CreatePanel("")
p.SetLayoutAnimated(0,0,0,100%x,200dip)
p.LoadLayout("Event")
clv.InsertAt(0,p,200dip,dummy)
lblDatum.Text = "--.--.----"
lblName.Text = "HEUTE KEIN SPIEL"
ivHome.Visible = False ' .SetBitmap(homeimg)
ivRival.Visible = False ' .SetBitmap(rivalimg)
End If
Log(result)
'Dim jp As JSONParser
'jp.Initialize(result)
'Dim jRoot As Map = jp.NextObject
Else
Log($"JobError: ${job2.ErrorMessage}"$)
End If
job2.Release
End Sub