Skip to content

Commit

Permalink
fix: use CustomScrollView for personalized page
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Nov 22, 2023
1 parent 88b8785 commit 7d05c40
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 45 deletions.
11 changes: 11 additions & 0 deletions lib/extensions/string.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'package:html_unescape/html_unescape.dart';

final htmlEscape = HtmlUnescape();

extension UnescapeHtml on String {
String unescapeHtml() => htmlEscape.convert(this);
}

extension NullableUnescapeHtml on String? {
String? unescapeHtml() => this == null ? null : htmlEscape.convert(this!);
}
95 changes: 56 additions & 39 deletions lib/pages/home/personalized.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,47 +46,64 @@ class PersonalizedPage extends HookConsumerWidget {
[newReleases.pages],
);

return ListView(
return CustomScrollView(
controller: controller,
children: [
if (!featuredPlaylistsQuery.hasPageData &&
!featuredPlaylistsQuery.isLoadingNextPage)
const ShimmerCategories()
else
HorizontalPlaybuttonCardView<PlaylistSimple>(
items: playlists.toList(),
title: Text(context.l10n.featured),
isLoadingNextPage: featuredPlaylistsQuery.isLoadingNextPage,
hasNextPage: featuredPlaylistsQuery.hasNextPage,
onFetchMore: featuredPlaylistsQuery.fetchNext,
slivers: [
SliverList.list(
children: [
AnimatedSwitcher(
duration: const Duration(milliseconds: 300),
child: !featuredPlaylistsQuery.hasPageData &&
!featuredPlaylistsQuery.isLoadingNextPage
? const ShimmerCategories()
: HorizontalPlaybuttonCardView<PlaylistSimple>(
items: playlists.toList(),
title: Text(context.l10n.featured),
isLoadingNextPage:
featuredPlaylistsQuery.isLoadingNextPage,
hasNextPage: featuredPlaylistsQuery.hasNextPage,
onFetchMore: featuredPlaylistsQuery.fetchNext,
),
),
if (auth != null)
AnimatedSwitcher(
duration: const Duration(milliseconds: 300),
child: newReleases.hasPageData &&
userArtistsQuery.hasData &&
!newReleases.isLoadingNextPage
? HorizontalPlaybuttonCardView<Album>(
items: albums,
title: Text(context.l10n.new_releases),
isLoadingNextPage: newReleases.isLoadingNextPage,
hasNextPage: newReleases.hasNextPage,
onFetchMore: newReleases.fetchNext,
)
: const ShimmerCategories(),
),
],
),
SliverSafeArea(
sliver: SliverList.builder(
itemCount: madeForUser.data?["content"]?["items"]?.length ?? 0,
itemBuilder: (context, index) {
final item = madeForUser.data?["content"]?["items"]?[index];
final playlists = item["content"]?["items"]
?.where((itemL2) => itemL2["type"] == "playlist")
.map((itemL2) => PlaylistSimple.fromJson(itemL2))
.toList()
.cast<PlaylistSimple>() ??
<PlaylistSimple>[];
if (playlists.isEmpty) return const SizedBox.shrink();
return HorizontalPlaybuttonCardView<PlaylistSimple>(
items: playlists,
title: Text(item["name"] ?? ""),
hasNextPage: false,
isLoadingNextPage: false,
onFetchMore: () {},
);
},
),
if (auth != null &&
newReleases.hasPageData &&
userArtistsQuery.hasData &&
!newReleases.isLoadingNextPage)
HorizontalPlaybuttonCardView<Album>(
items: albums,
title: Text(context.l10n.new_releases),
isLoadingNextPage: newReleases.isLoadingNextPage,
hasNextPage: newReleases.hasNextPage,
onFetchMore: newReleases.fetchNext,
),
...?madeForUser.data?["content"]?["items"]?.map((item) {
final playlists = item["content"]?["items"]
?.where((itemL2) => itemL2["type"] == "playlist")
.map((itemL2) => PlaylistSimple.fromJson(itemL2))
.toList()
.cast<PlaylistSimple>() ??
<PlaylistSimple>[];
if (playlists.isEmpty) return const SizedBox.shrink();
return HorizontalPlaybuttonCardView<PlaylistSimple>(
items: playlists,
title: Text(item["name"] ?? ""),
hasNextPage: false,
isLoadingNextPage: false,
onFetchMore: () {},
);
})
),
],
);
}
Expand Down
15 changes: 9 additions & 6 deletions lib/services/sourced_track/sources/jiosaavn.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:spotube/services/sourced_track/models/source_info.dart';
import 'package:spotube/services/sourced_track/models/source_map.dart';
import 'package:spotube/services/sourced_track/sourced_track.dart';
import 'package:jiosaavn/jiosaavn.dart';
import 'package:spotube/extensions/string.dart';

final jiosaavnClient = JioSaavnClient();

Expand Down Expand Up @@ -74,14 +75,14 @@ class JioSaavnSourcedTrack extends SourcedTrack {
result.primaryArtists,
if (result.featuredArtists.isNotEmpty) ", ",
result.featuredArtists
].join("").replaceAll("&amp;", "&"),
].join("").unescapeHtml(),
artistUrl:
"https://www.jiosaavn.com/artist/${result.primaryArtistsId.split(",").firstOrNull ?? ""}",
duration: Duration(seconds: int.parse(result.duration)),
id: result.id,
pageUrl: result.url,
thumbnail: result.image?.last.link ?? "",
title: result.name!,
title: result.name!.unescapeHtml(),
album: result.album.name,
),
source: SourceMap(
Expand Down Expand Up @@ -115,10 +116,12 @@ class JioSaavnSourcedTrack extends SourcedTrack {
return results
.where(
(s) {
final sameName = s.name?.replaceAll("&amp;", "&") == track.name;
final artistNames =
"${s.primaryArtists}${s.featuredArtists.isNotEmpty ? ", " : ""}${s.featuredArtists}"
.replaceAll("&amp;", "&");
final sameName = s.name?.unescapeHtml() == track.name;
final artistNames = [
s.primaryArtists,
if (s.featuredArtists.isNotEmpty) ", ",
s.featuredArtists
].join("").unescapeHtml();
final sameArtists = artistNames.split(", ").any(
(artist) =>
trackArtistNames?.any((ar) => artist == ar) ?? false,
Expand Down
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.15.4"
html_unescape:
dependency: "direct main"
description:
name: html_unescape
sha256: "15362d7a18f19d7b742ef8dcb811f5fd2a2df98db9f80ea393c075189e0b61e3"
url: "https://pub.dev"
source: hosted
version: "2.0.0"
http:
dependency: "direct main"
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ dependencies:
dart_discord_rpc:
git:
url: https:/Tommypop2/dart_discord_rpc.git
html_unescape: ^2.0.0

dev_dependencies:
build_runner: ^2.3.2
Expand Down

0 comments on commit 7d05c40

Please sign in to comment.