示例#1
0
        public void ClearFavoriteContact()
        {
            LoadedContacts.Select(x => x.IsFavorite = false);

            Application.Current.Properties.Remove(typeof(Contact).FullName);
            Application.Current.SavePropertiesAsync();
        }
示例#2
0
        public async Task <IEnumerable <ContactList> > GetContactsGroups(bool forceReload = false)
        {
            List <ContactList> result = new List <ContactList>();

            // Reload contact list if requested, otherwise reuse
            if (forceReload == true || LoadedContacts == null || !LoadedContacts.Any())
            {
                LoadedContacts = await _platformContactService.GetContacts();
            }

            foreach (var contact in LoadedContacts)
            {
                contact.IsFavorite = false;
            }

            // Get favorite contact
            var favoriteContact = LoadFavoriteContact();

            // Update favorite contact in list
            if (favoriteContact != null)
            {
                var matchingContact = LoadedContacts.FirstOrDefault(x => x.Number == favoriteContact.Number);

                if (matchingContact != null)
                {
                    matchingContact.IsFavorite = true;
                    favoriteContact            = matchingContact;

                    var favoriteContactList = new ContactList
                    {
                        favoriteContact
                    };

                    favoriteContactList.Heading = "Favorite";
                    result.Add(favoriteContactList);
                }
            }

            var headers       = LoadedContacts.Select(x => GetHeading(x));
            var uniqueHeaders = new HashSet <string>(headers).ToList();

            uniqueHeaders.Sort((x, y) => string.Compare(x, y));

            foreach (var uniqueHeader in uniqueHeaders)
            {
                var group = new ContactList
                {
                    Heading = uniqueHeader
                };

                group.AddRange(LoadedContacts.Where(x => !string.IsNullOrEmpty(x.Name) && x.Name[0].ToString() == uniqueHeader));

                result.Add(group);
            }

            return(result);
        }
示例#3
0
        public void SaveFavoriteContact(Contact contact)
        {
            LoadedContacts.Select(x => x.IsFavorite = false);

            string json = JsonConvert.SerializeObject(contact);

            Application.Current.Properties[contact.GetType().FullName] = json;
            Application.Current.SavePropertiesAsync();
        }
示例#4
0
        public ContactsViewModel(IWorkUnitProvider workUnitProvider)
        {
            WorkUnitProvider = workUnitProvider;

            LoadAllContacts = new SimplerCommand
            {
                Action = () =>
                {
                    WorkUnit       = WorkUnitProvider.ProvideWorkUnit();
                    LoadedContacts = new ObservableCollection <Contact>(WorkUnit.Contacts.GetAll());
                    NotifyChangesMade();
                }
            };
            SaveAllContacts = new SimpleCommand
            {
                Action = () => {
                    WorkUnit.Save();
                    LoadedContacts.ToList().ForEach(c => WorkUnit.Reload(c));
                    NotifyChangesMade();
                },
                CanExecuteFunc = () => WorkUnit?.IsChanged() ?? false
            };
            OnEditEnding = new SimplerCommand
            {
                Action = SaveAllContacts.RaiseCanExecuteChanged
            };
            DeleteSelected = new SimpleCommand
            {
                Action = () =>
                {
                    SelectedContacts.ToList().ForEach(c => LoadedContacts.Remove(c));
                },
                CanExecuteFunc = () => {
                    return(SelectedContacts?.Count > 0);
                }
            };
            OnSelectionChange = new SimplerCommand <IList>
            {
                Action = o =>
                {
                    SelectedContacts = new ObservableCollection <Contact>(o.OfType <Contact>());
                }
            };
        }