Sub Class_Globals
Private Root As B4XView
Private xui As XUI
' Private Activity As Activity
Private B4XTable1 As B4XTable
Private const CSVFile As String = "songlist.csv"
End Sub
Public Sub Initialize
' B4XPages.GetManager.LogEvents = True
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("CMCK_Song_List")
xui.SetDataFolder(File.DirAssets)
B4XTable1.RowHeight = 30dip
B4XTable1.NumberOfFrozenColumns = 1
B4XTable1.AddColumn("Song", B4XTable1.COLUMN_TYPE_TEXT)
B4XTable1.AddColumn("Singer", B4XTable1.COLUMN_TYPE_TEXT)
DownloadAndSaveFile("https://drive.google.com/file/d/1q9nKZ6SqiegtLiq64pVJbk9fTuc5AMpS/view?usp=sharing")
LoadData
B4XTable1.MaximumRowsPerPage = 30
B4XTable1.BuildLayoutsCache(B4XTable1.MaximumRowsPerPage)
End Sub
Private Sub LoadData
Dim data As List
data.Initialize
If File.Exists(xui.DefaultFolder,CSVFile) Then
Dim su As StringUtils
data = su.LoadCSV(xui.DefaultFolder, CSVFile, ",")
Else
data.Initialize
End If
B4XTable1.SetData(data)
End Sub
Sub DownloadAndSaveFile (Link As String)
Dim j As HttpJob
j.Initialize("", Me)
j.Download(Link)
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Log ("Success")
Dim out As OutputStream = File.OpenOutput(xui.DefaultFolder, CSVFile, False)
File.Copy2(j.GetInputStream, out)
out.Close '<------ very important
End If
j.Release
End Sub