B4A Library ContactsUtils v2.00 : redesigned, recoded and enhanced new version

Hi everybody,

I worked a lot on ContactsUtils library (from @walt61) since my last post at the end of January. I redesigned, recoded and enhanced the library. Below is a summary of the modifications:​
  1. Initialize has now 4 (string) parameterswhich can all be passed empty:
    • AccountType and AccountName allow to filter automatically all find and get functions and are also used when creating a contact or group.​
    • CustomFilter enables to set a particular selection which will be added to selection of find and get functions (when not empty, the 2 previous parameters will not be used in find and get functions).​
    • CustomDisplay enables to replace standard Android DisplayName. The parameter must contain “%firstname” and/or “%lastname”.​
  2. New function SetTypesallows to change "map Types" labels, enabling translation.
    • First parameter should be one among "address", "email", "event", "phone" and "website".​
    • Second parameter defines values given in a string "xx1=value1,xx2=value2, ...", first xx being the default. To reset all maps, if needed, Initialize function can be recalled. ContactsUtils uses this function itself to initialize map types. Just have a look at the end of the file !​
  3. New functions AddCustom, SetCustom and DeleteCustom have been added to manage Google personalized fields.​
  4. New function GetContactInfos delivers part or all information on a contact in a map parameter which keys identify the items: "address", "custom", "email", "event", "group", "job", "name", "note", "phone" and "website".​
  5. Address, email, event, phone and website now support Google personalized labels: type value is zero and label is stored in "data3" field.​
  6. Find functions returning lists have been simplified (sort option was suppressed because cursor sorting is not performant) and now have only one string parameter “SelXXXX” which accepts joker characters (operator is automatically set to LIKE in this case):
    • xxx% to find items starting with xxx,​
    • %xxx to find items ending with xxx (not very useful I agree),​
    • %xxx% to find items containing xxx.​
  7. Most elementary items are now defined with a cuXXXX object and include a DataId field which is the Id of the item, facilitating and securing its update or deletion.​
  8. SetNote manages the standard Google note (Android sets for each contact a note record whose text is set to null if not used). Field DataId of cuNote is not used. Set field Text to empty to reset the note. AddNote2, DeleteNote2 and SetNote2 enable to manage as many other notes as desired.​
  9. Most set and delete functions now have only one parameter: the cuXXXX object associated with the field. Whereas add functions now have 2 parameters : the ContactId and the cuXXXX object
  10. Most functions return a return code: the result of add, update or delete cursor action, except for the functions returning a list, its size being implicitly a return code.
  11. SetDisplayName function has been deleted since the new parameter CustomDisplay of Initialize function and also because this field is deeply managed by Android.
  12. Library has been a more "reorganized" in sections: definitions, find functions, add functions, create functions, delete functions, get functions, set functions and at least init functions. In each section, functions are in alphabetic order, public ones first then private ones.
 

Attachments

  • ContactsUtils v2-00.bas
    35.1 KB · Views: 346

Alain75

Member
A little fix because data3 was not set with SetNames (and creation of private function SetString)
SetData fix:
...
If nf(i)<>"UserType" Then data = obj.As(JavaObject).GetField(nf(i))
If Regex.IsMatch("\d{2}/\d{2}/\d{4}",data) Then data = Regex.Replace("(..)/(..)/(....)",data,"$3-$2-$1")
Select nc(i)
    Case "data2":    If nf(i)="DataType" Then SetData2(v, map, data) Else SetString(v,nc(i),data)
    [S]Case "data3": ' Already treated through data2[/S]
    Case "data3":    If nf(i)<>"UserType" Then SetString(v,nc(i),data)
    Case Else:        SetString(v,nc(i),data)
End Select
...
Private Sub SetString(v As ContentValues,field As String, data As String)
    If data<>"" And data<>"null" Then v.PutString(field,data) Else v.PutNull(field)
End Sub
 

Attachments

  • ContactsUtils v2-01.bas
    35.4 KB · Views: 227
Top