feat: Also update total episode count on refresh
This commit is contained in:
@@ -75,6 +75,7 @@ abstract class Anime with _$Anime {
|
|||||||
required String title,
|
required String title,
|
||||||
required bool isAiring,
|
required bool isAiring,
|
||||||
required String? broadcastDay,
|
required String? broadcastDay,
|
||||||
|
required int? episodes,
|
||||||
}) = _Anime;
|
}) = _Anime;
|
||||||
|
|
||||||
factory Anime.fromJson(Map<String, Object?> json) {
|
factory Anime.fromJson(Map<String, Object?> json) {
|
||||||
@@ -88,6 +89,7 @@ abstract class Anime with _$Anime {
|
|||||||
return Anime(
|
return Anime(
|
||||||
title: (json['title']! as Map<String, dynamic>)['romaji']! as String,
|
title: (json['title']! as Map<String, dynamic>)['romaji']! as String,
|
||||||
isAiring: json['status'] == 'RELEASING',
|
isAiring: json['status'] == 'RELEASING',
|
||||||
|
episodes: json['episodes'] as int?,
|
||||||
broadcastDay: airingDayOfTheWeek,
|
broadcastDay: airingDayOfTheWeek,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -570,7 +570,7 @@ as String?,
|
|||||||
/// @nodoc
|
/// @nodoc
|
||||||
mixin _$Anime {
|
mixin _$Anime {
|
||||||
|
|
||||||
String get title; bool get isAiring; String? get broadcastDay;
|
String get title; bool get isAiring; String? get broadcastDay; int? get episodes;
|
||||||
/// Create a copy of Anime
|
/// Create a copy of Anime
|
||||||
/// with the given fields replaced by the non-null parameter values.
|
/// with the given fields replaced by the non-null parameter values.
|
||||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||||
@@ -581,16 +581,16 @@ $AnimeCopyWith<Anime> get copyWith => _$AnimeCopyWithImpl<Anime>(this as Anime,
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
bool operator ==(Object other) {
|
bool operator ==(Object other) {
|
||||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is Anime&&(identical(other.title, title) || other.title == title)&&(identical(other.isAiring, isAiring) || other.isAiring == isAiring)&&(identical(other.broadcastDay, broadcastDay) || other.broadcastDay == broadcastDay));
|
return identical(this, other) || (other.runtimeType == runtimeType&&other is Anime&&(identical(other.title, title) || other.title == title)&&(identical(other.isAiring, isAiring) || other.isAiring == isAiring)&&(identical(other.broadcastDay, broadcastDay) || other.broadcastDay == broadcastDay)&&(identical(other.episodes, episodes) || other.episodes == episodes));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int get hashCode => Object.hash(runtimeType,title,isAiring,broadcastDay);
|
int get hashCode => Object.hash(runtimeType,title,isAiring,broadcastDay,episodes);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'Anime(title: $title, isAiring: $isAiring, broadcastDay: $broadcastDay)';
|
return 'Anime(title: $title, isAiring: $isAiring, broadcastDay: $broadcastDay, episodes: $episodes)';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -601,7 +601,7 @@ abstract mixin class $AnimeCopyWith<$Res> {
|
|||||||
factory $AnimeCopyWith(Anime value, $Res Function(Anime) _then) = _$AnimeCopyWithImpl;
|
factory $AnimeCopyWith(Anime value, $Res Function(Anime) _then) = _$AnimeCopyWithImpl;
|
||||||
@useResult
|
@useResult
|
||||||
$Res call({
|
$Res call({
|
||||||
String title, bool isAiring, String? broadcastDay
|
String title, bool isAiring, String? broadcastDay, int? episodes
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@@ -618,12 +618,13 @@ class _$AnimeCopyWithImpl<$Res>
|
|||||||
|
|
||||||
/// Create a copy of Anime
|
/// Create a copy of Anime
|
||||||
/// with the given fields replaced by the non-null parameter values.
|
/// with the given fields replaced by the non-null parameter values.
|
||||||
@pragma('vm:prefer-inline') @override $Res call({Object? title = null,Object? isAiring = null,Object? broadcastDay = freezed,}) {
|
@pragma('vm:prefer-inline') @override $Res call({Object? title = null,Object? isAiring = null,Object? broadcastDay = freezed,Object? episodes = freezed,}) {
|
||||||
return _then(_self.copyWith(
|
return _then(_self.copyWith(
|
||||||
title: null == title ? _self.title : title // ignore: cast_nullable_to_non_nullable
|
title: null == title ? _self.title : title // ignore: cast_nullable_to_non_nullable
|
||||||
as String,isAiring: null == isAiring ? _self.isAiring : isAiring // ignore: cast_nullable_to_non_nullable
|
as String,isAiring: null == isAiring ? _self.isAiring : isAiring // ignore: cast_nullable_to_non_nullable
|
||||||
as bool,broadcastDay: freezed == broadcastDay ? _self.broadcastDay : broadcastDay // ignore: cast_nullable_to_non_nullable
|
as bool,broadcastDay: freezed == broadcastDay ? _self.broadcastDay : broadcastDay // ignore: cast_nullable_to_non_nullable
|
||||||
as String?,
|
as String?,episodes: freezed == episodes ? _self.episodes : episodes // ignore: cast_nullable_to_non_nullable
|
||||||
|
as int?,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -708,10 +709,10 @@ return $default(_that);case _:
|
|||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
|
|
||||||
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( String title, bool isAiring, String? broadcastDay)? $default,{required TResult orElse(),}) {final _that = this;
|
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( String title, bool isAiring, String? broadcastDay, int? episodes)? $default,{required TResult orElse(),}) {final _that = this;
|
||||||
switch (_that) {
|
switch (_that) {
|
||||||
case _Anime() when $default != null:
|
case _Anime() when $default != null:
|
||||||
return $default(_that.title,_that.isAiring,_that.broadcastDay);case _:
|
return $default(_that.title,_that.isAiring,_that.broadcastDay,_that.episodes);case _:
|
||||||
return orElse();
|
return orElse();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -729,10 +730,10 @@ return $default(_that.title,_that.isAiring,_that.broadcastDay);case _:
|
|||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
|
|
||||||
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( String title, bool isAiring, String? broadcastDay) $default,) {final _that = this;
|
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( String title, bool isAiring, String? broadcastDay, int? episodes) $default,) {final _that = this;
|
||||||
switch (_that) {
|
switch (_that) {
|
||||||
case _Anime():
|
case _Anime():
|
||||||
return $default(_that.title,_that.isAiring,_that.broadcastDay);case _:
|
return $default(_that.title,_that.isAiring,_that.broadcastDay,_that.episodes);case _:
|
||||||
throw StateError('Unexpected subclass');
|
throw StateError('Unexpected subclass');
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -749,10 +750,10 @@ return $default(_that.title,_that.isAiring,_that.broadcastDay);case _:
|
|||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
|
|
||||||
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( String title, bool isAiring, String? broadcastDay)? $default,) {final _that = this;
|
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( String title, bool isAiring, String? broadcastDay, int? episodes)? $default,) {final _that = this;
|
||||||
switch (_that) {
|
switch (_that) {
|
||||||
case _Anime() when $default != null:
|
case _Anime() when $default != null:
|
||||||
return $default(_that.title,_that.isAiring,_that.broadcastDay);case _:
|
return $default(_that.title,_that.isAiring,_that.broadcastDay,_that.episodes);case _:
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -764,12 +765,13 @@ return $default(_that.title,_that.isAiring,_that.broadcastDay);case _:
|
|||||||
|
|
||||||
|
|
||||||
class _Anime implements Anime {
|
class _Anime implements Anime {
|
||||||
const _Anime({required this.title, required this.isAiring, required this.broadcastDay});
|
const _Anime({required this.title, required this.isAiring, required this.broadcastDay, required this.episodes});
|
||||||
|
|
||||||
|
|
||||||
@override final String title;
|
@override final String title;
|
||||||
@override final bool isAiring;
|
@override final bool isAiring;
|
||||||
@override final String? broadcastDay;
|
@override final String? broadcastDay;
|
||||||
|
@override final int? episodes;
|
||||||
|
|
||||||
/// Create a copy of Anime
|
/// Create a copy of Anime
|
||||||
/// with the given fields replaced by the non-null parameter values.
|
/// with the given fields replaced by the non-null parameter values.
|
||||||
@@ -781,16 +783,16 @@ _$AnimeCopyWith<_Anime> get copyWith => __$AnimeCopyWithImpl<_Anime>(this, _$ide
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
bool operator ==(Object other) {
|
bool operator ==(Object other) {
|
||||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _Anime&&(identical(other.title, title) || other.title == title)&&(identical(other.isAiring, isAiring) || other.isAiring == isAiring)&&(identical(other.broadcastDay, broadcastDay) || other.broadcastDay == broadcastDay));
|
return identical(this, other) || (other.runtimeType == runtimeType&&other is _Anime&&(identical(other.title, title) || other.title == title)&&(identical(other.isAiring, isAiring) || other.isAiring == isAiring)&&(identical(other.broadcastDay, broadcastDay) || other.broadcastDay == broadcastDay)&&(identical(other.episodes, episodes) || other.episodes == episodes));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int get hashCode => Object.hash(runtimeType,title,isAiring,broadcastDay);
|
int get hashCode => Object.hash(runtimeType,title,isAiring,broadcastDay,episodes);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'Anime(title: $title, isAiring: $isAiring, broadcastDay: $broadcastDay)';
|
return 'Anime(title: $title, isAiring: $isAiring, broadcastDay: $broadcastDay, episodes: $episodes)';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -801,7 +803,7 @@ abstract mixin class _$AnimeCopyWith<$Res> implements $AnimeCopyWith<$Res> {
|
|||||||
factory _$AnimeCopyWith(_Anime value, $Res Function(_Anime) _then) = __$AnimeCopyWithImpl;
|
factory _$AnimeCopyWith(_Anime value, $Res Function(_Anime) _then) = __$AnimeCopyWithImpl;
|
||||||
@override @useResult
|
@override @useResult
|
||||||
$Res call({
|
$Res call({
|
||||||
String title, bool isAiring, String? broadcastDay
|
String title, bool isAiring, String? broadcastDay, int? episodes
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@@ -818,12 +820,13 @@ class __$AnimeCopyWithImpl<$Res>
|
|||||||
|
|
||||||
/// Create a copy of Anime
|
/// Create a copy of Anime
|
||||||
/// with the given fields replaced by the non-null parameter values.
|
/// with the given fields replaced by the non-null parameter values.
|
||||||
@override @pragma('vm:prefer-inline') $Res call({Object? title = null,Object? isAiring = null,Object? broadcastDay = freezed,}) {
|
@override @pragma('vm:prefer-inline') $Res call({Object? title = null,Object? isAiring = null,Object? broadcastDay = freezed,Object? episodes = freezed,}) {
|
||||||
return _then(_Anime(
|
return _then(_Anime(
|
||||||
title: null == title ? _self.title : title // ignore: cast_nullable_to_non_nullable
|
title: null == title ? _self.title : title // ignore: cast_nullable_to_non_nullable
|
||||||
as String,isAiring: null == isAiring ? _self.isAiring : isAiring // ignore: cast_nullable_to_non_nullable
|
as String,isAiring: null == isAiring ? _self.isAiring : isAiring // ignore: cast_nullable_to_non_nullable
|
||||||
as bool,broadcastDay: freezed == broadcastDay ? _self.broadcastDay : broadcastDay // ignore: cast_nullable_to_non_nullable
|
as bool,broadcastDay: freezed == broadcastDay ? _self.broadcastDay : broadcastDay // ignore: cast_nullable_to_non_nullable
|
||||||
as String?,
|
as String?,episodes: freezed == episodes ? _self.episodes : episodes // ignore: cast_nullable_to_non_nullable
|
||||||
|
as int?,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,29 +44,36 @@ class CalendarBloc extends Bloc<CalendarEvent, CalendarState> {
|
|||||||
|
|
||||||
String? broadcastDay;
|
String? broadcastDay;
|
||||||
bool airing;
|
bool airing;
|
||||||
|
int? episodes;
|
||||||
try {
|
try {
|
||||||
switch (anime.source) {
|
switch (anime.source) {
|
||||||
case TrackingDataSource.mal:
|
case TrackingDataSource.mal:
|
||||||
final apiData = await Jikan().getAnime(int.parse(anime.id));
|
final apiData = await Jikan().getAnime(int.parse(anime.id));
|
||||||
airing = apiData.airing;
|
airing = apiData.airing;
|
||||||
broadcastDay = apiData.broadcast?.split(' ').first;
|
broadcastDay = apiData.broadcast?.split(' ').first;
|
||||||
|
episodes = apiData.episodes;
|
||||||
case TrackingDataSource.anilist:
|
case TrackingDataSource.anilist:
|
||||||
final apiData = await GetIt.I.get<AniListClient>().getAnimeById(
|
final apiData = await GetIt.I.get<AniListClient>().getAnimeById(
|
||||||
anime.id,
|
anime.id,
|
||||||
);
|
);
|
||||||
airing = apiData.isAiring;
|
airing = apiData.isAiring;
|
||||||
broadcastDay = apiData.broadcastDay;
|
broadcastDay = apiData.broadcastDay;
|
||||||
|
episodes = apiData.episodes;
|
||||||
}
|
}
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
print('API request for anime ${anime.id} failed: $ex');
|
print('API request for anime ${anime.id} failed: $ex');
|
||||||
airing = false;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
print('Anime "${anime.title}": airing=$airing');
|
print('Anime "${anime.title}": airing=$airing; episodes=$episodes');
|
||||||
if (!airing) {
|
if (!airing) {
|
||||||
al.add(
|
al.add(
|
||||||
AnimeUpdatedEvent(
|
AnimeUpdatedEvent(
|
||||||
anime.copyWith(airing: false, broadcastDay: null),
|
anime.copyWith(
|
||||||
|
airing: false,
|
||||||
|
broadcastDay: null,
|
||||||
|
episodesTotal: episodes,
|
||||||
|
),
|
||||||
commit: true,
|
commit: true,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -74,13 +81,17 @@ class CalendarBloc extends Bloc<CalendarEvent, CalendarState> {
|
|||||||
print('Updating Anime "${anime.title}": broadcastDay=$broadcastDay');
|
print('Updating Anime "${anime.title}": broadcastDay=$broadcastDay');
|
||||||
al.add(
|
al.add(
|
||||||
AnimeUpdatedEvent(
|
AnimeUpdatedEvent(
|
||||||
anime.copyWith(airing: true, broadcastDay: broadcastDay),
|
anime.copyWith(
|
||||||
|
airing: true,
|
||||||
|
broadcastDay: broadcastDay,
|
||||||
|
episodesTotal: episodes,
|
||||||
|
),
|
||||||
commit: true,
|
commit: true,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prevent hammering Jikan
|
// Prevent hammering Jikan/AniList
|
||||||
await Future<void>.delayed(const Duration(milliseconds: 500));
|
await Future<void>.delayed(const Duration(milliseconds: 500));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user