Skip to content

Commit

Permalink
Merge pull request #650 from Ivanf1/redesign-tab-drag
Browse files Browse the repository at this point in the history
Enable drag handle for items in tabs list
  • Loading branch information
Chaphasilor authored Mar 31, 2024
2 parents 958e974 + 84aab57 commit b73898a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
3 changes: 2 additions & 1 deletion lib/components/MusicScreen/music_screen_tab_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,8 @@ class _MusicScreenTabViewState extends State<MusicScreenTabView>
settings.tabSortOrder[widget.tabContentType],
settings.onlyShowFullyDownloaded,
widget.view?.id,
settings.isOffline);
settings.isOffline,
settings.tabOrder,);
if (refreshHash == null) {
refreshHash = newRefreshHash;
} else if (refreshHash != newRefreshHash) {
Expand Down
7 changes: 6 additions & 1 deletion lib/components/TabsSettingsScreen/hide_tab_toggle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import '../../models/finamp_models.dart';
class HideTabToggle extends StatelessWidget {
const HideTabToggle({
Key? key,
required this.index,
required this.tabContentType,
}) : super(key: key);

final TabContentType tabContentType;
final int index;

@override
Widget build(BuildContext context) {
Expand All @@ -19,7 +21,10 @@ class HideTabToggle extends StatelessWidget {
builder: (_, box, __) {
return SwitchListTile.adaptive(
title: Text(tabContentType.toLocalisedString(context)),
// secondary: const Icon(Icons.drag_handle),
secondary: ReorderableDragStartListener(
index: index,
child: const Icon(Icons.drag_handle),
),
// This should never be null, but it gets set to true if it is.
value: FinampSettingsHelper.finampSettings.showTabs[tabContentType] ??
true,
Expand Down
14 changes: 8 additions & 6 deletions lib/screens/tabs_settings_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class _TabsSettingsScreenState extends State<TabsSettingsScreen> {
FinampSettingsHelper.finampSettings.tabOrder[index],
key:
ValueKey(FinampSettingsHelper.finampSettings.tabOrder[index]),
index: index,
);
},
onReorder: (oldIndex, newIndex) {
Expand All @@ -54,13 +55,14 @@ class _TabsSettingsScreenState extends State<TabsSettingsScreen> {
newIndex -= 1;
}

final oldValue =
FinampSettingsHelper.finampSettings.tabOrder[oldIndex];
final newValue =
FinampSettingsHelper.finampSettings.tabOrder[newIndex];
final currentTabOrder = FinampSettingsHelper.finampSettings.tabOrder;

// move all values below newIndex down by one
final oldTab = currentTabOrder[oldIndex];
currentTabOrder.removeAt(oldIndex);
currentTabOrder.insert(newIndex, oldTab);
FinampSettingsHelper.setTabOrder(currentTabOrder);

FinampSettingsHelper.setTabOrder(oldIndex, newValue);
FinampSettingsHelper.setTabOrder(newIndex, oldValue);
});
},
),
Expand Down
4 changes: 2 additions & 2 deletions lib/services/finamp_settings_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@ class FinampSettingsHelper {
.put("FinampSettings", finampSettingsTemp);
}

static void setTabOrder(int index, TabContentType tabContentType) {
static void setTabOrder(List<TabContentType> newTabOrder) {
FinampSettings finampSettingsTemp = finampSettings;
finampSettingsTemp.tabOrder[index] = tabContentType;
finampSettingsTemp.tabOrder = newTabOrder;
Hive.box<FinampSettings>("FinampSettings")
.put("FinampSettings", finampSettingsTemp);
}
Expand Down

0 comments on commit b73898a

Please sign in to comment.