diff --git a/lib/Data/data.dart b/lib/Data/data.dart index 3188be7..95c8dac 100644 --- a/lib/Data/data.dart +++ b/lib/Data/data.dart @@ -12,8 +12,8 @@ import 'package:lister/Data/constanst.dart'; class Data extends ChangeNotifier{ var allShows = [ - Show(malId: 20, title: "Naruto", epsCompleted: 190, epsTotal: 220, status: ShowStatus.completed, imageURL: "https://cdn.myanimelist.net/images/anime/13/17405l.jpg", airStatus: AirStatus.finished), - Show(malId: 50380, title: "Paripi Koumei", epsCompleted: 8, epsTotal: 12, status: ShowStatus.watching, imageURL: "https://cdn.myanimelist.net/images/anime/1970/122297l.jpg", airStatus: AirStatus.finished), + Show(malId: 20, title: "Naruto", epsCompleted: 190, epsTotal: 220, status: ShowStatus.completed, imageURL: "https://cdn.myanimelist.net/images/anime/13/17405l.jpg", airStatus: AirStatus.finished, gogoName: ''), + Show(malId: 50380, title: "Paripi Koumei", epsCompleted: 8, epsTotal: 12, status: ShowStatus.watching, imageURL: "https://cdn.myanimelist.net/images/anime/1970/122297l.jpg", airStatus: AirStatus.finished, gogoName: ''), // Show(malId: 44511, title: "Chainsaw Man", epsCompleted: 0, epsTotal: 24, status: ShowStatus.planned, imageURL: "https://cdn.myanimelist.net/images/anime/1806/126216l.jpg"), ]; @@ -59,41 +59,37 @@ class Data extends ChangeNotifier{ updatingStatus++; notifyListeners(); + if(show.gogoName == ""){ + print('${show.title} -- ${show.gogoName}'); + continue; + } + if(show.airStatus != AirStatus.finished ){ + print(show.gogoName); API.Response showstatus = await API.get( - Uri.parse(kMoreDetailsURL + show.malId.toString()) + Uri.parse("https://lister-api1.herokuapp.com/${show.gogoName}") ); print(show.malId); var jsonResponse = showstatus.body; - if(showstatus.statusCode == 200){ - var data = jsonDecode(jsonResponse); - print(data["data"]["airing"]); + var data = jsonDecode(jsonResponse); - if(data["data"]["status"] == "Finished Airing"){ + if(data['error'] != true){ + + if(data['status'] == 'Completed'){ show.airStatus = AirStatus.finished; if(show.epsCompleted == show.epsTotal){ show.status = ShowStatus.completed; } } else{ - API.Response detailsRes = await API.get( - Uri.parse(kAirDetailsBaseURL + show.gogoName) - ); - - jsonResponse = detailsRes.body; - - if(detailsRes.statusCode == 200){ - var data = jsonDecode(jsonResponse); - - show.epsTotal = int.parse(data['totalEpisodes']); - } + show.epsTotal = data['epstotal']; } - } + } } } @@ -240,13 +236,19 @@ class Data extends ChangeNotifier{ var data = jsonDecode(jsonResponse); show.gogoName = data[0]['animeId']; + saveAllShows(); + + print(data[0]['animeId']); } + print("added ${show.title} -- ${show.gogoName}"); + show.status = ShowStatus.planned; allShows.insert(0, show); distribute(); notifyListeners(); saveAllShows(); + updateAiringShows(); } } diff --git a/lib/Models/Show.dart b/lib/Models/Show.dart index 036f612..73be329 100644 --- a/lib/Models/Show.dart +++ b/lib/Models/Show.dart @@ -8,7 +8,7 @@ class Show{ ShowStatus status; String imageURL; AirStatus airStatus; - String gogoName = ""; + String gogoName; Show({ required this.malId, @@ -18,7 +18,7 @@ class Show{ required this.status, required this.imageURL, required this.airStatus, - gogoName = " ", + required this.gogoName, }); int getEpsCompleted(){ @@ -32,6 +32,9 @@ class Show{ } static fromMap(Map jsonData) { + + print("loading ${jsonData['title']} -- ${jsonData['gogoName']}"); + return Show( malId: jsonData['malId'], title: jsonData['title'], @@ -44,7 +47,9 @@ class Show{ ); } - static Map toMap(Show show) => { + static Map toMap(Show show) { + print("Storing ${show.title} -- ${show.gogoName}"); + return { 'malId': show.malId, 'title': show.title, 'epsCompleted': show.epsCompleted, @@ -54,4 +59,5 @@ class Show{ 'airStatus': show.airStatus.index, 'gogoName' : show.gogoName }; + } } \ No newline at end of file diff --git a/lib/Pages/AddPage.dart b/lib/Pages/AddPage.dart index 4a28632..a371fc3 100644 --- a/lib/Pages/AddPage.dart +++ b/lib/Pages/AddPage.dart @@ -110,7 +110,8 @@ class _PageState extends State { epsTotal: i['episodes'] ?? 0, status: ShowStatus.planned, imageURL: i['images']['jpg']['large_image_url'], - airStatus: thisAirStatus + airStatus: thisAirStatus, + gogoName: ' ' )); setState(() {}); } diff --git a/lib/Pages/All.dart b/lib/Pages/All.dart index b321b9c..140808e 100644 --- a/lib/Pages/All.dart +++ b/lib/Pages/All.dart @@ -52,8 +52,8 @@ class _AllState extends State { children: [ Row( mainAxisAlignment: MainAxisAlignment.center, - children: const [ - Text( + children: [ + const Text( "Updating Shows", style: TextStyle( color: Colors.white, @@ -61,8 +61,11 @@ class _AllState extends State { ), ), Padding( - padding: EdgeInsets.all(8.0), - child: SpinKitRing(color: Colors.redAccent, size: 40), + padding: const EdgeInsets.all(8.0), + child: AnimatedContainer( + duration: const Duration(milliseconds: 500), + child: const SpinKitRing(color: Colors.redAccent, size: 40) + ), ) ], ), diff --git a/lib/main.dart b/lib/main.dart index 917633e..16dd825 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -31,7 +31,7 @@ class MyApp extends StatelessWidget { ), ], child: MaterialApp( - title: 'Flutter Demo', + title: 'Lister', theme: ThemeData.dark(), home: const MyHomePage(title: 'Lister'), ),