Skip to content

Commit

Permalink
fix floating action buttons on music screen not adhering to tab order
Browse files Browse the repository at this point in the history
- there still seems to be some issue when switching from playlists tab to albums, there the FAB stays hidden for some reason...
  • Loading branch information
Chaphasilor committed May 3, 2024
1 parent 2cb066d commit 6967675
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
30 changes: 13 additions & 17 deletions lib/screens/music_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,10 @@ class _MusicScreenState extends ConsumerState<MusicScreen>
super.dispose();
}

FloatingActionButton? getFloatingActionButton() {
var tabList = FinampSettingsHelper.finampSettings.showTabs.entries
.where((element) => element.value)
.map((e) => e.key)
.toList();
FloatingActionButton? getFloatingActionButton(List<TabContentType> sortedTabs) {

// Show the floating action button only on the albums, artists, generes and songs tab.
if (_tabController!.index == tabList.indexOf(TabContentType.songs)) {
if (_tabController!.index == sortedTabs.indexOf(TabContentType.songs)) {
return FloatingActionButton(
tooltip: AppLocalizations.of(context)!.shuffleAll,
onPressed: () async {
Expand All @@ -118,7 +114,7 @@ class _MusicScreenState extends ConsumerState<MusicScreen>
child: const Icon(Icons.shuffle),
);
} else if (_tabController!.index ==
tabList.indexOf(TabContentType.artists)) {
sortedTabs.indexOf(TabContentType.artists)) {
return FloatingActionButton(
tooltip: AppLocalizations.of(context)!.startMix,
onPressed: () async {
Expand All @@ -137,7 +133,7 @@ class _MusicScreenState extends ConsumerState<MusicScreen>
},
child: const Icon(Icons.explore));
} else if (_tabController!.index ==
tabList.indexOf(TabContentType.albums)) {
sortedTabs.indexOf(TabContentType.albums)) {
return FloatingActionButton(
tooltip: AppLocalizations.of(context)!.startMix,
onPressed: () async {
Expand All @@ -155,7 +151,7 @@ class _MusicScreenState extends ConsumerState<MusicScreen>
},
child: const Icon(Icons.explore));
} else if (_tabController!.index ==
tabList.indexOf(TabContentType.genres)) {
sortedTabs.indexOf(TabContentType.genres)) {
return FloatingActionButton(
tooltip: AppLocalizations.of(context)!.startMix,
onPressed: () async {
Expand Down Expand Up @@ -193,12 +189,12 @@ class _MusicScreenState extends ConsumerState<MusicScreen>

// Get the tabs from the user's tab order, and filter them to only
// include enabled tabs
final tabs = finampSettings!.tabOrder.where(
final sortedTabs = finampSettings!.tabOrder.where(
(e) => FinampSettingsHelper.finampSettings.showTabs[e] ?? false);

if (tabs.length != _tabController?.length) {
if (sortedTabs.length != _tabController?.length) {
_musicScreenLogger.info(
"Rebuilding MusicScreen tab controller (${tabs.length} != ${_tabController?.length})");
"Rebuilding MusicScreen tab controller (${sortedTabs.length} != ${_tabController?.length})");
_buildTabController();
}

Expand Down Expand Up @@ -231,7 +227,7 @@ class _MusicScreenState extends ConsumerState<MusicScreen>
AppLocalizations.of(context)!.music),
bottom: TabBar(
controller: _tabController,
tabs: tabs
tabs: sortedTabs
.map((tabType) => Tab(
text:
tabType.toLocalisedString(context).toUpperCase(),
Expand Down Expand Up @@ -261,10 +257,10 @@ class _MusicScreenState extends ConsumerState<MusicScreen>
]
: [
SortOrderButton(
tabs.elementAt(_tabController!.index),
sortedTabs.elementAt(_tabController!.index),
),
SortByMenuButton(
tabs.elementAt(_tabController!.index),
sortedTabs.elementAt(_tabController!.index),
),
if (finampSettings.isOffline)
IconButton(
Expand Down Expand Up @@ -307,15 +303,15 @@ class _MusicScreenState extends ConsumerState<MusicScreen>
right: FinampSettingsHelper.finampSettings.showFastScroller
? 24.0
: 8.0),
child: getFloatingActionButton(),
child: getFloatingActionButton(sortedTabs.toList()),
),
body: TabBarView(
controller: _tabController,
physics: FinampSettingsHelper.finampSettings.disableGesture
? const NeverScrollableScrollPhysics()
: const AlwaysScrollableScrollPhysics(),
dragStartBehavior: DragStartBehavior.down,
children: tabs
children: sortedTabs
.map((tabType) => MusicScreenTabView(
tabContentType: tabType,
searchTerm: searchQuery,
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/tabs_settings_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class _TabsSettingsScreenState extends State<TabsSettingsScreen> {
newIndex -= 1;
}

final currentTabOrder = FinampSettingsHelper.finampSettings.tabOrder;
var currentTabOrder = FinampSettingsHelper.finampSettings.tabOrder;

// move all values below newIndex down by one
final oldTab = currentTabOrder[oldIndex];
Expand Down

0 comments on commit 6967675

Please sign in to comment.