/// <summary> /// Used for the Home Page, Gets All Manga Titles. /// </summary> /// <returns>List of minimally filled Manga Objects (Id, Title, ImageString, Hits, LastDate)</returns> public static async Task GetIndividualMangaTitlesAsync(Func <Manga.Manga, bool> callback) { //List<Manga.Manga> mangas = new List<Manga.Manga>(); Uri uri = new Uri(MANGA_URL + "list/0/"); HttpClient client = new HttpClient(); dynamic json = null; try { string jsonString = await client.GetStringAsync(uri); json = JsonConvert.DeserializeObject(jsonString); } catch (Exception e) { Debug.WriteLine(e.TargetSite); Debug.WriteLine(e.StackTrace); } if (json != null) { for (int i = 0; i < json.manga.Count; i++) { try { Manga.Manga manga = new Manga.Manga { Id = json.manga[i].i, Title = json.manga[i].t, ImageString = json.manga[i].im, Hits = json.manga[i].h, Categories = new List <string>() }; manga.SetStatus((int)json.manga[i].s); if (manga.ImageString != null) { //Debug.WriteLine("valid image [ " + manga.ImageString + " ]"); //manga.Image = new BitmapImage(new Uri(IMAGE_URL + manga.ImageString)); manga.ImageString = IMAGE_URL + manga.ImageString; } else { manga.ImageString = IMAGE_URL; //manga.Image = new BitmapImage(); } if (json.manga[i].ld != null) { manga.LastDate = (long)json.manga[i].ld; } for (int k = 0; k < json.manga[i].c.Count; k++) { string category = json.manga[i].c[k]; //Debug.WriteLine("category [ " + category + " ]"); manga.Categories.Add(category); } //mangas.Add(manga); if (!callback.Invoke(manga)) { break; } } catch (Exception e) { Debug.WriteLine(e.TargetSite); Debug.WriteLine(e.StackTrace); } } } Debug.WriteLine("Done Getting Manga 1"); //callback.Invoke(mangas); }
public static async Task GetManga(string id, Func <Manga.Manga, bool> callback) { Manga.Manga manga = null; Uri uri = new Uri(MANGA_URL + "manga/" + id); HttpClient client = new HttpClient(); dynamic json = null; try { string jsonString = await client.GetStringAsync(uri); json = JsonConvert.DeserializeObject(jsonString); } catch (Exception e) { Debug.WriteLine(e.TargetSite); Debug.WriteLine(e.StackTrace); } if (json != null) { try { manga = new Manga.Manga { Id = id, Title = json.title, ImageString = json.image, Description = json.description, Artist = json.artist, Author = json.author, Chapters = new List <Manga.Chapter>(), Categories = new List <string>() }; manga.SetStatus((int)json.status); if (json.last_chapter_date != null) { manga.LastDate = (long)json.last_chapter_date; } if (manga.ImageString != null) { //Debug.WriteLine("valid image [ " + manga.ImageString + " ]"); //manga.Image = new BitmapImage(new Uri(IMAGE_URL + manga.ImageString)); manga.ImageString = IMAGE_URL + manga.ImageString; } else { manga.ImageString = IMAGE_URL; //manga.Image = new BitmapImage(); } for (int k = 0; k < json.categories.Count; k++) { string category = (string)json.categories[k]; //Debug.WriteLine("category [ " + category + " ]"); manga.Categories.Add(category); } for (int i = 0; i < json.chapters.Count; i++) { Manga.Chapter chapter = new Manga.Chapter { Id = json.chapters[i][3], Title = json.chapters[i][2], Number = (double)json.chapters[i][0] }; if (json.chapters[i][1] != null) { chapter.Date = json.chapters[i][1]; } manga.Chapters.Add(chapter); } } catch (Exception e) { Debug.WriteLine(e.TargetSite); Debug.WriteLine(e.StackTrace); } } callback.Invoke(manga); }