Skip to content

Commit

Permalink
fix: local track not showing up in queue
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed May 23, 2024
1 parent 22caa81 commit d82261c
Show file tree
Hide file tree
Showing 8 changed files with 382 additions and 332 deletions.
106 changes: 51 additions & 55 deletions lib/components/library/user_local_tracks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,20 @@ import 'package:file_selector/file_selector.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:collection/collection.dart';
import 'package:fuzzywuzzy/fuzzywuzzy.dart';
import 'package:go_router/go_router.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:metadata_god/metadata_god.dart';
import 'package:mime/mime.dart';
import 'package:path/path.dart';
import 'package:path_provider/path_provider.dart';
import 'package:skeletonizer/skeletonizer.dart';

import 'package:spotify/spotify.dart';
import 'package:spotube/collections/fake.dart';
import 'package:spotube/collections/spotube_icons.dart';
import 'package:spotube/components/shared/expandable_search/expandable_search.dart';
import 'package:spotube/components/shared/fallbacks/not_found.dart';
import 'package:spotube/components/shared/inter_scrollbar/inter_scrollbar.dart';
import 'package:spotube/components/shared/sort_tracks_dropdown.dart';
import 'package:spotube/components/shared/track_tile/track_tile.dart';
import 'package:spotube/extensions/artist_simple.dart';
import 'package:spotube/extensions/context.dart';
import 'package:spotube/extensions/track.dart';
import 'package:spotube/models/local_track.dart';
import 'package:spotube/provider/proxy_playlist/proxy_playlist_provider.dart';
import 'package:spotube/provider/user_preferences/user_preferences_provider.dart';
import 'package:spotube/utils/platform.dart';
import 'package:spotube/utils/service_utils.dart';
// ignore: depend_on_referenced_packages
import 'package:flutter_rust_bridge/flutter_rust_bridge.dart' show FfiException;

Expand Down Expand Up @@ -63,7 +51,8 @@ enum SortBy {
album,
}

final localTracksProvider = FutureProvider<Map<String, List<LocalTrack>>>((ref) async {
final localTracksProvider =
FutureProvider<Map<String, List<LocalTrack>>>((ref) async {
try {
if (kIsWeb) return {};
final Map<String, List<LocalTrack>> tracks = {};
Expand All @@ -82,7 +71,6 @@ final localTracksProvider = FutureProvider<Map<String, List<LocalTrack>>>((ref)
for (var location in [downloadLocation, ...localLibraryLocations]) {
if (location.isEmpty) continue;
final entities = <FileSystemEntity>[];
final dir = Directory(location);
if (await Directory(location).exists()) {
entities.addAll(Directory(location).listSync(recursive: true));
}
Expand Down Expand Up @@ -110,7 +98,11 @@ final localTracksProvider = FutureProvider<Map<String, List<LocalTrack>>>((ref)
);
}

return {"metadata": metadata, "file": file, "art": imageFile.path};
return {
"metadata": metadata,
"file": file,
"art": imageFile.path
};
} catch (e, stack) {
if (e is FfiException) {
return {"file": file};
Expand Down Expand Up @@ -152,7 +144,6 @@ class UserLocalTracks extends HookConsumerWidget {

@override
Widget build(BuildContext context, ref) {

final preferencesNotifier = ref.watch(userPreferencesProvider.notifier);
final preferences = ref.watch(userPreferencesProvider);

Expand All @@ -163,69 +154,74 @@ class UserLocalTracks extends HookConsumerWidget {
);
if (dirStr == null) return;
if (preferences.localLibraryLocation.contains(dirStr)) return;
preferencesNotifier.setLocalLibraryLocation([...preferences.localLibraryLocation, dirStr]);
preferencesNotifier.setLocalLibraryLocation(
[...preferences.localLibraryLocation, dirStr]);
} else {
String? dirStr = await getDirectoryPath(
initialDirectory: preferences.downloadLocation,
);
if (dirStr == null) return;
if (preferences.localLibraryLocation.contains(dirStr)) return;
preferencesNotifier.setLocalLibraryLocation([...preferences.localLibraryLocation, dirStr]);
preferencesNotifier.setLocalLibraryLocation(
[...preferences.localLibraryLocation, dirStr]);
}
}, [preferences.localLibraryLocation]);

final removeLocalLibraryLocation = useCallback((String location) {
if (!preferences.localLibraryLocation.contains(location)) return;
preferencesNotifier.setLocalLibraryLocation([...preferences.localLibraryLocation]..remove(location));
preferencesNotifier.setLocalLibraryLocation(
[...preferences.localLibraryLocation]..remove(location),
);
}, [preferences.localLibraryLocation]);

// This is just to pre-load the tracks.
// For now, this gets all of them.
ref.watch(localTracksProvider);

return Column(
children: [
Padding(
return Column(children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
const SizedBox(width: 5),
TextButton.icon(
icon: const Icon(SpotubeIcons.folderAdd),
label: Text(context.l10n.add_library_location),
onPressed: addLocalLibraryLocation,
)
]
)
),
Expanded(
child: ListView.builder(
itemCount: preferences.localLibraryLocation.length+1,
child: Row(children: [
const SizedBox(width: 5),
TextButton.icon(
icon: const Icon(SpotubeIcons.folderAdd),
label: Text(context.l10n.add_library_location),
onPressed: addLocalLibraryLocation,
)
])),
Expanded(
child: ListView.builder(
itemCount: preferences.localLibraryLocation.length + 1,
itemBuilder: (context, index) {
late final String location;
if (index == 0) {
location = preferences.downloadLocation;
} else {
location = preferences.localLibraryLocation[index-1];
location = preferences.localLibraryLocation[index - 1];
}
return ListTile(
title: preferences.downloadLocation != location ? Text(location)
: Text(context.l10n.downloads),
trailing: preferences.downloadLocation != location ? Tooltip(
message: context.l10n.remove_library_location,
child: IconButton(
icon: Icon(SpotubeIcons.folderRemove, color: Colors.red[400]),
onPressed: () => removeLocalLibraryLocation(location),
),
) : null,
onTap: () async {
context.go("/library/local${location == preferences.downloadLocation ? "?downloads=1" : ""}", extra: location);
}
);
}
),
),
]
);
title: preferences.downloadLocation != location
? Text(location)
: Text(context.l10n.downloads),
trailing: preferences.downloadLocation != location
? Tooltip(
message: context.l10n.remove_library_location,
child: IconButton(
icon: Icon(SpotubeIcons.folderRemove,
color: Colors.red[400]),
onPressed: () =>
removeLocalLibraryLocation(location),
),
)
: null,
onTap: () async {
context.go(
"/library/local${location == preferences.downloadLocation ? "?downloads=1" : ""}",
extra: location,
);
});
}),
),
]);
}
}
Loading

0 comments on commit d82261c

Please sign in to comment.