mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 16:05:18 +00:00
chore: remove tuple and replace with records
This commit is contained in:
parent
88137f01b2
commit
19d0ddcdd9
@ -14,7 +14,6 @@ import 'package:spotube/provider/authentication_provider.dart';
|
|||||||
import 'package:spotube/services/queries/queries.dart';
|
import 'package:spotube/services/queries/queries.dart';
|
||||||
|
|
||||||
import 'package:spotube/utils/type_conversion_utils.dart';
|
import 'package:spotube/utils/type_conversion_utils.dart';
|
||||||
import 'package:tuple/tuple.dart';
|
|
||||||
|
|
||||||
class UserAlbums extends HookConsumerWidget {
|
class UserAlbums extends HookConsumerWidget {
|
||||||
const UserAlbums({Key? key}) : super(key: key);
|
const UserAlbums({Key? key}) : super(key: key);
|
||||||
@ -36,13 +35,13 @@ class UserAlbums extends HookConsumerWidget {
|
|||||||
return albumsQuery.data?.toList() ?? [];
|
return albumsQuery.data?.toList() ?? [];
|
||||||
}
|
}
|
||||||
return albumsQuery.data
|
return albumsQuery.data
|
||||||
?.map((e) => Tuple2(
|
?.map((e) => (
|
||||||
weightedRatio(e.name!, searchText.value),
|
weightedRatio(e.name!, searchText.value),
|
||||||
e,
|
e,
|
||||||
))
|
))
|
||||||
.sorted((a, b) => b.item1.compareTo(a.item1))
|
.sorted((a, b) => b.$1.compareTo(a.$1))
|
||||||
.where((e) => e.item1 > 50)
|
.where((e) => e.$1 > 50)
|
||||||
.map((e) => e.item2)
|
.map((e) => e.$2)
|
||||||
.toList() ??
|
.toList() ??
|
||||||
[];
|
[];
|
||||||
}, [albumsQuery.data, searchText.value]);
|
}, [albumsQuery.data, searchText.value]);
|
||||||
|
@ -10,7 +10,6 @@ import 'package:spotube/components/artist/artist_card.dart';
|
|||||||
import 'package:spotube/extensions/context.dart';
|
import 'package:spotube/extensions/context.dart';
|
||||||
import 'package:spotube/provider/authentication_provider.dart';
|
import 'package:spotube/provider/authentication_provider.dart';
|
||||||
import 'package:spotube/services/queries/queries.dart';
|
import 'package:spotube/services/queries/queries.dart';
|
||||||
import 'package:tuple/tuple.dart';
|
|
||||||
|
|
||||||
class UserArtists extends HookConsumerWidget {
|
class UserArtists extends HookConsumerWidget {
|
||||||
const UserArtists({Key? key}) : super(key: key);
|
const UserArtists({Key? key}) : super(key: key);
|
||||||
@ -31,13 +30,13 @@ class UserArtists extends HookConsumerWidget {
|
|||||||
return artists.toList();
|
return artists.toList();
|
||||||
}
|
}
|
||||||
return artists
|
return artists
|
||||||
.map((e) => Tuple2(
|
.map((e) => (
|
||||||
weightedRatio(e.name!, searchText.value),
|
weightedRatio(e.name!, searchText.value),
|
||||||
e,
|
e,
|
||||||
))
|
))
|
||||||
.sorted((a, b) => b.item1.compareTo(a.item1))
|
.sorted((a, b) => b.$1.compareTo(a.$1))
|
||||||
.where((e) => e.item1 > 50)
|
.where((e) => e.$1 > 50)
|
||||||
.map((e) => e.item2)
|
.map((e) => e.$2)
|
||||||
.toList();
|
.toList();
|
||||||
}, [artistQuery.data, searchText.value]);
|
}, [artistQuery.data, searchText.value]);
|
||||||
|
|
||||||
|
@ -29,7 +29,6 @@ import 'package:spotube/utils/primitive_utils.dart';
|
|||||||
import 'package:spotube/utils/service_utils.dart';
|
import 'package:spotube/utils/service_utils.dart';
|
||||||
import 'package:spotube/utils/type_conversion_utils.dart';
|
import 'package:spotube/utils/type_conversion_utils.dart';
|
||||||
import 'package:flutter_rust_bridge/flutter_rust_bridge.dart' show FfiException;
|
import 'package:flutter_rust_bridge/flutter_rust_bridge.dart' show FfiException;
|
||||||
import 'package:tuple/tuple.dart';
|
|
||||||
|
|
||||||
const supportedAudioTypes = [
|
const supportedAudioTypes = [
|
||||||
"audio/webm",
|
"audio/webm",
|
||||||
@ -245,7 +244,7 @@ class UserLocalTracks extends HookConsumerWidget {
|
|||||||
return sortedTracks;
|
return sortedTracks;
|
||||||
}
|
}
|
||||||
return sortedTracks
|
return sortedTracks
|
||||||
.map((e) => Tuple2(
|
.map((e) => (
|
||||||
weightedRatio(
|
weightedRatio(
|
||||||
"${e.name} - ${TypeConversionUtils.artists_X_String<Artist>(e.artists ?? [])}",
|
"${e.name} - ${TypeConversionUtils.artists_X_String<Artist>(e.artists ?? [])}",
|
||||||
searchText.value,
|
searchText.value,
|
||||||
@ -254,10 +253,10 @@ class UserLocalTracks extends HookConsumerWidget {
|
|||||||
))
|
))
|
||||||
.toList()
|
.toList()
|
||||||
.sorted(
|
.sorted(
|
||||||
(a, b) => b.item1.compareTo(a.item1),
|
(a, b) => b.$1.compareTo(a.$1),
|
||||||
)
|
)
|
||||||
.where((e) => e.item1 > 50)
|
.where((e) => e.$1 > 50)
|
||||||
.map((e) => e.item2)
|
.map((e) => e.$2)
|
||||||
.toList()
|
.toList()
|
||||||
.toList();
|
.toList();
|
||||||
}, [searchText.value, sortedTracks]);
|
}, [searchText.value, sortedTracks]);
|
||||||
|
@ -15,7 +15,6 @@ import 'package:spotube/hooks/use_breakpoint_value.dart';
|
|||||||
import 'package:spotube/hooks/use_breakpoints.dart';
|
import 'package:spotube/hooks/use_breakpoints.dart';
|
||||||
import 'package:spotube/provider/authentication_provider.dart';
|
import 'package:spotube/provider/authentication_provider.dart';
|
||||||
import 'package:spotube/services/queries/queries.dart';
|
import 'package:spotube/services/queries/queries.dart';
|
||||||
import 'package:tuple/tuple.dart';
|
|
||||||
|
|
||||||
class UserPlaylists extends HookConsumerWidget {
|
class UserPlaylists extends HookConsumerWidget {
|
||||||
const UserPlaylists({Key? key}) : super(key: key);
|
const UserPlaylists({Key? key}) : super(key: key);
|
||||||
@ -61,13 +60,10 @@ class UserPlaylists extends HookConsumerWidget {
|
|||||||
likedTracksPlaylist,
|
likedTracksPlaylist,
|
||||||
...?playlistsQuery.data,
|
...?playlistsQuery.data,
|
||||||
]
|
]
|
||||||
.map((e) => Tuple2(
|
.map((e) => (weightedRatio(e.name!, searchText.value), e))
|
||||||
weightedRatio(e.name!, searchText.value),
|
.sorted((a, b) => b.$1.compareTo(a.$1))
|
||||||
e,
|
.where((e) => e.$1 > 50)
|
||||||
))
|
.map((e) => e.$2)
|
||||||
.sorted((a, b) => b.item1.compareTo(a.item1))
|
|
||||||
.where((e) => e.item1 > 50)
|
|
||||||
.map((e) => e.item2)
|
|
||||||
.toList();
|
.toList();
|
||||||
},
|
},
|
||||||
[playlistsQuery.data, searchText.value],
|
[playlistsQuery.data, searchText.value],
|
||||||
|
@ -107,11 +107,12 @@ class PlayerControls extends HookConsumerWidget {
|
|||||||
if (!compact)
|
if (!compact)
|
||||||
HookBuilder(
|
HookBuilder(
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
final progressObj = useProgress(ref);
|
final (
|
||||||
|
:bufferProgress,
|
||||||
final progressStatic = progressObj.item1;
|
:duration,
|
||||||
final position = progressObj.item2;
|
:position,
|
||||||
final duration = progressObj.item3;
|
:progressStatic
|
||||||
|
) = useProgress(ref);
|
||||||
|
|
||||||
final totalMinutes = PrimitiveUtils.zeroPadNumStr(
|
final totalMinutes = PrimitiveUtils.zeroPadNumStr(
|
||||||
duration.inMinutes.remainder(60),
|
duration.inMinutes.remainder(60),
|
||||||
@ -144,7 +145,7 @@ class PlayerControls extends HookConsumerWidget {
|
|||||||
// there's an edge case for value being bigger
|
// there's an edge case for value being bigger
|
||||||
// than total duration. Keeping it resolved
|
// than total duration. Keeping it resolved
|
||||||
value: progress.value.toDouble(),
|
value: progress.value.toDouble(),
|
||||||
secondaryTrackValue: progressObj.item4,
|
secondaryTrackValue: bufferProgress,
|
||||||
onChanged: playlist.isFetching == true || buffering
|
onChanged: playlist.isFetching == true || buffering
|
||||||
? null
|
? null
|
||||||
: (v) {
|
: (v) {
|
||||||
|
@ -24,7 +24,7 @@ class PlayerOverlay extends HookConsumerWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, ref) {
|
Widget build(BuildContext context, ref) {
|
||||||
final canShow = ref.watch(
|
final canShow = ref.watch(
|
||||||
ProxyPlaylistNotifier.provider.select((s) => s != null),
|
ProxyPlaylistNotifier.provider.select((s) => s.active != null),
|
||||||
);
|
);
|
||||||
final playlistNotifier = ref.watch(ProxyPlaylistNotifier.notifier);
|
final playlistNotifier = ref.watch(ProxyPlaylistNotifier.notifier);
|
||||||
final playlist = ref.watch(ProxyPlaylistNotifier.provider);
|
final playlist = ref.watch(ProxyPlaylistNotifier.provider);
|
||||||
@ -73,7 +73,10 @@ class PlayerOverlay extends HookConsumerWidget {
|
|||||||
// animated
|
// animated
|
||||||
return TweenAnimationBuilder<double>(
|
return TweenAnimationBuilder<double>(
|
||||||
duration: const Duration(milliseconds: 250),
|
duration: const Duration(milliseconds: 250),
|
||||||
tween: Tween<double>(begin: 0, end: progress.item1),
|
tween: Tween<double>(
|
||||||
|
begin: 0,
|
||||||
|
end: progress.progressStatic,
|
||||||
|
),
|
||||||
builder: (context, value, child) {
|
builder: (context, value, child) {
|
||||||
return LinearProgressIndicator(
|
return LinearProgressIndicator(
|
||||||
value: value,
|
value: value,
|
||||||
|
@ -22,7 +22,6 @@ import 'package:spotify/spotify.dart';
|
|||||||
import 'package:spotube/provider/authentication_provider.dart';
|
import 'package:spotube/provider/authentication_provider.dart';
|
||||||
import 'package:spotube/utils/platform.dart';
|
import 'package:spotube/utils/platform.dart';
|
||||||
import 'package:spotube/utils/type_conversion_utils.dart';
|
import 'package:spotube/utils/type_conversion_utils.dart';
|
||||||
import 'package:tuple/tuple.dart';
|
|
||||||
|
|
||||||
class TrackCollectionView<T> extends HookConsumerWidget {
|
class TrackCollectionView<T> extends HookConsumerWidget {
|
||||||
final logger = getLogger(TrackCollectionView);
|
final logger = getLogger(TrackCollectionView);
|
||||||
@ -122,19 +121,10 @@ class TrackCollectionView<T> extends HookConsumerWidget {
|
|||||||
return tracksSnapshot.data;
|
return tracksSnapshot.data;
|
||||||
}
|
}
|
||||||
return tracksSnapshot.data
|
return tracksSnapshot.data
|
||||||
?.map((e) => Tuple2(
|
?.map((e) => (weightedRatio(e.name!, searchText.value), e))
|
||||||
weightedRatio(
|
.sorted((a, b) => b.$1.compareTo(a.$1))
|
||||||
"${e.name} - ${TypeConversionUtils.artists_X_String<Artist>(e.artists ?? [])}",
|
.where((e) => e.$1 > 50)
|
||||||
searchText.value,
|
.map((e) => e.$2)
|
||||||
),
|
|
||||||
e,
|
|
||||||
))
|
|
||||||
.toList()
|
|
||||||
.sorted(
|
|
||||||
(a, b) => b.item1.compareTo(a.item1),
|
|
||||||
)
|
|
||||||
.where((e) => e.item1 > 50)
|
|
||||||
.map((e) => e.item2)
|
|
||||||
.toList();
|
.toList();
|
||||||
}, [tracksSnapshot.data, searchText.value]);
|
}, [tracksSnapshot.data, searchText.value]);
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
import 'package:tuple/tuple.dart';
|
|
||||||
|
|
||||||
extension MultiSortListMap on List<Map> {
|
extension MultiSortListMap on List<Map> {
|
||||||
/// [preference] - List of properties in which you want to sort the list
|
/// [preference] - List of properties in which you want to sort the list
|
||||||
@ -48,7 +47,7 @@ extension MultiSortListMap on List<Map> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension MultiSortListTupleMap<V> on List<Tuple2<Map, V>> {
|
extension MultiSortListTupleMap<V> on List<(Map, V)> {
|
||||||
/// [preference] - List of properties in which you want to sort the list
|
/// [preference] - List of properties in which you want to sort the list
|
||||||
/// i.e.
|
/// i.e.
|
||||||
/// ```
|
/// ```
|
||||||
@ -61,7 +60,7 @@ extension MultiSortListTupleMap<V> on List<Tuple2<Map, V>> {
|
|||||||
/// ```
|
/// ```
|
||||||
/// List<bool> criteria = [true. false];
|
/// List<bool> criteria = [true. false];
|
||||||
/// ```
|
/// ```
|
||||||
List<Tuple2<Map, V>> sortByProperties(
|
List<(Map, V)> sortByProperties(
|
||||||
List<bool> criteria, List<String> preference) {
|
List<bool> criteria, List<String> preference) {
|
||||||
if (preference.isEmpty || criteria.isEmpty || isEmpty) {
|
if (preference.isEmpty || criteria.isEmpty || isEmpty) {
|
||||||
return this;
|
return this;
|
||||||
@ -71,17 +70,17 @@ extension MultiSortListTupleMap<V> on List<Tuple2<Map, V>> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
int compare(int i, Tuple2<Map, V> a, Tuple2<Map, V> b) {
|
int compare(int i, (Map, V) a, (Map, V) b) {
|
||||||
if (a.item1[preference[i]] == b.item1[preference[i]]) {
|
if (a.$1[preference[i]] == b.$1[preference[i]]) {
|
||||||
return 0;
|
return 0;
|
||||||
} else if (a.item1[preference[i]] > b.item1[preference[i]]) {
|
} else if (a.$1[preference[i]] > b.$1[preference[i]]) {
|
||||||
return criteria[i] ? 1 : -1;
|
return criteria[i] ? 1 : -1;
|
||||||
} else {
|
} else {
|
||||||
return criteria[i] ? -1 : 1;
|
return criteria[i] ? -1 : 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int sortAll(Tuple2<Map, V> a, Tuple2<Map, V> b) {
|
int sortAll((Map, V) a, (Map, V) b) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int result = 0;
|
int result = 0;
|
||||||
while (i < preference.length) {
|
while (i < preference.length) {
|
||||||
|
@ -2,9 +2,13 @@ import 'package:flutter_hooks/flutter_hooks.dart';
|
|||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:spotube/provider/proxy_playlist/proxy_playlist_provider.dart';
|
import 'package:spotube/provider/proxy_playlist/proxy_playlist_provider.dart';
|
||||||
import 'package:spotube/services/audio_player/audio_player.dart';
|
import 'package:spotube/services/audio_player/audio_player.dart';
|
||||||
import 'package:tuple/tuple.dart';
|
|
||||||
|
|
||||||
Tuple4<double, Duration, Duration, double> useProgress(WidgetRef ref) {
|
({
|
||||||
|
double progressStatic,
|
||||||
|
Duration position,
|
||||||
|
Duration duration,
|
||||||
|
double bufferProgress
|
||||||
|
}) useProgress(WidgetRef ref) {
|
||||||
ref.watch(ProxyPlaylistNotifier.provider);
|
ref.watch(ProxyPlaylistNotifier.provider);
|
||||||
|
|
||||||
final bufferProgress =
|
final bufferProgress =
|
||||||
@ -25,11 +29,12 @@ Tuple4<double, Duration, Duration, double> useProgress(WidgetRef ref) {
|
|||||||
final sliderMax = duration.inSeconds;
|
final sliderMax = duration.inSeconds;
|
||||||
final sliderValue = position.inSeconds;
|
final sliderValue = position.inSeconds;
|
||||||
|
|
||||||
return Tuple4(
|
return (
|
||||||
|
progressStatic:
|
||||||
sliderMax == 0 || sliderValue > sliderMax ? 0 : sliderValue / sliderMax,
|
sliderMax == 0 || sliderValue > sliderMax ? 0 : sliderValue / sliderMax,
|
||||||
position,
|
position: position,
|
||||||
duration,
|
duration: duration,
|
||||||
sliderMax == 0 || bufferProgress > sliderMax
|
bufferProgress: sliderMax == 0 || bufferProgress > sliderMax
|
||||||
? 0
|
? 0
|
||||||
: bufferProgress / sliderMax,
|
: bufferProgress / sliderMax,
|
||||||
);
|
);
|
||||||
|
@ -7,7 +7,6 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|||||||
import 'package:spotube/collections/spotube_icons.dart';
|
import 'package:spotube/collections/spotube_icons.dart';
|
||||||
import 'package:spotube/components/shared/page_window_title_bar.dart';
|
import 'package:spotube/components/shared/page_window_title_bar.dart';
|
||||||
import 'package:spotube/provider/blacklist_provider.dart';
|
import 'package:spotube/provider/blacklist_provider.dart';
|
||||||
import 'package:tuple/tuple.dart';
|
|
||||||
|
|
||||||
class BlackListPage extends HookConsumerWidget {
|
class BlackListPage extends HookConsumerWidget {
|
||||||
const BlackListPage({Key? key}) : super(key: key);
|
const BlackListPage({Key? key}) : super(key: key);
|
||||||
@ -23,13 +22,15 @@ class BlackListPage extends HookConsumerWidget {
|
|||||||
return blacklist;
|
return blacklist;
|
||||||
}
|
}
|
||||||
return blacklist
|
return blacklist
|
||||||
.map((e) => Tuple2(
|
.map(
|
||||||
|
(e) => (
|
||||||
weightedRatio("${e.name} ${e.type.name}", searchText.value),
|
weightedRatio("${e.name} ${e.type.name}", searchText.value),
|
||||||
e,
|
e,
|
||||||
))
|
),
|
||||||
.sorted((a, b) => b.item1.compareTo(a.item1))
|
)
|
||||||
.where((e) => e.item1 > 50)
|
.sorted((a, b) => b.$1.compareTo(a.$1))
|
||||||
.map((e) => e.item2)
|
.where((e) => e.$1 > 50)
|
||||||
|
.map((e) => e.$2)
|
||||||
.toList();
|
.toList();
|
||||||
},
|
},
|
||||||
[blacklist, searchText.value],
|
[blacklist, searchText.value],
|
||||||
|
Loading…
Reference in New Issue
Block a user