//Call API Repository to get all books or the next page private async Task GetBooks(string keyword, int currentPage) { if (string.IsNullOrEmpty(keyword)) { CustomActionSheets actionSheet = null; var btcolor = (Color)App.Current.Resources[ColorKeys.Primary]; actionSheet = new CustomActionSheets(Labels.Labels.NotValidWord, new System.Tuple <Command, string, Color, Color, Color>[] { new System.Tuple <Command, string, Color, Color, Color>(new Command(async() => { await actionSheet.PopPopupAsync(); }), Labels.Labels.OK, btcolor, Color.White, btcolor) }); await actionSheet.DisplayActionSheet(); return; } IsBusy = true; var books = await new ApiRepository().GetBooksByKeyword(keyword, currentPage); if (currentPage == 0) { _keywordBackup = keyword; page = 0; Books.Clear(); } if (!books.Success || books.Items == null) { CustomActionSheets actionSheet = null; var btcolor = (Color)App.Current.Resources[ColorKeys.Primary]; actionSheet = new CustomActionSheets(Labels.Labels.NoMoreResults, new System.Tuple <Command, string, Color, Color, Color>[] { new System.Tuple <Command, string, Color, Color, Color>(new Command(async() => { await actionSheet.PopPopupAsync(); }), Labels.Labels.OK, btcolor, Color.White, btcolor) }); await actionSheet.DisplayActionSheet(); IsBusy = false; return; } books.Items.ToList().ForEach(b => { if (string.IsNullOrWhiteSpace(b.VolumeInfo.ImageLinks?.SmallThumbnail) || string.IsNullOrWhiteSpace(b.VolumeInfo.ImageLinks?.Thumbnail)) { b.VolumeInfo.ImageLinks = new Models.Common.ImageLinks() { Thumbnail = (string)App.Current.Resources[IconKeys.Book], SmallThumbnail = (string)App.Current.Resources[IconKeys.Book] }; } Books.Add(b); }); IsBusy = false; page++; }
public async Task OnOpenLink() { string link = Book.VolumeInfo.PreviewLink; var btcolor = (Color)App.Current.Resources[ColorKeys.Primary]; if (string.IsNullOrEmpty(link)) { CustomActionSheets invalidActionSheet = null; invalidActionSheet = new CustomActionSheets(Labels.Labels.LinkNotAvailable, new System.Tuple <Command, string, Color, Color, Color>[] { new System.Tuple <Command, string, Color, Color, Color>(new Command(async() => { await invalidActionSheet.PopPopupAsync(); }), Labels.Labels.OK, btcolor, Color.White, btcolor) }); await invalidActionSheet.DisplayActionSheet(); return; } CustomActionSheets actionSheet = null; actionSheet = new CustomActionSheets(Labels.Labels.HowOpen, new System.Tuple <Command, string, Color, Color, Color>[] { new System.Tuple <Command, string, Color, Color, Color>(new Command(async() => { await Launcher.OpenAsync(new System.Uri(link)); await actionSheet.PopPopupAsync(); }), Labels.Labels.PhoneBrowser, btcolor, Color.White, btcolor), new System.Tuple <Command, string, Color, Color, Color>(new Command(async() => { var webPage = new WebPageView(link); await Navigation.PushAsync(webPage); await actionSheet.PopAllPopupAsync(); }), Labels.Labels.App, btcolor, Color.White, btcolor) }); await actionSheet.DisplayActionSheet(); return; }