diff --git a/lib/src/data/manga.dart b/lib/src/data/manga.dart index 57a7076..7bb9ebc 100644 --- a/lib/src/data/manga.dart +++ b/lib/src/data/manga.dart @@ -1,4 +1,5 @@ import 'package:anitrack/src/data/data_base.dart'; +import 'package:anitrack/src/data/other_titles.dart'; import 'package:anitrack/src/data/source.dart'; import 'package:anitrack/src/data/type.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; @@ -33,6 +34,9 @@ abstract class MangaTrackingData /// URL to the thumbnail/cover art for the manga. String thumbnailUrl, + /// Other titles the manga can have. + @OtherTitlesConverter() OtherTitles otherTitles, + /// The source where we got the data from. @TrackingDataSourceConverter() TrackingDataSource source, ) = _MangaTrackingData; diff --git a/lib/src/data/manga.freezed.dart b/lib/src/data/manga.freezed.dart index f2b82c8..32ca787 100644 --- a/lib/src/data/manga.freezed.dart +++ b/lib/src/data/manga.freezed.dart @@ -22,7 +22,8 @@ mixin _$MangaTrackingData { int get chaptersRead;/// Chapters read. int get volumesOwned;/// Episodes watched. int? get chaptersTotal;/// URL to the thumbnail/cover art for the manga. - String get thumbnailUrl;/// The source where we got the data from. + String get thumbnailUrl;/// Other titles the manga can have. +@OtherTitlesConverter() OtherTitles get otherTitles;/// The source where we got the data from. @TrackingDataSourceConverter() TrackingDataSource get source; /// Create a copy of MangaTrackingData /// with the given fields replaced by the non-null parameter values. @@ -36,16 +37,16 @@ $MangaTrackingDataCopyWith get copyWith => _$MangaTrackingDat @override bool operator ==(Object other) { - return identical(this, other) || (other.runtimeType == runtimeType&&other is MangaTrackingData&&(identical(other.id, id) || other.id == id)&&(identical(other.state, state) || other.state == state)&&(identical(other.title, title) || other.title == title)&&(identical(other.chaptersRead, chaptersRead) || other.chaptersRead == chaptersRead)&&(identical(other.volumesOwned, volumesOwned) || other.volumesOwned == volumesOwned)&&(identical(other.chaptersTotal, chaptersTotal) || other.chaptersTotal == chaptersTotal)&&(identical(other.thumbnailUrl, thumbnailUrl) || other.thumbnailUrl == thumbnailUrl)&&(identical(other.source, source) || other.source == source)); + return identical(this, other) || (other.runtimeType == runtimeType&&other is MangaTrackingData&&(identical(other.id, id) || other.id == id)&&(identical(other.state, state) || other.state == state)&&(identical(other.title, title) || other.title == title)&&(identical(other.chaptersRead, chaptersRead) || other.chaptersRead == chaptersRead)&&(identical(other.volumesOwned, volumesOwned) || other.volumesOwned == volumesOwned)&&(identical(other.chaptersTotal, chaptersTotal) || other.chaptersTotal == chaptersTotal)&&(identical(other.thumbnailUrl, thumbnailUrl) || other.thumbnailUrl == thumbnailUrl)&&(identical(other.otherTitles, otherTitles) || other.otherTitles == otherTitles)&&(identical(other.source, source) || other.source == source)); } @JsonKey(includeFromJson: false, includeToJson: false) @override -int get hashCode => Object.hash(runtimeType,id,state,title,chaptersRead,volumesOwned,chaptersTotal,thumbnailUrl,source); +int get hashCode => Object.hash(runtimeType,id,state,title,chaptersRead,volumesOwned,chaptersTotal,thumbnailUrl,otherTitles,source); @override String toString() { - return 'MangaTrackingData(id: $id, state: $state, title: $title, chaptersRead: $chaptersRead, volumesOwned: $volumesOwned, chaptersTotal: $chaptersTotal, thumbnailUrl: $thumbnailUrl, source: $source)'; + return 'MangaTrackingData(id: $id, state: $state, title: $title, chaptersRead: $chaptersRead, volumesOwned: $volumesOwned, chaptersTotal: $chaptersTotal, thumbnailUrl: $thumbnailUrl, otherTitles: $otherTitles, source: $source)'; } @@ -56,11 +57,11 @@ abstract mixin class $MangaTrackingDataCopyWith<$Res> { factory $MangaTrackingDataCopyWith(MangaTrackingData value, $Res Function(MangaTrackingData) _then) = _$MangaTrackingDataCopyWithImpl; @useResult $Res call({ - String id,@MediumTrackingStateConverter() MediumTrackingState state, String title, int chaptersRead, int volumesOwned, int? chaptersTotal, String thumbnailUrl,@TrackingDataSourceConverter() TrackingDataSource source + String id,@MediumTrackingStateConverter() MediumTrackingState state, String title, int chaptersRead, int volumesOwned, int? chaptersTotal, String thumbnailUrl,@OtherTitlesConverter() OtherTitles otherTitles,@TrackingDataSourceConverter() TrackingDataSource source }); - +$OtherTitlesCopyWith<$Res> get otherTitles; } /// @nodoc @@ -73,7 +74,7 @@ class _$MangaTrackingDataCopyWithImpl<$Res> /// Create a copy of MangaTrackingData /// with the given fields replaced by the non-null parameter values. -@pragma('vm:prefer-inline') @override $Res call({Object? id = null,Object? state = null,Object? title = null,Object? chaptersRead = null,Object? volumesOwned = null,Object? chaptersTotal = freezed,Object? thumbnailUrl = null,Object? source = null,}) { +@pragma('vm:prefer-inline') @override $Res call({Object? id = null,Object? state = null,Object? title = null,Object? chaptersRead = null,Object? volumesOwned = null,Object? chaptersTotal = freezed,Object? thumbnailUrl = null,Object? otherTitles = null,Object? source = null,}) { return _then(_self.copyWith( id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable as String,state: null == state ? _self.state : state // ignore: cast_nullable_to_non_nullable @@ -82,11 +83,21 @@ as String,chaptersRead: null == chaptersRead ? _self.chaptersRead : chaptersRead as int,volumesOwned: null == volumesOwned ? _self.volumesOwned : volumesOwned // ignore: cast_nullable_to_non_nullable as int,chaptersTotal: freezed == chaptersTotal ? _self.chaptersTotal : chaptersTotal // ignore: cast_nullable_to_non_nullable as int?,thumbnailUrl: null == thumbnailUrl ? _self.thumbnailUrl : thumbnailUrl // ignore: cast_nullable_to_non_nullable -as String,source: null == source ? _self.source : source // ignore: cast_nullable_to_non_nullable +as String,otherTitles: null == otherTitles ? _self.otherTitles : otherTitles // ignore: cast_nullable_to_non_nullable +as OtherTitles,source: null == source ? _self.source : source // ignore: cast_nullable_to_non_nullable as TrackingDataSource, )); } - +/// Create a copy of MangaTrackingData +/// with the given fields replaced by the non-null parameter values. +@override +@pragma('vm:prefer-inline') +$OtherTitlesCopyWith<$Res> get otherTitles { + + return $OtherTitlesCopyWith<$Res>(_self.otherTitles, (value) { + return _then(_self.copyWith(otherTitles: value)); + }); +} } @@ -168,10 +179,10 @@ return $default(_that);case _: /// } /// ``` -@optionalTypeArgs TResult maybeWhen(TResult Function( String id, @MediumTrackingStateConverter() MediumTrackingState state, String title, int chaptersRead, int volumesOwned, int? chaptersTotal, String thumbnailUrl, @TrackingDataSourceConverter() TrackingDataSource source)? $default,{required TResult orElse(),}) {final _that = this; +@optionalTypeArgs TResult maybeWhen(TResult Function( String id, @MediumTrackingStateConverter() MediumTrackingState state, String title, int chaptersRead, int volumesOwned, int? chaptersTotal, String thumbnailUrl, @OtherTitlesConverter() OtherTitles otherTitles, @TrackingDataSourceConverter() TrackingDataSource source)? $default,{required TResult orElse(),}) {final _that = this; switch (_that) { case _MangaTrackingData() when $default != null: -return $default(_that.id,_that.state,_that.title,_that.chaptersRead,_that.volumesOwned,_that.chaptersTotal,_that.thumbnailUrl,_that.source);case _: +return $default(_that.id,_that.state,_that.title,_that.chaptersRead,_that.volumesOwned,_that.chaptersTotal,_that.thumbnailUrl,_that.otherTitles,_that.source);case _: return orElse(); } @@ -189,10 +200,10 @@ return $default(_that.id,_that.state,_that.title,_that.chaptersRead,_that.volume /// } /// ``` -@optionalTypeArgs TResult when(TResult Function( String id, @MediumTrackingStateConverter() MediumTrackingState state, String title, int chaptersRead, int volumesOwned, int? chaptersTotal, String thumbnailUrl, @TrackingDataSourceConverter() TrackingDataSource source) $default,) {final _that = this; +@optionalTypeArgs TResult when(TResult Function( String id, @MediumTrackingStateConverter() MediumTrackingState state, String title, int chaptersRead, int volumesOwned, int? chaptersTotal, String thumbnailUrl, @OtherTitlesConverter() OtherTitles otherTitles, @TrackingDataSourceConverter() TrackingDataSource source) $default,) {final _that = this; switch (_that) { case _MangaTrackingData(): -return $default(_that.id,_that.state,_that.title,_that.chaptersRead,_that.volumesOwned,_that.chaptersTotal,_that.thumbnailUrl,_that.source);case _: +return $default(_that.id,_that.state,_that.title,_that.chaptersRead,_that.volumesOwned,_that.chaptersTotal,_that.thumbnailUrl,_that.otherTitles,_that.source);case _: throw StateError('Unexpected subclass'); } @@ -209,10 +220,10 @@ return $default(_that.id,_that.state,_that.title,_that.chaptersRead,_that.volume /// } /// ``` -@optionalTypeArgs TResult? whenOrNull(TResult? Function( String id, @MediumTrackingStateConverter() MediumTrackingState state, String title, int chaptersRead, int volumesOwned, int? chaptersTotal, String thumbnailUrl, @TrackingDataSourceConverter() TrackingDataSource source)? $default,) {final _that = this; +@optionalTypeArgs TResult? whenOrNull(TResult? Function( String id, @MediumTrackingStateConverter() MediumTrackingState state, String title, int chaptersRead, int volumesOwned, int? chaptersTotal, String thumbnailUrl, @OtherTitlesConverter() OtherTitles otherTitles, @TrackingDataSourceConverter() TrackingDataSource source)? $default,) {final _that = this; switch (_that) { case _MangaTrackingData() when $default != null: -return $default(_that.id,_that.state,_that.title,_that.chaptersRead,_that.volumesOwned,_that.chaptersTotal,_that.thumbnailUrl,_that.source);case _: +return $default(_that.id,_that.state,_that.title,_that.chaptersRead,_that.volumesOwned,_that.chaptersTotal,_that.thumbnailUrl,_that.otherTitles,_that.source);case _: return null; } @@ -224,7 +235,7 @@ return $default(_that.id,_that.state,_that.title,_that.chaptersRead,_that.volume @JsonSerializable() class _MangaTrackingData extends MangaTrackingData { - _MangaTrackingData(this.id, @MediumTrackingStateConverter() this.state, this.title, this.chaptersRead, this.volumesOwned, this.chaptersTotal, this.thumbnailUrl, @TrackingDataSourceConverter() this.source): super._(); + _MangaTrackingData(this.id, @MediumTrackingStateConverter() this.state, this.title, this.chaptersRead, this.volumesOwned, this.chaptersTotal, this.thumbnailUrl, @OtherTitlesConverter() this.otherTitles, @TrackingDataSourceConverter() this.source): super._(); factory _MangaTrackingData.fromJson(Map json) => _$MangaTrackingDataFromJson(json); /// The ID of the manga @@ -241,6 +252,8 @@ class _MangaTrackingData extends MangaTrackingData { @override final int? chaptersTotal; /// URL to the thumbnail/cover art for the manga. @override final String thumbnailUrl; +/// Other titles the manga can have. +@override@OtherTitlesConverter() final OtherTitles otherTitles; /// The source where we got the data from. @override@TrackingDataSourceConverter() final TrackingDataSource source; @@ -257,16 +270,16 @@ Map toJson() { @override bool operator ==(Object other) { - return identical(this, other) || (other.runtimeType == runtimeType&&other is _MangaTrackingData&&(identical(other.id, id) || other.id == id)&&(identical(other.state, state) || other.state == state)&&(identical(other.title, title) || other.title == title)&&(identical(other.chaptersRead, chaptersRead) || other.chaptersRead == chaptersRead)&&(identical(other.volumesOwned, volumesOwned) || other.volumesOwned == volumesOwned)&&(identical(other.chaptersTotal, chaptersTotal) || other.chaptersTotal == chaptersTotal)&&(identical(other.thumbnailUrl, thumbnailUrl) || other.thumbnailUrl == thumbnailUrl)&&(identical(other.source, source) || other.source == source)); + return identical(this, other) || (other.runtimeType == runtimeType&&other is _MangaTrackingData&&(identical(other.id, id) || other.id == id)&&(identical(other.state, state) || other.state == state)&&(identical(other.title, title) || other.title == title)&&(identical(other.chaptersRead, chaptersRead) || other.chaptersRead == chaptersRead)&&(identical(other.volumesOwned, volumesOwned) || other.volumesOwned == volumesOwned)&&(identical(other.chaptersTotal, chaptersTotal) || other.chaptersTotal == chaptersTotal)&&(identical(other.thumbnailUrl, thumbnailUrl) || other.thumbnailUrl == thumbnailUrl)&&(identical(other.otherTitles, otherTitles) || other.otherTitles == otherTitles)&&(identical(other.source, source) || other.source == source)); } @JsonKey(includeFromJson: false, includeToJson: false) @override -int get hashCode => Object.hash(runtimeType,id,state,title,chaptersRead,volumesOwned,chaptersTotal,thumbnailUrl,source); +int get hashCode => Object.hash(runtimeType,id,state,title,chaptersRead,volumesOwned,chaptersTotal,thumbnailUrl,otherTitles,source); @override String toString() { - return 'MangaTrackingData(id: $id, state: $state, title: $title, chaptersRead: $chaptersRead, volumesOwned: $volumesOwned, chaptersTotal: $chaptersTotal, thumbnailUrl: $thumbnailUrl, source: $source)'; + return 'MangaTrackingData(id: $id, state: $state, title: $title, chaptersRead: $chaptersRead, volumesOwned: $volumesOwned, chaptersTotal: $chaptersTotal, thumbnailUrl: $thumbnailUrl, otherTitles: $otherTitles, source: $source)'; } @@ -277,11 +290,11 @@ abstract mixin class _$MangaTrackingDataCopyWith<$Res> implements $MangaTracking factory _$MangaTrackingDataCopyWith(_MangaTrackingData value, $Res Function(_MangaTrackingData) _then) = __$MangaTrackingDataCopyWithImpl; @override @useResult $Res call({ - String id,@MediumTrackingStateConverter() MediumTrackingState state, String title, int chaptersRead, int volumesOwned, int? chaptersTotal, String thumbnailUrl,@TrackingDataSourceConverter() TrackingDataSource source + String id,@MediumTrackingStateConverter() MediumTrackingState state, String title, int chaptersRead, int volumesOwned, int? chaptersTotal, String thumbnailUrl,@OtherTitlesConverter() OtherTitles otherTitles,@TrackingDataSourceConverter() TrackingDataSource source }); - +@override $OtherTitlesCopyWith<$Res> get otherTitles; } /// @nodoc @@ -294,7 +307,7 @@ class __$MangaTrackingDataCopyWithImpl<$Res> /// Create a copy of MangaTrackingData /// with the given fields replaced by the non-null parameter values. -@override @pragma('vm:prefer-inline') $Res call({Object? id = null,Object? state = null,Object? title = null,Object? chaptersRead = null,Object? volumesOwned = null,Object? chaptersTotal = freezed,Object? thumbnailUrl = null,Object? source = null,}) { +@override @pragma('vm:prefer-inline') $Res call({Object? id = null,Object? state = null,Object? title = null,Object? chaptersRead = null,Object? volumesOwned = null,Object? chaptersTotal = freezed,Object? thumbnailUrl = null,Object? otherTitles = null,Object? source = null,}) { return _then(_MangaTrackingData( null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable as String,null == state ? _self.state : state // ignore: cast_nullable_to_non_nullable @@ -303,12 +316,22 @@ as String,null == chaptersRead ? _self.chaptersRead : chaptersRead // ignore: ca as int,null == volumesOwned ? _self.volumesOwned : volumesOwned // ignore: cast_nullable_to_non_nullable as int,freezed == chaptersTotal ? _self.chaptersTotal : chaptersTotal // ignore: cast_nullable_to_non_nullable as int?,null == thumbnailUrl ? _self.thumbnailUrl : thumbnailUrl // ignore: cast_nullable_to_non_nullable -as String,null == source ? _self.source : source // ignore: cast_nullable_to_non_nullable +as String,null == otherTitles ? _self.otherTitles : otherTitles // ignore: cast_nullable_to_non_nullable +as OtherTitles,null == source ? _self.source : source // ignore: cast_nullable_to_non_nullable as TrackingDataSource, )); } - +/// Create a copy of MangaTrackingData +/// with the given fields replaced by the non-null parameter values. +@override +@pragma('vm:prefer-inline') +$OtherTitlesCopyWith<$Res> get otherTitles { + + return $OtherTitlesCopyWith<$Res>(_self.otherTitles, (value) { + return _then(_self.copyWith(otherTitles: value)); + }); +} } // dart format on diff --git a/lib/src/data/manga.g.dart b/lib/src/data/manga.g.dart index 2ab0637..d449caa 100644 --- a/lib/src/data/manga.g.dart +++ b/lib/src/data/manga.g.dart @@ -17,6 +17,7 @@ _MangaTrackingData _$MangaTrackingDataFromJson(Map json) => (json['volumesOwned'] as num).toInt(), (json['chaptersTotal'] as num?)?.toInt(), json['thumbnailUrl'] as String, + const OtherTitlesConverter().fromJson(json['otherTitles'] as String), const TrackingDataSourceConverter().fromJson(json['source'] as String), ); @@ -29,5 +30,6 @@ Map _$MangaTrackingDataToJson(_MangaTrackingData instance) => 'volumesOwned': instance.volumesOwned, 'chaptersTotal': instance.chaptersTotal, 'thumbnailUrl': instance.thumbnailUrl, + 'otherTitles': const OtherTitlesConverter().toJson(instance.otherTitles), 'source': const TrackingDataSourceConverter().toJson(instance.source), }; diff --git a/lib/src/service/anilist/model.dart b/lib/src/service/anilist/model.dart index 1d8cb33..6c975d1 100644 --- a/lib/src/service/anilist/model.dart +++ b/lib/src/service/anilist/model.dart @@ -45,6 +45,8 @@ abstract class AnimeSearchResult with _$AnimeSearchResult { abstract class MangaSearchResult with _$MangaSearchResult { const factory MangaSearchResult({ required String title, + required String? titleEnglish, + required String? titleJapanese, required String id, required int? chapters, required String imageUrl, @@ -54,6 +56,10 @@ abstract class MangaSearchResult with _$MangaSearchResult { factory MangaSearchResult.fromJson(Map json) { return MangaSearchResult( title: (json['title']! as Map)['romaji']! as String, + titleEnglish: + (json['title']! as Map)['english'] as String?, + titleJapanese: + (json['title']! as Map)['native'] as String?, id: (json['id']! as int).toString(), chapters: json['chapters'] as int?, imageUrl: diff --git a/lib/src/service/anilist/model.freezed.dart b/lib/src/service/anilist/model.freezed.dart index 654a6b1..a964b64 100644 --- a/lib/src/service/anilist/model.freezed.dart +++ b/lib/src/service/anilist/model.freezed.dart @@ -295,7 +295,7 @@ as String?, /// @nodoc mixin _$MangaSearchResult { - String get title; String get id; int? get chapters; String get imageUrl; String? get description; + String get title; String? get titleEnglish; String? get titleJapanese; String get id; int? get chapters; String get imageUrl; String? get description; /// Create a copy of MangaSearchResult /// with the given fields replaced by the non-null parameter values. @JsonKey(includeFromJson: false, includeToJson: false) @@ -306,16 +306,16 @@ $MangaSearchResultCopyWith get copyWith => _$MangaSearchResul @override bool operator ==(Object other) { - return identical(this, other) || (other.runtimeType == runtimeType&&other is MangaSearchResult&&(identical(other.title, title) || other.title == title)&&(identical(other.id, id) || other.id == id)&&(identical(other.chapters, chapters) || other.chapters == chapters)&&(identical(other.imageUrl, imageUrl) || other.imageUrl == imageUrl)&&(identical(other.description, description) || other.description == description)); + return identical(this, other) || (other.runtimeType == runtimeType&&other is MangaSearchResult&&(identical(other.title, title) || other.title == title)&&(identical(other.titleEnglish, titleEnglish) || other.titleEnglish == titleEnglish)&&(identical(other.titleJapanese, titleJapanese) || other.titleJapanese == titleJapanese)&&(identical(other.id, id) || other.id == id)&&(identical(other.chapters, chapters) || other.chapters == chapters)&&(identical(other.imageUrl, imageUrl) || other.imageUrl == imageUrl)&&(identical(other.description, description) || other.description == description)); } @override -int get hashCode => Object.hash(runtimeType,title,id,chapters,imageUrl,description); +int get hashCode => Object.hash(runtimeType,title,titleEnglish,titleJapanese,id,chapters,imageUrl,description); @override String toString() { - return 'MangaSearchResult(title: $title, id: $id, chapters: $chapters, imageUrl: $imageUrl, description: $description)'; + return 'MangaSearchResult(title: $title, titleEnglish: $titleEnglish, titleJapanese: $titleJapanese, id: $id, chapters: $chapters, imageUrl: $imageUrl, description: $description)'; } @@ -326,7 +326,7 @@ abstract mixin class $MangaSearchResultCopyWith<$Res> { factory $MangaSearchResultCopyWith(MangaSearchResult value, $Res Function(MangaSearchResult) _then) = _$MangaSearchResultCopyWithImpl; @useResult $Res call({ - String title, String id, int? chapters, String imageUrl, String? description + String title, String? titleEnglish, String? titleJapanese, String id, int? chapters, String imageUrl, String? description }); @@ -343,10 +343,12 @@ class _$MangaSearchResultCopyWithImpl<$Res> /// Create a copy of MangaSearchResult /// with the given fields replaced by the non-null parameter values. -@pragma('vm:prefer-inline') @override $Res call({Object? title = null,Object? id = null,Object? chapters = freezed,Object? imageUrl = null,Object? description = freezed,}) { +@pragma('vm:prefer-inline') @override $Res call({Object? title = null,Object? titleEnglish = freezed,Object? titleJapanese = freezed,Object? id = null,Object? chapters = freezed,Object? imageUrl = null,Object? description = freezed,}) { return _then(_self.copyWith( title: null == title ? _self.title : title // ignore: cast_nullable_to_non_nullable -as String,id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable +as String,titleEnglish: freezed == titleEnglish ? _self.titleEnglish : titleEnglish // ignore: cast_nullable_to_non_nullable +as String?,titleJapanese: freezed == titleJapanese ? _self.titleJapanese : titleJapanese // ignore: cast_nullable_to_non_nullable +as String?,id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable as String,chapters: freezed == chapters ? _self.chapters : chapters // ignore: cast_nullable_to_non_nullable as int?,imageUrl: null == imageUrl ? _self.imageUrl : imageUrl // ignore: cast_nullable_to_non_nullable as String,description: freezed == description ? _self.description : description // ignore: cast_nullable_to_non_nullable @@ -435,10 +437,10 @@ return $default(_that);case _: /// } /// ``` -@optionalTypeArgs TResult maybeWhen(TResult Function( String title, String id, int? chapters, String imageUrl, String? description)? $default,{required TResult orElse(),}) {final _that = this; +@optionalTypeArgs TResult maybeWhen(TResult Function( String title, String? titleEnglish, String? titleJapanese, String id, int? chapters, String imageUrl, String? description)? $default,{required TResult orElse(),}) {final _that = this; switch (_that) { case _MangaSearchResult() when $default != null: -return $default(_that.title,_that.id,_that.chapters,_that.imageUrl,_that.description);case _: +return $default(_that.title,_that.titleEnglish,_that.titleJapanese,_that.id,_that.chapters,_that.imageUrl,_that.description);case _: return orElse(); } @@ -456,10 +458,10 @@ return $default(_that.title,_that.id,_that.chapters,_that.imageUrl,_that.descrip /// } /// ``` -@optionalTypeArgs TResult when(TResult Function( String title, String id, int? chapters, String imageUrl, String? description) $default,) {final _that = this; +@optionalTypeArgs TResult when(TResult Function( String title, String? titleEnglish, String? titleJapanese, String id, int? chapters, String imageUrl, String? description) $default,) {final _that = this; switch (_that) { case _MangaSearchResult(): -return $default(_that.title,_that.id,_that.chapters,_that.imageUrl,_that.description);case _: +return $default(_that.title,_that.titleEnglish,_that.titleJapanese,_that.id,_that.chapters,_that.imageUrl,_that.description);case _: throw StateError('Unexpected subclass'); } @@ -476,10 +478,10 @@ return $default(_that.title,_that.id,_that.chapters,_that.imageUrl,_that.descrip /// } /// ``` -@optionalTypeArgs TResult? whenOrNull(TResult? Function( String title, String id, int? chapters, String imageUrl, String? description)? $default,) {final _that = this; +@optionalTypeArgs TResult? whenOrNull(TResult? Function( String title, String? titleEnglish, String? titleJapanese, String id, int? chapters, String imageUrl, String? description)? $default,) {final _that = this; switch (_that) { case _MangaSearchResult() when $default != null: -return $default(_that.title,_that.id,_that.chapters,_that.imageUrl,_that.description);case _: +return $default(_that.title,_that.titleEnglish,_that.titleJapanese,_that.id,_that.chapters,_that.imageUrl,_that.description);case _: return null; } @@ -491,10 +493,12 @@ return $default(_that.title,_that.id,_that.chapters,_that.imageUrl,_that.descrip class _MangaSearchResult implements MangaSearchResult { - const _MangaSearchResult({required this.title, required this.id, required this.chapters, required this.imageUrl, required this.description}); + const _MangaSearchResult({required this.title, required this.titleEnglish, required this.titleJapanese, required this.id, required this.chapters, required this.imageUrl, required this.description}); @override final String title; +@override final String? titleEnglish; +@override final String? titleJapanese; @override final String id; @override final int? chapters; @override final String imageUrl; @@ -510,16 +514,16 @@ _$MangaSearchResultCopyWith<_MangaSearchResult> get copyWith => __$MangaSearchRe @override bool operator ==(Object other) { - return identical(this, other) || (other.runtimeType == runtimeType&&other is _MangaSearchResult&&(identical(other.title, title) || other.title == title)&&(identical(other.id, id) || other.id == id)&&(identical(other.chapters, chapters) || other.chapters == chapters)&&(identical(other.imageUrl, imageUrl) || other.imageUrl == imageUrl)&&(identical(other.description, description) || other.description == description)); + return identical(this, other) || (other.runtimeType == runtimeType&&other is _MangaSearchResult&&(identical(other.title, title) || other.title == title)&&(identical(other.titleEnglish, titleEnglish) || other.titleEnglish == titleEnglish)&&(identical(other.titleJapanese, titleJapanese) || other.titleJapanese == titleJapanese)&&(identical(other.id, id) || other.id == id)&&(identical(other.chapters, chapters) || other.chapters == chapters)&&(identical(other.imageUrl, imageUrl) || other.imageUrl == imageUrl)&&(identical(other.description, description) || other.description == description)); } @override -int get hashCode => Object.hash(runtimeType,title,id,chapters,imageUrl,description); +int get hashCode => Object.hash(runtimeType,title,titleEnglish,titleJapanese,id,chapters,imageUrl,description); @override String toString() { - return 'MangaSearchResult(title: $title, id: $id, chapters: $chapters, imageUrl: $imageUrl, description: $description)'; + return 'MangaSearchResult(title: $title, titleEnglish: $titleEnglish, titleJapanese: $titleJapanese, id: $id, chapters: $chapters, imageUrl: $imageUrl, description: $description)'; } @@ -530,7 +534,7 @@ abstract mixin class _$MangaSearchResultCopyWith<$Res> implements $MangaSearchRe factory _$MangaSearchResultCopyWith(_MangaSearchResult value, $Res Function(_MangaSearchResult) _then) = __$MangaSearchResultCopyWithImpl; @override @useResult $Res call({ - String title, String id, int? chapters, String imageUrl, String? description + String title, String? titleEnglish, String? titleJapanese, String id, int? chapters, String imageUrl, String? description }); @@ -547,10 +551,12 @@ class __$MangaSearchResultCopyWithImpl<$Res> /// Create a copy of MangaSearchResult /// with the given fields replaced by the non-null parameter values. -@override @pragma('vm:prefer-inline') $Res call({Object? title = null,Object? id = null,Object? chapters = freezed,Object? imageUrl = null,Object? description = freezed,}) { +@override @pragma('vm:prefer-inline') $Res call({Object? title = null,Object? titleEnglish = freezed,Object? titleJapanese = freezed,Object? id = null,Object? chapters = freezed,Object? imageUrl = null,Object? description = freezed,}) { return _then(_MangaSearchResult( title: null == title ? _self.title : title // ignore: cast_nullable_to_non_nullable -as String,id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable +as String,titleEnglish: freezed == titleEnglish ? _self.titleEnglish : titleEnglish // ignore: cast_nullable_to_non_nullable +as String?,titleJapanese: freezed == titleJapanese ? _self.titleJapanese : titleJapanese // ignore: cast_nullable_to_non_nullable +as String?,id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable as String,chapters: freezed == chapters ? _self.chapters : chapters // ignore: cast_nullable_to_non_nullable as int?,imageUrl: null == imageUrl ? _self.imageUrl : imageUrl // ignore: cast_nullable_to_non_nullable as String,description: freezed == description ? _self.description : description // ignore: cast_nullable_to_non_nullable diff --git a/lib/src/service/database.dart b/lib/src/service/database.dart index 982686f..3e37925 100644 --- a/lib/src/service/database.dart +++ b/lib/src/service/database.dart @@ -7,6 +7,7 @@ import 'package:anitrack/src/service/migrations/0000_airing.dart'; import 'package:anitrack/src/service/migrations/0000_score.dart'; import 'package:anitrack/src/service/migrations/0001_anime_watcher.dart'; import 'package:anitrack/src/service/migrations/0002_anilist.dart'; +import 'package:anitrack/src/service/migrations/0003_other_titles.dart'; import 'package:path/path.dart' as p; import 'package:path_provider/path_provider.dart'; import 'package:sqflite_common_ffi/sqflite_ffi.dart'; @@ -105,7 +106,7 @@ class DatabaseService { print('Opening database at $databasePath'); _db = await openDatabase( databasePath, - version: 5, + version: 6, onConfigure: (db) async { // In order to do schema changes during database upgrades, we disable foreign // keys in the onConfigure phase, but re-enable them here. @@ -130,6 +131,9 @@ class DatabaseService { if (oldVersion < 5) { await migrateFromV4ToV5(db); } + if (oldVersion < 6) { + await migrateFromV5ToV6(db); + } }, ); } diff --git a/lib/src/service/migrations/0003_other_titles.dart b/lib/src/service/migrations/0003_other_titles.dart new file mode 100644 index 0000000..e0a7220 --- /dev/null +++ b/lib/src/service/migrations/0003_other_titles.dart @@ -0,0 +1,15 @@ +import 'package:anitrack/src/service/database.dart'; +import 'package:sqflite/sqflite.dart'; + +Future migrateFromV5ToV6(Database db) async { + await db.execute( + ''' + ALTER TABLE $animeTable ADD COLUMN otherTitles TEXT NOT NULL DEFAULT '{}'; + ''', + ); + await db.execute( + ''' + ALTER TABLE $mangaTable ADD COLUMN otherTitles TEXT NOT NULL DEFAULT '{}'; + ''', + ); +} diff --git a/lib/src/ui/bloc/anime_search_bloc.dart b/lib/src/ui/bloc/anime_search_bloc.dart index c0cd136..733540b 100644 --- a/lib/src/ui/bloc/anime_search_bloc.dart +++ b/lib/src/ui/bloc/anime_search_bloc.dart @@ -156,6 +156,10 @@ class AnimeSearchBloc extends Bloc { 0, event.result.total, event.result.thumbnailUrl, + OtherTitles( + english: event.result.titleEnglish, + japanese: event.result.titleJapanese, + ), TrackingDataSource.anilist, ), ), diff --git a/lib/src/ui/bloc/settings_bloc.dart b/lib/src/ui/bloc/settings_bloc.dart index 69252ae..9c505b3 100644 --- a/lib/src/ui/bloc/settings_bloc.dart +++ b/lib/src/ui/bloc/settings_bloc.dart @@ -211,6 +211,7 @@ class SettingsBloc extends Bloc { // 0 means that MAL does not know totalChapters == 0 ? null : totalChapters, data.imageUrl, + OtherTitles(), TrackingDataSource.mal, ), );