'Class module
Sub Class_Globals
Public thisPage As Page
Dim header As HeaderBar
Private scr_content As ScrollView
Dim allGroups,allSubgroups,allFeatures As List
Dim act_groups,act_subgroups,act_features As ActionSheet
Dim pnl_groups,pnl_subgroups,pnl_features As Panel
Dim nearbys As List
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(Eventname As String)
RenderUtils.showBusyMessage
thisPage.Initialize("pageNearby")
thisPage.RootPanel.Color=Colors.Black
allGroups = DatabaseInterface.getLutGroups
allSubgroups = DatabaseInterface.getLutSubgroups
allFeatures = DatabaseInterface.getFeaturesList
renderHeaderPanel
refreshContent
End Sub
Public Sub closePage
Main.NavControl.RemoveCurrentPage
End Sub
Private Sub pageSearch_Resize(Width As Int, Height As Int)
refreshContent
End Sub
Private Sub refreshContent
If scr_content.IsInitialized Then
scr_content.RemoveViewFromParent
End If
scr_content.Initialize("",Main.screenWidth,Main.screenHeight-Main.headerBarHeight) ' set height of scrollview later
' *********************************
' ADD STUFF TO scr_content, then set height accordingly
' *********************************
Dim pnl As Panel
pnl = scr_content.Panel
nearbys = DatabaseInterface.getNearbys
Dim totalHeight As Int
totalHeight=0
'1. get all the favourites from the settings table
nearbys = DatabaseInterface.getNearbys
' now add in others
For i = 0 To nearbys.Size-1
Dim thisResult As Map
thisResult = nearbys.Get(i)
' add in a panel for each with
' header (title and modifier button for increment, decrement & remove), and 'show all' button to do a search
' maximum 3 entries, or 1 entry of 'none' if not found
Dim cp As Map
cp = getNearbyPanelMap(thisResult)
' Log("THIS CP HAS HEIHGT "&cp.Get("height"))
pnl.AddView(cp.Get("panel"),0,totalHeight,Main.screenWidth,cp.Get("height"))
totalHeight=totalHeight+cp.Get("height")
Next
' add on 3 dropdowns which will add them to the others
pnl_groups.Initialize("pnl_groups")
pnl_subgroups.Initialize("pnl_subgroups")
pnl_features.Initialize("pnl_features")
pnl_groups=RenderUtils.renderShadowPanelWithClick(pnl_groups,"Add Nearest Group",Main.colour_white,"#000000",Main.colour_purple,Main.colour_lightgrey,Main.screenWidth,Main.screenWidth*0.15,Me)
pnl_subgroups=RenderUtils.renderShadowPanelWithClick(pnl_subgroups,"Add Nearest Sub-Group",Main.colour_white,"#000000",Main.colour_purple,Main.colour_lightgrey,Main.screenWidth,Main.screenWidth*0.15,Me)
pnl_features=RenderUtils.renderShadowPanelWithClick(pnl_features,"Add Nearest Feature",Main.colour_white,"#000000",Main.colour_purple,Main.colour_lightgrey,Main.screenWidth,Main.screenWidth*0.15,Me)
pnl.AddView(pnl_groups,0,totalHeight,Main.screenWidth,Main.screenWidth*0.15)
totalHeight=totalHeight+(Main.screenWidth*0.15)
pnl.AddView(pnl_subgroups,0,totalHeight,Main.screenWidth,Main.screenWidth*0.15)
totalHeight=totalHeight+(Main.screenWidth*0.15)
pnl.AddView(pnl_features,0,totalHeight,Main.screenWidth,Main.screenWidth*0.15)
totalHeight=totalHeight+(Main.screenWidth*0.15)
scr_content.ContentHeight=totalHeight
thisPage.RootPanel.AddView(scr_content,0,Main.headerBarHeight,Main.screenWidth,Main.screenHeight-Main.headerBarHeight)
RenderUtils.hideMessage
End Sub
Sub shadowPanel_Click
act_groups.Initialize("act_filter","","Cancel","",MiscUtils.MapToList(allGroups,"full_value"))
act_groups.Show(thisPage.RootPanel)
End Sub
Sub btn_settings_Click
Dim p As Button
p = Sender
'Dim thisResult As Map
'thisResult = p.Tag
Log("trying to delete "&p.Tag)
DatabaseInterface.nearbyDelete(p.Tag)
refreshContent
End Sub
Sub btn_search_Click
Dim p As Button
p = Sender
Dim thisResult As Map
thisResult = p.Tag
Dim restrictions As List
restrictions.Initialize
'Msgbox("locate id : "&refId,"title")
Select Case thisResult.Get("type")
Case "G"
restrictions.Add("e.id=eg.establishment_id")
restrictions.Add("e.id=et.establishment_id")
restrictions.Add("et.type_id=t.id")
restrictions.Add("eg.group_id="&thisResult.Get("ref_id"))
restrictions.Add("e.address_street=s.id")
SearchUtils.clearSearch
SearchUtils.AddSearchElement("EG",thisResult.Get("ref_id"),"establishment e,establishment_type et, establishment_group eg,lut_type t,lut_street s",restrictions,"R")
Dim ps As pageSearch
ps.Initialize("")
Main.NavControl.ShowPage(ps.thisPage)
Case "S"
restrictions.Add("e.id=eg.establishment_id")
restrictions.Add("e.id=et.establishment_id")
restrictions.Add("e.id=es.establishment_id")
restrictions.Add("et.type_id=t.id")
restrictions.Add("es.subgroup_id="&thisResult.Get("ref_id"))
restrictions.Add("e.address_street=s.id")
SearchUtils.clearSearch
SearchUtils.AddSearchElement("ES",thisResult.Get("ref_id"),"establishment e,establishment_type et, establishment_group eg,lut_type t,lut_street s,establishment_subgroup es",restrictions,"R")
Dim ps As pageSearch
ps.Initialize("")
Main.NavControl.ShowPage(ps.thisPage)
Case "F"
restrictions.Add("e.id=eg.establishment_id")
restrictions.Add("e.id=et.establishment_id")
restrictions.Add("et.type_id=t.id")
restrictions.Add("ef.establishment_id=e.id")
restrictions.Add("ef.feature_id="&thisResult.Get("ref_id"))
restrictions.Add("e.address_street=s.id")
SearchUtils.clearSearch
SearchUtils.AddSearchElement("EF",thisResult.Get("ref_id"),"establishment e,establishment_type et, establishment_group eg,lut_type t,lut_street s,establishment_feature ef",restrictions,"R")
Dim ps As pageSearch
ps.Initialize("")
Main.NavControl.ShowPage(ps.thisPage)
End Select
End Sub
Private Sub renderHeaderPanel
header.Initialize(Me,"Nearby",MiscUtils.HexToColor(Main.colour_purple,255),True,True,False,"","",Null,"","")
thisPage.RootPanel.AddView(header.getPanelView, 0, 0, Main.screenWidth, Main.headerBarHeight)
End Sub
Private Sub act_groups_Click(item As String)
For Each v As Map In allGroups
If v.Get("full_value")=item Then
Log("match for group, adding "&item)
DatabaseInterface.nearbyAdd("G",v.Get("id"))
refreshContent
Return
End If
Next
End Sub
Private Sub act_subgroups_Click(item As String)
For Each v As Map In allSubgroups
If v.Get("full_value")=item Then
Log("match for subgroup, adding "&item)
DatabaseInterface.nearbyAdd("S",v.Get("id"))
refreshContent
Return
End If
Next
End Sub
Private Sub act_features_Click(item As String)
Dim id As String
id=DBUtils.GetTableValue(Main.SQL,"lut_feature","id","value='"&item&"'")
If (IsNumber(id)) Then
' add
DatabaseInterface.nearbyAdd("F",id)
refreshContent
End If
End Sub
Sub pnl_groups_Click
act_groups.Initialize("act_groups","","Cancel","",MiscUtils.MapToList(allGroups,"full_value"))
act_groups.Show(thisPage.RootPanel)
End Sub
Sub pnl_subgroups_Click
act_subgroups.Initialize("act_subgroups","","Cancel","",MiscUtils.MapToList(allSubgroups,"full_value"))
act_subgroups.Show(thisPage.RootPanel)
End Sub
Sub pnl_features_Click
act_features.Initialize("act_features","","Cancel","",MiscUtils.MapToList(allFeatures,"value"))
act_features.Show(thisPage.RootPanel)
End Sub
Sub pnlButton_Click(callType As String,refId As String)
' add this favourite to search history, and open search activity
End Sub
Sub pnlButton_LongClick(p As PanelButton)
' might be one of the top row panels, if so ignore them (can't delete them)
If (p=Null) Then Return
End Sub
' returnas a map, one contains the panel with all the results, other for the panel height
Private Sub getNearbyPanelMap(thisNearby As Map) As Map
Dim l As Map
l.Initialize
Dim p As Panel
p.Initialize("")
Dim title As String
title=DatabaseInterface.getNearbyTitle(thisNearby.Get("type"),thisNearby.Get("ref_id"))
Dim pnl_title As Panel
pnl_title=RenderUtils.renderSectionTitlePanel(title,Main.screenWidth*0.7,Main.screenWidth*0.15)
Dim btn_settings,btn_search As Button
btn_settings.Initialize("btn_settings",btn_settings.STYLE_SYSTEM)
Dim bitmapSettings As Bitmap
bitmapSettings.Initialize(File.DirAssets,"btn_delete.png")
RenderUtils.SetBackgroundImage(btn_settings,bitmapSettings,0)
btn_settings.Tag=thisNearby.Get("id")
btn_search.Initialize("btn_search",btn_search.STYLE_SYSTEM)
Dim bitmapSearch As Bitmap
bitmapSearch.Initialize(File.DirAssets,"btn_search.png")
RenderUtils.SetBackgroundImage(btn_search,bitmapSearch,0)
btn_search.Tag=thisNearby
pnl_title.AddView(btn_settings,Main.screenWidth*0.7,0,Main.screenWidth*0.15,Main.screenWidth*0.15)
pnl_title.AddView(btn_search,Main.screenWidth*0.85,0,Main.screenWidth*0.15,Main.screenWidth*0.15)
' put in splitter index
Dim lbl_splitter1a,lbl_splitter1b,lbl_splitter2a,lbl_splitter2b As Label
lbl_splitter1a.Initialize("")
lbl_splitter1a.Color=MiscUtils.HexToColor("#f07fea",70)
lbl_splitter2a.Initialize("")
lbl_splitter2a.Color=MiscUtils.HexToColor("#f07fea",70)
lbl_splitter1b.Initialize("")
lbl_splitter1b.Color=MiscUtils.HexToColor("#460543",255)
lbl_splitter2b.Initialize("")
lbl_splitter2b.Color=MiscUtils.HexToColor("#460543",255)
pnl_title.AddView(lbl_splitter1a,Main.screenWidth*0.7,3%x,1dip,(Main.screenWidth*0.15)-6%x)
pnl_title.AddView(lbl_splitter1b,(Main.screenWidth*0.7)-1dip,3%x,1dip,(Main.screenWidth*0.15)-6%x)
pnl_title.AddView(lbl_splitter2a,Main.screenWidth*0.85,3%x,1dip,(Main.screenWidth*0.15)-6%x)
pnl_title.AddView(lbl_splitter2b,(Main.screenWidth*0.85)-1dip,3%x,1dip,(Main.screenWidth*0.15)-6%x)
p.AddView(pnl_title,0,0,100%x,Main.screenWidth*0.15)
p.AddView(btn_settings,Main.screenWidth*0.7,0,Main.screenWidth*0.15,Main.screenWidth*0.15)
p.AddView(btn_search,Main.screenWidth*0.85,0,Main.screenWidth*0.15,Main.screenWidth*0.15)
Dim height As Int
height=Main.screenWidth*0.15
Dim rowHeight As Int
rowHeight=Main.screenWidth*0.2
' now add in results
' now need to be a bit cute here. I want to show closest 3 places, but the closest might be shut, so limit to first 10 only
' and that'll do it I reckon
Dim resultsPanelButtons As List
resultsPanelButtons.Initialize
resultsPanelButtons=runSearch(thisNearby.Get("type"),thisNearby.Get("ref_id"),Main.nearby_limit)
If (resultsPanelButtons.Size<1) Then
Dim lbl_noresults As Label
lbl_noresults=RenderUtils.renderLabel("Nothing Nearby")
lbl_noresults.Color=Colors.Black
p.AddView(lbl_noresults,0,height,Main.screenWidth,rowHeight)
height = height+rowHeight
Else
'Dim total As Int
'total=resultsPanelButtons.Size
For Each pb As PanelButton In resultsPanelButtons
p.AddView(pb.Render,0,height,Main.screenWidth,rowHeight)
height = height+rowHeight
'height=15%x+(total*rowHeight)
Next
'p.AddView(renderUltimateListView(resultsInfo),0,15%x,100%x,height-15%x)
End If
l.Put("panel",p)
l.Put("height",height)
Return l
End Sub
' return panels in 'panel' map, and height in 'height' value
' returns LIST OF DATA
Private Sub runSearch(nearbyType As String,Search_id As String, number As Int) As List
Dim centreLocation As Location
centreLocation.Initialize2(Main.currentLocation.Latitude,Main.currentLocation.Longitude)
Dim restrictions As List
restrictions.Initialize
Dim q As String
Dim tables,search_type As String
' if establishment_id is set, then use that as the starting lat/lon,
' else if traveller_point_id is set, use that
' sle Else use current Location
If (Main.establishment_id<>Null AND IsNumber(Main.establishment_id) AND Main.establishment_id>0) Then
centreLocation=EstablishmentInterface.getEstablishmentLocation(Main.establishment_id)
Else If (Main.traveller_point_id<>Null AND IsNumber(Main.traveller_point_id) AND Main.traveller_point_id>0) Then
centreLocation.Initialize2(Main.mapCentre_lat,Main.mapCentre_lon)
Else
centreLocation=Main.currentLocation
End If
'Log("NEARBY SEARCHING FOR "&nearbyType)
If (nearbyType="G") Then
restrictions.Add("e.id=eg.establishment_id")
restrictions.Add("e.id=et.establishment_id")
restrictions.Add("et.type_id=t.id")
restrictions.Add("eg.group_id="&Search_id)
restrictions.Add("e.address_street=s.id")
tables="establishment e,establishment_type et, establishment_group eg,lut_type t,lut_street s"
search_type="EG"
Else If (nearbyType="S") Then
restrictions.Add("e.id=et.establishment_id")
restrictions.Add("e.id=eg.establishment_id")
restrictions.Add("e.id=es.establishment_id")
restrictions.Add("et.type_id=t.id")
restrictions.Add("es.subgroup_id="&Search_id)
restrictions.Add("e.address_street=s.id")
tables="establishment e,establishment_type et, establishment_group eg,lut_type t,lut_street s,establishment_subgroup es"
search_type="ES"
Else If (nearbyType="F") Then
restrictions.Add("e.id=et.establishment_id")
restrictions.Add("e.id=eg.establishment_id")
restrictions.Add("et.type_id=t.id")
restrictions.Add("ef.establishment_id=e.id")
restrictions.Add("ef.feature_id="&Search_id)
restrictions.Add("e.address_street=s.id")
tables="establishment e,establishment_type et, establishment_group eg,lut_type t,lut_street s,establishment_feature ef"
search_type="EF"
End If
Dim s As Search
s.Initialize(Me,search_type,Search_id,tables,restrictions,"R",centreLocation,number)
'Return s.RowInfos
Dim result_panels As List
result_panels=s.getResultPanels 'return panelButtons for each result
Return result_panels
End Sub