/// <summary> /// Searches the server for featured quizzes and sets the chunk equal to the servers response /// </summary> private async Task Search() { List <QuizInfo> chunk = new List <QuizInfo>(); chunk = SearchUtils.GetQuizzesByAuthorChunked("BizQuiz", this.currentChunk); if (chunk.Count < 20) { this.quizzesRemaining = false; } await Task.Run(() => this.AddQuizzes(chunk)); }
/// <summary> /// Sets up the network quizzes owned by this user as cards /// </summary> private void SetupNetworkQuizzes(string category) { List <QuizInfo> chunk = SearchUtils.GetQuizzesByAuthorChunked(CredentialManager.Username, this.currentChunk); if (chunk.Count == 0) { return; } this.AddQuizzes( chunk.Where(quizInfo => (quizInfo.Category == category) || (category == "All")).ToList(), true); }
/// <summary> /// Refreshes the page's quiz content /// </summary> private async Task RefreshAsync() { this.LabelNoQuiz.IsVisible = false; this.SearchedStack.Children.Clear(); this.quizzesFeatured.Clear(); try { if (CredentialManager.IsLoggedIn) { this.PickerCategory.IsVisible = true; this.ToolbarItemSearchButton.IsEnabled = true; Device.BeginInvokeOnMainThread(() => { this.SearchedStack.Children.Clear(); this.ActivityIndicator.IsVisible = true; this.ActivityIndicator.IsRunning = true; }); await Task.Run(() => this.AddQuizzes(SearchUtils.GetQuizzesByAuthorChunked("BizQuiz", 1))); Device.BeginInvokeOnMainThread(() => { this.ActivityIndicator.IsVisible = false; this.ActivityIndicator.IsRunning = false; }); } else { this.PickerCategory.IsVisible = false; this.ToolbarItemSearchButton.IsEnabled = false; this.SearchedStack.Children.Clear(); this.SearchedStack.Children.Add( new Frame() { CornerRadius = 10, HorizontalOptions = LayoutOptions.CenterAndExpand, Content = new Label { Text = "Create an account to create, search for, and use quizzes " + "created by the BizQuiz community!", HorizontalTextAlignment = TextAlignment.Center, FontSize = 38 } }); } } catch (Exception ex) { BugReportHandler.SaveReport(ex); await this.DisplayAlert("Error", "Couldn't get quizzes", "Ok"); } }
/// <summary> /// Conducts a search of the online database /// </summary> /// <returns></returns> private async Task SearchAsync() { try { this.isLoading = true; Device.BeginInvokeOnMainThread(() => { this.SearchedStack.Children.Clear(); this.ActivityIndicator.IsRunning = true; }); List <QuizInfo> chunk = new List <QuizInfo>(); if (this.searchType == SearchType.Title) { chunk = SearchUtils.GetQuizzesByQuizNameChunked(this.SearchBar.Text, this.currentChunk); } else { chunk = SearchUtils.GetQuizzesByAuthorChunked(this.SearchBar.Text, this.currentChunk); } if (chunk.Count < 20) { await Task.Run(() => this.AddQuizzes(chunk)); } Device.BeginInvokeOnMainThread(() => { if (this.SearchedStack.Children.Count() == 0) { this.LableNone.IsVisible = true; } else { this.LableNone.IsVisible = false; } this.ActivityIndicator.IsRunning = false; }); this.isLoading = false; } catch (Exception ex) { BugReportHandler.SaveReport(ex); await this.DisplayAlert("Search Failed", "Try again later", "Ok"); } }