Skip to content

Commit

Permalink
get season complete and fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
javoeria committed Sep 4, 2022
1 parent 5307837 commit d272f1e
Show file tree
Hide file tree
Showing 25 changed files with 364 additions and 275 deletions.
3 changes: 3 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ linter:
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
depend_on_referenced_packages: false
library_private_types_in_public_api: false
prefer_const_constructors: false
use_build_context_synchronously: false
use_key_in_widget_constructors: false

# Additional information about this file can be found at
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.4.32'
ext.kotlin_version = '1.6.10'
repositories {
google()
jcenter()
Expand Down
42 changes: 0 additions & 42 deletions lib/jikan_v4.dart

This file was deleted.

22 changes: 15 additions & 7 deletions lib/oauth.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import 'dart:convert';
import 'dart:math';

import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/foundation.dart' show kReleaseMode;
import 'package:flutter/services.dart' show PlatformException;
import 'package:flutter_web_auth/flutter_web_auth.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:http/http.dart' as http;
import 'package:flutter_web_auth/flutter_web_auth.dart';
import 'package:myanimelist/constants.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:slack_notifier/slack_notifier.dart';

const clientId = '030823330de353c3bb50727a8c2f864f';
Expand All @@ -24,7 +24,7 @@ class MalClient {
try {
final uri = await FlutterWebAuth.authenticate(url: loginUrl, callbackUrlScheme: 'javoeria.animedb');
final queryParams = Uri.parse(uri).queryParameters;
print(queryParams);
// print(queryParams);
if (queryParams['code'] == null) return null;

Fluttertoast.showToast(msg: 'Login Successful');
Expand All @@ -48,7 +48,15 @@ class MalClient {
const url = '$apiBaseUrl/anime/suggestions?limit=20';
final response = await http.get(Uri.parse(url), headers: {'Authorization': 'Bearer $accessToken'});
final suggestionsJson = jsonDecode(response.body);
return suggestionsJson['data'];
return suggestionsJson['data'] ?? [];
}

Future<List<dynamic>> getSeason(int year, String season) async {
final url =
'$apiBaseUrl/anime/season/$year/$season?fields=media_type,num_episodes,status,start_season,start_date,mean,num_list_users,synopsis,studios,genres&limit=500&sort=anime_num_list_users';
final response = await http.get(Uri.parse(url), headers: {'X-MAL-CLIENT-ID': clientId});
final seasonJson = jsonDecode(response.body);
return seasonJson['data'] ?? [];
}

Future<List<dynamic>> getRelated(int id, {bool anime = true}) async {
Expand All @@ -65,7 +73,7 @@ class MalClient {
if (sort != null) url += '&sort=$sort';
final response = await http.get(Uri.parse(url), headers: {'X-MAL-CLIENT-ID': clientId});
final listJson = jsonDecode(response.body);
return listJson['data'];
return listJson['data'] ?? [];
}

Future<Map<String, dynamic>?> getStatus(int id, {bool anime = true}) async {
Expand Down
6 changes: 3 additions & 3 deletions lib/screens/feed_screen.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:url_launcher/url_launcher.dart';
import 'package:url_launcher/url_launcher_string.dart';
import 'package:xml/xml.dart';

class FeedScreen extends StatelessWidget {
Expand Down Expand Up @@ -78,8 +78,8 @@ class FeedScreen extends StatelessWidget {
),
onTap: () async {
String url = article.getElement('link')!.text.trim();
if (await canLaunch(url)) {
await launch(url);
if (await canLaunchUrlString(url)) {
await launchUrlString(url);
} else {
throw 'Could not launch $url';
}
Expand Down
7 changes: 4 additions & 3 deletions lib/screens/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ class HomeScreen extends StatelessWidget {
profile == null
? ListTile(
title: Text('Login'),
leading: Icon(FontAwesomeIcons.signInAlt, color: Theme.of(context).unselectedWidgetColor),
leading:
Icon(FontAwesomeIcons.rightToBracket, color: Theme.of(context).unselectedWidgetColor),
onTap: () async {
FirebaseAnalytics.instance.logLogin();
String? username = await MalClient().login();
Expand All @@ -89,7 +90,7 @@ class HomeScreen extends StatelessWidget {
)
: ExpansionTile(
title: Text('User'),
leading: Icon(FontAwesomeIcons.userAlt),
leading: Icon(FontAwesomeIcons.userLarge),
children: <Widget>[
ListTile(
title: Text('Profile'),
Expand Down Expand Up @@ -457,7 +458,7 @@ class HomeScreen extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
IconButton(
icon: Icon(FontAwesomeIcons.cog, color: Theme.of(context).unselectedWidgetColor),
icon: Icon(FontAwesomeIcons.gear, color: Theme.of(context).unselectedWidgetColor),
tooltip: 'Settings',
onPressed: () async {
FirebaseAnalytics.instance.logEvent(name: 'settings');
Expand Down
12 changes: 11 additions & 1 deletion lib/screens/later_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class LaterScreen extends StatelessWidget {
actions: <Widget>[CustomMenu()],
),
body: FutureBuilder(
future: Jikan().getSeasonUpcoming(),
future: getSeasonComplete(),
builder: (context, AsyncSnapshot<BuiltList<Anime>> snapshot) {
if (snapshot.connectionState != ConnectionState.done) {
return Center(child: CircularProgressIndicator());
Expand Down Expand Up @@ -54,4 +54,14 @@ class LaterScreen extends StatelessWidget {
),
);
}

Future<BuiltList<Anime>> getSeasonComplete() async {
BuiltList<Anime> response = BuiltList();
int page = 0;
while (page < 4 && response.length == page * 25) {
response += await Jikan().getSeasonUpcoming(page: page + 1);
page += 1;
}
return response;
}
}
4 changes: 2 additions & 2 deletions lib/screens/recommendation_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class RecommendationScreen extends StatelessWidget {
SizedBox(height: 8.0),
Text(item.content),
SizedBox(height: 8.0),
Text((anime ? 'Anime' : 'Manga') +
' rec by ${item.user.username} - ${f.format(DateTime.parse(item.date))}'),
Text(
'${anime ? 'Anime' : 'Manga'} rec by ${item.user.username} - ${f.format(DateTime.parse(item.date))}'),
],
),
);
Expand Down
50 changes: 49 additions & 1 deletion lib/screens/seasonal_anime_screen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import 'package:intl/intl.dart' show DateFormat;
import 'package:jikan_api/jikan_api.dart';
import 'package:myanimelist/oauth.dart';
import 'package:myanimelist/widgets/season/custom_menu.dart';
import 'package:myanimelist/widgets/season/season_list.dart';

Expand Down Expand Up @@ -45,7 +47,7 @@ class SeasonalAnimeScreen extends StatelessWidget {
actions: <Widget>[CustomMenu()],
),
body: FutureBuilder(
future: Jikan().getSeason(year: year, season: seasonClass(type)),
future: getSeasonComplete(),
builder: (context, AsyncSnapshot<BuiltList<Anime>> snapshot) {
if (snapshot.connectionState != ConnectionState.done) {
return Center(child: CircularProgressIndicator());
Expand All @@ -71,4 +73,50 @@ class SeasonalAnimeScreen extends StatelessWidget {
),
);
}

Future<BuiltList<Anime>> getSeasonComplete() async {
final DateFormat f = DateFormat('MMM d, yyyy');
List<dynamic> response = await MalClient().getSeason(year, type.toLowerCase());
List<Anime> season = response.map((item) {
String type = ['tv', 'ova', 'ona'].contains(item['node']['media_type'])
? item['node']['media_type'].toUpperCase()
: item['node']['media_type'][0].toUpperCase() + item['node']['media_type'].substring(1);
if (item['node']['start_date'].toString().split('-').length == 2) item['node']['start_date'] += '-01';
Map<String, dynamic> jsonMap = {
'mal_id': item['node']['id'],
'url': 'https://myanimelist.net/anime/${item['node']['id']}',
'images': {
'jpg': {'large_image_url': item['node']['main_picture']['large'] ?? item['node']['main_picture']['medium']}
},
'trailer': {},
'title': item['node']['title'],
'type': type,
'episodes': item['node']['num_episodes'] == 0 ? null : item['node']['num_episodes'],
'airing': item['node']['status'] == 'currently_airing',
'aired': {'string': f.format(DateTime.parse(item['node']['start_date']))},
'score': item['node']['mean'],
'members': item['node']['num_list_users'],
'synopsis': item['node']['synopsis'] == '' ? null : item['node']['synopsis'],
'season': item['node']['start_season']['season'],
'year': item['node']['start_season']['year'],
'broadcast': {},
'studios': (item['node']['studios'] ?? []).map((i) => {
'mal_id': i['id'],
'type': 'anime',
'name': i['name'],
'url': 'https://myanimelist.net/anime/producer/${i['id']}'
}),
'genres': (item['node']['genres'] ?? []).map((i) => {
'mal_id': i['id'],
'type': 'anime',
'name': i['name'],
'url': 'https://myanimelist.net/anime/genre/${i['id']}'
}),
};
jsonMap['demographics'] = jsonMap['genres'];
return Anime.fromJson(jsonMap);
}).toList();

return BuiltList(season.where((a) => a.year == year && a.season == type.toLowerCase()));
}
}
6 changes: 3 additions & 3 deletions lib/screens/user_profile_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,16 @@ class _UserProfileScreenState extends State<UserProfileScreen> {
: Align(
alignment: Alignment.centerRight,
child: Container(
width: 200.0,
height: 200.0,
color: Colors.grey,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.camera_alt, size: 48.0, color: Colors.grey[700]),
Text('No Picture', style: TextStyle(color: Colors.grey[700])),
],
),
width: 200.0,
height: 200.0,
color: Colors.grey,
),
),
),
Expand Down
6 changes: 3 additions & 3 deletions lib/screens/watch_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:jikan_api/jikan_api.dart';
import 'package:myanimelist/constants.dart';
import 'package:myanimelist/screens/anime_screen.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:url_launcher/url_launcher_string.dart';

class WatchScreen extends StatelessWidget {
const WatchScreen({this.episodes = true});
Expand Down Expand Up @@ -133,8 +133,8 @@ class VideoImage extends StatelessWidget {
child: InkWell(
onTap: () async {
String url = promo is WatchPromo ? promo.videoUrl : promo.episodes[0].url;
if (await canLaunch(url)) {
await launch(url);
if (await canLaunchUrlString(url)) {
await launchUrlString(url);
} else {
throw 'Could not launch $url';
}
Expand Down
Loading

0 comments on commit d272f1e

Please sign in to comment.