Skip to content

Commit

Permalink
Integrated with lister API + minor bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vinayak5002 committed Oct 3, 2022
1 parent 3b27b2f commit ba632b7
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 28 deletions.
40 changes: 21 additions & 19 deletions lib/Data/data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
];

Expand Down Expand Up @@ -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'];
}
}

}
}
}

Expand Down Expand Up @@ -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();
}
}

Expand Down
12 changes: 9 additions & 3 deletions lib/Models/Show.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Show{
ShowStatus status;
String imageURL;
AirStatus airStatus;
String gogoName = "";
String gogoName;

Show({
required this.malId,
Expand All @@ -18,7 +18,7 @@ class Show{
required this.status,
required this.imageURL,
required this.airStatus,
gogoName = " ",
required this.gogoName,
});

int getEpsCompleted(){
Expand All @@ -32,6 +32,9 @@ class Show{
}

static fromMap(Map<String, dynamic> jsonData) {

print("loading ${jsonData['title']} -- ${jsonData['gogoName']}");

return Show(
malId: jsonData['malId'],
title: jsonData['title'],
Expand All @@ -44,7 +47,9 @@ class Show{
);
}

static Map<String, dynamic> toMap(Show show) => {
static Map<String, dynamic> toMap(Show show) {
print("Storing ${show.title} -- ${show.gogoName}");
return {
'malId': show.malId,
'title': show.title,
'epsCompleted': show.epsCompleted,
Expand All @@ -54,4 +59,5 @@ class Show{
'airStatus': show.airStatus.index,
'gogoName' : show.gogoName
};
}
}
3 changes: 2 additions & 1 deletion lib/Pages/AddPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ class _PageState extends State<Page> {
epsTotal: i['episodes'] ?? 0,
status: ShowStatus.planned,
imageURL: i['images']['jpg']['large_image_url'],
airStatus: thisAirStatus
airStatus: thisAirStatus,
gogoName: ' '
));
setState(() {});
}
Expand Down
11 changes: 7 additions & 4 deletions lib/Pages/All.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,20 @@ class _AllState extends State<All> {
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
Text(
children: [
const Text(
"Updating Shows",
style: TextStyle(
color: Colors.white,
fontSize: 18,
),
),
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)
),
)
],
),
Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class MyApp extends StatelessWidget {
),
],
child: MaterialApp(
title: 'Flutter Demo',
title: 'Lister',
theme: ThemeData.dark(),
home: const MyHomePage(title: 'Lister'),
),
Expand Down

0 comments on commit ba632b7

Please sign in to comment.