From 9e25c742d4e43e4e10d2b48afb8e6d90288ffa11 Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Sun, 14 Apr 2024 12:10:34 +0600 Subject: [PATCH] feat: add Spotify homepage personalized recommendations (#1402) * feat: add spotify homepage recommendations * chore: bring back made for user sectin --- lib/collections/assets.gen.dart | 2 +- lib/collections/fake.dart | 27 + lib/collections/routes.dart | 9 + lib/components/home/sections/feed.dart | 52 + .../horizontal_playbutton_card_view.dart | 25 +- lib/main.dart | 3 + lib/models/spotify/home_feed.dart | 247 +++ lib/models/spotify/home_feed.freezed.dart | 1666 +++++++++++++++++ lib/models/spotify/home_feed.g.dart | 169 ++ lib/pages/home/feed/feed_section.dart | 62 + lib/pages/home/home.dart | 2 + lib/pages/mobile_login/mobile_login.dart | 4 +- lib/provider/authentication_provider.dart | 18 +- lib/provider/spotify/views/home.dart | 22 + lib/provider/spotify/views/home_section.dart | 26 + .../spotify_endpoints.dart | 124 ++ pubspec.lock | 10 +- pubspec.yaml | 2 + 18 files changed, 2455 insertions(+), 15 deletions(-) create mode 100644 lib/components/home/sections/feed.dart create mode 100644 lib/models/spotify/home_feed.dart create mode 100644 lib/models/spotify/home_feed.freezed.dart create mode 100644 lib/models/spotify/home_feed.g.dart create mode 100644 lib/pages/home/feed/feed_section.dart create mode 100644 lib/provider/spotify/views/home.dart create mode 100644 lib/provider/spotify/views/home_section.dart diff --git a/lib/collections/assets.gen.dart b/lib/collections/assets.gen.dart index 8a2950fb..2a30260b 100644 --- a/lib/collections/assets.gen.dart +++ b/lib/collections/assets.gen.dart @@ -88,7 +88,7 @@ class Assets { AssetGenImage('assets/user-placeholder.png'); /// List of all assets - List get values => [ + static List get values => [ albumPlaceholder, bengaliPatternsBg, branding, diff --git a/lib/collections/fake.dart b/lib/collections/fake.dart index c5379ec6..4df19dfc 100644 --- a/lib/collections/fake.dart +++ b/lib/collections/fake.dart @@ -1,5 +1,6 @@ import 'package:spotify/spotify.dart'; import 'package:spotube/extensions/track.dart'; +import 'package:spotube/models/spotify/home_feed.dart'; import 'package:spotube/models/spotify_friends.dart'; abstract class FakeData { @@ -196,4 +197,30 @@ abstract class FakeData { ), ], ); + + static final feedSection = SpotifyHomeFeedSection( + typename: "HomeGenericSectionData", + uri: "spotify:section:lol", + title: "Dummy", + items: [ + for (int i = 0; i < 10; i++) + SpotifyHomeFeedSectionItem( + typename: "PlaylistResponseWrapper", + playlist: SpotifySectionPlaylist( + name: "Playlist $i", + description: "Really super important description $i", + format: "daily-mix", + images: [ + const SpotifySectionItemImage( + height: 1, + width: 1, + url: "https://dummyimage.com/100x100/cfcfcf/cfcfcf.jpg", + ), + ], + owner: "Spotify", + uri: "spotify:playlist:id", + ), + ) + ], + ); } diff --git a/lib/collections/routes.dart b/lib/collections/routes.dart index aeeb4837..080cbd8a 100644 --- a/lib/collections/routes.dart +++ b/lib/collections/routes.dart @@ -9,6 +9,7 @@ import 'package:spotube/pages/album/album.dart'; import 'package:spotube/pages/connect/connect.dart'; import 'package:spotube/pages/connect/control/control.dart'; import 'package:spotube/pages/getting_started/getting_started.dart'; +import 'package:spotube/pages/home/feed/feed_section.dart'; import 'package:spotube/pages/home/genres/genre_playlists.dart'; import 'package:spotube/pages/home/genres/genres.dart'; import 'package:spotube/pages/home/home.dart'; @@ -76,6 +77,14 @@ final routerProvider = Provider((ref) { ), ), ), + GoRoute( + path: "feeds/:feedId", + pageBuilder: (context, state) => SpotubePage( + child: HomeFeedSectionPage( + sectionUri: state.pathParameters["feedId"] as String, + ), + ), + ) ], ), GoRoute( diff --git a/lib/components/home/sections/feed.dart b/lib/components/home/sections/feed.dart new file mode 100644 index 00000000..793cd2c3 --- /dev/null +++ b/lib/components/home/sections/feed.dart @@ -0,0 +1,52 @@ +import 'package:flutter/material.dart'; +import 'package:hooks_riverpod/hooks_riverpod.dart'; +import 'package:spotube/collections/spotube_icons.dart'; +import 'package:spotube/components/shared/horizontal_playbutton_card_view/horizontal_playbutton_card_view.dart'; +import 'package:spotube/provider/spotify/views/home.dart'; +import 'package:spotube/utils/service_utils.dart'; + +class HomePageFeedSection extends HookConsumerWidget { + const HomePageFeedSection({super.key}); + + @override + Widget build(BuildContext context, ref) { + final homeFeed = ref.watch(homeViewProvider); + final nonShortSections = homeFeed.asData?.value?.sections + .where((s) => s.typename == "HomeGenericSectionData") + .toList() ?? + []; + + return SliverList.builder( + itemCount: nonShortSections.length, + itemBuilder: (context, index) { + final section = nonShortSections[index]; + if (section.items.isEmpty) return const SizedBox.shrink(); + + return HorizontalPlaybuttonCardView( + items: [ + for (final item in section.items) + if (item.album != null) + item.album!.asAlbum + else if (item.artist != null) + item.artist!.asArtist + else if (item.playlist != null) + item.playlist!.asPlaylist + ], + title: Text(section.title ?? "No Titel"), + hasNextPage: false, + isLoadingNextPage: false, + onFetchMore: () {}, + titleTrailing: Directionality( + textDirection: TextDirection.rtl, + child: TextButton.icon( + label: const Text("Browse More"), + icon: const Icon(SpotubeIcons.angleRight), + onPressed: () => + ServiceUtils.push(context, "/feeds/${section.uri}"), + ), + ), + ); + }, + ); + } +} diff --git a/lib/components/shared/horizontal_playbutton_card_view/horizontal_playbutton_card_view.dart b/lib/components/shared/horizontal_playbutton_card_view/horizontal_playbutton_card_view.dart index 8f0e6048..e142cb35 100644 --- a/lib/components/shared/horizontal_playbutton_card_view/horizontal_playbutton_card_view.dart +++ b/lib/components/shared/horizontal_playbutton_card_view/horizontal_playbutton_card_view.dart @@ -17,18 +17,21 @@ class HorizontalPlaybuttonCardView extends HookWidget { final VoidCallback onFetchMore; final bool isLoadingNextPage; final bool hasNextPage; + final Widget? titleTrailing; - const HorizontalPlaybuttonCardView({ + HorizontalPlaybuttonCardView({ required this.title, required this.items, required this.hasNextPage, required this.onFetchMore, required this.isLoadingNextPage, + this.titleTrailing, super.key, }) : assert( - items is List || - items is List || - items is List, + items.every( + (item) => + item is PlaylistSimple || item is Artist || item is AlbumSimple, + ), ); @override @@ -48,9 +51,15 @@ class HorizontalPlaybuttonCardView extends HookWidget { mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [ - DefaultTextStyle( - style: textTheme.titleMedium!, - child: title, + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + DefaultTextStyle( + style: textTheme.titleMedium!, + child: title, + ), + if (titleTrailing != null) titleTrailing!, + ], ), SizedBox( height: height, @@ -87,7 +96,7 @@ class HorizontalPlaybuttonCardView extends HookWidget { return switch (item) { PlaylistSimple() => PlaylistCard(item as PlaylistSimple), - Album() => AlbumCard(item as Album), + AlbumSimple() => AlbumCard(item as Album), Artist() => Padding( padding: const EdgeInsets.symmetric( horizontal: 12.0), diff --git a/lib/main.dart b/lib/main.dart index 95724c79..0bb72932 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -39,6 +39,7 @@ import 'package:spotube/hooks/configurators/use_init_sys_tray.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:flutter_native_splash/flutter_native_splash.dart'; import 'package:flutter_displaymode/flutter_displaymode.dart'; +import 'package:timezone/data/latest.dart' as tz; Future main(List rawArgs) async { final arguments = await startCLI(rawArgs); @@ -47,6 +48,8 @@ Future main(List rawArgs) async { await registerWindowsScheme("spotify"); + tz.initializeTimeZones(); + FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding); MediaKit.ensureInitialized(); diff --git a/lib/models/spotify/home_feed.dart b/lib/models/spotify/home_feed.dart new file mode 100644 index 00000000..e5c2f666 --- /dev/null +++ b/lib/models/spotify/home_feed.dart @@ -0,0 +1,247 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:spotify/spotify.dart'; + +part 'home_feed.freezed.dart'; +part 'home_feed.g.dart'; + +@freezed +class SpotifySectionPlaylist with _$SpotifySectionPlaylist { + const SpotifySectionPlaylist._(); + + const factory SpotifySectionPlaylist({ + required String description, + required String format, + required List images, + required String name, + required String owner, + required String uri, + }) = _SpotifySectionPlaylist; + + factory SpotifySectionPlaylist.fromJson(Map json) => + _$SpotifySectionPlaylistFromJson(json); + + String get id => uri.split(":").last; + + Playlist get asPlaylist { + return Playlist() + ..id = id + ..name = name + ..description = description + ..collaborative = false + ..images = images.map((e) => e.asImage).toList() + ..owner = (User()..displayName = "Spotify") + ..uri = uri + ..type = "playlist"; + } +} + +@freezed +class SpotifySectionArtist with _$SpotifySectionArtist { + const SpotifySectionArtist._(); + + const factory SpotifySectionArtist({ + required String name, + required String uri, + required List images, + }) = _SpotifySectionArtist; + + factory SpotifySectionArtist.fromJson(Map json) => + _$SpotifySectionArtistFromJson(json); + + String get id => uri.split(":").last; + + Artist get asArtist { + return Artist() + ..id = id + ..name = name + ..images = images.map((e) => e.asImage).toList() + ..type = "artist" + ..uri = uri; + } +} + +@freezed +class SpotifySectionAlbum with _$SpotifySectionAlbum { + const SpotifySectionAlbum._(); + + const factory SpotifySectionAlbum({ + required List artists, + required List images, + required String name, + required String uri, + }) = _SpotifySectionAlbum; + + factory SpotifySectionAlbum.fromJson(Map json) => + _$SpotifySectionAlbumFromJson(json); + + String get id => uri.split(":").last; + + Album get asAlbum { + return Album() + ..id = id + ..name = name + ..artists = artists.map((a) => a.asArtist).toList() + ..albumType = AlbumType.album + ..images = images.map((e) => e.asImage).toList() + ..uri = uri; + } +} + +@freezed +class SpotifySectionAlbumArtist with _$SpotifySectionAlbumArtist { + const SpotifySectionAlbumArtist._(); + + const factory SpotifySectionAlbumArtist({ + required String name, + required String uri, + }) = _SpotifySectionAlbumArtist; + + factory SpotifySectionAlbumArtist.fromJson(Map json) => + _$SpotifySectionAlbumArtistFromJson(json); + + String get id => uri.split(":").last; + + Artist get asArtist { + return Artist() + ..id = id + ..name = name + ..type = "artist" + ..uri = uri; + } +} + +@freezed +class SpotifySectionItemImage with _$SpotifySectionItemImage { + const SpotifySectionItemImage._(); + + const factory SpotifySectionItemImage({ + required num? height, + required String url, + required num? width, + }) = _SpotifySectionItemImage; + + factory SpotifySectionItemImage.fromJson(Map json) => + _$SpotifySectionItemImageFromJson(json); + + Image get asImage { + return Image() + ..height = height?.toInt() + ..width = width?.toInt() + ..url = url; + } +} + +@freezed +class SpotifyHomeFeedSectionItem with _$SpotifyHomeFeedSectionItem { + factory SpotifyHomeFeedSectionItem({ + required String typename, + SpotifySectionPlaylist? playlist, + SpotifySectionArtist? artist, + SpotifySectionAlbum? album, + }) = _SpotifyHomeFeedSectionItem; + + factory SpotifyHomeFeedSectionItem.fromJson(Map json) => + _$SpotifyHomeFeedSectionItemFromJson(json); +} + +@freezed +class SpotifyHomeFeedSection with _$SpotifyHomeFeedSection { + factory SpotifyHomeFeedSection({ + required String typename, + String? title, + required String uri, + required List items, + }) = _SpotifyHomeFeedSection; + + factory SpotifyHomeFeedSection.fromJson(Map json) => + _$SpotifyHomeFeedSectionFromJson(json); +} + +@freezed +class SpotifyHomeFeed with _$SpotifyHomeFeed { + factory SpotifyHomeFeed({ + required String greeting, + required List sections, + }) = _SpotifyHomeFeed; + + factory SpotifyHomeFeed.fromJson(Map json) => + _$SpotifyHomeFeedFromJson(json); +} + +Map transformSectionItemTypeJsonMap( + Map json) { + final data = json["content"]["data"]; + final objType = json["content"]["data"]["__typename"]; + return { + "typename": json["content"]["__typename"], + if (objType == "Playlist") + "playlist": { + "name": data["name"], + "description": data["description"], + "format": data["format"], + "images": (data["images"]["items"] as List) + .expand((j) => j["sources"] as dynamic) + .toList() + .cast>(), + "owner": data["ownerV2"]["data"]["name"], + "uri": data["uri"] + }, + if (objType == "Artist") + "artist": { + "name": data["profile"]["name"], + "uri": data["uri"], + "images": data["visuals"]["avatarImage"]["sources"], + }, + if (objType == "Album") + "album": { + "name": data["name"], + "uri": data["uri"], + "images": data["coverArt"]["sources"], + "artists": data["artists"]["items"] + .map( + (artist) => { + "name": artist["profile"]["name"], + "uri": artist["uri"], + }, + ) + .toList() + }, + }; +} + +Map transformSectionItemJsonMap(Map json) { + return { + "typename": json["data"]["__typename"], + "title": json["data"]?["title"]?["text"], + "uri": json["uri"], + "items": (json["sectionItems"]["items"] as List) + .map( + (data) => + transformSectionItemTypeJsonMap(data as Map) + as dynamic, + ) + .where( + (w) => + w["playlist"] != null || + w["artist"] != null || + w["album"] != null, + ) + .toList() + .cast>() + }; +} + +Map transformHomeFeedJsonMap(Map json) { + return { + "greeting": json["data"]["home"]["greeting"]["text"], + "sections": + (json["data"]["home"]["sectionContainer"]["sections"]["items"] as List) + .map( + (item) => + transformSectionItemJsonMap(item as Map) + as dynamic, + ) + .toList() + .cast>() + }; +} diff --git a/lib/models/spotify/home_feed.freezed.dart b/lib/models/spotify/home_feed.freezed.dart new file mode 100644 index 00000000..97c4ffc7 --- /dev/null +++ b/lib/models/spotify/home_feed.freezed.dart @@ -0,0 +1,1666 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'home_feed.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +SpotifySectionPlaylist _$SpotifySectionPlaylistFromJson( + Map json) { + return _SpotifySectionPlaylist.fromJson(json); +} + +/// @nodoc +mixin _$SpotifySectionPlaylist { + String get description => throw _privateConstructorUsedError; + String get format => throw _privateConstructorUsedError; + List get images => + throw _privateConstructorUsedError; + String get name => throw _privateConstructorUsedError; + String get owner => throw _privateConstructorUsedError; + String get uri => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $SpotifySectionPlaylistCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $SpotifySectionPlaylistCopyWith<$Res> { + factory $SpotifySectionPlaylistCopyWith(SpotifySectionPlaylist value, + $Res Function(SpotifySectionPlaylist) then) = + _$SpotifySectionPlaylistCopyWithImpl<$Res, SpotifySectionPlaylist>; + @useResult + $Res call( + {String description, + String format, + List images, + String name, + String owner, + String uri}); +} + +/// @nodoc +class _$SpotifySectionPlaylistCopyWithImpl<$Res, + $Val extends SpotifySectionPlaylist> + implements $SpotifySectionPlaylistCopyWith<$Res> { + _$SpotifySectionPlaylistCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? description = null, + Object? format = null, + Object? images = null, + Object? name = null, + Object? owner = null, + Object? uri = null, + }) { + return _then(_value.copyWith( + description: null == description + ? _value.description + : description // ignore: cast_nullable_to_non_nullable + as String, + format: null == format + ? _value.format + : format // ignore: cast_nullable_to_non_nullable + as String, + images: null == images + ? _value.images + : images // ignore: cast_nullable_to_non_nullable + as List, + name: null == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String, + owner: null == owner + ? _value.owner + : owner // ignore: cast_nullable_to_non_nullable + as String, + uri: null == uri + ? _value.uri + : uri // ignore: cast_nullable_to_non_nullable + as String, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$SpotifySectionPlaylistImplCopyWith<$Res> + implements $SpotifySectionPlaylistCopyWith<$Res> { + factory _$$SpotifySectionPlaylistImplCopyWith( + _$SpotifySectionPlaylistImpl value, + $Res Function(_$SpotifySectionPlaylistImpl) then) = + __$$SpotifySectionPlaylistImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {String description, + String format, + List images, + String name, + String owner, + String uri}); +} + +/// @nodoc +class __$$SpotifySectionPlaylistImplCopyWithImpl<$Res> + extends _$SpotifySectionPlaylistCopyWithImpl<$Res, + _$SpotifySectionPlaylistImpl> + implements _$$SpotifySectionPlaylistImplCopyWith<$Res> { + __$$SpotifySectionPlaylistImplCopyWithImpl( + _$SpotifySectionPlaylistImpl _value, + $Res Function(_$SpotifySectionPlaylistImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? description = null, + Object? format = null, + Object? images = null, + Object? name = null, + Object? owner = null, + Object? uri = null, + }) { + return _then(_$SpotifySectionPlaylistImpl( + description: null == description + ? _value.description + : description // ignore: cast_nullable_to_non_nullable + as String, + format: null == format + ? _value.format + : format // ignore: cast_nullable_to_non_nullable + as String, + images: null == images + ? _value._images + : images // ignore: cast_nullable_to_non_nullable + as List, + name: null == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String, + owner: null == owner + ? _value.owner + : owner // ignore: cast_nullable_to_non_nullable + as String, + uri: null == uri + ? _value.uri + : uri // ignore: cast_nullable_to_non_nullable + as String, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$SpotifySectionPlaylistImpl extends _SpotifySectionPlaylist { + const _$SpotifySectionPlaylistImpl( + {required this.description, + required this.format, + required final List images, + required this.name, + required this.owner, + required this.uri}) + : _images = images, + super._(); + + factory _$SpotifySectionPlaylistImpl.fromJson(Map json) => + _$$SpotifySectionPlaylistImplFromJson(json); + + @override + final String description; + @override + final String format; + final List _images; + @override + List get images { + if (_images is EqualUnmodifiableListView) return _images; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_images); + } + + @override + final String name; + @override + final String owner; + @override + final String uri; + + @override + String toString() { + return 'SpotifySectionPlaylist(description: $description, format: $format, images: $images, name: $name, owner: $owner, uri: $uri)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$SpotifySectionPlaylistImpl && + (identical(other.description, description) || + other.description == description) && + (identical(other.format, format) || other.format == format) && + const DeepCollectionEquality().equals(other._images, _images) && + (identical(other.name, name) || other.name == name) && + (identical(other.owner, owner) || other.owner == owner) && + (identical(other.uri, uri) || other.uri == uri)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash(runtimeType, description, format, + const DeepCollectionEquality().hash(_images), name, owner, uri); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$SpotifySectionPlaylistImplCopyWith<_$SpotifySectionPlaylistImpl> + get copyWith => __$$SpotifySectionPlaylistImplCopyWithImpl< + _$SpotifySectionPlaylistImpl>(this, _$identity); + + @override + Map toJson() { + return _$$SpotifySectionPlaylistImplToJson( + this, + ); + } +} + +abstract class _SpotifySectionPlaylist extends SpotifySectionPlaylist { + const factory _SpotifySectionPlaylist( + {required final String description, + required final String format, + required final List images, + required final String name, + required final String owner, + required final String uri}) = _$SpotifySectionPlaylistImpl; + const _SpotifySectionPlaylist._() : super._(); + + factory _SpotifySectionPlaylist.fromJson(Map json) = + _$SpotifySectionPlaylistImpl.fromJson; + + @override + String get description; + @override + String get format; + @override + List get images; + @override + String get name; + @override + String get owner; + @override + String get uri; + @override + @JsonKey(ignore: true) + _$$SpotifySectionPlaylistImplCopyWith<_$SpotifySectionPlaylistImpl> + get copyWith => throw _privateConstructorUsedError; +} + +SpotifySectionArtist _$SpotifySectionArtistFromJson(Map json) { + return _SpotifySectionArtist.fromJson(json); +} + +/// @nodoc +mixin _$SpotifySectionArtist { + String get name => throw _privateConstructorUsedError; + String get uri => throw _privateConstructorUsedError; + List get images => + throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $SpotifySectionArtistCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $SpotifySectionArtistCopyWith<$Res> { + factory $SpotifySectionArtistCopyWith(SpotifySectionArtist value, + $Res Function(SpotifySectionArtist) then) = + _$SpotifySectionArtistCopyWithImpl<$Res, SpotifySectionArtist>; + @useResult + $Res call({String name, String uri, List images}); +} + +/// @nodoc +class _$SpotifySectionArtistCopyWithImpl<$Res, + $Val extends SpotifySectionArtist> + implements $SpotifySectionArtistCopyWith<$Res> { + _$SpotifySectionArtistCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? name = null, + Object? uri = null, + Object? images = null, + }) { + return _then(_value.copyWith( + name: null == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String, + uri: null == uri + ? _value.uri + : uri // ignore: cast_nullable_to_non_nullable + as String, + images: null == images + ? _value.images + : images // ignore: cast_nullable_to_non_nullable + as List, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$SpotifySectionArtistImplCopyWith<$Res> + implements $SpotifySectionArtistCopyWith<$Res> { + factory _$$SpotifySectionArtistImplCopyWith(_$SpotifySectionArtistImpl value, + $Res Function(_$SpotifySectionArtistImpl) then) = + __$$SpotifySectionArtistImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({String name, String uri, List images}); +} + +/// @nodoc +class __$$SpotifySectionArtistImplCopyWithImpl<$Res> + extends _$SpotifySectionArtistCopyWithImpl<$Res, _$SpotifySectionArtistImpl> + implements _$$SpotifySectionArtistImplCopyWith<$Res> { + __$$SpotifySectionArtistImplCopyWithImpl(_$SpotifySectionArtistImpl _value, + $Res Function(_$SpotifySectionArtistImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? name = null, + Object? uri = null, + Object? images = null, + }) { + return _then(_$SpotifySectionArtistImpl( + name: null == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String, + uri: null == uri + ? _value.uri + : uri // ignore: cast_nullable_to_non_nullable + as String, + images: null == images + ? _value._images + : images // ignore: cast_nullable_to_non_nullable + as List, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$SpotifySectionArtistImpl extends _SpotifySectionArtist { + const _$SpotifySectionArtistImpl( + {required this.name, + required this.uri, + required final List images}) + : _images = images, + super._(); + + factory _$SpotifySectionArtistImpl.fromJson(Map json) => + _$$SpotifySectionArtistImplFromJson(json); + + @override + final String name; + @override + final String uri; + final List _images; + @override + List get images { + if (_images is EqualUnmodifiableListView) return _images; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_images); + } + + @override + String toString() { + return 'SpotifySectionArtist(name: $name, uri: $uri, images: $images)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$SpotifySectionArtistImpl && + (identical(other.name, name) || other.name == name) && + (identical(other.uri, uri) || other.uri == uri) && + const DeepCollectionEquality().equals(other._images, _images)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash( + runtimeType, name, uri, const DeepCollectionEquality().hash(_images)); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$SpotifySectionArtistImplCopyWith<_$SpotifySectionArtistImpl> + get copyWith => + __$$SpotifySectionArtistImplCopyWithImpl<_$SpotifySectionArtistImpl>( + this, _$identity); + + @override + Map toJson() { + return _$$SpotifySectionArtistImplToJson( + this, + ); + } +} + +abstract class _SpotifySectionArtist extends SpotifySectionArtist { + const factory _SpotifySectionArtist( + {required final String name, + required final String uri, + required final List images}) = + _$SpotifySectionArtistImpl; + const _SpotifySectionArtist._() : super._(); + + factory _SpotifySectionArtist.fromJson(Map json) = + _$SpotifySectionArtistImpl.fromJson; + + @override + String get name; + @override + String get uri; + @override + List get images; + @override + @JsonKey(ignore: true) + _$$SpotifySectionArtistImplCopyWith<_$SpotifySectionArtistImpl> + get copyWith => throw _privateConstructorUsedError; +} + +SpotifySectionAlbum _$SpotifySectionAlbumFromJson(Map json) { + return _SpotifySectionAlbum.fromJson(json); +} + +/// @nodoc +mixin _$SpotifySectionAlbum { + List get artists => + throw _privateConstructorUsedError; + List get images => + throw _privateConstructorUsedError; + String get name => throw _privateConstructorUsedError; + String get uri => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $SpotifySectionAlbumCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $SpotifySectionAlbumCopyWith<$Res> { + factory $SpotifySectionAlbumCopyWith( + SpotifySectionAlbum value, $Res Function(SpotifySectionAlbum) then) = + _$SpotifySectionAlbumCopyWithImpl<$Res, SpotifySectionAlbum>; + @useResult + $Res call( + {List artists, + List images, + String name, + String uri}); +} + +/// @nodoc +class _$SpotifySectionAlbumCopyWithImpl<$Res, $Val extends SpotifySectionAlbum> + implements $SpotifySectionAlbumCopyWith<$Res> { + _$SpotifySectionAlbumCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? artists = null, + Object? images = null, + Object? name = null, + Object? uri = null, + }) { + return _then(_value.copyWith( + artists: null == artists + ? _value.artists + : artists // ignore: cast_nullable_to_non_nullable + as List, + images: null == images + ? _value.images + : images // ignore: cast_nullable_to_non_nullable + as List, + name: null == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String, + uri: null == uri + ? _value.uri + : uri // ignore: cast_nullable_to_non_nullable + as String, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$SpotifySectionAlbumImplCopyWith<$Res> + implements $SpotifySectionAlbumCopyWith<$Res> { + factory _$$SpotifySectionAlbumImplCopyWith(_$SpotifySectionAlbumImpl value, + $Res Function(_$SpotifySectionAlbumImpl) then) = + __$$SpotifySectionAlbumImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {List artists, + List images, + String name, + String uri}); +} + +/// @nodoc +class __$$SpotifySectionAlbumImplCopyWithImpl<$Res> + extends _$SpotifySectionAlbumCopyWithImpl<$Res, _$SpotifySectionAlbumImpl> + implements _$$SpotifySectionAlbumImplCopyWith<$Res> { + __$$SpotifySectionAlbumImplCopyWithImpl(_$SpotifySectionAlbumImpl _value, + $Res Function(_$SpotifySectionAlbumImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? artists = null, + Object? images = null, + Object? name = null, + Object? uri = null, + }) { + return _then(_$SpotifySectionAlbumImpl( + artists: null == artists + ? _value._artists + : artists // ignore: cast_nullable_to_non_nullable + as List, + images: null == images + ? _value._images + : images // ignore: cast_nullable_to_non_nullable + as List, + name: null == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String, + uri: null == uri + ? _value.uri + : uri // ignore: cast_nullable_to_non_nullable + as String, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$SpotifySectionAlbumImpl extends _SpotifySectionAlbum { + const _$SpotifySectionAlbumImpl( + {required final List artists, + required final List images, + required this.name, + required this.uri}) + : _artists = artists, + _images = images, + super._(); + + factory _$SpotifySectionAlbumImpl.fromJson(Map json) => + _$$SpotifySectionAlbumImplFromJson(json); + + final List _artists; + @override + List get artists { + if (_artists is EqualUnmodifiableListView) return _artists; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_artists); + } + + final List _images; + @override + List get images { + if (_images is EqualUnmodifiableListView) return _images; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_images); + } + + @override + final String name; + @override + final String uri; + + @override + String toString() { + return 'SpotifySectionAlbum(artists: $artists, images: $images, name: $name, uri: $uri)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$SpotifySectionAlbumImpl && + const DeepCollectionEquality().equals(other._artists, _artists) && + const DeepCollectionEquality().equals(other._images, _images) && + (identical(other.name, name) || other.name == name) && + (identical(other.uri, uri) || other.uri == uri)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash( + runtimeType, + const DeepCollectionEquality().hash(_artists), + const DeepCollectionEquality().hash(_images), + name, + uri); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$SpotifySectionAlbumImplCopyWith<_$SpotifySectionAlbumImpl> get copyWith => + __$$SpotifySectionAlbumImplCopyWithImpl<_$SpotifySectionAlbumImpl>( + this, _$identity); + + @override + Map toJson() { + return _$$SpotifySectionAlbumImplToJson( + this, + ); + } +} + +abstract class _SpotifySectionAlbum extends SpotifySectionAlbum { + const factory _SpotifySectionAlbum( + {required final List artists, + required final List images, + required final String name, + required final String uri}) = _$SpotifySectionAlbumImpl; + const _SpotifySectionAlbum._() : super._(); + + factory _SpotifySectionAlbum.fromJson(Map json) = + _$SpotifySectionAlbumImpl.fromJson; + + @override + List get artists; + @override + List get images; + @override + String get name; + @override + String get uri; + @override + @JsonKey(ignore: true) + _$$SpotifySectionAlbumImplCopyWith<_$SpotifySectionAlbumImpl> get copyWith => + throw _privateConstructorUsedError; +} + +SpotifySectionAlbumArtist _$SpotifySectionAlbumArtistFromJson( + Map json) { + return _SpotifySectionAlbumArtist.fromJson(json); +} + +/// @nodoc +mixin _$SpotifySectionAlbumArtist { + String get name => throw _privateConstructorUsedError; + String get uri => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $SpotifySectionAlbumArtistCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $SpotifySectionAlbumArtistCopyWith<$Res> { + factory $SpotifySectionAlbumArtistCopyWith(SpotifySectionAlbumArtist value, + $Res Function(SpotifySectionAlbumArtist) then) = + _$SpotifySectionAlbumArtistCopyWithImpl<$Res, SpotifySectionAlbumArtist>; + @useResult + $Res call({String name, String uri}); +} + +/// @nodoc +class _$SpotifySectionAlbumArtistCopyWithImpl<$Res, + $Val extends SpotifySectionAlbumArtist> + implements $SpotifySectionAlbumArtistCopyWith<$Res> { + _$SpotifySectionAlbumArtistCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? name = null, + Object? uri = null, + }) { + return _then(_value.copyWith( + name: null == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String, + uri: null == uri + ? _value.uri + : uri // ignore: cast_nullable_to_non_nullable + as String, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$SpotifySectionAlbumArtistImplCopyWith<$Res> + implements $SpotifySectionAlbumArtistCopyWith<$Res> { + factory _$$SpotifySectionAlbumArtistImplCopyWith( + _$SpotifySectionAlbumArtistImpl value, + $Res Function(_$SpotifySectionAlbumArtistImpl) then) = + __$$SpotifySectionAlbumArtistImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({String name, String uri}); +} + +/// @nodoc +class __$$SpotifySectionAlbumArtistImplCopyWithImpl<$Res> + extends _$SpotifySectionAlbumArtistCopyWithImpl<$Res, + _$SpotifySectionAlbumArtistImpl> + implements _$$SpotifySectionAlbumArtistImplCopyWith<$Res> { + __$$SpotifySectionAlbumArtistImplCopyWithImpl( + _$SpotifySectionAlbumArtistImpl _value, + $Res Function(_$SpotifySectionAlbumArtistImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? name = null, + Object? uri = null, + }) { + return _then(_$SpotifySectionAlbumArtistImpl( + name: null == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String, + uri: null == uri + ? _value.uri + : uri // ignore: cast_nullable_to_non_nullable + as String, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$SpotifySectionAlbumArtistImpl extends _SpotifySectionAlbumArtist { + const _$SpotifySectionAlbumArtistImpl({required this.name, required this.uri}) + : super._(); + + factory _$SpotifySectionAlbumArtistImpl.fromJson(Map json) => + _$$SpotifySectionAlbumArtistImplFromJson(json); + + @override + final String name; + @override + final String uri; + + @override + String toString() { + return 'SpotifySectionAlbumArtist(name: $name, uri: $uri)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$SpotifySectionAlbumArtistImpl && + (identical(other.name, name) || other.name == name) && + (identical(other.uri, uri) || other.uri == uri)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash(runtimeType, name, uri); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$SpotifySectionAlbumArtistImplCopyWith<_$SpotifySectionAlbumArtistImpl> + get copyWith => __$$SpotifySectionAlbumArtistImplCopyWithImpl< + _$SpotifySectionAlbumArtistImpl>(this, _$identity); + + @override + Map toJson() { + return _$$SpotifySectionAlbumArtistImplToJson( + this, + ); + } +} + +abstract class _SpotifySectionAlbumArtist extends SpotifySectionAlbumArtist { + const factory _SpotifySectionAlbumArtist( + {required final String name, + required final String uri}) = _$SpotifySectionAlbumArtistImpl; + const _SpotifySectionAlbumArtist._() : super._(); + + factory _SpotifySectionAlbumArtist.fromJson(Map json) = + _$SpotifySectionAlbumArtistImpl.fromJson; + + @override + String get name; + @override + String get uri; + @override + @JsonKey(ignore: true) + _$$SpotifySectionAlbumArtistImplCopyWith<_$SpotifySectionAlbumArtistImpl> + get copyWith => throw _privateConstructorUsedError; +} + +SpotifySectionItemImage _$SpotifySectionItemImageFromJson( + Map json) { + return _SpotifySectionItemImage.fromJson(json); +} + +/// @nodoc +mixin _$SpotifySectionItemImage { + num? get height => throw _privateConstructorUsedError; + String get url => throw _privateConstructorUsedError; + num? get width => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $SpotifySectionItemImageCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $SpotifySectionItemImageCopyWith<$Res> { + factory $SpotifySectionItemImageCopyWith(SpotifySectionItemImage value, + $Res Function(SpotifySectionItemImage) then) = + _$SpotifySectionItemImageCopyWithImpl<$Res, SpotifySectionItemImage>; + @useResult + $Res call({num? height, String url, num? width}); +} + +/// @nodoc +class _$SpotifySectionItemImageCopyWithImpl<$Res, + $Val extends SpotifySectionItemImage> + implements $SpotifySectionItemImageCopyWith<$Res> { + _$SpotifySectionItemImageCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? height = freezed, + Object? url = null, + Object? width = freezed, + }) { + return _then(_value.copyWith( + height: freezed == height + ? _value.height + : height // ignore: cast_nullable_to_non_nullable + as num?, + url: null == url + ? _value.url + : url // ignore: cast_nullable_to_non_nullable + as String, + width: freezed == width + ? _value.width + : width // ignore: cast_nullable_to_non_nullable + as num?, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$SpotifySectionItemImageImplCopyWith<$Res> + implements $SpotifySectionItemImageCopyWith<$Res> { + factory _$$SpotifySectionItemImageImplCopyWith( + _$SpotifySectionItemImageImpl value, + $Res Function(_$SpotifySectionItemImageImpl) then) = + __$$SpotifySectionItemImageImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({num? height, String url, num? width}); +} + +/// @nodoc +class __$$SpotifySectionItemImageImplCopyWithImpl<$Res> + extends _$SpotifySectionItemImageCopyWithImpl<$Res, + _$SpotifySectionItemImageImpl> + implements _$$SpotifySectionItemImageImplCopyWith<$Res> { + __$$SpotifySectionItemImageImplCopyWithImpl( + _$SpotifySectionItemImageImpl _value, + $Res Function(_$SpotifySectionItemImageImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? height = freezed, + Object? url = null, + Object? width = freezed, + }) { + return _then(_$SpotifySectionItemImageImpl( + height: freezed == height + ? _value.height + : height // ignore: cast_nullable_to_non_nullable + as num?, + url: null == url + ? _value.url + : url // ignore: cast_nullable_to_non_nullable + as String, + width: freezed == width + ? _value.width + : width // ignore: cast_nullable_to_non_nullable + as num?, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$SpotifySectionItemImageImpl extends _SpotifySectionItemImage { + const _$SpotifySectionItemImageImpl( + {required this.height, required this.url, required this.width}) + : super._(); + + factory _$SpotifySectionItemImageImpl.fromJson(Map json) => + _$$SpotifySectionItemImageImplFromJson(json); + + @override + final num? height; + @override + final String url; + @override + final num? width; + + @override + String toString() { + return 'SpotifySectionItemImage(height: $height, url: $url, width: $width)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$SpotifySectionItemImageImpl && + (identical(other.height, height) || other.height == height) && + (identical(other.url, url) || other.url == url) && + (identical(other.width, width) || other.width == width)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash(runtimeType, height, url, width); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$SpotifySectionItemImageImplCopyWith<_$SpotifySectionItemImageImpl> + get copyWith => __$$SpotifySectionItemImageImplCopyWithImpl< + _$SpotifySectionItemImageImpl>(this, _$identity); + + @override + Map toJson() { + return _$$SpotifySectionItemImageImplToJson( + this, + ); + } +} + +abstract class _SpotifySectionItemImage extends SpotifySectionItemImage { + const factory _SpotifySectionItemImage( + {required final num? height, + required final String url, + required final num? width}) = _$SpotifySectionItemImageImpl; + const _SpotifySectionItemImage._() : super._(); + + factory _SpotifySectionItemImage.fromJson(Map json) = + _$SpotifySectionItemImageImpl.fromJson; + + @override + num? get height; + @override + String get url; + @override + num? get width; + @override + @JsonKey(ignore: true) + _$$SpotifySectionItemImageImplCopyWith<_$SpotifySectionItemImageImpl> + get copyWith => throw _privateConstructorUsedError; +} + +SpotifyHomeFeedSectionItem _$SpotifyHomeFeedSectionItemFromJson( + Map json) { + return _SpotifyHomeFeedSectionItem.fromJson(json); +} + +/// @nodoc +mixin _$SpotifyHomeFeedSectionItem { + String get typename => throw _privateConstructorUsedError; + SpotifySectionPlaylist? get playlist => throw _privateConstructorUsedError; + SpotifySectionArtist? get artist => throw _privateConstructorUsedError; + SpotifySectionAlbum? get album => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $SpotifyHomeFeedSectionItemCopyWith + get copyWith => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $SpotifyHomeFeedSectionItemCopyWith<$Res> { + factory $SpotifyHomeFeedSectionItemCopyWith(SpotifyHomeFeedSectionItem value, + $Res Function(SpotifyHomeFeedSectionItem) then) = + _$SpotifyHomeFeedSectionItemCopyWithImpl<$Res, + SpotifyHomeFeedSectionItem>; + @useResult + $Res call( + {String typename, + SpotifySectionPlaylist? playlist, + SpotifySectionArtist? artist, + SpotifySectionAlbum? album}); + + $SpotifySectionPlaylistCopyWith<$Res>? get playlist; + $SpotifySectionArtistCopyWith<$Res>? get artist; + $SpotifySectionAlbumCopyWith<$Res>? get album; +} + +/// @nodoc +class _$SpotifyHomeFeedSectionItemCopyWithImpl<$Res, + $Val extends SpotifyHomeFeedSectionItem> + implements $SpotifyHomeFeedSectionItemCopyWith<$Res> { + _$SpotifyHomeFeedSectionItemCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? typename = null, + Object? playlist = freezed, + Object? artist = freezed, + Object? album = freezed, + }) { + return _then(_value.copyWith( + typename: null == typename + ? _value.typename + : typename // ignore: cast_nullable_to_non_nullable + as String, + playlist: freezed == playlist + ? _value.playlist + : playlist // ignore: cast_nullable_to_non_nullable + as SpotifySectionPlaylist?, + artist: freezed == artist + ? _value.artist + : artist // ignore: cast_nullable_to_non_nullable + as SpotifySectionArtist?, + album: freezed == album + ? _value.album + : album // ignore: cast_nullable_to_non_nullable + as SpotifySectionAlbum?, + ) as $Val); + } + + @override + @pragma('vm:prefer-inline') + $SpotifySectionPlaylistCopyWith<$Res>? get playlist { + if (_value.playlist == null) { + return null; + } + + return $SpotifySectionPlaylistCopyWith<$Res>(_value.playlist!, (value) { + return _then(_value.copyWith(playlist: value) as $Val); + }); + } + + @override + @pragma('vm:prefer-inline') + $SpotifySectionArtistCopyWith<$Res>? get artist { + if (_value.artist == null) { + return null; + } + + return $SpotifySectionArtistCopyWith<$Res>(_value.artist!, (value) { + return _then(_value.copyWith(artist: value) as $Val); + }); + } + + @override + @pragma('vm:prefer-inline') + $SpotifySectionAlbumCopyWith<$Res>? get album { + if (_value.album == null) { + return null; + } + + return $SpotifySectionAlbumCopyWith<$Res>(_value.album!, (value) { + return _then(_value.copyWith(album: value) as $Val); + }); + } +} + +/// @nodoc +abstract class _$$SpotifyHomeFeedSectionItemImplCopyWith<$Res> + implements $SpotifyHomeFeedSectionItemCopyWith<$Res> { + factory _$$SpotifyHomeFeedSectionItemImplCopyWith( + _$SpotifyHomeFeedSectionItemImpl value, + $Res Function(_$SpotifyHomeFeedSectionItemImpl) then) = + __$$SpotifyHomeFeedSectionItemImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {String typename, + SpotifySectionPlaylist? playlist, + SpotifySectionArtist? artist, + SpotifySectionAlbum? album}); + + @override + $SpotifySectionPlaylistCopyWith<$Res>? get playlist; + @override + $SpotifySectionArtistCopyWith<$Res>? get artist; + @override + $SpotifySectionAlbumCopyWith<$Res>? get album; +} + +/// @nodoc +class __$$SpotifyHomeFeedSectionItemImplCopyWithImpl<$Res> + extends _$SpotifyHomeFeedSectionItemCopyWithImpl<$Res, + _$SpotifyHomeFeedSectionItemImpl> + implements _$$SpotifyHomeFeedSectionItemImplCopyWith<$Res> { + __$$SpotifyHomeFeedSectionItemImplCopyWithImpl( + _$SpotifyHomeFeedSectionItemImpl _value, + $Res Function(_$SpotifyHomeFeedSectionItemImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? typename = null, + Object? playlist = freezed, + Object? artist = freezed, + Object? album = freezed, + }) { + return _then(_$SpotifyHomeFeedSectionItemImpl( + typename: null == typename + ? _value.typename + : typename // ignore: cast_nullable_to_non_nullable + as String, + playlist: freezed == playlist + ? _value.playlist + : playlist // ignore: cast_nullable_to_non_nullable + as SpotifySectionPlaylist?, + artist: freezed == artist + ? _value.artist + : artist // ignore: cast_nullable_to_non_nullable + as SpotifySectionArtist?, + album: freezed == album + ? _value.album + : album // ignore: cast_nullable_to_non_nullable + as SpotifySectionAlbum?, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$SpotifyHomeFeedSectionItemImpl implements _SpotifyHomeFeedSectionItem { + _$SpotifyHomeFeedSectionItemImpl( + {required this.typename, this.playlist, this.artist, this.album}); + + factory _$SpotifyHomeFeedSectionItemImpl.fromJson( + Map json) => + _$$SpotifyHomeFeedSectionItemImplFromJson(json); + + @override + final String typename; + @override + final SpotifySectionPlaylist? playlist; + @override + final SpotifySectionArtist? artist; + @override + final SpotifySectionAlbum? album; + + @override + String toString() { + return 'SpotifyHomeFeedSectionItem(typename: $typename, playlist: $playlist, artist: $artist, album: $album)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$SpotifyHomeFeedSectionItemImpl && + (identical(other.typename, typename) || + other.typename == typename) && + (identical(other.playlist, playlist) || + other.playlist == playlist) && + (identical(other.artist, artist) || other.artist == artist) && + (identical(other.album, album) || other.album == album)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => + Object.hash(runtimeType, typename, playlist, artist, album); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$SpotifyHomeFeedSectionItemImplCopyWith<_$SpotifyHomeFeedSectionItemImpl> + get copyWith => __$$SpotifyHomeFeedSectionItemImplCopyWithImpl< + _$SpotifyHomeFeedSectionItemImpl>(this, _$identity); + + @override + Map toJson() { + return _$$SpotifyHomeFeedSectionItemImplToJson( + this, + ); + } +} + +abstract class _SpotifyHomeFeedSectionItem + implements SpotifyHomeFeedSectionItem { + factory _SpotifyHomeFeedSectionItem( + {required final String typename, + final SpotifySectionPlaylist? playlist, + final SpotifySectionArtist? artist, + final SpotifySectionAlbum? album}) = _$SpotifyHomeFeedSectionItemImpl; + + factory _SpotifyHomeFeedSectionItem.fromJson(Map json) = + _$SpotifyHomeFeedSectionItemImpl.fromJson; + + @override + String get typename; + @override + SpotifySectionPlaylist? get playlist; + @override + SpotifySectionArtist? get artist; + @override + SpotifySectionAlbum? get album; + @override + @JsonKey(ignore: true) + _$$SpotifyHomeFeedSectionItemImplCopyWith<_$SpotifyHomeFeedSectionItemImpl> + get copyWith => throw _privateConstructorUsedError; +} + +SpotifyHomeFeedSection _$SpotifyHomeFeedSectionFromJson( + Map json) { + return _SpotifyHomeFeedSection.fromJson(json); +} + +/// @nodoc +mixin _$SpotifyHomeFeedSection { + String get typename => throw _privateConstructorUsedError; + String? get title => throw _privateConstructorUsedError; + String get uri => throw _privateConstructorUsedError; + List get items => + throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $SpotifyHomeFeedSectionCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $SpotifyHomeFeedSectionCopyWith<$Res> { + factory $SpotifyHomeFeedSectionCopyWith(SpotifyHomeFeedSection value, + $Res Function(SpotifyHomeFeedSection) then) = + _$SpotifyHomeFeedSectionCopyWithImpl<$Res, SpotifyHomeFeedSection>; + @useResult + $Res call( + {String typename, + String? title, + String uri, + List items}); +} + +/// @nodoc +class _$SpotifyHomeFeedSectionCopyWithImpl<$Res, + $Val extends SpotifyHomeFeedSection> + implements $SpotifyHomeFeedSectionCopyWith<$Res> { + _$SpotifyHomeFeedSectionCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? typename = null, + Object? title = freezed, + Object? uri = null, + Object? items = null, + }) { + return _then(_value.copyWith( + typename: null == typename + ? _value.typename + : typename // ignore: cast_nullable_to_non_nullable + as String, + title: freezed == title + ? _value.title + : title // ignore: cast_nullable_to_non_nullable + as String?, + uri: null == uri + ? _value.uri + : uri // ignore: cast_nullable_to_non_nullable + as String, + items: null == items + ? _value.items + : items // ignore: cast_nullable_to_non_nullable + as List, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$SpotifyHomeFeedSectionImplCopyWith<$Res> + implements $SpotifyHomeFeedSectionCopyWith<$Res> { + factory _$$SpotifyHomeFeedSectionImplCopyWith( + _$SpotifyHomeFeedSectionImpl value, + $Res Function(_$SpotifyHomeFeedSectionImpl) then) = + __$$SpotifyHomeFeedSectionImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {String typename, + String? title, + String uri, + List items}); +} + +/// @nodoc +class __$$SpotifyHomeFeedSectionImplCopyWithImpl<$Res> + extends _$SpotifyHomeFeedSectionCopyWithImpl<$Res, + _$SpotifyHomeFeedSectionImpl> + implements _$$SpotifyHomeFeedSectionImplCopyWith<$Res> { + __$$SpotifyHomeFeedSectionImplCopyWithImpl( + _$SpotifyHomeFeedSectionImpl _value, + $Res Function(_$SpotifyHomeFeedSectionImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? typename = null, + Object? title = freezed, + Object? uri = null, + Object? items = null, + }) { + return _then(_$SpotifyHomeFeedSectionImpl( + typename: null == typename + ? _value.typename + : typename // ignore: cast_nullable_to_non_nullable + as String, + title: freezed == title + ? _value.title + : title // ignore: cast_nullable_to_non_nullable + as String?, + uri: null == uri + ? _value.uri + : uri // ignore: cast_nullable_to_non_nullable + as String, + items: null == items + ? _value._items + : items // ignore: cast_nullable_to_non_nullable + as List, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$SpotifyHomeFeedSectionImpl implements _SpotifyHomeFeedSection { + _$SpotifyHomeFeedSectionImpl( + {required this.typename, + this.title, + required this.uri, + required final List items}) + : _items = items; + + factory _$SpotifyHomeFeedSectionImpl.fromJson(Map json) => + _$$SpotifyHomeFeedSectionImplFromJson(json); + + @override + final String typename; + @override + final String? title; + @override + final String uri; + final List _items; + @override + List get items { + if (_items is EqualUnmodifiableListView) return _items; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_items); + } + + @override + String toString() { + return 'SpotifyHomeFeedSection(typename: $typename, title: $title, uri: $uri, items: $items)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$SpotifyHomeFeedSectionImpl && + (identical(other.typename, typename) || + other.typename == typename) && + (identical(other.title, title) || other.title == title) && + (identical(other.uri, uri) || other.uri == uri) && + const DeepCollectionEquality().equals(other._items, _items)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash(runtimeType, typename, title, uri, + const DeepCollectionEquality().hash(_items)); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$SpotifyHomeFeedSectionImplCopyWith<_$SpotifyHomeFeedSectionImpl> + get copyWith => __$$SpotifyHomeFeedSectionImplCopyWithImpl< + _$SpotifyHomeFeedSectionImpl>(this, _$identity); + + @override + Map toJson() { + return _$$SpotifyHomeFeedSectionImplToJson( + this, + ); + } +} + +abstract class _SpotifyHomeFeedSection implements SpotifyHomeFeedSection { + factory _SpotifyHomeFeedSection( + {required final String typename, + final String? title, + required final String uri, + required final List items}) = + _$SpotifyHomeFeedSectionImpl; + + factory _SpotifyHomeFeedSection.fromJson(Map json) = + _$SpotifyHomeFeedSectionImpl.fromJson; + + @override + String get typename; + @override + String? get title; + @override + String get uri; + @override + List get items; + @override + @JsonKey(ignore: true) + _$$SpotifyHomeFeedSectionImplCopyWith<_$SpotifyHomeFeedSectionImpl> + get copyWith => throw _privateConstructorUsedError; +} + +SpotifyHomeFeed _$SpotifyHomeFeedFromJson(Map json) { + return _SpotifyHomeFeed.fromJson(json); +} + +/// @nodoc +mixin _$SpotifyHomeFeed { + String get greeting => throw _privateConstructorUsedError; + List get sections => + throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $SpotifyHomeFeedCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $SpotifyHomeFeedCopyWith<$Res> { + factory $SpotifyHomeFeedCopyWith( + SpotifyHomeFeed value, $Res Function(SpotifyHomeFeed) then) = + _$SpotifyHomeFeedCopyWithImpl<$Res, SpotifyHomeFeed>; + @useResult + $Res call({String greeting, List sections}); +} + +/// @nodoc +class _$SpotifyHomeFeedCopyWithImpl<$Res, $Val extends SpotifyHomeFeed> + implements $SpotifyHomeFeedCopyWith<$Res> { + _$SpotifyHomeFeedCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? greeting = null, + Object? sections = null, + }) { + return _then(_value.copyWith( + greeting: null == greeting + ? _value.greeting + : greeting // ignore: cast_nullable_to_non_nullable + as String, + sections: null == sections + ? _value.sections + : sections // ignore: cast_nullable_to_non_nullable + as List, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$SpotifyHomeFeedImplCopyWith<$Res> + implements $SpotifyHomeFeedCopyWith<$Res> { + factory _$$SpotifyHomeFeedImplCopyWith(_$SpotifyHomeFeedImpl value, + $Res Function(_$SpotifyHomeFeedImpl) then) = + __$$SpotifyHomeFeedImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({String greeting, List sections}); +} + +/// @nodoc +class __$$SpotifyHomeFeedImplCopyWithImpl<$Res> + extends _$SpotifyHomeFeedCopyWithImpl<$Res, _$SpotifyHomeFeedImpl> + implements _$$SpotifyHomeFeedImplCopyWith<$Res> { + __$$SpotifyHomeFeedImplCopyWithImpl( + _$SpotifyHomeFeedImpl _value, $Res Function(_$SpotifyHomeFeedImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? greeting = null, + Object? sections = null, + }) { + return _then(_$SpotifyHomeFeedImpl( + greeting: null == greeting + ? _value.greeting + : greeting // ignore: cast_nullable_to_non_nullable + as String, + sections: null == sections + ? _value._sections + : sections // ignore: cast_nullable_to_non_nullable + as List, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$SpotifyHomeFeedImpl implements _SpotifyHomeFeed { + _$SpotifyHomeFeedImpl( + {required this.greeting, + required final List sections}) + : _sections = sections; + + factory _$SpotifyHomeFeedImpl.fromJson(Map json) => + _$$SpotifyHomeFeedImplFromJson(json); + + @override + final String greeting; + final List _sections; + @override + List get sections { + if (_sections is EqualUnmodifiableListView) return _sections; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_sections); + } + + @override + String toString() { + return 'SpotifyHomeFeed(greeting: $greeting, sections: $sections)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$SpotifyHomeFeedImpl && + (identical(other.greeting, greeting) || + other.greeting == greeting) && + const DeepCollectionEquality().equals(other._sections, _sections)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash( + runtimeType, greeting, const DeepCollectionEquality().hash(_sections)); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$SpotifyHomeFeedImplCopyWith<_$SpotifyHomeFeedImpl> get copyWith => + __$$SpotifyHomeFeedImplCopyWithImpl<_$SpotifyHomeFeedImpl>( + this, _$identity); + + @override + Map toJson() { + return _$$SpotifyHomeFeedImplToJson( + this, + ); + } +} + +abstract class _SpotifyHomeFeed implements SpotifyHomeFeed { + factory _SpotifyHomeFeed( + {required final String greeting, + required final List sections}) = + _$SpotifyHomeFeedImpl; + + factory _SpotifyHomeFeed.fromJson(Map json) = + _$SpotifyHomeFeedImpl.fromJson; + + @override + String get greeting; + @override + List get sections; + @override + @JsonKey(ignore: true) + _$$SpotifyHomeFeedImplCopyWith<_$SpotifyHomeFeedImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/models/spotify/home_feed.g.dart b/lib/models/spotify/home_feed.g.dart new file mode 100644 index 00000000..73a4f909 --- /dev/null +++ b/lib/models/spotify/home_feed.g.dart @@ -0,0 +1,169 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'home_feed.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$SpotifySectionPlaylistImpl _$$SpotifySectionPlaylistImplFromJson( + Map json) => + _$SpotifySectionPlaylistImpl( + description: json['description'] as String, + format: json['format'] as String, + images: (json['images'] as List) + .map((e) => + SpotifySectionItemImage.fromJson(e as Map)) + .toList(), + name: json['name'] as String, + owner: json['owner'] as String, + uri: json['uri'] as String, + ); + +Map _$$SpotifySectionPlaylistImplToJson( + _$SpotifySectionPlaylistImpl instance) => + { + 'description': instance.description, + 'format': instance.format, + 'images': instance.images, + 'name': instance.name, + 'owner': instance.owner, + 'uri': instance.uri, + }; + +_$SpotifySectionArtistImpl _$$SpotifySectionArtistImplFromJson( + Map json) => + _$SpotifySectionArtistImpl( + name: json['name'] as String, + uri: json['uri'] as String, + images: (json['images'] as List) + .map((e) => + SpotifySectionItemImage.fromJson(e as Map)) + .toList(), + ); + +Map _$$SpotifySectionArtistImplToJson( + _$SpotifySectionArtistImpl instance) => + { + 'name': instance.name, + 'uri': instance.uri, + 'images': instance.images, + }; + +_$SpotifySectionAlbumImpl _$$SpotifySectionAlbumImplFromJson( + Map json) => + _$SpotifySectionAlbumImpl( + artists: (json['artists'] as List) + .map((e) => + SpotifySectionAlbumArtist.fromJson(e as Map)) + .toList(), + images: (json['images'] as List) + .map((e) => + SpotifySectionItemImage.fromJson(e as Map)) + .toList(), + name: json['name'] as String, + uri: json['uri'] as String, + ); + +Map _$$SpotifySectionAlbumImplToJson( + _$SpotifySectionAlbumImpl instance) => + { + 'artists': instance.artists, + 'images': instance.images, + 'name': instance.name, + 'uri': instance.uri, + }; + +_$SpotifySectionAlbumArtistImpl _$$SpotifySectionAlbumArtistImplFromJson( + Map json) => + _$SpotifySectionAlbumArtistImpl( + name: json['name'] as String, + uri: json['uri'] as String, + ); + +Map _$$SpotifySectionAlbumArtistImplToJson( + _$SpotifySectionAlbumArtistImpl instance) => + { + 'name': instance.name, + 'uri': instance.uri, + }; + +_$SpotifySectionItemImageImpl _$$SpotifySectionItemImageImplFromJson( + Map json) => + _$SpotifySectionItemImageImpl( + height: json['height'] as num?, + url: json['url'] as String, + width: json['width'] as num?, + ); + +Map _$$SpotifySectionItemImageImplToJson( + _$SpotifySectionItemImageImpl instance) => + { + 'height': instance.height, + 'url': instance.url, + 'width': instance.width, + }; + +_$SpotifyHomeFeedSectionItemImpl _$$SpotifyHomeFeedSectionItemImplFromJson( + Map json) => + _$SpotifyHomeFeedSectionItemImpl( + typename: json['typename'] as String, + playlist: json['playlist'] == null + ? null + : SpotifySectionPlaylist.fromJson( + json['playlist'] as Map), + artist: json['artist'] == null + ? null + : SpotifySectionArtist.fromJson( + json['artist'] as Map), + album: json['album'] == null + ? null + : SpotifySectionAlbum.fromJson(json['album'] as Map), + ); + +Map _$$SpotifyHomeFeedSectionItemImplToJson( + _$SpotifyHomeFeedSectionItemImpl instance) => + { + 'typename': instance.typename, + 'playlist': instance.playlist, + 'artist': instance.artist, + 'album': instance.album, + }; + +_$SpotifyHomeFeedSectionImpl _$$SpotifyHomeFeedSectionImplFromJson( + Map json) => + _$SpotifyHomeFeedSectionImpl( + typename: json['typename'] as String, + title: json['title'] as String?, + uri: json['uri'] as String, + items: (json['items'] as List) + .map((e) => + SpotifyHomeFeedSectionItem.fromJson(e as Map)) + .toList(), + ); + +Map _$$SpotifyHomeFeedSectionImplToJson( + _$SpotifyHomeFeedSectionImpl instance) => + { + 'typename': instance.typename, + 'title': instance.title, + 'uri': instance.uri, + 'items': instance.items, + }; + +_$SpotifyHomeFeedImpl _$$SpotifyHomeFeedImplFromJson( + Map json) => + _$SpotifyHomeFeedImpl( + greeting: json['greeting'] as String, + sections: (json['sections'] as List) + .map( + (e) => SpotifyHomeFeedSection.fromJson(e as Map)) + .toList(), + ); + +Map _$$SpotifyHomeFeedImplToJson( + _$SpotifyHomeFeedImpl instance) => + { + 'greeting': instance.greeting, + 'sections': instance.sections, + }; diff --git a/lib/pages/home/feed/feed_section.dart b/lib/pages/home/feed/feed_section.dart new file mode 100644 index 00000000..40ac2482 --- /dev/null +++ b/lib/pages/home/feed/feed_section.dart @@ -0,0 +1,62 @@ +import 'package:flutter/material.dart'; +import 'package:hooks_riverpod/hooks_riverpod.dart'; +import 'package:skeletonizer/skeletonizer.dart'; +import 'package:spotube/collections/fake.dart'; +import 'package:spotube/components/album/album_card.dart'; +import 'package:spotube/components/artist/artist_card.dart'; +import 'package:spotube/components/playlist/playlist_card.dart'; +import 'package:spotube/components/shared/page_window_title_bar.dart'; +import 'package:spotube/extensions/constrains.dart'; +import 'package:spotube/provider/spotify/views/home_section.dart'; + +class HomeFeedSectionPage extends HookConsumerWidget { + final String sectionUri; + const HomeFeedSectionPage({super.key, required this.sectionUri}); + + @override + Widget build(BuildContext context, ref) { + final homeFeedSection = ref.watch(homeSectionViewProvider(sectionUri)); + final section = homeFeedSection.asData?.value ?? FakeData.feedSection; + + return Skeletonizer( + enabled: homeFeedSection.isLoading, + child: Scaffold( + appBar: PageWindowTitleBar( + title: Text(section.title ?? ""), + centerTitle: false, + automaticallyImplyLeading: true, + titleSpacing: 0, + ), + body: CustomScrollView( + slivers: [ + SliverLayoutBuilder( + builder: (context, constrains) { + return SliverGrid.builder( + gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent( + maxCrossAxisExtent: 200, + mainAxisExtent: constrains.smAndDown ? 225 : 250, + crossAxisSpacing: 8, + mainAxisSpacing: 8, + ), + itemCount: section.items.length, + itemBuilder: (context, index) { + final item = section.items[index]; + + if (item.album != null) { + return AlbumCard(item.album!.asAlbum); + } else if (item.artist != null) { + return ArtistCard(item.artist!.asArtist); + } else if (item.playlist != null) { + return PlaylistCard(item.playlist!.asPlaylist); + } + return const SizedBox(); + }, + ); + }, + ), + ], + ), + ), + ); + } +} diff --git a/lib/pages/home/home.dart b/lib/pages/home/home.dart index 5b959621..e37898a8 100644 --- a/lib/pages/home/home.dart +++ b/lib/pages/home/home.dart @@ -5,6 +5,7 @@ import 'package:gap/gap.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:spotube/components/connect/connect_device.dart'; import 'package:spotube/components/home/sections/featured.dart'; +import 'package:spotube/components/home/sections/feed.dart'; import 'package:spotube/components/home/sections/friends.dart'; import 'package:spotube/components/home/sections/genres.dart'; import 'package:spotube/components/home/sections/made_for_user.dart'; @@ -66,6 +67,7 @@ class HomePage extends HookConsumerWidget { const SliverToBoxAdapter(child: HomeFeaturedSection()), const HomePageFriendsSection(), const SliverToBoxAdapter(child: HomeNewReleasesSection()), + const HomePageFeedSection(), const SliverSafeArea(sliver: HomeMadeForUserSection()), ], ), diff --git a/lib/pages/mobile_login/mobile_login.dart b/lib/pages/mobile_login/mobile_login.dart index 1afca919..0a1ff8b3 100644 --- a/lib/pages/mobile_login/mobile_login.dart +++ b/lib/pages/mobile_login/mobile_login.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'package:go_router/go_router.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; @@ -12,7 +11,6 @@ class WebViewLogin extends HookConsumerWidget { @override Widget build(BuildContext context, ref) { - final mounted = useIsMounted(); final authenticationNotifier = ref.watch(authenticationProvider.notifier); if (kIsDesktop) { @@ -57,7 +55,7 @@ class WebViewLogin extends HookConsumerWidget { authenticationNotifier.setCredentials( await AuthenticationCredentials.fromCookie(cookieHeader), ); - if (mounted()) { + if (context.mounted) { // ignore: use_build_context_synchronously GoRouter.of(context).go("/"); } diff --git a/lib/provider/authentication_provider.dart b/lib/provider/authentication_provider.dart index f7549ad7..a82f82c0 100644 --- a/lib/provider/authentication_provider.dart +++ b/lib/provider/authentication_provider.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'dart:convert'; +import 'package:collection/collection.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:http/http.dart'; @@ -25,12 +26,16 @@ class AuthenticationCredentials { static Future fromCookie(String cookie) async { try { + final spDc = cookie + .split("; ") + .firstWhereOrNull((c) => c.trim().startsWith("sp_dc=")) + ?.trim(); final res = await get( Uri.parse( "https://open.spotify.com/get_access_token?reason=transport&productType=web_player", ), headers: { - "Cookie": cookie, + "Cookie": spDc ?? "", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36" }, @@ -44,7 +49,7 @@ class AuthenticationCredentials { } return AuthenticationCredentials( - cookie: cookie, + cookie: "${res.headers["set-cookie"]}; $spDc", accessToken: body['accessToken'], expiration: DateTime.fromMillisecondsSinceEpoch( body['accessTokenExpirationTimestampMs'], @@ -64,6 +69,15 @@ class AuthenticationCredentials { } } + /// Returns the cookie value + String? getCookie(String key) => cookie + .split("; ") + .firstWhereOrNull((c) => c.trim().startsWith("$key=")) + ?.trim() + .split("=") + .last + .replaceAll(";", ""); + factory AuthenticationCredentials.fromJson(Map json) { return AuthenticationCredentials( cookie: json['cookie'] as String, diff --git a/lib/provider/spotify/views/home.dart b/lib/provider/spotify/views/home.dart new file mode 100644 index 00000000..810d110d --- /dev/null +++ b/lib/provider/spotify/views/home.dart @@ -0,0 +1,22 @@ +import 'package:hooks_riverpod/hooks_riverpod.dart'; +import 'package:spotube/provider/authentication_provider.dart'; +import 'package:spotube/provider/custom_spotify_endpoint_provider.dart'; +import 'package:spotube/provider/user_preferences/user_preferences_provider.dart'; + +final homeViewProvider = FutureProvider((ref) async { + final country = ref.watch( + userPreferencesProvider.select((s) => s.recommendationMarket), + ); + final spTCookie = ref.watch( + authenticationProvider.select((s) => s?.getCookie("sp_t")), + ); + + if (spTCookie == null) return null; + + final spotify = ref.watch(customSpotifyEndpointProvider); + + return spotify.getHomeFeed( + country: country, + spTCookie: spTCookie, + ); +}); diff --git a/lib/provider/spotify/views/home_section.dart b/lib/provider/spotify/views/home_section.dart new file mode 100644 index 00000000..1078fa72 --- /dev/null +++ b/lib/provider/spotify/views/home_section.dart @@ -0,0 +1,26 @@ +import 'package:hooks_riverpod/hooks_riverpod.dart'; +import 'package:spotube/models/spotify/home_feed.dart'; +import 'package:spotube/provider/authentication_provider.dart'; +import 'package:spotube/provider/custom_spotify_endpoint_provider.dart'; +import 'package:spotube/provider/user_preferences/user_preferences_provider.dart'; + +final homeSectionViewProvider = + FutureProvider.family( + (ref, sectionUri) async { + final country = ref.watch( + userPreferencesProvider.select((s) => s.recommendationMarket), + ); + final spTCookie = ref.watch( + authenticationProvider.select((s) => s?.getCookie("sp_t")), + ); + + if (spTCookie == null) return null; + + final spotify = ref.watch(customSpotifyEndpointProvider); + + return spotify.getHomeFeedSection( + sectionUri, + country: country, + spTCookie: spTCookie, + ); +}); diff --git a/lib/services/custom_spotify_endpoints/spotify_endpoints.dart b/lib/services/custom_spotify_endpoints/spotify_endpoints.dart index d1c078a7..d8600366 100644 --- a/lib/services/custom_spotify_endpoints/spotify_endpoints.dart +++ b/lib/services/custom_spotify_endpoints/spotify_endpoints.dart @@ -2,7 +2,9 @@ import 'dart:convert'; import 'package:http/http.dart' as http; import 'package:spotify/spotify.dart'; +import 'package:spotube/models/spotify/home_feed.dart'; import 'package:spotube/models/spotify_friends.dart'; +import 'package:timezone/timezone.dart' as tz; class CustomSpotifyEndpoints { static const _baseUrl = 'https://api.spotify.com/v1'; @@ -175,4 +177,126 @@ class CustomSpotifyEndpoints { ); return SpotifyFriends.fromJson(jsonDecode(res.body)); } + + Future getHomeFeed({ + required String spTCookie, + required Market country, + }) async { + final headers = { + 'app-platform': 'WebPlayer', + 'authorization': 'Bearer $accessToken', + 'content-type': 'application/json;charset=UTF-8', + 'dnt': '1', + 'origin': 'https://open.spotify.com', + 'referer': 'https://open.spotify.com/' + }; + final response = await http.get( + Uri( + scheme: "https", + host: "api-partner.spotify.com", + path: "/pathfinder/v1/query", + queryParameters: { + "operationName": "home", + "variables": jsonEncode({ + "timeZone": tz.local.name, + "sp_t": spTCookie, + "country": country.name, + "facet": null, + "sectionItemsLimit": 10 + }), + "extensions": jsonEncode( + { + "persistedQuery": { + "version": 1, + + /// GraphQL persisted Query hash + /// This can change overtime. We've to lookout for it + /// Docs: https://www.apollographql.com/docs/graphos/operations/persisted-queries/ + "sha256Hash": + "eb3fba2d388cf4fc4d696b1757a58584e9538a3b515ea742e9cc9465807340be", + } + }, + ), + }, + ), + headers: headers, + ); + + if (response.statusCode >= 400) { + throw Exception( + "[RequestException] " + "Status: ${response.statusCode}\n" + "Body: ${response.body}", + ); + } + + final data = SpotifyHomeFeed.fromJson( + transformHomeFeedJsonMap( + jsonDecode(response.body), + ), + ); + + return data; + } + + Future getHomeFeedSection( + String sectionUri, { + required String spTCookie, + required Market country, + }) async { + final headers = { + 'app-platform': 'WebPlayer', + 'authorization': 'Bearer $accessToken', + 'content-type': 'application/json;charset=UTF-8', + 'dnt': '1', + 'origin': 'https://open.spotify.com', + 'referer': 'https://open.spotify.com/' + }; + final response = await http.get( + Uri( + scheme: "https", + host: "api-partner.spotify.com", + path: "/pathfinder/v1/query", + queryParameters: { + "operationName": "homeSection", + "variables": jsonEncode({ + "timeZone": tz.local.name, + "sp_t": spTCookie, + "country": country.name, + "uri": sectionUri + }), + "extensions": jsonEncode( + { + "persistedQuery": { + "version": 1, + + /// GraphQL persisted Query hash + /// This can change overtime. We've to lookout for it + /// Docs: https://www.apollographql.com/docs/graphos/operations/persisted-queries/ + "sha256Hash": + "eb3fba2d388cf4fc4d696b1757a58584e9538a3b515ea742e9cc9465807340be", + } + }, + ), + }, + ), + headers: headers, + ); + + if (response.statusCode >= 400) { + throw Exception( + "[RequestException] " + "Status: ${response.statusCode}\n" + "Body: ${response.body}", + ); + } + + final data = SpotifyHomeFeedSection.fromJson( + transformSectionItemJsonMap( + jsonDecode(response.body)["data"]["homeSections"]["sections"][0], + ), + ); + + return data; + } } diff --git a/pubspec.lock b/pubspec.lock index bc1f962f..8d19f604 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -434,7 +434,7 @@ packages: source: hosted version: "0.3.3+5" crypto: - dependency: transitive + dependency: "direct main" description: name: crypto sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab @@ -2238,6 +2238,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.3" + timezone: + dependency: "direct main" + description: + name: timezone + sha256: "1cfd8ddc2d1cfd836bc93e67b9be88c3adaeca6f40a00ca999104c30693cdca0" + url: "https://pub.dev" + source: hosted + version: "0.9.2" timing: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index dfd77387..16f51981 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -131,6 +131,8 @@ dependencies: lrc: ^1.0.2 pub_api_client: ^2.4.0 pubspec_parse: ^1.2.2 + timezone: ^0.9.2 + crypto: ^3.0.3 dev_dependencies: build_runner: ^2.4.9