From 58ea71e6949c7ee820f192e8ed4ad18dd201d488 Mon Sep 17 00:00:00 2001 From: "Alexander \"PapaTutuWawa" Date: Sun, 26 Jul 2026 18:42:32 +0200 Subject: [PATCH] feat: Also update total episode count on refresh --- lib/src/service/anilist/model.dart | 2 + lib/src/service/anilist/model.freezed.dart | 43 ++++++++++++---------- lib/src/ui/bloc/calendar_bloc.dart | 21 ++++++++--- 3 files changed, 41 insertions(+), 25 deletions(-) diff --git a/lib/src/service/anilist/model.dart b/lib/src/service/anilist/model.dart index 6c975d1..aac73f0 100644 --- a/lib/src/service/anilist/model.dart +++ b/lib/src/service/anilist/model.dart @@ -75,6 +75,7 @@ abstract class Anime with _$Anime { required String title, required bool isAiring, required String? broadcastDay, + required int? episodes, }) = _Anime; factory Anime.fromJson(Map json) { @@ -88,6 +89,7 @@ abstract class Anime with _$Anime { return Anime( title: (json['title']! as Map)['romaji']! as String, isAiring: json['status'] == 'RELEASING', + episodes: json['episodes'] as int?, broadcastDay: airingDayOfTheWeek, ); } diff --git a/lib/src/service/anilist/model.freezed.dart b/lib/src/service/anilist/model.freezed.dart index a964b64..1d59e21 100644 --- a/lib/src/service/anilist/model.freezed.dart +++ b/lib/src/service/anilist/model.freezed.dart @@ -570,7 +570,7 @@ as String?, /// @nodoc 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 /// with the given fields replaced by the non-null parameter values. @JsonKey(includeFromJson: false, includeToJson: false) @@ -581,16 +581,16 @@ $AnimeCopyWith get copyWith => _$AnimeCopyWithImpl(this as Anime, @override 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 -int get hashCode => Object.hash(runtimeType,title,isAiring,broadcastDay); +int get hashCode => Object.hash(runtimeType,title,isAiring,broadcastDay,episodes); @override 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; @useResult $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 /// 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( 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 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 Function( String title, bool isAiring, String? broadcastDay)? $default,{required TResult orElse(),}) {final _that = this; +@optionalTypeArgs TResult maybeWhen(TResult Function( String title, bool isAiring, String? broadcastDay, int? episodes)? $default,{required TResult orElse(),}) {final _that = this; switch (_that) { 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(); } @@ -729,10 +730,10 @@ return $default(_that.title,_that.isAiring,_that.broadcastDay);case _: /// } /// ``` -@optionalTypeArgs TResult when(TResult Function( String title, bool isAiring, String? broadcastDay) $default,) {final _that = this; +@optionalTypeArgs TResult when(TResult Function( String title, bool isAiring, String? broadcastDay, int? episodes) $default,) {final _that = this; switch (_that) { 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'); } @@ -749,10 +750,10 @@ return $default(_that.title,_that.isAiring,_that.broadcastDay);case _: /// } /// ``` -@optionalTypeArgs TResult? whenOrNull(TResult? Function( String title, bool isAiring, String? broadcastDay)? $default,) {final _that = this; +@optionalTypeArgs TResult? whenOrNull(TResult? Function( String title, bool isAiring, String? broadcastDay, int? episodes)? $default,) {final _that = this; switch (_that) { 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; } @@ -764,12 +765,13 @@ return $default(_that.title,_that.isAiring,_that.broadcastDay);case _: 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 bool isAiring; @override final String? broadcastDay; +@override final int? episodes; /// Create a copy of Anime /// with the given fields replaced by the non-null parameter values. @@ -781,16 +783,16 @@ _$AnimeCopyWith<_Anime> get copyWith => __$AnimeCopyWithImpl<_Anime>(this, _$ide @override 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 -int get hashCode => Object.hash(runtimeType,title,isAiring,broadcastDay); +int get hashCode => Object.hash(runtimeType,title,isAiring,broadcastDay,episodes); @override 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; @override @useResult $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 /// 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( 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 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?, )); } diff --git a/lib/src/ui/bloc/calendar_bloc.dart b/lib/src/ui/bloc/calendar_bloc.dart index 24853bb..0d43628 100644 --- a/lib/src/ui/bloc/calendar_bloc.dart +++ b/lib/src/ui/bloc/calendar_bloc.dart @@ -44,29 +44,36 @@ class CalendarBloc extends Bloc { String? broadcastDay; bool airing; + int? episodes; try { switch (anime.source) { case TrackingDataSource.mal: final apiData = await Jikan().getAnime(int.parse(anime.id)); airing = apiData.airing; broadcastDay = apiData.broadcast?.split(' ').first; + episodes = apiData.episodes; case TrackingDataSource.anilist: final apiData = await GetIt.I.get().getAnimeById( anime.id, ); airing = apiData.isAiring; broadcastDay = apiData.broadcastDay; + episodes = apiData.episodes; } } catch (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) { al.add( AnimeUpdatedEvent( - anime.copyWith(airing: false, broadcastDay: null), + anime.copyWith( + airing: false, + broadcastDay: null, + episodesTotal: episodes, + ), commit: true, ), ); @@ -74,13 +81,17 @@ class CalendarBloc extends Bloc { print('Updating Anime "${anime.title}": broadcastDay=$broadcastDay'); al.add( AnimeUpdatedEvent( - anime.copyWith(airing: true, broadcastDay: broadcastDay), + anime.copyWith( + airing: true, + broadcastDay: broadcastDay, + episodesTotal: episodes, + ), commit: true, ), ); } - // Prevent hammering Jikan + // Prevent hammering Jikan/AniList await Future.delayed(const Duration(milliseconds: 500)); }