Skip to content

Commit

Permalink
feat: black list artist or track
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Jan 6, 2023
1 parent f79223c commit 947c143
Show file tree
Hide file tree
Showing 10 changed files with 465 additions and 62 deletions.
31 changes: 22 additions & 9 deletions lib/components/artist/artist_card.dart
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
import 'package:auto_size_text/auto_size_text.dart';
import 'package:fluent_ui/fluent_ui.dart' hide Colors;
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:platform_ui/platform_ui.dart';
import 'package:spotify/spotify.dart';
import 'package:spotube/components/shared/hover_builder.dart';
import 'package:spotube/components/shared/image/universal_image.dart';
import 'package:spotube/hooks/use_platform_property.dart';
import 'package:spotube/provider/blacklist_provider.dart';
import 'package:spotube/utils/service_utils.dart';
import 'package:spotube/utils/type_conversion_utils.dart';

class ArtistCard extends HookWidget {
class ArtistCard extends HookConsumerWidget {
final Artist artist;
const ArtistCard(this.artist, {Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
Widget build(BuildContext context, ref) {
final backgroundImage = UniversalImage.imageProvider(
TypeConversionUtils.image_X_UrlString(
artist.images,
placeholder: ImagePlaceholder.artist,
),
);
final isBlackListed = ref.watch(
BlackListNotifier.provider.select(
(blacklist) => blacklist.contains(
BlacklistedElement.artist(artist.id!, artist.name!),
),
),
);
final boxShadow = usePlatformProperty<BoxShadow?>(
(context) => PlatformProperty(
android: BoxShadow(
Expand Down Expand Up @@ -78,14 +86,19 @@ class ArtistCard extends HookWidget {
boxShadow: [
if (boxShadow != null) boxShadow,
],
border: [TargetPlatform.windows, TargetPlatform.macOS]
.contains(platform)
border: isBlackListed
? Border.all(
color: PlatformTheme.of(context).borderColor ??
Colors.transparent,
width: 1,
color: Colors.red[400]!,
width: 2,
)
: null,
: [TargetPlatform.windows, TargetPlatform.macOS]
.contains(platform)
? Border.all(
color: PlatformTheme.of(context).borderColor ??
Colors.transparent,
width: 1,
)
: null,
),
child: Padding(
padding: const EdgeInsets.all(15),
Expand Down
75 changes: 75 additions & 0 deletions lib/components/settings/blacklist_dialog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:collection/collection.dart';
import 'package:fuzzywuzzy/fuzzywuzzy.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:platform_ui/platform_ui.dart';
import 'package:spotube/provider/blacklist_provider.dart';
import 'package:tuple/tuple.dart';

class BlackListDialog extends HookConsumerWidget {
const BlackListDialog({Key? key}) : super(key: key);

@override
Widget build(BuildContext context, ref) {
final blacklist = ref.watch(BlackListNotifier.provider);
final searchText = useState("");

final filteredBlacklist = useMemoized(
() {
if (searchText.value.isEmpty) {
return blacklist;
}
return blacklist
.map((e) => Tuple2(
weightedRatio("${e.name} ${e.type.name}", searchText.value),
e,
))
.sorted((a, b) => b.item1.compareTo(a.item1))
.where((e) => e.item1 > 50)
.map((e) => e.item2)
.toList();
},
[blacklist, searchText.value],
);

return PlatformAlertDialog(
title: const PlatformText("Blacklist"),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: PlatformTextField(
onChanged: (value) => searchText.value = value,
placeholder: "Search",
prefixIcon: Icons.search_rounded,
),
),
ListView.builder(
shrinkWrap: true,
itemCount: filteredBlacklist.length,
itemBuilder: (context, index) {
final item = filteredBlacklist.elementAt(index);
return ListTile(
leading: PlatformText("${index + 1}."),
minLeadingWidth: 20,
title: PlatformText("${item.name} (${item.type.name})"),
subtitle: PlatformText.caption(item.id),
trailing: IconButton(
icon: Icon(Icons.delete_forever_rounded,
color: Colors.red[400]),
onPressed: () {
ref
.read(BlackListNotifier.provider.notifier)
.remove(filteredBlacklist.elementAt(index));
},
),
);
},
),
],
),
);
}
}
54 changes: 41 additions & 13 deletions lib/components/shared/adaptive/adaptive_popup_menu_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ class Action extends StatelessWidget {
final Widget icon;
final void Function() onPressed;
final bool isExpanded;
final Color? backgroundColor;
const Action({
Key? key,
required this.icon,
required this.text,
required this.onPressed,
this.isExpanded = true,
this.backgroundColor,
}) : super(key: key);

@override
Expand All @@ -23,6 +25,7 @@ class Action extends StatelessWidget {
return PlatformIconButton(
icon: icon,
onPressed: onPressed,
backgroundColor: backgroundColor,
tooltip: text is PlatformText
? (text as PlatformText).data
: text.toStringShallow().split(",").last.replaceAll(
Expand All @@ -31,18 +34,42 @@ class Action extends StatelessWidget {
),
);
}
return PlatformTextButton(
style: TextButton.styleFrom(
foregroundColor: PlatformTextTheme.of(context).body?.color,
padding: const EdgeInsets.all(20),
),
onPressed: onPressed,
child: Row(
children: [
icon,
const SizedBox(width: 10),
text,
],
if (backgroundColor == null) {
return PlatformTextButton(
style: TextButton.styleFrom(
foregroundColor:
backgroundColor ?? PlatformTextTheme.of(context).body?.color,
backgroundColor: backgroundColor,
padding: const EdgeInsets.all(20),
),
onPressed: onPressed,
child: Row(
children: [
icon,
const SizedBox(width: 10),
text,
],
),
);
}

return Padding(
padding: const EdgeInsets.all(8.0),
child: PlatformFilledButton(
style: TextButton.styleFrom(
foregroundColor:
backgroundColor ?? PlatformTextTheme.of(context).body?.color,
backgroundColor: backgroundColor,
padding: const EdgeInsets.all(20),
),
onPressed: onPressed,
child: Row(
children: [
icon,
const SizedBox(width: 10),
text,
],
),
),
);
}
Expand Down Expand Up @@ -75,7 +102,7 @@ class AdaptiveActions extends HookWidget {
children: actions
.map(
(action) => SizedBox(
width: 200,
width: 250,
child: Row(
children: [
Expanded(child: action),
Expand All @@ -99,6 +126,7 @@ class AdaptiveActions extends HookWidget {
icon: action.icon,
onPressed: action.onPressed,
text: action.text,
backgroundColor: action.backgroundColor,
isExpanded: false,
);
}).toList(),
Expand Down
83 changes: 70 additions & 13 deletions lib/components/shared/track_table/track_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:spotube/components/root/sidebar.dart';
import 'package:spotube/hooks/use_breakpoints.dart';
import 'package:spotube/models/logger.dart';
import 'package:spotube/provider/auth_provider.dart';
import 'package:spotube/provider/blacklist_provider.dart';
import 'package:spotube/provider/playback_provider.dart';
import 'package:spotube/provider/spotify_provider.dart';
import 'package:spotube/services/mutations/mutations.dart';
Expand Down Expand Up @@ -62,6 +63,13 @@ class TrackTile extends HookConsumerWidget {
@override
Widget build(BuildContext context, ref) {
final breakpoint = useBreakpoints();
final isBlackListed = ref.watch(
BlackListNotifier.provider.select(
(blacklist) => blacklist.contains(
BlacklistedElement.track(track.value.id!, track.value.name!),
),
),
);
final auth = ref.watch(authProvider);
final spotify = ref.watch(spotifyProvider);
final removingTrack = useState<String?>(null);
Expand Down Expand Up @@ -179,9 +187,11 @@ class TrackTile extends HookConsumerWidget {
return AnimatedContainer(
duration: const Duration(milliseconds: 500),
decoration: BoxDecoration(
color: isActive
? Theme.of(context).popupMenuTheme.color
: Colors.transparent,
color: isBlackListed
? Colors.red[100]
: isActive
? Theme.of(context).popupMenuTheme.color
: Colors.transparent,
borderRadius: BorderRadius.circular(isActive ? 10 : 0),
),
child: Material(
Expand Down Expand Up @@ -238,22 +248,43 @@ class TrackTile extends HookConsumerWidget {
backgroundColor: PlatformTheme.of(context).primaryColor,
hoverColor:
PlatformTheme.of(context).primaryColor?.withOpacity(0.5),
onPressed: () => onTrackPlayButtonPressed?.call(
track.value,
),
onPressed: !isBlackListed
? () => onTrackPlayButtonPressed?.call(
track.value,
)
: null,
),
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
PlatformText(
track.value.name ?? "",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: breakpoint.isSm ? 14 : 17,
),
overflow: TextOverflow.ellipsis,
Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Flexible(
child: PlatformText(
track.value.name ?? "",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: breakpoint.isSm ? 14 : 17,
),
overflow: TextOverflow.ellipsis,
),
),
if (isBlackListed) ...[
const SizedBox(width: 5),
PlatformText(
"Blacklisted",
style: TextStyle(
color: Colors.red[400],
fontSize: 12,
fontWeight: FontWeight.bold,
),
),
]
],
),
isLocal
? PlatformText(
Expand Down Expand Up @@ -327,6 +358,32 @@ class TrackTile extends HookConsumerWidget {
onPressed: () {
actionShare(track.value);
},
),
Action(
icon: Icon(
Icons.playlist_remove_rounded,
color: isBlackListed ? Colors.white : Colors.red[400],
),
backgroundColor: isBlackListed ? Colors.red[400] : null,
text: PlatformText(
"${isBlackListed ? "Remove from" : "Add to"} blacklist",
style: TextStyle(
color: isBlackListed ? Colors.white : Colors.red[400],
),
),
onPressed: () {
if (isBlackListed) {
ref.read(BlackListNotifier.provider.notifier).remove(
BlacklistedElement.track(
track.value.id!, track.value.name!),
);
} else {
ref.read(BlackListNotifier.provider.notifier).add(
BlacklistedElement.track(
track.value.id!, track.value.name!),
);
}
},
)
],
),
Expand Down
13 changes: 12 additions & 1 deletion lib/components/shared/track_table/tracks_table_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:spotube/components/shared/sort_tracks_dropdown.dart';
import 'package:spotube/components/shared/track_table/track_tile.dart';
import 'package:spotube/components/library/user_local_tracks.dart';
import 'package:spotube/hooks/use_breakpoints.dart';
import 'package:spotube/provider/blacklist_provider.dart';
import 'package:spotube/provider/downloader_provider.dart';
import 'package:spotube/provider/playback_provider.dart';
import 'package:spotube/utils/primitive_utils.dart';
Expand Down Expand Up @@ -217,7 +218,17 @@ class TracksTableView extends HookConsumerWidget {
selected.value = [...selected.value, track.value.id!];
}
} else {
onTrackPlayButtonPressed?.call(track.value);
final isBlackListed = ref.read(
BlackListNotifier.provider.select(
(blacklist) => blacklist.contains(
BlacklistedElement.track(
track.value.id!, track.value.name!),
),
),
);
if (!isBlackListed) {
onTrackPlayButtonPressed?.call(track.value);
}
}
},
child: TrackTile(
Expand Down
Loading

0 comments on commit 947c143

Please sign in to comment.