#Region Module Attributes
#FullScreen: False
#IncludeTitle: True
#ApplicationLabel: ParkEddy
#VersionCode: 1
#VersionName:
#SupportedOrientations: portrait
#End Region
'Activity module
Sub Process_Globals
Private COUNTRIES_LIST = "countries_list", COUNTRY_POPULATION = "country_population" As String, elencopark = "elencopark" As String
End Sub
Sub Globals
Type TwoLines (First As String, Second As String)
Dim lblPopulation As Label
Dim ListView1 As ListView
Dim lblCountry As Label
Dim park As String
Dim lbl_indirizzo As Label
Dim lbl_ubicazione As Label
Dim lbl_zona As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
FetchCountriesList
End Sub
Sub FetchCountriesList
ProgressDialogShow("Fetching list of macchine")
'Gets all the available countries
ExecuteRemoteQuery("SELECT n_macchina, zona FROM elenco ORDER BY n_macchina", COUNTRIES_LIST)
End Sub
Sub ListView1_ItemClick (Position As Int, Value As Object)
Dim tl As TwoLines
tl = Value
lblCountry.Text = tl.Second
lblPopulation.Text = "Calling server..."
ExecuteRemoteQuery("SELECT tot_euro FROM Elenco WHERE n_macchina='" & tl.First & "'", COUNTRY_POPULATION)
End Sub
Sub ExecuteRemoteQuery(Query As String, JobName As String)
Dim job As HttpJob
job.Initialize(JobName, Me)
job.PostString("https://www.xxxxxx.com/proviamo/execute.php", Query)
End Sub
Sub JobDone(Job As HttpJob)
ProgressDialogHide
If Job.Success Then
Dim res As String
res = Job.GetString
Log("Response from server: " & res)
Dim parser As JSONParser
parser.Initialize(res)
Select Job.JobName
Case COUNTRIES_LIST
Dim COUNTRIES As List
COUNTRIES = parser.NextArray 'returns a list with maps
For i = 0 To COUNTRIES.Size - 1
Dim m As Map
m = COUNTRIES.Get(i)
'We are using a custom type named TwoLines (declared in Sub Globals).
'It allows us to later get the two values when the user presses on an item.
Dim tl As TwoLines
tl.First = m.Get("n_macchina")
tl.Second = m.Get("zona")
ListView1.AddTwoLines2(tl.First, tl.Second, tl)
Next
Case COUNTRY_POPULATION
Dim l As List
l = parser.NextArray
If l.Size = 0 Then
lblPopulation.Text = "N/A"
Else
Dim m As Map
m = l.Get(0)
lblPopulation.Text = NumberFormat2(m.Get("tot_euro"),0, 0, 0, True) & " (K)"
End If
Case elencopark
Dim l As List
l = parser.NextArray
If l.Size = 0 Then
lblPopulation.Text = "N/A"
Else
Dim m As Map
m.Initialize
For Each m As Map In l
Dim lbl_indirizzo As Label
Dim lbl_ubicazione As Label
Dim lbl_zona As Label
lbl_indirizzo.Text =m.Get("indirizzo")
lbl_zona.Text =m.Get("zona")
lbl_ubicazione.Text =m.Get("ubicazione")
Next
End If
End Select
Else
Log(Job.ErrorMessage)
ToastMessageShow("Error: " & Job.ErrorMessage, True)
End If
Job.Release
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub lblCountry_Click
park = lblCountry.text
Activity.LoadLayout("schedaPark")
ExecuteRemoteQuery("SELECT * FROM elenco WHERE n_macchina='" & park & "'", elencopark)
lbl_park.Text = park
End Sub
Sub cmd_torna_Click
Activity.LoadLayout("1")
FetchCountriesList
End Sub