Hello,
Can someone assist me in getting InitializeGroupTypes() to obtain all the contact groups?
I am trying to add group membership functionality to the ContactUtils module (see code below). cu.GetGroups() works fine as long as the map named groupTypes is properly initialized when cu.Initialize is invoked which is where my problem is. cu.Initialize calls a sub named InitializeGroupTypes which is suppose to obtain all the contact groups, but I can't get it to work properly so I am forced to 'strong-arm' a solution by using a workaround sub namedInitializeGroupTypes2().
The code below calls the new subroutine named cu.GetGroups(c.ID) in order to obtain contacts' membership groups.
The code below adds a new type named cuGroup, a new map called groupTypes and two new subroutines named GetGroups() and InitializeGroupTypes() to the ContactUtils module in hopes of adding group membership functionality. The problem is that InitializeGroupTypes() does not properly initialize groupTypes so I am forced to 'strong-arm' a solution by using a workaround sub called InitializeGroupTypes2()
Can someone assist me in getting InitializeGroupTypes() to obtain all the contact groups?
I am trying to add group membership functionality to the ContactUtils module (see code below). cu.GetGroups() works fine as long as the map named groupTypes is properly initialized when cu.Initialize is invoked which is where my problem is. cu.Initialize calls a sub named InitializeGroupTypes which is suppose to obtain all the contact groups, but I can't get it to work properly so I am forced to 'strong-arm' a solution by using a workaround sub namedInitializeGroupTypes2().
The code below calls the new subroutine named cu.GetGroups(c.ID) in order to obtain contacts' membership groups.
B4X:
'Activity Module
Sub Process_Globals
Dim cu As ContactsUtils 'GGH 01-13-14, requires lib: ContentResolver (version 1.00)
End Sub
Sub Globals
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
cu.Initialize
End If
For Each c As cuContact In cu.FindAllContacts(True)
For Each g As cuGroup In cu.GetGroups(c.Id)
Log(c.DisplayName&"-"&g.GroupID&"-"&g.GroupType)
Next
Next
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
The code below adds a new type named cuGroup, a new map called groupTypes and two new subroutines named GetGroups() and InitializeGroupTypes() to the ContactUtils module in hopes of adding group membership functionality. The problem is that InitializeGroupTypes() does not properly initialize groupTypes so I am forced to 'strong-arm' a solution by using a workaround sub called InitializeGroupTypes2()
B4X:
'ContactUtils Module
Sub Class_Globals
...
...
...
Type cuGroup (GroupID As Int, GroupType As String)
Private groupTypes As Map
End Sub
Public Sub Initialize
...
...
...
InitializeGroupTypes 'Does not work
'InitializeGroupTypes2 'Workaround sub
End Sub
...
...
...
'This sub works fine as long as groupTypes is properly initialized
Public Sub GetGroups(Id As Long) As List
Dim res As List
res.Initialize
For Each obj() As Object In GetData("vnd.android.cursor.item/group_membership", _
Array As String("data1", "group_sourceid"), Id, Null)
Dim g As cuGroup
g.Initialize
g.GroupID= obj(0)
g.GroupType = groupTypes.Get(obj(0))
res.Add(g)
Next
Return res
End Sub
'This sub does not work correctly for the for loop in
'this sub is never entered and I do not know why
Public Sub InitializeGroupTypes
groupTypes.Initialize
Dim crsr As Cursor = cr.Query(dataUri, Array As String("data1","data3"), _
"mimetype = ?", Array As String("vnd.android.cursor.dir/group"), "")
For i = 0 To crsr.RowCount-1
crsr.Position = i
groupTypes.Put(crsr.GetString2(0),crsr.GetString2(1))
Next
crsr.Close
End Sub
'This sub is being used in place of IntializeGroupTypes
'until I figure out how to get InitializeGroupTypes working
Private Sub InitializeGroupTypes2
groupTypes.Initialize
groupTypes.Put("1", "contact")
groupTypes.Put("2", "starred")
groupTypes.Put("3", "friends")
groupTypes.Put("4", "family")
groupTypes.Put("5", "coworker")
End Sub
...
...
...