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