Skip to content

Commit

Permalink
feat: add spotify homepage recommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Apr 14, 2024
1 parent 2d1f4b9 commit bf71e9b
Show file tree
Hide file tree
Showing 18 changed files with 2,456 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/collections/assets.gen.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions lib/collections/fake.dart
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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",
),
)
],
);
}
9 changes: 9 additions & 0 deletions lib/collections/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(
Expand Down
52 changes: 52 additions & 0 deletions lib/components/home/sections/feed.dart
Original file line number Diff line number Diff line change
@@ -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}"),
),
),
);
},
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,21 @@ class HorizontalPlaybuttonCardView<T> 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<PlaylistSimple> ||
items is List<Album> ||
items is List<Artist>,
items.every(
(item) =>
item is PlaylistSimple || item is Artist || item is AlbumSimple,
),
);

@override
Expand All @@ -48,9 +51,15 @@ class HorizontalPlaybuttonCardView<T> 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,
Expand Down Expand Up @@ -87,7 +96,7 @@ class HorizontalPlaybuttonCardView<T> 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),
Expand Down
3 changes: 3 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> main(List<String> rawArgs) async {
final arguments = await startCLI(rawArgs);
Expand All @@ -47,6 +48,8 @@ Future<void> main(List<String> rawArgs) async {

await registerWindowsScheme("spotify");

tz.initializeTimeZones();

FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);

MediaKit.ensureInitialized();
Expand Down
Loading

0 comments on commit bf71e9b

Please sign in to comment.