public TodoListViewModel() { // HACK: don't need these any more, I packaged a pre-populated SQLite database file // App.Database.SaveItem (new TodoItem{ Name = "Buy apples", Notes = "Macintosh" }); // App.Database.SaveItem (new TodoItem{ Name = "Buy pears", Notes = "" }); // App.Database.SaveItem (new TodoItem{ Name = "Buy milk", Notes = "Soy" }); // App.Database.SaveItem (new TodoItem{ Name = "Buy bananas", Notes = "" }); // App.Database.SaveItem (new TodoItem{ Name = "Buy kiwi", Notes = "" }); // App.Database.SaveItem (new TodoItem{ Name = "Buy oranges", Notes = "" }); var all = App.Database.GetItems().ToList(); foreach (var t in all) { contents.Add(new TodoItemCellViewModel(t)); } MessagingCenter.Subscribe <TodoItemViewModel, TodoItem> (this, "TodoSaved", (sender, model) => { App.Database.SaveItem(model); Reload(); }); MessagingCenter.Subscribe <TodoItemViewModel, TodoItem> (this, "TodoDeleted", (sender, model) => { App.Database.DeleteItem(model.ID); Reload(); }); MessagingCenter.Subscribe <TodoItemViewModel, TodoItem> (this, "TodoSpeak", (sender, model) => { Xamarin.Forms.DependencyService.Get <ITextToSpeech>().Speak(model.Name + " " + model.Notes); }); MessagingCenter.Subscribe <TodoListPage, TodoItem> (this, "TodoAdd", (sender, viewModel) => { var todo = new TodoItem(); var todovm = new TodoItemViewModel(todo); Navigation.Push(ViewFactory.CreatePage(todovm)); }); MessagingCenter.Subscribe <TodoListPage> (this, "TodoListSpeak", (sender) => { var todos = App.Database.GetItemsNotDone(); var tospeak = ""; foreach (var t in todos) { tospeak += t.Name + " "; } if (tospeak == "") { tospeak = "there are no tasks to do"; } Xamarin.Forms.DependencyService.Get <ITextToSpeech>().Speak(tospeak); //App.Speech.Speak(tospeak); }); }
public static Page GetMainPage () { RegisterTypes (); var mainNav = new NavigationPage (ViewFactory.CreatePage<TodoListViewModel> ()); MessagingCenter.Subscribe<TodoListViewModel, TodoItem> (mainNav, "TodoItemSelected", (sender, viewModel) => { var todovm = new TodoItemViewModel (viewModel); mainNav.Navigation.PushAsync (ViewFactory.CreatePage (todovm)); }); return mainNav; }
public static Page GetMainPage() { RegisterTypes(); var mainNav = new NavigationPage(ViewFactory.CreatePage <TodoListViewModel> ()); MessagingCenter.Subscribe <TodoListViewModel, TodoItem> (mainNav, "TodoItemSelected", (sender, viewModel) => { var todovm = new TodoItemViewModel(viewModel); mainNav.Navigation.PushAsync(ViewFactory.CreatePage(todovm)); }); return(mainNav); }
public TodoListViewModel () { // HACK: don't need these any more, I packaged a pre-populated SQLite database file // App.Database.SaveItem (new TodoItem{ Name = "Buy apples", Notes = "Macintosh" }); // App.Database.SaveItem (new TodoItem{ Name = "Buy pears", Notes = "" }); // App.Database.SaveItem (new TodoItem{ Name = "Buy milk", Notes = "Soy" }); // App.Database.SaveItem (new TodoItem{ Name = "Buy bananas", Notes = "" }); // App.Database.SaveItem (new TodoItem{ Name = "Buy kiwi", Notes = "" }); // App.Database.SaveItem (new TodoItem{ Name = "Buy oranges", Notes = "" }); var all = App.Database.GetItems ().ToList(); foreach (var t in all) { contents.Add (new TodoItemCellViewModel (t)); } MessagingCenter.Subscribe<TodoItemViewModel, TodoItem> (this, "TodoSaved", (sender, model) => { App.Database.SaveItem(model); Reload(); }); MessagingCenter.Subscribe<TodoItemViewModel, TodoItem> (this, "TodoDeleted", (sender, model) => { App.Database.DeleteItem(model.ID); Reload(); }); MessagingCenter.Subscribe<TodoItemViewModel, TodoItem> (this, "TodoSpeak", (sender, model) => { Xamarin.Forms.DependencyService.Get<ITextToSpeech>().Speak(model.Name + " " + model.Notes); }); MessagingCenter.Subscribe<TodoListPage, TodoItem> (this, "TodoAdd", (sender, viewModel) => { var todo = new TodoItem(); var todovm = new TodoItemViewModel(todo); Navigation.Push (ViewFactory.CreatePage (todovm)); }); MessagingCenter.Subscribe<TodoListPage> (this, "TodoListSpeak", (sender) => { var todos = App.Database.GetItemsNotDone(); var tospeak = ""; foreach (var t in todos) tospeak += t.Name + " "; if (tospeak == "") tospeak = "there are no tasks to do"; Xamarin.Forms.DependencyService.Get<ITextToSpeech>().Speak(tospeak); //App.Speech.Speak(tospeak); }); }