public static async Task <bool> AddToFavoriteAsync(int id) { var matches = _coursesSource.Courses.Where(n => n.Id.Equals(id)); if (matches.Count() == 0) { return(false); } else { string JsonDataString = await Api.AddToFavoriteAsync(id); if (JsonDataString == null) { return(false); } else { var matchIndex = _coursesSource.Courses.IndexOf(matches.First()); _coursesSource.Courses[matchIndex].CourseSocial.FavoriteId = (int)JsonObject.Parse(JsonDataString).GetNamedNumber("id"); MainPageSource.AddToFavorite(MainPage.CoursesPivotItemName, MainPage.FavoriteCoursesPivotItemName, id); return(true); } } }
private void Awake() { GoBtn = GameObject.Find("Btn_Go").GetComponent <Button>(); musicBtn = GameObject.Find("Btn_mute").GetComponent <Button>(); CatAnimRoot = GameObject.Find("Background").GetComponent <RectTransform>(); mainPagesource = GameObject.Find("看這裡").GetComponent <MainPageSource>(); }
private async void RestaurantsLoaded(object sender, RoutedEventArgs e) { this.FavoriteRestaurantsProgressRing.IsActive = true; var Group = await MainPageSource.GetGroupAsync(MainPage.FavoriteRestaurantsPivotItemName); this.FavoriteRestaurantsProgressRing.IsActive = false; if (Group == null) { this.FavoriteRestaurantsErrorMessageTextBlock.Text = ResourceLoader.GetForCurrentView("Resources").GetString("ErrorMessage"); this.FavoriteRestaurantsErrorMessageTextBlock.Visibility = Visibility.Visible; await ShowErrorAsync(); } else { this.DefaultViewModel[MainPage.FavoriteRestaurantsPivotItemName] = Group; if (Group.NextPageUri == null) { this.FavoriteRestaurantsScroll.ViewChanged -= ScrollViewer_ViewChanged; } if (Group.Items.Count.Equals(0)) { this.FavoriteRestaurantsErrorMessageTextBlock.Text = ResourceLoader.GetForCurrentView("Resources").GetString("EmptyListErrorMessage"); this.FavoriteRestaurantsErrorMessageTextBlock.Visibility = Visibility.Visible; } } }
private async void CoursesLoaded(object sender, RoutedEventArgs e) { if (this.CoursesMessage.Visibility == Visibility.Visible) { this.CoursesMessage.Visibility = Visibility.Collapsed; } if (this.RefreshButton.Visibility == Visibility.Visible) { this.RefreshButton.Visibility = Visibility.Collapsed; } this.CoursesProgressRing.IsActive = true; this.CoursesToggle.IsEnabled = false; var ThirdGroup = await MainPageSource.GetGroupAsync(CoursesPivotItemName); this.CoursesProgressRing.IsActive = false; if (ThirdGroup == null) { this.CoursesMessage.Text = ResourceLoader.GetForCurrentView("Resources").GetString("ErrorMessage"); this.CoursesMessage.Visibility = Visibility.Visible; this.RefreshButton.Visibility = Visibility.Visible; this.CategoriesScroll.ViewChanged -= Scroll_ViewChanged; await ShowErrorAsync(); } else { if (ThirdGroup.Items.Count.Equals(0)) { this.CoursesMessage.Text = ResourceLoader.GetForCurrentView("Resources").GetString("EmptyListErrorMessage"); this.CoursesMessage.Visibility = Visibility.Visible; this.CoursesScroll.ViewChanged -= Scroll_ViewChanged; } else { this.DefaultViewModel[CoursesPivotItemName] = ThirdGroup; if (ThirdGroup.NextPageUri == null) { this.CoursesScroll.ViewChanged -= Scroll_ViewChanged; } else { this.CoursesScroll.ViewChanged += Scroll_ViewChanged; } } } this.CoursesToggle.IsEnabled = true; }
private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e) { // TODO: Создание соответствующей модели данных для области проблемы, чтобы заменить пример данных if (this.RestarauntsMessage.Visibility == Visibility.Visible) { this.RestarauntsMessage.Visibility = Visibility.Collapsed; } if (this.RefreshButton.Visibility == Visibility.Visible) { this.RefreshButton.Visibility = Visibility.Collapsed; } this.RestaurantsProgressRing.IsActive = true; this.MainPagePivot.IsEnabled = false; var FirstGroup = await MainPageSource.GetGroupAsync(RestaurantsPivotItemName); this.RestaurantsProgressRing.IsActive = false; this.MainPagePivot.IsEnabled = true; if (FirstGroup == null) { this.RestarauntsMessage.Text = ResourceLoader.GetForCurrentView("Resources").GetString("ErrorMessage"); this.RestarauntsMessage.Visibility = Visibility.Visible; this.RefreshButton.Visibility = Visibility.Visible; this.RestaurantsScroll.ViewChanged -= Scroll_ViewChanged; await ShowErrorAsync(); } else { if (FirstGroup.Items.Count.Equals(0)) { this.RestarauntsMessage.Text = ResourceLoader.GetForCurrentView("Resources").GetString("EmptyListErrorMessage"); this.RestarauntsMessage.Visibility = Visibility.Visible; this.RestaurantsScroll.ViewChanged -= Scroll_ViewChanged; } else { this.DefaultViewModel[RestaurantsPivotItemName] = FirstGroup; if (FirstGroup.NextPageUri == null) { this.RestaurantsScroll.ViewChanged -= Scroll_ViewChanged; } else { this.RestaurantsScroll.ViewChanged += Scroll_ViewChanged; } } } }
private async void PromotedRestaurantsLoaded(object sender, RoutedEventArgs e) { if (this.PromotedRestaurantsMessage.Visibility == Visibility.Visible) { this.PromotedRestaurantsMessage.Visibility = Visibility.Collapsed; } if (this.RefreshButton.Visibility == Visibility.Visible) { this.RefreshButton.Visibility = Visibility.Collapsed; } this.PromotedRestaurantsProgressRing.IsActive = true; var SecondGroup = await MainPageSource.GetGroupAsync(PromotedRestaurantsPivotItemName); this.PromotedRestaurantsProgressRing.IsActive = false; if (SecondGroup == null) { this.PromotedRestaurantsMessage.Text = ResourceLoader.GetForCurrentView("Resources").GetString("ErrorMessage"); this.PromotedRestaurantsMessage.Visibility = Visibility.Visible; this.RefreshButton.Visibility = Visibility.Visible; this.MainPageCommandBar.ClosedDisplayMode = AppBarClosedDisplayMode.Compact; this.PromotedRestaurantsScroll.ViewChanged -= Scroll_ViewChanged; await ShowErrorAsync(); } else { if (SecondGroup.Items.Count.Equals(0)) { this.PromotedRestaurantsMessage.Text = ResourceLoader.GetForCurrentView("Resources").GetString("EmptyListErrorMessage"); this.PromotedRestaurantsMessage.Visibility = Visibility.Visible; this.PromotedRestaurantsScroll.ViewChanged -= Scroll_ViewChanged; } else { this.DefaultViewModel[PromotedRestaurantsPivotItemName] = SecondGroup; if (SecondGroup.NextPageUri == null) { this.PromotedRestaurantsScroll.ViewChanged -= Scroll_ViewChanged; } else { this.PromotedRestaurantsScroll.ViewChanged += Scroll_ViewChanged; } } } }
public static async Task <bool> RemoveFromFavoriteAsync(int id) { var matches = _coursesSource.Courses.Where(n => n.Id.Equals(id)); if (matches.Count() == 0) { return(false); } else { var matchIndex = _coursesSource.Courses.IndexOf(matches.First()); var FavoriteId = _coursesSource.Courses[matchIndex].CourseSocial.FavoriteId; if (FavoriteId == -1) { return(false); } else { bool isSuccess = await Api.RemoveFromFavoriteAsync(FavoriteId); if (isSuccess) { _coursesSource.Courses[matchIndex].CourseSocial.FavoriteId = -1; MainPageSource.RemoveFromFavorite(MainPage.FavoriteCoursesPivotItemName, id); return(true); } else { return(false); } } } }
public static async Task <Category> GetCategoryAsync(string id) { if (id.Contains(':')) { var matches = _categoriesSource.Categories.Where(n => n.Id == id); if (matches.Count() == 0) { int RestaurantId = Convert.ToInt32(id.Split(':').First()); int CategoryId = Convert.ToInt32(id.Split(':').Last()); Uri RequestUri = null; if (RestaurantId == -1) { RequestUri = new Uri("https://www.foodlook.az/api/categories/" + CategoryId.ToString() + "/courses/"); } else { RequestUri = new Uri("https://www.foodlook.az/api/restaurants/" + RestaurantId.ToString() + "/categories/" + CategoryId.ToString() + "/"); } if (RequestUri == null) { return(null); } else { string JsonDataString = await Api.GetJsonDataAsync(RequestUri); if (JsonDataString == null) { return(null); } else { var CategoriesGroup = await MainPageSource.GetGroupAsync(MainPage.CategoriesPivotItemName); if (CategoriesGroup == null) { return(null); } else { var CategoryItem = CategoriesGroup.Items.Where(n => n.Id == CategoryId); if (CategoryItem.Count() == 0) { return(null); } else { JsonObject JsonData = JsonObject.Parse(JsonDataString); Uri NextPageUri = (JsonData.GetNamedValue("next").ValueType == JsonValueType.String) ? new Uri(JsonData.GetNamedString("next")) : null; Category NewCategory = new Category(id, CategoryItem.First().Label, NextPageUri); foreach (var item in JsonData.GetNamedArray("results").Select(n => n.GetObject())) { int Id = (int)item.GetNamedNumber("id"); string Label = item.GetNamedString("label"); string ImagePath = item.GetNamedString("image");; string Description = ResourceLoader.GetForCurrentView("Resources").GetString("Price") + " " + item.GetNamedNumber("price").ToString() + " AZN";; NewCategory.Items.Add(new Item(Id, Label, ImagePath, Description)); } _categoriesSource.Categories.Add(NewCategory); return(NewCategory); } } } } } else { return(matches.First()); } } else { return(null); } }
private async void RefreshButton_Click(object sender, RoutedEventArgs e) { this.RefreshButton.IsEnabled = false; string GroupName = RestaurantsPivotItemName; if (this.MainPagePivot.SelectedIndex.Equals(PromotedRestaurantsPivotItemIndex)) { GroupName = PromotedRestaurantsPivotItemName; } else if (this.MainPagePivot.SelectedIndex.Equals(CoursesPivotItemIndex)) { GroupName = CoursesPivotItemName; } else if (this.MainPagePivot.SelectedIndex.Equals(CategoriesPivotItemIndex)) { GroupName = CategoriesPivotItemName; } if (!this.DefaultViewModel.ContainsKey(GroupName)) { var statusBar = StatusBar.GetForCurrentView(); statusBar.ProgressIndicator.Text = ResourceLoader.GetForCurrentView("Resources").GetString("DownloadingMessage"); statusBar.ProgressIndicator.ProgressValue = null; await statusBar.ProgressIndicator.ShowAsync(); var Group = await MainPageSource.GetGroupAsync(GroupName); await statusBar.ProgressIndicator.HideAsync(); if (Group == null) { this.RefreshButton.IsEnabled = true; this.CoursesMessage.Visibility = Visibility.Visible; this.CoursesMessage.Text = ResourceLoader.GetForCurrentView("Resources").GetString("ErrorMessage"); this.RefreshButton.Visibility = Visibility.Visible; await ShowErrorAsync(); } else { this.RefreshButton.IsEnabled = true; this.RefreshButton.Visibility = Visibility.Collapsed; if (GroupName == RestaurantsPivotItemName) { this.RestarauntsMessage.Visibility = Visibility.Collapsed; } else if (GroupName == PromotedRestaurantsPivotItemName) { this.PromotedRestaurantsMessage.Visibility = Visibility.Collapsed; } else if (GroupName == CoursesPivotItemName) { this.CoursesMessage.Visibility = Visibility.Collapsed; } else if (GroupName == CategoriesPivotItemName) { this.CategoriesMessage.Visibility = Visibility.Collapsed; } this.DefaultViewModel[GroupName] = Group; } } }
private async void Scroll_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e) { if (!e.IsIntermediate) { var Sender = sender as ScrollViewer; if (Sender.ScrollableHeight - Sender.VerticalOffset == 0) { lock (IncrementalLoadingHelper) { if (isIncrementalLoadingStarted) { return; } else { isIncrementalLoadingStarted = true; } } var GroupName = Sender.Tag.ToString(); var ThisGroup = this.DefaultViewModel[GroupName] as Group; if (ThisGroup.NextPageUri != null) { var statusBar = StatusBar.GetForCurrentView(); statusBar.ProgressIndicator.Text = ResourceLoader.GetForCurrentView("Resources").GetString("DownloadingMessage"); statusBar.ProgressIndicator.ProgressValue = null; await statusBar.ProgressIndicator.ShowAsync(); bool isSuccessful = await MainPageSource.LoadMoreItemsAsync(GroupName); await statusBar.ProgressIndicator.HideAsync(); if (isSuccessful) { var Group = await MainPageSource.GetGroupAsync(GroupName); if (Group.NextPageUri == null) { if (GroupName == RestaurantsPivotItemName) { this.RestaurantsScroll.ViewChanged -= Scroll_ViewChanged; } else if (GroupName == PromotedRestaurantsPivotItemName) { this.PromotedRestaurantsScroll.ViewChanged -= Scroll_ViewChanged; } else if (GroupName == CoursesPivotItemName || GroupName == VegetariaCoursesPivotItemName) { this.CoursesScroll.ViewChanged -= Scroll_ViewChanged; } else if (GroupName == CategoriesPivotItemName) { this.CategoriesScroll.ViewChanged -= Scroll_ViewChanged; } } } else { await ShowErrorAsync(); } } else { if (GroupName == RestaurantsPivotItemName) { this.RestaurantsScroll.ViewChanged -= Scroll_ViewChanged; } else if (GroupName == PromotedRestaurantsPivotItemName) { this.PromotedRestaurantsScroll.ViewChanged -= Scroll_ViewChanged; } else if (GroupName == CoursesPivotItemName || GroupName == VegetariaCoursesPivotItemName) { this.CoursesScroll.ViewChanged -= Scroll_ViewChanged; } else if (GroupName == CategoriesPivotItemName) { this.CategoriesScroll.ViewChanged -= Scroll_ViewChanged; } } lock (IncrementalLoadingHelper) { isIncrementalLoadingStarted = false; } } } }
private async void CoursesToggle_Click(object sender, RoutedEventArgs e) { var statusBar = StatusBar.GetForCurrentView(); statusBar.ProgressIndicator.Text = ResourceLoader.GetForCurrentView("Resources").GetString("DownloadingMessage"); statusBar.ProgressIndicator.ProgressValue = null; await statusBar.ProgressIndicator.ShowAsync(); this.CoursesToggle.IsEnabled = false; var Label = (sender as AppBarButton).Label.ToString(); if (Label == ResourceLoader.GetForCurrentView("Resources").GetString("CoursesToggleOne")) { var FourthGroup = await MainPageSource.GetGroupAsync(VegetariaCoursesPivotItemName); if (FourthGroup == null) { await ShowErrorAsync(); } else { this.DefaultViewModel[CoursesPivotItemName] = FourthGroup; if (FourthGroup.NextPageUri == null) { this.CoursesScroll.ViewChanged -= Scroll_ViewChanged; } else { this.CoursesScroll.ViewChanged += Scroll_ViewChanged; } if (this.CoursesMessage.Visibility == Visibility.Visible) { this.CoursesMessage.Visibility = Visibility.Collapsed; this.RefreshButton.Visibility = Visibility.Collapsed; } this.CoursesToggle.Label = ResourceLoader.GetForCurrentView("Resources").GetString("CoursesToggleTwo"); } } else if (Label == ResourceLoader.GetForCurrentView("Resources").GetString("CoursesToggleTwo")) { var ThirdGroup = await MainPageSource.GetGroupAsync(CoursesPivotItemName); if (ThirdGroup == null) { await ShowErrorAsync(); } else { this.DefaultViewModel[CoursesPivotItemName] = ThirdGroup; if (ThirdGroup.NextPageUri == null) { this.CoursesScroll.ViewChanged -= Scroll_ViewChanged; } else { this.CoursesScroll.ViewChanged += Scroll_ViewChanged; } if (this.CoursesMessage.Visibility == Visibility.Visible) { this.CoursesMessage.Visibility = Visibility.Collapsed; this.RefreshButton.Visibility = Visibility.Collapsed; } this.CoursesToggle.Label = ResourceLoader.GetForCurrentView("Resources").GetString("CoursesToggleOne"); } } await statusBar.ProgressIndicator.HideAsync(); this.CoursesToggle.IsEnabled = true; }