Skip to content

Commit

Permalink
Fix settings button visible on insertion settings page (#90)
Browse files Browse the repository at this point in the history
* Fix playlist settings button not hiding on settings page

* Add some tests for playlist add items selection route

* Convert 1 based index of insertSongsInPlaylist to 0 base
  • Loading branch information
Abestanis authored May 8, 2023
1 parent 9f4574b commit 5db7929
Show file tree
Hide file tree
Showing 8 changed files with 301 additions and 33 deletions.
7 changes: 2 additions & 5 deletions lib/routes/home_route/persistent_queue_route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,9 @@ class _PersistentQueueRouteState extends State<PersistentQueueRoute> with Select
onSubmit: (entries) {
int index;
if (selectedSong == null) {
index = 1;
index = 0;
} else {
index = songs.indexOf(selectedSong!) + 2;
if (index <= 0) {
index = 1;
}
index = songs.indexOf(selectedSong!) + 1;
}
ContentControl.instance.insertSongsInPlaylist(
index: index,
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/home_route/player_route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ class _SaveQueueAsPlaylistActionState extends State<_SaveQueueAsPlaylistAction>
bool success = false;
try {
await ContentControl.instance.insertSongsInPlaylist(
index: 1,
index: 0,
songs: songs,
playlist: playlist,
);
Expand Down
48 changes: 25 additions & 23 deletions lib/routes/selection_route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class _SelectionRouteState extends State<SelectionRoute> {
late final HomeRouter nestedHomeRouter = HomeRouter.selection(widget.selectionArguments);
late final ContentSelectionController controller;
late ChildBackButtonDispatcher _backButtonDispatcher;
bool settingsOpened = false;

@override
void didChangeDependencies() {
Expand All @@ -29,38 +28,41 @@ class _SelectionRouteState extends State<SelectionRoute> {
@override
void initState() {
super.initState();
var settingsOpened = false;
controller = ContentSelectionController.createAlwaysInSelection(
context: context,
actionsBuilder: (context) {
final l10n = getl10n(context);
final settingsPageBuilder = widget.selectionArguments.settingsPageBuilder;
return [
if (settingsPageBuilder != null)
AnimatedSwitcher(
duration: const Duration(milliseconds: 240),
switchInCurve: Curves.easeOutCubic,
switchOutCurve: Curves.easeInCubic,
child: settingsOpened
? const SizedBox.shrink()
: NFIconButton(
icon: const Icon(Icons.settings_rounded),
onPressed: () async {
if (!settingsOpened) {
setState(() {
settingsOpened = true;
});
await nestedHomeRouter.navigatorKey.currentState!.push(StackFadeRouteTransition(
child: Builder(builder: (context) => settingsPageBuilder(context)),
transitionSettings: AppRouter.instance.transitionSettings.greyDismissible,
));
if (mounted) {
StatefulBuilder(
builder: (context, setState) => AnimatedSwitcher(
duration: const Duration(milliseconds: 240),
switchInCurve: Curves.easeOutCubic,
switchOutCurve: Curves.easeInCubic,
child: settingsOpened
? const SizedBox.shrink()
: NFIconButton(
icon: const Icon(Icons.settings_rounded),
onPressed: () async {
if (!settingsOpened) {
setState(() {
settingsOpened = false;
settingsOpened = true;
});
await nestedHomeRouter.navigatorKey.currentState!.push(StackFadeRouteTransition(
child: Builder(builder: (context) => settingsPageBuilder(context)),
transitionSettings: AppRouter.instance.transitionSettings.greyDismissible,
));
if (mounted) {
setState(() {
settingsOpened = false;
});
}
}
}
},
),
},
),
),
),
const SizedBox(width: 6.0),
AnimatedBuilder(
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/selection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1741,7 +1741,7 @@ class _AddToPlaylistSelectionAction extends StatelessWidget {
onItemTap: (index) {
final playlist = playlists[index];
ContentControl.instance.insertSongsInPlaylist(
index: playlist.length + 1,
index: playlist.length,
songs: ContentUtils.flatten(ContentUtils.selectionPackAndSort(controller.data).merged),
playlist: playlist,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,8 @@ public void onMethodCall(@NonNull MethodCall call, @NotNull MethodChannel.Result
);
values.put(
MediaStore.Audio.Playlists.Members.PLAY_ORDER,
i + index
// Play order is one based, so add 1 to the zero based index.
i + index + 1
);
valuesList.add(values);
}
Expand Down
2 changes: 1 addition & 1 deletion sweyer_plugin/lib/sweyer_plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class SweyerPlugin {
required PlatformPlaylist playlist,
}) {
assert(songs.isNotEmpty);
assert(index >= 0 && index <= playlist.songIds.length + 1);
assert(index >= 0 && index <= playlist.songIds.length);
return SweyerPluginPlatform.instance.insertSongsInPlaylist(
index: index,
songIds: songs.map((song) => song.sourceId).toList(),
Expand Down
5 changes: 4 additions & 1 deletion test/fakes/fake_sweyer_plugin_platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ class FakeSweyerPluginPlatform extends SweyerPluginPlatform {
required int index,
required List<int> songIds,
required int playlistId,
}) async {}
}) async {
final playlist = playlists!.firstWhere((playlist) => playlist.id == playlistId);
playlist.songIds.insertAll(index, songIds);
}

@override
Future<bool> isIntentActionView() async {
Expand Down
Loading

0 comments on commit 5db7929

Please sign in to comment.