Skip to content

Commit

Permalink
changelog: [skip ci]
Browse files Browse the repository at this point in the history
improved like feature
  • Loading branch information
gokadzev committed Jun 17, 2022
1 parent de34226 commit ff10676
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 42 deletions.
53 changes: 30 additions & 23 deletions lib/customWidgets/song_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ import 'package:musify/API/musify.dart';
import 'package:musify/services/audio_manager.dart';
import 'package:musify/style/appColors.dart';

class SongBar extends StatefulWidget {
final dynamic song;
const SongBar({Key? key, required this.song}) : super(key: key);
class SongBar extends StatelessWidget {
SongBar(this.song);

@override
State<SongBar> createState() => _SongBarState();
}
late final dynamic song;
late final songLikeStatus =
ValueNotifier<bool>(isSongAlreadyLiked(song["ytid"]));

class _SongBarState extends State<SongBar> {
@override
Widget build(BuildContext context) {
return Card(
Expand All @@ -24,7 +22,7 @@ class _SongBarState extends State<SongBar> {
child: InkWell(
borderRadius: BorderRadius.circular(20.0),
onTap: () {
playSong((widget.song));
playSong((song));
},
splashColor: accent,
hoverColor: accent,
Expand All @@ -42,34 +40,43 @@ class _SongBarState extends State<SongBar> {
),
),
title: Text(
((widget.song)['title'])
((song)['title'])
.toString()
.split("(")[0]
.replaceAll("&quot;", "\"")
.replaceAll("&amp;", "&"),
style: TextStyle(color: accent),
),
subtitle: Text(
widget.song['more_info']["singers"],
song['more_info']["singers"],
style: TextStyle(color: accentLight),
),
trailing: Row(mainAxisSize: MainAxisSize.min, children: [
IconButton(
color: accent,
icon: isSongAlreadyLiked((widget.song)['ytid'])
? Icon(MdiIcons.star)
: Icon(MdiIcons.starOutline),
onPressed: () => {
setState(() {
isSongAlreadyLiked((widget.song)['ytid'])
? removeUserLikedSong((widget.song)['ytid'])
: addUserLikedSong((widget.song)['ytid']);
})
}),
ValueListenableBuilder<bool>(
valueListenable: songLikeStatus,
builder: (_, value, __) {
if (value == true) {
return IconButton(
color: accent,
icon: Icon(MdiIcons.star),
onPressed: () => {
removeUserLikedSong((song)['ytid']),
songLikeStatus.value = false
});
} else {
return IconButton(
color: accent,
icon: Icon(MdiIcons.starOutline),
onPressed: () => {
addUserLikedSong((song)['ytid']),
songLikeStatus.value = true
});
}
}),
IconButton(
color: accent,
icon: Icon(MdiIcons.downloadOutline),
onPressed: () => downloadSong((widget.song)),
onPressed: () => downloadSong((song)),
),
]),
)
Expand Down
3 changes: 1 addition & 2 deletions lib/ui/homePage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ class _HomePageState extends State<HomePage> {
(data as dynamic).data.length,
itemBuilder: (context, index) {
return SongBar(
song: (data as dynamic)
.data[index]);
(data as dynamic).data[index]);
})))
],
),
Expand Down
38 changes: 25 additions & 13 deletions lib/ui/player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ get isPlaying => buttonNotifier.value == MPlayerState.playing;

get isPaused => buttonNotifier.value == MPlayerState.paused;

final songLikeStatus = ValueNotifier<bool>(isSongAlreadyLiked(ytid));

enum MPlayerState { stopped, playing, paused, loading }

class AudioApp extends StatefulWidget {
Expand Down Expand Up @@ -305,19 +307,29 @@ class AudioAppState extends State<AudioApp> {
changeLoopStatus();
},
),
IconButton(
color: accent,
icon: isSongAlreadyLiked(ytid)
? Icon(MdiIcons.star)
: Icon(MdiIcons.starOutline),
iconSize: size.width * 0.056,
onPressed: () => {
setState(() {
isSongAlreadyLiked(ytid)
? removeUserLikedSong(ytid)
: addUserLikedSong(ytid);
})
}),
ValueListenableBuilder<bool>(
valueListenable: songLikeStatus,
builder: (_, value, __) {
if (value == true) {
return IconButton(
color: accent,
icon: Icon(MdiIcons.star),
iconSize: size.width * 0.056,
onPressed: () => {
removeUserLikedSong(ytid),
songLikeStatus.value = false
});
} else {
return IconButton(
color: accent,
icon: Icon(MdiIcons.starOutline),
iconSize: size.width * 0.056,
onPressed: () => {
addUserLikedSong(ytid),
songLikeStatus.value = true
});
}
}),
],
),
),
Expand Down
3 changes: 1 addition & 2 deletions lib/ui/playlistPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,7 @@ class _PlaylistPageState extends State<PlaylistPage> {
return Padding(
padding: const EdgeInsets.only(
top: 5, bottom: 5),
child: SongBar(
song: _songsList[index]));
child: SongBar(_songsList[index]));
})
: Align(
alignment: Alignment.center,
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/searchPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class _SearchPageState extends State<SearchPage> {
itemBuilder: (BuildContext ctxt, int index) {
return Padding(
padding: const EdgeInsets.only(top: 5, bottom: 5),
child: SongBar(song: searchedList[index]));
child: SongBar(searchedList[index]));
},
)
],
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/userLikedSongsPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class _UserLikedSongsState extends State<UserLikedSongs> {
itemBuilder: (BuildContext context, int index) {
return Padding(
padding: const EdgeInsets.only(top: 5, bottom: 5),
child: SongBar(song: userLikedSongsList[index]));
child: SongBar(userLikedSongsList[index]));
})
],
)
Expand Down

0 comments on commit ff10676

Please sign in to comment.