mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-11-28 23:25:52 +01:00
QueueTab returns MornyeLibraryScreen for the Mornye root Library, and the page switcher renders only on that root, so its Mornye chip branch and _FilterChip could never build.
297 lines
8.6 KiB
Dart
297 lines
8.6 KiB
Dart
part of 'queue_tab.dart';
|
|
|
|
class _QueueItemSliverRow extends ConsumerWidget {
|
|
final String itemId;
|
|
final ColorScheme colorScheme;
|
|
final Widget Function(BuildContext, DownloadItem, ColorScheme) itemBuilder;
|
|
|
|
const _QueueItemSliverRow({
|
|
super.key,
|
|
required this.itemId,
|
|
required this.colorScheme,
|
|
required this.itemBuilder,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final item = ref.watch(
|
|
downloadQueueLookupProvider.select((lookup) => lookup.byItemId[itemId]),
|
|
);
|
|
if (item == null) {
|
|
return const SizedBox.shrink();
|
|
}
|
|
|
|
return RepaintBoundary(child: itemBuilder(context, item, colorScheme));
|
|
}
|
|
}
|
|
|
|
class _LibraryTool {
|
|
const _LibraryTool({
|
|
required this.icon,
|
|
required this.onPressed,
|
|
this.label,
|
|
this.tooltip,
|
|
this.onLongPress,
|
|
});
|
|
|
|
final Widget icon;
|
|
final String? label;
|
|
final String? tooltip;
|
|
|
|
/// Receives the tool button's own context, which a menu can anchor below.
|
|
final ValueChanged<BuildContext> onPressed;
|
|
final VoidCallback? onLongPress;
|
|
}
|
|
|
|
/// A Library page's tools (sort, filter, view) as one connected Material 3
|
|
/// Expressive button group, so the related controls read as one object.
|
|
/// The group is 44dp tall on phones and 40dp for desktop pointer input;
|
|
/// both keep the 48dp touch target.
|
|
class _LibraryToolGroup extends StatefulWidget {
|
|
const _LibraryToolGroup({required this.tools});
|
|
|
|
final List<_LibraryTool> tools;
|
|
|
|
@override
|
|
State<_LibraryToolGroup> createState() => _LibraryToolGroupState();
|
|
}
|
|
|
|
class _LibraryToolGroupState extends State<_LibraryToolGroup> {
|
|
// The button group attaches each node to its tool's button, which makes
|
|
// the node's context the button's own.
|
|
final _focusNodes = <FocusNode>[];
|
|
|
|
FocusNode _focusNodeAt(int index) {
|
|
while (_focusNodes.length <= index) {
|
|
_focusNodes.add(FocusNode(debugLabel: 'Library tool $index'));
|
|
}
|
|
return _focusNodes[index];
|
|
}
|
|
|
|
BuildContext _toolContext(int index) =>
|
|
_focusNodeAt(index).context ?? context;
|
|
|
|
/// Runs the long press of the tool under the pointer, if it has one.
|
|
void _handleLongPress(LongPressStartDetails details) {
|
|
for (final (index, tool) in widget.tools.indexed) {
|
|
final box = _focusNodeAt(index).context?.findRenderObject();
|
|
if (box is! RenderBox || !box.hasSize) continue;
|
|
final x = box.globalToLocal(details.globalPosition).dx;
|
|
if (x >= 0 && x < box.size.width) {
|
|
tool.onLongPress?.call();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
for (final node in _focusNodes) {
|
|
node.dispose();
|
|
}
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final tools = widget.tools;
|
|
final height = isDesktopPlatform ? 40.0 : 44.0;
|
|
return GestureDetector(
|
|
onLongPressStart: tools.any((tool) => tool.onLongPress != null)
|
|
? _handleLongPress
|
|
: null,
|
|
excludeFromSemantics: true,
|
|
child: _TouchTargetPadding(
|
|
minHeight: context.tokens.minTouchTarget,
|
|
child: MaterialExpressiveScope(
|
|
skipAutofocus: true,
|
|
child: M3EButtonGroup(
|
|
type: M3EButtonGroupType.connected,
|
|
style: M3EButtonStyle.filled,
|
|
size: M3EButtonSize.sm.copyWith(height: height),
|
|
// Tools are actions, not options: nothing stays selected, and a
|
|
// press reports the tool through the selection callback.
|
|
onSelectedIndexChanged: (index) {
|
|
if (index != null) tools[index].onPressed(_toolContext(index));
|
|
},
|
|
actions: [
|
|
for (final (index, tool) in tools.indexed)
|
|
M3EButtonGroupAction(
|
|
icon: tool.icon,
|
|
label: tool.label == null ? null : Text(tool.label!),
|
|
tooltip: tool.tooltip,
|
|
focusNode: _focusNodeAt(index),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Grows [child] to [minHeight] and sends a touch above or below it to the
|
|
/// nearest point of [child], so a compact control keeps its full touch
|
|
/// target.
|
|
class _TouchTargetPadding extends SingleChildRenderObjectWidget {
|
|
const _TouchTargetPadding({required this.minHeight, required super.child});
|
|
|
|
final double minHeight;
|
|
|
|
@override
|
|
_RenderTouchTargetPadding createRenderObject(BuildContext context) =>
|
|
_RenderTouchTargetPadding(minHeight);
|
|
|
|
@override
|
|
void updateRenderObject(
|
|
BuildContext context,
|
|
_RenderTouchTargetPadding renderObject,
|
|
) {
|
|
renderObject.minHeight = minHeight;
|
|
}
|
|
}
|
|
|
|
class _RenderTouchTargetPadding extends RenderShiftedBox {
|
|
_RenderTouchTargetPadding(this._minHeight) : super(null);
|
|
|
|
double _minHeight;
|
|
|
|
set minHeight(double value) {
|
|
if (value == _minHeight) return;
|
|
_minHeight = value;
|
|
markNeedsLayout();
|
|
}
|
|
|
|
Size _paddedSize(BoxConstraints constraints, Size childSize) =>
|
|
constraints.constrain(
|
|
Size(
|
|
childSize.width,
|
|
childSize.height < _minHeight ? _minHeight : childSize.height,
|
|
),
|
|
);
|
|
|
|
@override
|
|
Size computeDryLayout(covariant BoxConstraints constraints) => _paddedSize(
|
|
constraints,
|
|
child?.getDryLayout(constraints.loosen()) ?? Size.zero,
|
|
);
|
|
|
|
@override
|
|
void performLayout() {
|
|
final child = this.child;
|
|
if (child == null) {
|
|
size = _paddedSize(constraints, Size.zero);
|
|
return;
|
|
}
|
|
child.layout(constraints.loosen(), parentUsesSize: true);
|
|
size = _paddedSize(constraints, child.size);
|
|
(child.parentData! as BoxParentData).offset = Offset(
|
|
0,
|
|
(size.height - child.size.height) / 2,
|
|
);
|
|
}
|
|
|
|
@override
|
|
bool hitTestChildren(BoxHitTestResult result, {required Offset position}) {
|
|
final child = this.child;
|
|
if (child == null) return false;
|
|
final offset = (child.parentData! as BoxParentData).offset;
|
|
final bottom = child.size.height - 1;
|
|
final local = Offset(
|
|
position.dx - offset.dx,
|
|
clampDouble(position.dy - offset.dy, 0, bottom < 0 ? 0 : bottom),
|
|
);
|
|
return result.addWithPaintOffset(
|
|
offset: position - local,
|
|
position: position,
|
|
hitTest: (result, transformed) =>
|
|
child.hitTest(result, position: transformed),
|
|
);
|
|
}
|
|
}
|
|
|
|
enum _CollectionEntryType { wishlist, loved, favoriteArtists, playlist }
|
|
|
|
class _CollectionEntry {
|
|
final _CollectionEntryType type;
|
|
final int playlistIndex;
|
|
|
|
const _CollectionEntry._(this.type, [this.playlistIndex = -1]);
|
|
|
|
static const wishlist = _CollectionEntry._(_CollectionEntryType.wishlist);
|
|
static const loved = _CollectionEntry._(_CollectionEntryType.loved);
|
|
static const favoriteArtists = _CollectionEntry._(
|
|
_CollectionEntryType.favoriteArtists,
|
|
);
|
|
static _CollectionEntry playlist(int index) =>
|
|
_CollectionEntry._(_CollectionEntryType.playlist, index);
|
|
}
|
|
|
|
/// Library page switcher on Material: primary tabs, since the pages are
|
|
/// views of one collection rather than filters. Counts trail each label.
|
|
class _LibraryPageTabs extends StatefulWidget {
|
|
const _LibraryPageTabs({
|
|
required this.tabs,
|
|
required this.selectedIndex,
|
|
required this.onSelected,
|
|
});
|
|
|
|
/// Label and item count per page; a null count is hidden.
|
|
final List<(String, int?)> tabs;
|
|
final int selectedIndex;
|
|
final ValueChanged<int> onSelected;
|
|
|
|
@override
|
|
State<_LibraryPageTabs> createState() => _LibraryPageTabsState();
|
|
}
|
|
|
|
class _LibraryPageTabsState extends State<_LibraryPageTabs>
|
|
with SingleTickerProviderStateMixin {
|
|
late final TabController _controller = TabController(
|
|
length: widget.tabs.length,
|
|
initialIndex: widget.selectedIndex,
|
|
vsync: this,
|
|
);
|
|
|
|
@override
|
|
void didUpdateWidget(covariant _LibraryPageTabs oldWidget) {
|
|
super.didUpdateWidget(oldWidget);
|
|
if (widget.selectedIndex != _controller.index) {
|
|
_controller.animateTo(widget.selectedIndex);
|
|
}
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_controller.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
// Inherits the tab's label color, so the count follows the selection.
|
|
const countStyle = TextStyle(fontWeight: FontWeight.w400);
|
|
return TabBar(
|
|
controller: _controller,
|
|
isScrollable: true,
|
|
tabAlignment: TabAlignment.start,
|
|
onTap: widget.onSelected,
|
|
tabs: [
|
|
for (final (label, count) in widget.tabs)
|
|
Tab(
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Text(label),
|
|
if (count != null) ...[
|
|
const SizedBox(width: 6),
|
|
Text('$count', style: countStyle),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|