async void HandleAddContactButtonClicked(object sender, EventArgs e) { AppCenterService.Track(AppCenterConstants.AddContactButtonTapped); var contactDetailPage = ServiceCollection.Container.Resolve <ContactDetailPage>(new TypedParameter(typeof(bool), true), new TypedParameter(typeof(ContactModel), new ContactModel())); await _mainThread.InvokeOnMainThreadAsync(() => Navigation.PushModalAsync(new BaseNavigationPage(contactDetailPage))); }
protected BaseContentPage(TViewModel viewModel, AppCenterService appCenterService) { BindingContext = ViewModel = viewModel; AppCenterService = appCenterService; BackgroundColor = ColorConstants.PageBackgroundColor; }
public App() { _appCenterService = ServiceCollection.Container.Resolve <AppCenterService>(); var contactsListPage = ServiceCollection.Container.Resolve <ContactsListPage>(); MainPage = new BaseNavigationPage(contactsListPage); }
protected override void OnAppearing() { base.OnAppearing(); AppCenterService.Track(AppCenterConstants.ContactsListPageAppeared); if (Content is Layout <View> layout && layout.Children.OfType <RefreshView>().First() is RefreshView refreshView) { refreshView.IsRefreshing = true; } }
public ContactsListPage(IMainThread mainThread, AppCenterService appCenterService, ContactsListViewModel contactsListViewModel) : base(contactsListViewModel, appCenterService) { _mainThread = mainThread; ToolbarItems.Add(new ToolbarItem { Text = "+", AutomationId = AutomationIdConstants.AddContactButon } .Invoke(toolBarItem => toolBarItem.Clicked += HandleAddContactButtonClicked)); Title = PageTitleConstants.ContactsListPage; Content = new Grid { RowDefinitions = Rows.Define( (Row.List, Star), (Row.RestoreButton, AbsoluteGridLength(50))), Children = { new RefreshView { RefreshColor = Color.Black, Content = new CollectionView { ItemTemplate = new ContactsListDataTemplateSelector(), BackgroundColor = Color.Transparent, AutomationId = AutomationIdConstants.ContactsListView, SelectionMode = SelectionMode.Single }.Bind(CollectionView.ItemsSourceProperty, nameof(ContactsListViewModel.AllContactsList)) .Invoke(collectionView => collectionView.SelectionChanged += HandleSelectionChanged) }.RowSpan(All <Row>()) .Bind(RefreshView.CommandProperty, nameof(ContactsListViewModel.RefreshCommand)) .Bind(RefreshView.IsRefreshingProperty, nameof(ContactsListViewModel.IsRefreshing)), new Button { Text = "Restore Deleted Contacts", TextColor = ColorConstants.TextColor, AutomationId = AutomationIdConstants.RestoreDeletedContactsButton, BackgroundColor = new Color(ColorConstants.NavigationBarBackgroundColor.R, ColorConstants.NavigationBarBackgroundColor.G, ColorConstants.NavigationBarBackgroundColor.B, 0.25) }.Padding(10, 5).Margin(25).Center() .Row(Row.RestoreButton) .Invoke(button => button.Clicked += HandleRestoreDeletedContactsButtonClicked) } }; On <Xamarin.Forms.PlatformConfiguration.iOS>().SetUseSafeArea(true); }
public ContactsListViewModel(ApiService apiService, ContactDatabase contactDatabase, AppCenterService appCenterService, DatabaseSyncService databaseSyncService) : base(appCenterService) { _apiService = apiService; _contactDatabase = contactDatabase; _databaseSyncService = databaseSyncService; RefreshCommand = new AsyncCommand(() => { AppCenterService.Track(AppCenterConstants.PullToRefreshTriggered); return(ExecuteRefreshCommand()); }); RestoreDeletedContactsCommand = new AsyncCommand(() => { AppCenterService.Track(AppCenterConstants.RestoreDeletedContactsTapped); return(ExecuteRestoreDeletedContactsCommand()); }); }
public BaseViewModel(AppCenterService appCenterService) => AppCenterService = appCenterService;
public ContactDetailViewModel(ApiService apiService, ContactDatabase contactDatabase, IMainThread mainThread, AppCenterService appCenterService) : base(appCenterService) { _apiService = apiService; _mainThread = mainThread; _contactDatabase = contactDatabase; SaveButtonTappedCommand = new AsyncCommand <bool>(ExecuteSaveButtonTappedCommand, _ => !IsSaving); }
protected override void OnAppearing() { base.OnAppearing(); AppCenterService.Track(AppCenterConstants.ContactDetailPageAppeared); }
public ContactDetailPage(bool isNewContact, IMainThread mainThread, ContactModel selectedContact, AppCenterService appCenterService, ContactDetailViewModel contactDetailViewModel) : base(contactDetailViewModel, appCenterService) { _mainThread = mainThread; _isNewContact = isNewContact; ViewModel.Contact = selectedContact; ViewModel.SaveContactCompleted += HandleSaveContactCompleted; ToolbarItems.Add(new ToolbarItem { Text = "Save", Priority = 0, AutomationId = AutomationIdConstants.SaveContactButton, CommandParameter = _isNewContact } .Bind(MenuItem.CommandProperty, nameof(ContactDetailViewModel.SaveButtonTappedCommand))); if (isNewContact) { ToolbarItems.Add(new ToolbarItem { Text = "Cancel", Priority = 1, AutomationId = AutomationIdConstants.CancelContactButton } .Invoke(toolBarItem => toolBarItem.Clicked += HandleCancelToolBarItemClicked)); } Title = PageTitleConstants.ContactDetailsPage; Padding = new Thickness(20, 0, 20, 0); Content = new StackLayout { Margin = new Thickness(0, 10, 0, 0), Children = { new ContactDetailLabel { Text = "First Name" }, new ContactDetailEntry { ReturnType = ReturnType.Next, AutomationId = AutomationIdConstants.FirstNameEntry } .Bind(Entry.TextProperty, nameof(ContactDetailViewModel.FirstNameText)), new ContactDetailLabel { Text = "Last Name" }, new ContactDetailEntry { ReturnType = ReturnType.Next, AutomationId = AutomationIdConstants.LastNameEntry } .Bind(Entry.TextProperty, nameof(ContactDetailViewModel.LastNameText)), new ContactDetailLabel { Text = "Phone Number" }, new ContactDetailEntry { AutomationId = AutomationIdConstants.PhoneNumberEntry } .Bind(Entry.TextProperty, nameof(ContactDetailViewModel.PhoneNumberText)), new ActivityIndicator() .Bind(IsVisibleProperty, nameof(ContactDetailViewModel.IsSaving)) .Bind(ActivityIndicator.IsRunningProperty, nameof(ContactDetailViewModel.IsSaving)) } }; }