Skip to content

Commit

Permalink
Merge pull request gokadzev#191 from Spyy004/master
Browse files Browse the repository at this point in the history
Re-rendering of user liked songs list & cleaner implementation for liking/disliking song
  • Loading branch information
gokadzev authored Mar 25, 2023
2 parents e5e6ac0 + 021446b commit c3172d1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 36 deletions.
3 changes: 3 additions & 0 deletions lib/API/musify.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Map activePlaylist = {
'list': [],
};

late final currentLikedSongsLength =
ValueNotifier<int>(userLikedSongsList.length);

final lyrics = ValueNotifier<String>('null');
String lastFetchedLyrics = 'null';

Expand Down
36 changes: 20 additions & 16 deletions lib/screens/user_liked_songs_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,26 @@ class _UserLikedSongsState extends State<UserLikedSongs> {
],
),
const Padding(padding: EdgeInsets.only(top: 20)),
ListView.builder(
shrinkWrap: true,
physics: const BouncingScrollPhysics(),
addAutomaticKeepAlives: false,
addRepaintBoundaries: false,
itemCount: userLikedSongsList.length,
itemBuilder: (BuildContext context, int index) {
return Padding(
padding: const EdgeInsets.only(top: 5, bottom: 5),
child: SongBar(
userLikedSongsList[index],
true,
),
);
},
)
ValueListenableBuilder(
valueListenable: currentLikedSongsLength,
builder: (_, value, __) {
return ListView.builder(
shrinkWrap: true,
physics: const BouncingScrollPhysics(),
addAutomaticKeepAlives: false,
addRepaintBoundaries: false,
itemCount: userLikedSongsList.length,
itemBuilder: (BuildContext context, int index) {
return Padding(
padding: const EdgeInsets.only(top: 5, bottom: 5),
child: SongBar(
userLikedSongsList[index],
true,
),
);
},
);
})
],
),
),
Expand Down
39 changes: 19 additions & 20 deletions lib/widgets/song_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ import 'package:musify/style/app_themes.dart';

class SongBar extends StatelessWidget {
SongBar(this.song, this.clearPlaylist, {super.key});

late final dynamic song;
late final bool clearPlaylist;

final likeStatusToIconMapper = {
true: FluentIcons.star_24_filled,
false: FluentIcons.star_24_regular
};

late final songLikeStatus =
ValueNotifier<bool>(isSongAlreadyLiked(song['ytid']));

Expand Down Expand Up @@ -99,25 +104,19 @@ class SongBar extends StatelessWidget {
ValueListenableBuilder<bool>(
valueListenable: songLikeStatus,
builder: (_, value, __) {
if (value == true) {
return IconButton(
color: colorScheme.primary,
icon: const Icon(FluentIcons.star_24_filled),
onPressed: () => {
updateLikeStatus(song['ytid'], false),
songLikeStatus.value = false
},
);
} else {
return IconButton(
color: colorScheme.primary,
icon: const Icon(FluentIcons.star_24_regular),
onPressed: () => {
updateLikeStatus(song['ytid'], true),
songLikeStatus.value = true
},
);
}
return IconButton(
onPressed: () => {
songLikeStatus.value = !songLikeStatus.value,
updateLikeStatus(
song['ytid'],
songLikeStatus.value,
),
currentLikedSongsLength.value = value
? currentLikedSongsLength.value + 1
: currentLikedSongsLength.value - 1
},
icon: Icon(likeStatusToIconMapper[value]),
);
},
),
IconButton(
Expand Down

0 comments on commit c3172d1

Please sign in to comment.