public void GetContactList(ContactListFragment fragment,ViewGroup rootview)
        {
            nn_activity.RunOnUiThread(()=>{
                fragment.AddSpinner(rootview,"Loading");
            });

                var book = new Xamarin.Contacts.AddressBook (nn_activity);
                book.ToList ().ForEach (p=>{
                    string name = "";
                    if (p.FirstName != null) {
                        name += p.FirstName+" ";
                    }
                    if (p.LastName != null) {
                        name += p.LastName;
                    }

                    List<Phone> phonelist = p.Phones.ToList ();
                    if (phonelist.Count > 0) {
                        foreach(var phone in phonelist){
                            if(phone.Type.Equals(Xamarin.Contacts.PhoneType.Mobile)){
                                ContactInfo info = new ContactInfo (name,phone.Number);
                                contactinfolist.Add (info);
                                break;
                            }

                        }
                    }
                }
                );
                nn_activity.RunOnUiThread(()=>{
                fragment.RemoveSpinner(rootview);
                fragment.adapter.notifycontactlistdatachange();
                });
        }
Exemple #2
0
        public void GetEmailList(EmailListFragment fragment,ViewGroup rootview)
        {
            nn_activity.RunOnUiThread(()=>{
                fragment.AddSpinner(rootview,"Loading");
            });

            var book = new Xamarin.Contacts.AddressBook (nn_activity);
            book.ToList ().ForEach (p=>{
                string name = "";
                if (p.FirstName != null) {
                    name += p.FirstName+" ";
                }
                if (p.LastName != null) {
                    name += p.LastName;
                }

                List<Email> emaillist = p.Emails.ToList ();
                if (emaillist.Count > 0) {
                    foreach(var email in emaillist){
                        ContactInfo info = new ContactInfo (name,email.Address);
                        contactinfolist.Add (info);
                        break;
                    }
                }
            }
            );
            nn_activity.RunOnUiThread(()=>{
                fragment.RemoveSpinner(rootview);
                fragment.adapter.notifycontactlistdatachange();
            });
        }
        public void GetContactList(ContactListFragment fragment,ViewGroup rootview)
        {
            nn_activity.RunOnUiThread(()=>{
                fragment.AddSpinner(rootview,"Loading");
            });

                var book = new Xamarin.Contacts.AddressBook (nn_activity);
                List<Contact> list = book.ToList ();
                list.Sort (
                delegate(Contact x, Contact y)
                {
                    if (String.IsNullOrEmpty(x.FirstName) && String.IsNullOrEmpty(y.FirstName)) return 0;
                    else if (x.FirstName == null) return -1;
                    else if (y.FirstName == null) return 1;
                    else return x.FirstName.CompareTo(y.FirstName);
                });
                list.ForEach (p=>{
                    string name = "";
                    if (p.FirstName != null) {
                        name += p.FirstName+" ";
                    }
                    if (p.LastName != null) {
                        name += p.LastName;
                    }

                    List<Phone> phonelist = p.Phones.ToList ();
                    if (phonelist.Count > 0) {
                        foreach(var phone in phonelist){
                            if(phone.Type.Equals(Xamarin.Contacts.PhoneType.Mobile)){
                                ContactInfo info = new ContactInfo (name,phone.Number);
                                contactinfolist.Add (info);
                                break;
                            }

                        }
                    }
                }
                );
                nn_activity.RunOnUiThread(()=>{
                fragment.RemoveSpinner(rootview);
                fragment.adapter.notifycontactlistdatachange();
                });
        }
        public IEnumerable<SelectableContact> GetContactsWithEmailAddresses()
        {
            #if MONOANDROID
            var androidGlobals = this.GetService<Cirrious.MvvmCross.Droid.Interfaces.IMvxAndroidGlobals>();
            var ab = new AddressBook(androidGlobals.ApplicationContext);
            #else
            var ab = new AddressBook();
            #endif

            var allContacts = ab.ToList();

            return (from c in allContacts
                    orderby c.DisplayName
                    where c.Emails != null && c.Emails.Any()
                    let email = c.Emails.FirstOrDefault()
                    where email != null && !string.IsNullOrEmpty(email.Address)
                    select
                        new SelectableContact
                        {
                            DisplayName = c.DisplayName,
                            Email = email.Address,
                            IsSelected = false
                        }).ToList();
        }