mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-11-21 20:00:49 +01:00
fix(desktop): put delete beside Remove RG in the selection toolbar
The desktop selection toolbar left Remove RG and the delete button each alone on a row. Delete is now a compact toolbar pill, filled with the error role, that shares a row with Remove RG, delete first. Phones keep the full-width delete button.
This commit is contained in:
1 parent
8b062dc353
commit
2d2aeea4de
3 files changed
+121
-45
No files matched your search
@@ -43,28 +43,16 @@ class LibraryTrackSelectionBar extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
final hasSelection = selectedCount > 0;
|
||||
final delete = AppActionButton(
|
||||
isDestructive: true,
|
||||
onPressed: hasSelection ? onDelete : null,
|
||||
icon: const Icon(Icons.delete_outline),
|
||||
label: Text(
|
||||
hasSelection
|
||||
? context.l10n.selectionDeleteTracksCount(selectedCount)
|
||||
: context.l10n.selectionSelectToDelete,
|
||||
),
|
||||
fontSize: isDesktopPlatform ? 14 : 17,
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor: hasSelection
|
||||
? colorScheme.error
|
||||
: colorScheme.surfaceContainerHighest,
|
||||
foregroundColor: hasSelection
|
||||
? colorScheme.onError
|
||||
: colorScheme.onSurfaceVariant,
|
||||
padding: isDesktopPlatform
|
||||
? const EdgeInsets.symmetric(horizontal: 16, vertical: 8)
|
||||
: const EdgeInsets.symmetric(vertical: 16),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
),
|
||||
final deleteLabel = hasSelection
|
||||
? context.l10n.selectionDeleteTracksCount(selectedCount)
|
||||
: context.l10n.selectionSelectToDelete;
|
||||
Widget replayGain({required bool remove}) => SelectionActionButton(
|
||||
icon: remove ? Icons.remove_circle_outline : Icons.graphic_eq,
|
||||
label: remove
|
||||
? context.l10n.selectionRemoveReplayGainCount(selectedCount)
|
||||
: context.l10n.selectionReplayGainCount(selectedCount),
|
||||
onPressed: hasSelection ? () => onReplayGain(remove: remove) : null,
|
||||
colorScheme: colorScheme,
|
||||
);
|
||||
return SelectionBottomBar(
|
||||
selectedCount: selectedCount,
|
||||
@@ -100,26 +88,53 @@ class LibraryTrackSelectionBar extends StatelessWidget {
|
||||
onPressed: hasSelection ? onConvert : null,
|
||||
colorScheme: colorScheme,
|
||||
),
|
||||
for (final remove in [false, true])
|
||||
SelectionActionButton(
|
||||
icon: remove ? Icons.remove_circle_outline : Icons.graphic_eq,
|
||||
label: remove
|
||||
? context.l10n.selectionRemoveReplayGainCount(selectedCount)
|
||||
: context.l10n.selectionReplayGainCount(selectedCount),
|
||||
onPressed: hasSelection
|
||||
? () => onReplayGain(remove: remove)
|
||||
: null,
|
||||
colorScheme: colorScheme,
|
||||
),
|
||||
replayGain(remove: false),
|
||||
// Desktop keeps delete a toolbar button. It shares a row with
|
||||
// the other removal, delete first, so neither wraps onto a row
|
||||
// of its own.
|
||||
if (isDesktopPlatform)
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
spacing: 8,
|
||||
children: [
|
||||
SelectionActionButton(
|
||||
icon: Icons.delete_outline,
|
||||
label: deleteLabel,
|
||||
onPressed: hasSelection ? onDelete : null,
|
||||
colorScheme: colorScheme,
|
||||
destructive: true,
|
||||
),
|
||||
replayGain(remove: true),
|
||||
],
|
||||
)
|
||||
else
|
||||
replayGain(remove: true),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
// Desktop keeps the destructive action at its own width, as a
|
||||
// toolbar button, instead of a full-width sheet button.
|
||||
if (isDesktopPlatform)
|
||||
Align(alignment: AlignmentDirectional.centerStart, child: delete)
|
||||
else
|
||||
SizedBox(width: double.infinity, child: delete),
|
||||
if (!isDesktopPlatform) ...[
|
||||
const SizedBox(height: 8),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: AppActionButton(
|
||||
isDestructive: true,
|
||||
onPressed: hasSelection ? onDelete : null,
|
||||
icon: const Icon(Icons.delete_outline),
|
||||
label: Text(deleteLabel),
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor: hasSelection
|
||||
? colorScheme.error
|
||||
: colorScheme.surfaceContainerHighest,
|
||||
foregroundColor: hasSelection
|
||||
? colorScheme.onError
|
||||
: colorScheme.onSurfaceVariant,
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -45,20 +45,25 @@ class SelectionActionButton extends StatelessWidget {
|
||||
final VoidCallback? onPressed;
|
||||
final ColorScheme colorScheme;
|
||||
|
||||
/// Fills the button as the destructive action, such as delete.
|
||||
final bool destructive;
|
||||
|
||||
const SelectionActionButton({
|
||||
super.key,
|
||||
required this.icon,
|
||||
required this.label,
|
||||
required this.onPressed,
|
||||
required this.colorScheme,
|
||||
this.destructive = false,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (context.isMornye) {
|
||||
return AppActionButton(
|
||||
outlined: true,
|
||||
tonal: true,
|
||||
outlined: !destructive,
|
||||
tonal: !destructive,
|
||||
isDestructive: destructive,
|
||||
onPressed: onPressed,
|
||||
icon: Icon(icon),
|
||||
label: Text(label, maxLines: 2, overflow: TextOverflow.ellipsis),
|
||||
@@ -75,12 +80,16 @@ class SelectionActionButton extends StatelessWidget {
|
||||
onTap: onPressed,
|
||||
excludeSemantics: true,
|
||||
child: ExpressiveButton(
|
||||
tonal: true,
|
||||
tonal: !destructive,
|
||||
onPressed: onPressed,
|
||||
icon: Icon(icon, size: 18),
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor: colorScheme.secondaryContainer,
|
||||
foregroundColor: colorScheme.onSecondaryContainer,
|
||||
backgroundColor: destructive
|
||||
? colorScheme.error
|
||||
: colorScheme.secondaryContainer,
|
||||
foregroundColor: destructive
|
||||
? colorScheme.onError
|
||||
: colorScheme.onSecondaryContainer,
|
||||
minimumSize: compact
|
||||
? const Size(0, 40)
|
||||
: Size(48, context.tokens.minTouchTarget),
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mornye/l10n/l10n.dart';
|
||||
import 'package:mornye/theme/mornye_theme.dart';
|
||||
import 'package:mornye/utils/desktop_platform.dart';
|
||||
import 'package:mornye/widgets/library_track_selection_bar.dart';
|
||||
import 'package:mornye/widgets/selection_action_button.dart';
|
||||
|
||||
@@ -128,5 +129,56 @@ void main() {
|
||||
expect(tester.takeException(), isNull);
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('desktop delete leads the Remove RG row ($mornye)', (
|
||||
tester,
|
||||
) async {
|
||||
debugDesktopPlatformOverride = true;
|
||||
addTearDown(() => debugDesktopPlatformOverride = null);
|
||||
tester.view.physicalSize = const Size(1280, 800);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
var deleted = false;
|
||||
await tester.pumpWidget(
|
||||
_app(
|
||||
mornye,
|
||||
Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: LibraryTrackSelectionBar(
|
||||
selectedCount: 1,
|
||||
allSelected: false,
|
||||
onClose: () {},
|
||||
onToggleSelectAll: () {},
|
||||
bottomPadding: 0,
|
||||
onReEnrich: () {},
|
||||
onConvert: () {},
|
||||
onReplayGain: ({required remove}) {},
|
||||
onDelete: () => deleted = true,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
Rect button(IconData icon) => tester.getRect(
|
||||
find.byWidgetPredicate(
|
||||
(widget) => widget is SelectionActionButton && widget.icon == icon,
|
||||
),
|
||||
);
|
||||
final delete = button(Icons.delete_outline);
|
||||
final removeGain = button(Icons.remove_circle_outline);
|
||||
// Same row and height, delete on the leading side.
|
||||
expect(delete.top, removeGain.top);
|
||||
expect(delete.height, removeGain.height);
|
||||
expect(delete.right, lessThan(removeGain.left));
|
||||
// Nothing sits alone below the row.
|
||||
final lowest = tester
|
||||
.widgetList<SelectionActionButton>(find.byType(SelectionActionButton))
|
||||
.map((widget) => button(widget.icon).top)
|
||||
.reduce((a, b) => a > b ? a : b);
|
||||
expect(lowest, delete.top);
|
||||
await tester.tap(find.text('Delete 1 track'));
|
||||
expect(deleted, isTrue);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user