async Task <List <Person> > AddressBookUpdate() { IAddressBook addressBook = DependencyService.Get <IAddressBook> (); List <Person> bookList = addressBook.GetPeople(); string lastUpdatedString = DependencyService.Get <IUserPreferences> ().GetString("LastUpdated"); DateTime lastUpdated = DateTime.FromBinary(Convert.ToInt64(lastUpdatedString)); PersonRepository repo = new PersonRepository(); List <Person> result = null; if (lastUpdated <= DateTime.MinValue) { repo.DeleteAll(); foreach (Person p in bookList) { repo.Create(p); } result = bookList; } DependencyService.Get <IUserPreferences> ().SetString("LastUpdated", DateTime.Now.ToBinary().ToString()); return(result); }
async void LoadPeople() { dictionary = new List <KeyValuePair <string, Person> > (); encoder = new T9Encoder(); searchBar.TextChanged += OnSearchBarTextChanged; people = new PersonRepository().ReadAll(); people.Sort((Person p1, Person p2) => { return(p1.DisplayName.CompareTo(p2.DisplayName)); }); resultList.BackgroundColor = Color.FromHex("#cfd2d6"); //resultList.VerticalOptions = LayoutOptions.Center; resultList.ItemTemplate = new DataTemplate(() => { // Create views with bindings for displaying each property. Label nameLabel = new Label(); nameLabel.SetBinding(Label.TextProperty, "DisplayName"); nameLabel.Font = Font.OfSize("GillSans-Bold", NamedSize.Medium); nameLabel.TextColor = Color.White; nameLabel.VerticalOptions = LayoutOptions.Center; Label detailsLabel = new Label(); detailsLabel.SetBinding(Label.TextProperty, "Details"); detailsLabel.VerticalOptions = LayoutOptions.Center; detailsLabel.Font = Font.OfSize("GillSans", NamedSize.Small); detailsLabel.TextColor = Color.FromHex("#78b9b5"); return(new ContactViewCell { View = new StackLayout { Spacing = 0, Padding = new Thickness(5, 3, 1, 3), Orientation = StackOrientation.Vertical, BackgroundColor = Color.FromHex("#494c53"), VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, Children = { //img, nameLabel, detailsLabel } } }); }); resultList.ItemTapped += OnItemTapped; searchBar.Focus(); IAddressBook addressBook = DependencyService.Get <IAddressBook> (); people = addressBook.GetPeople(); resultList.ItemsSource = SearchResult; }