public static bool Delete(Course course) { var tile = GetActiveTile(course); if (tile == null) { return false; } tile.Delete(); return true; }
public static void Update(string courseId, int newsCount) { Course course = new Course(); course.Id = courseId; // TODO: Add additional information to this call to populate more interesting data var data = CreateTileData(course, newsCount); var tile = GetActiveTile(course); if (tile != null) { tile.Update(data); } }
// Make this a single function to avoid multiple tiles of the same course public static void CreateOrUpdate(Course course) { // TODO: Add additional information to this call to populate more interesting data var data = CreateTileData(course, 0); var tile = GetActiveTile(course); if (tile != null) { tile.Update(data); } else { ShellTile.Create(GetCourseUri(course), data, false); } }
public void ShowCourse(Course course) { _frame.Navigate(PhoneNavigationController.MakeCoursePageUri(course)); }
public static Uri MakeCoursePageUri(Course course) { return NoppaUtility.MakeUri("/CoursePage.xaml", "id", course.Id); }
private static ShellTileData CreateTileData(Course course, int newsCount) { // TODO: Get more content as parameters in this function, // in particular, don't call any async methods in here // because that information should already be available to // the caller. If it's not, when the new information is // available, it can check whether the tile is active and // update it then. return new IconicTileData() { Title = course.Id, Count = newsCount }; }
public static bool Exists(Course course) { return course != null && GetActiveTile(course) != null; }
private static Uri GetCourseUri(Course course) { return NoppaUtility.MakeUri("/CoursePage.xaml", "id", course.Id); }
private static ShellTile GetActiveTile(Course course) { var uri = GetCourseUri(course); var tiles = ShellTile.ActiveTiles; foreach (var tile in tiles) { if (tile.NavigationUri.Equals(uri)) { return tile; } } return null; }
public async Task LoadContentAsync(INavigationController navigationController) { if (IsLoading) { return; } IsLoading = true; _course = await NoppaAPI.GetCourse(Code); _toggleSecondaryTileCommand.NotifyCanExecuteChanged(); UpdateToggleCommandText(); List<CourseContentViewModel> viewmodels = new List<CourseContentViewModel>() { new LecturesViewModel(), new ExercisesViewModel(), new ResultsViewModel(), new AssignmentsViewModel(), new EventsViewModel(navigationController) }; List<Task<CourseContentViewModel>> tasks = new List<Task<CourseContentViewModel>>(); await Task.WhenAll( /* Load Overview (already in the contents) */ OverviewModel.LoadDataAsync(Code), /* Load News (already in the contents) */ NewsModel.LoadDataAsync(Code) ); foreach (var vm in viewmodels) tasks.Add(vm.LoadDataAsync(Code)); /* Add items in the order they are finished. */ while (tasks.Count > 0) { var task = await Task.WhenAny(tasks); tasks.Remove(task); var content = await task; if (!content.IsEmpty) { int index = _contents.Count; // Find the correct position for (int i = 0; i < _contents.Count; i++) { if (_contents[i].Index > content.Index) { index = i; break; } } _contents.Insert(index, content); NotifyPropertyChanged("Contents"); } } if (OverviewModel.OodiUrl != null) { OodiPageUri = new Uri(OverviewModel.OodiUrl); } IsLoading = false; }