mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-11-29 07:34:13 +01:00
Home showed either the chosen extension's feed or the person's own sections, never both, so anyone with a feed extension lost the shortcuts, mixes and Library shelves, and the Material Home also carried the search field. Home is now the person's own page in both styles and never asks for a feed. Search is a destination in both styles (Home, Library, Store, Search, Settings; Mornye phones keep Settings as a page) and opens on the feed before anything is typed. Recent searches wait for the field while a feed fills the page; a tap beside the empty field, Back, or the Search destination pressed again returns to the feed. Without a feed Search opens on recent searches, and with neither a provider nor a feed it shows the provider prompt under the field. The Mornye bar's search button opens the feed first and focuses the field when pressed on Search, or at once when there is no feed. The Mornye desktop Search page keeps its recents row and Browse tiles. Both styles now share one destination order, so the search tab flag of the shell navigation service and the style argument of the tab order helpers go. The Material rail and Cmd/Ctrl+1..5 gain Search. With an empty Library and nothing played, Home says so in both styles and offers a "Find music" button that opens Search; the Library's empty state on Mornye leads there too. The feed setting is renamed from Home feed to Search feed (English and Indonesian; other languages keep the old wording until translated). The feed no longer repeats the greeting or Top Picks, which Home already shows.
277 lines
8.1 KiB
Dart
277 lines
8.1 KiB
Dart
import 'package:material_ui/material_ui.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:mornye/l10n/app_localizations.dart';
|
|
import 'package:mornye/services/shell_navigation_service.dart';
|
|
import 'package:mornye/widgets/view_queue_snackbar_action.dart';
|
|
|
|
void main() {
|
|
for (final showRepo in [false, true]) {
|
|
testWidgets('first search request reaches the lazy page (repo=$showRepo)', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(
|
|
MaterialApp(home: _SearchShell(showRepo: showRepo)),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
expect(find.byType(TextField), findsNothing);
|
|
|
|
await tester.tap(find.text('Search'));
|
|
await tester.pumpAndSettle();
|
|
final field = tester.widget<TextField>(find.byType(TextField));
|
|
expect(field.focusNode!.hasFocus, isTrue);
|
|
expect(tester.testTextInput.isVisible, isTrue);
|
|
});
|
|
|
|
testWidgets(
|
|
'search returns from an album to its own tab (repo=$showRepo)',
|
|
(tester) async {
|
|
await tester.pumpWidget(
|
|
MaterialApp(home: _SearchShell(showRepo: showRepo)),
|
|
);
|
|
await tester.tap(find.text('Search'));
|
|
await tester.pumpAndSettle();
|
|
final navigator =
|
|
ShellNavigationService.searchTabNavigatorKey.currentState!;
|
|
expect(ShellNavigationService.activeTabNavigator(), same(navigator));
|
|
navigator.push(
|
|
MaterialPageRoute<void>(
|
|
builder: (_) => const Scaffold(body: Text('Album')),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.text('Search'));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Album'), findsNothing);
|
|
final field = tester.widget<TextField>(find.byType(TextField));
|
|
expect(field.focusNode!.hasFocus, isTrue);
|
|
expect(tester.testTextInput.isVisible, isTrue);
|
|
},
|
|
);
|
|
}
|
|
|
|
testWidgets(
|
|
'search selects its tab before requesting focus and stops when shell is absent',
|
|
(tester) async {
|
|
final owner = Object();
|
|
ShellNavigationService.syncState(currentTabIndex: 0, showRepoTab: false);
|
|
var selectedSearch = false;
|
|
var focusRequests = 0;
|
|
void onSearch() {
|
|
expect(selectedSearch, isTrue);
|
|
focusRequests++;
|
|
}
|
|
|
|
ShellNavigationService.searchRequests.addListener(onSearch);
|
|
addTearDown(() {
|
|
ShellNavigationService.searchRequests.removeListener(onSearch);
|
|
ShellNavigationService.unregisterTabSelectionHandler(owner);
|
|
});
|
|
ShellNavigationService.registerTabSelectionHandler(
|
|
owner: owner,
|
|
handler: (tab) {
|
|
selectedSearch = tab == ShellTab.search;
|
|
ShellNavigationService.syncState(
|
|
currentTabIndex: 2,
|
|
showRepoTab: false,
|
|
);
|
|
},
|
|
);
|
|
ShellNavigationService.requestSearch();
|
|
expect(focusRequests, 0);
|
|
await tester.pump();
|
|
expect(focusRequests, 1);
|
|
ShellNavigationService.unregisterTabSelectionHandler(owner);
|
|
ShellNavigationService.requestSearch();
|
|
expect(focusRequests, 1);
|
|
},
|
|
);
|
|
|
|
group('ShellNavigationService tab requests', () {
|
|
test('forwards a named tab request to the registered shell', () {
|
|
final owner = Object();
|
|
ShellTab? requestedTab;
|
|
addTearDown(
|
|
() => ShellNavigationService.unregisterTabSelectionHandler(owner),
|
|
);
|
|
|
|
ShellNavigationService.registerTabSelectionHandler(
|
|
owner: owner,
|
|
handler: (tab) => requestedTab = tab,
|
|
);
|
|
|
|
expect(ShellNavigationService.requestTab(ShellTab.library), isTrue);
|
|
expect(requestedTab, ShellTab.library);
|
|
});
|
|
|
|
test('does not remove a newer shell handler', () {
|
|
final oldOwner = Object();
|
|
final currentOwner = Object();
|
|
ShellTab? requestedTab;
|
|
addTearDown(
|
|
() =>
|
|
ShellNavigationService.unregisterTabSelectionHandler(currentOwner),
|
|
);
|
|
|
|
ShellNavigationService.registerTabSelectionHandler(
|
|
owner: oldOwner,
|
|
handler: (_) {},
|
|
);
|
|
ShellNavigationService.registerTabSelectionHandler(
|
|
owner: currentOwner,
|
|
handler: (tab) => requestedTab = tab,
|
|
);
|
|
|
|
ShellNavigationService.unregisterTabSelectionHandler(oldOwner);
|
|
|
|
expect(ShellNavigationService.requestTab(ShellTab.settings), isTrue);
|
|
expect(requestedTab, ShellTab.settings);
|
|
});
|
|
|
|
test('reports when no shell can handle the request', () {
|
|
final owner = Object();
|
|
ShellNavigationService.registerTabSelectionHandler(
|
|
owner: owner,
|
|
handler: (_) {},
|
|
);
|
|
ShellNavigationService.unregisterTabSelectionHandler(owner);
|
|
|
|
expect(ShellNavigationService.requestTab(ShellTab.library), isFalse);
|
|
});
|
|
|
|
testWidgets('View Queue snackbar action requests the Library tab', (
|
|
tester,
|
|
) async {
|
|
final owner = Object();
|
|
ShellTab? requestedTab;
|
|
addTearDown(
|
|
() => ShellNavigationService.unregisterTabSelectionHandler(owner),
|
|
);
|
|
ShellNavigationService.registerTabSelectionHandler(
|
|
owner: owner,
|
|
handler: (tab) => requestedTab = tab,
|
|
);
|
|
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
|
supportedLocales: AppLocalizations.supportedLocales,
|
|
home: Scaffold(
|
|
body: Builder(
|
|
builder: (context) => buildViewQueueSnackBarAction(context),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
await tester.tap(find.text('View Queue'));
|
|
|
|
expect(requestedTab, ShellTab.library);
|
|
});
|
|
});
|
|
}
|
|
|
|
class _SearchShell extends StatefulWidget {
|
|
const _SearchShell({required this.showRepo});
|
|
|
|
final bool showRepo;
|
|
|
|
@override
|
|
State<_SearchShell> createState() => _SearchShellState();
|
|
}
|
|
|
|
class _SearchShellState extends State<_SearchShell> {
|
|
final _pages = PageController(initialPage: 1);
|
|
GlobalKey<NavigatorState> get _navigatorKey =>
|
|
ShellNavigationService.searchTabNavigatorKey;
|
|
int get _searchIndex => widget.showRepo ? 3 : 2;
|
|
late final _observer = ShellChromeObserver(_navigatorKey);
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
ShellNavigationService.syncState(
|
|
currentTabIndex: 1,
|
|
showRepoTab: widget.showRepo,
|
|
);
|
|
ShellNavigationService.registerTabSelectionHandler(
|
|
owner: this,
|
|
handler: (_) {
|
|
ShellNavigationService.syncState(
|
|
currentTabIndex: _searchIndex,
|
|
showRepoTab: widget.showRepo,
|
|
);
|
|
_pages.jumpToPage(_searchIndex);
|
|
},
|
|
);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
ShellNavigationService.unregisterTabSelectionHandler(this);
|
|
_observer.detach();
|
|
_pages.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) => Scaffold(
|
|
body: Column(
|
|
children: [
|
|
TextButton(
|
|
onPressed: ShellNavigationService.requestSearch,
|
|
child: const Text('Search'),
|
|
),
|
|
Expanded(
|
|
child: PageView.builder(
|
|
controller: _pages,
|
|
itemCount: _searchIndex + 1,
|
|
itemBuilder: (_, index) => index != _searchIndex
|
|
? const Text('Library')
|
|
: Navigator(
|
|
key: _navigatorKey,
|
|
observers: [_observer],
|
|
onGenerateRoute: (_) => MaterialPageRoute<void>(
|
|
builder: (_) => const _SearchHome(),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
class _SearchHome extends StatefulWidget {
|
|
const _SearchHome();
|
|
|
|
@override
|
|
State<_SearchHome> createState() => _SearchHomeState();
|
|
}
|
|
|
|
class _SearchHomeState extends State<_SearchHome> {
|
|
final _focus = FocusNode();
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
ShellNavigationService.searchRequests.addListener(_onSearch);
|
|
}
|
|
|
|
void _onSearch() {
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
if (mounted) _focus.requestFocus();
|
|
});
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
ShellNavigationService.searchRequests.removeListener(_onSearch);
|
|
_focus.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) =>
|
|
Scaffold(body: TextField(focusNode: _focus));
|
|
}
|