diff --git a/lib/app_config.dart b/lib/app_config.dart index a67db65..6f3250c 100644 --- a/lib/app_config.dart +++ b/lib/app_config.dart @@ -1,4 +1,4 @@ -AppConfig appConfig = AppConfig(version: 32, codeName: '2.0.7'); +AppConfig appConfig = AppConfig(version: 33, codeName: '2.0.8'); class AppConfig { int version; diff --git a/lib/main.dart b/lib/main.dart index c70bd0c..b9e9809 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -23,7 +23,6 @@ import 'services/library.dart'; import 'services/lyrics.dart'; import 'services/media_player.dart'; import 'services/settings_manager.dart'; -import 'services/yt_account.dart'; import 'themes/colors.dart'; import 'themes/dark.dart'; import 'themes/light.dart'; @@ -102,7 +101,6 @@ void main() async { GetIt.I.registerSingleton(fileStorage); GetIt.I.registerSingleton(libraryService); - GetIt.I.registerSingleton(YTAccount()); GetIt.I.registerSingleton(Lyrics()); runApp( diff --git a/lib/screens/main_screen/main_screen.dart b/lib/screens/main_screen/main_screen.dart index a71f3c8..10c6d3d 100644 --- a/lib/screens/main_screen/main_screen.dart +++ b/lib/screens/main_screen/main_screen.dart @@ -5,14 +5,12 @@ import 'package:device_info_plus/device_info_plus.dart'; import 'package:fluent_ui/fluent_ui.dart' as fluent_ui; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'package:get_it/get_it.dart'; import 'package:go_router/go_router.dart'; import 'package:receive_sharing_intent/receive_sharing_intent.dart'; import 'package:salomon_bottom_bar/salomon_bottom_bar.dart'; import 'package:window_manager/window_manager.dart'; import '../../generated/l10n.dart'; -import '../../services/yt_account.dart'; import '../../themes/text_styles.dart'; import '../../utils/adaptive_widgets/adaptive_widgets.dart'; import '../../utils/bottom_modals.dart'; @@ -111,153 +109,96 @@ class _MainScreenState extends State with WindowListener { @override Widget build(BuildContext context) { double screenWidth = MediaQuery.of(context).size.width; - return ValueListenableBuilder( - valueListenable: GetIt.I().isLogged, - builder: (context, isLogged, child) { - return Platform.isWindows - ? _buildWindowsMain( - _goBranch, - widget.navigationShell, - isLogged: isLogged, - ) - : Scaffold( - body: Column ( + return Platform.isWindows + ? _buildWindowsMain( + _goBranch, + widget.navigationShell, + ) + : Scaffold( + body: Column( + children: [ + Expanded( + child: Row( children: [ - Expanded( - child: Row( - children: [ - if (screenWidth >= 450) - NavigationRail( - backgroundColor: - Theme.of(context).scaffoldBackgroundColor, - labelType: NavigationRailLabelType.none, - selectedLabelTextStyle: - smallTextStyle(context, bold: true), - extended: (screenWidth > 1000), - onDestinationSelected: (index) { - int currentIndex = isLogged - ? index - : index >= 2 - ? index + 1 - : index; - _goBranch(currentIndex); - }, - destinations: [ - NavigationRailDestination( - selectedIcon: const Icon( - CupertinoIcons.music_house_fill), - icon: - const Icon(CupertinoIcons.music_house), - label: Text( - S.of(context).Home, - style: - smallTextStyle(context, bold: false), - ), - ), - NavigationRailDestination( - selectedIcon: const Icon( - Icons.library_music_outlined), - icon: const Icon( - Icons.library_music_outlined), - label: Text( - S.of(context).Saved, - style: - smallTextStyle(context, bold: false), - ), - ), - if (isLogged) - NavigationRailDestination( - selectedIcon: const Icon( - CupertinoIcons.music_note_2), - icon: - const Icon(CupertinoIcons.music_note), - label: Text( - S.of(context).YTMusic, - style: smallTextStyle(context, - bold: false), - ), - ), - NavigationRailDestination( - selectedIcon: const Icon( - CupertinoIcons.gear_alt_fill), - icon: const Icon(CupertinoIcons.gear_alt), - label: Text( - S.of(context).Settings, - style: - smallTextStyle(context, bold: false), - ), - ) - ], - selectedIndex: isLogged - ? widget.navigationShell.currentIndex - : widget.navigationShell.currentIndex >= 2 - ? widget.navigationShell.currentIndex - - 1 - : widget.navigationShell.currentIndex, - ), - Expanded( - child: widget.navigationShell, - ), - ], - ), - ), - const BottomPlayer() - ], - ), - bottomNavigationBar: screenWidth < 450 - ? SalomonBottomBar( - currentIndex: isLogged - ? widget.navigationShell.currentIndex - : widget.navigationShell.currentIndex >= 2 - ? widget.navigationShell.currentIndex - 1 - : widget.navigationShell.currentIndex, - items: [ - SalomonBottomBarItem( - activeIcon: + if (screenWidth >= 450) + NavigationRail( + backgroundColor: + Theme.of(context).scaffoldBackgroundColor, + labelType: NavigationRailLabelType.none, + selectedLabelTextStyle: + smallTextStyle(context, bold: true), + extended: (screenWidth > 1000), + onDestinationSelected: _goBranch, + destinations: [ + NavigationRailDestination( + selectedIcon: const Icon(CupertinoIcons.music_house_fill), icon: const Icon(CupertinoIcons.music_house), - title: Text(S.of(context).Home), + label: Text( + S.of(context).Home, + style: smallTextStyle(context, bold: false), + ), ), - SalomonBottomBarItem( - activeIcon: const Icon(Icons.library_music), + NavigationRailDestination( + selectedIcon: + const Icon(Icons.library_music_outlined), icon: const Icon(Icons.library_music_outlined), - title: Text(S.of(context).Saved), - ), - if (isLogged) - SalomonBottomBarItem( - activeIcon: - const Icon(CupertinoIcons.music_note_2), - icon: const Icon(CupertinoIcons.music_note), - title: Text(S.of(context).YTMusic), + label: Text( + S.of(context).Saved, + style: smallTextStyle(context, bold: false), ), - SalomonBottomBarItem( - activeIcon: - const Icon(CupertinoIcons.settings_solid), - icon: const Icon(CupertinoIcons.settings), - title: Text(S.of(context).Settings), ), + NavigationRailDestination( + selectedIcon: + const Icon(CupertinoIcons.gear_alt_fill), + icon: const Icon(CupertinoIcons.gear_alt), + label: Text( + S.of(context).Settings, + style: smallTextStyle(context, bold: false), + ), + ) ], - backgroundColor: - Theme.of(context).colorScheme.surfaceContainerLow, - onTap: (index) { - int currentIndex = isLogged - ? index - : index >= 2 - ? index + 1 - : index; - _goBranch(currentIndex); - }, - ) - : null, - ); - }); + selectedIndex: widget.navigationShell.currentIndex, + ), + Expanded( + child: widget.navigationShell, + ), + ], + ), + ), + const BottomPlayer() + ], + ), + bottomNavigationBar: screenWidth < 450 + ? SalomonBottomBar( + currentIndex: widget.navigationShell.currentIndex, + items: [ + SalomonBottomBarItem( + activeIcon: const Icon(CupertinoIcons.music_house_fill), + icon: const Icon(CupertinoIcons.music_house), + title: Text(S.of(context).Home), + ), + SalomonBottomBarItem( + activeIcon: const Icon(Icons.library_music), + icon: const Icon(Icons.library_music_outlined), + title: Text(S.of(context).Saved), + ), + SalomonBottomBarItem( + activeIcon: const Icon(CupertinoIcons.settings_solid), + icon: const Icon(CupertinoIcons.settings), + title: Text(S.of(context).Settings), + ), + ], + backgroundColor: + Theme.of(context).colorScheme.surfaceContainerLow, + onTap: _goBranch, + ) + : null, + ); } _buildWindowsMain( - Function goTOBranch, - StatefulNavigationShell navigationShell, { - bool isLogged = false, - }) { + Function goTOBranch, StatefulNavigationShell navigationShell) { return Directionality( textDirection: fluent_ui.TextDirection.ltr, child: fluent_ui.NavigationView( @@ -287,11 +228,7 @@ class _MainScreenState extends State with WindowListener { ); }, pane: fluent_ui.NavigationPane( - selected: isLogged - ? widget.navigationShell.currentIndex - : widget.navigationShell.currentIndex >= 2 - ? widget.navigationShell.currentIndex - 1 - : widget.navigationShell.currentIndex, + selected: widget.navigationShell.currentIndex, size: const fluent_ui.NavigationPaneSize( compactWidth: 60, ), @@ -316,17 +253,6 @@ class _MainScreenState extends State with WindowListener { body: const SizedBox.shrink(), onTap: () => goTOBranch(1), ), - if (isLogged) - fluent_ui.PaneItem( - key: const ValueKey('/ytmusic'), - icon: const Icon( - fluent_ui.FluentIcons.music_note, - size: 30, - ), - title: Text(S.of(context).YTMusic), - body: const SizedBox.shrink(), - onTap: () => goTOBranch(2), - ), ], footerItems: [ fluent_ui.PaneItem( @@ -337,7 +263,7 @@ class _MainScreenState extends State with WindowListener { ), title: Text(S.of(context).Settings), body: const SizedBox.shrink(), - onTap: () => goTOBranch(3), + onTap: () => goTOBranch(2), ) ]), ), diff --git a/lib/screens/settings_screen/account/account_screen.dart b/lib/screens/settings_screen/account/account_screen.dart deleted file mode 100644 index 3756e79..0000000 --- a/lib/screens/settings_screen/account/account_screen.dart +++ /dev/null @@ -1,87 +0,0 @@ -import 'package:cached_network_image/cached_network_image.dart'; -import 'package:flutter/material.dart'; -import 'package:get_it/get_it.dart'; -import '../../../generated/l10n.dart'; -import '../../../services/yt_account.dart'; -import '../../../themes/text_styles.dart'; -import '../../../utils/adaptive_widgets/adaptive_widgets.dart'; -import '../color_icon.dart'; - -class AccountScreen extends StatelessWidget { - const AccountScreen({super.key}); - - @override - Widget build(BuildContext context) { - return AdaptiveScaffold( - appBar: AdaptiveAppBar( - title: Text( - S.of(context).Google_Account, - style: mediumTextStyle( - context, - bold: false, - ), - ), - centerTitle: true, - ), - body: Center( - child: Container( - constraints: const BoxConstraints(maxWidth: 1000), - child: ValueListenableBuilder( - valueListenable: GetIt.I().user, - builder: (context, user, child) { - return ListView( - padding: const EdgeInsets.symmetric(horizontal: 8), - children: [ - AdaptiveListTile( - margin: const EdgeInsets.symmetric(vertical: 4), - title: Text( - user != null ? user.name : 'Log In', - style: textStyle(context, bold: false) - .copyWith(fontSize: 16), - ), - leading: user != null - ? CircleAvatar( - backgroundImage: CachedNetworkImageProvider( - user.photos.first['url'], - ), - ) - : const ColorIcon( - color: null, - icon: Icons.login, - ), - trailing: user != null - ? AdaptiveFilledButton( - onPressed: () async { - await GetIt.I().logOut(context); - }, - child: const Text('Log Out'), - ) - : null, - onTap: () async { - if (user == null) { - await GetIt.I().login(context); - } - }, - subtitle: user != null ? Text(user.channelHandle) : null, - ), - ], - ); - }), - ), - ), - ); - } -} - - - // onTap: (context) async { - // // await GetIt.I().toggleLogin(context); - // // await GetIt.I().refreshHeaders(); - // }, - // trailing: (context) => - // ValueListenableBuilder( - // valueListenable: GetIt.I().isLogged, - // builder: (context, value, child) { - // return Text(value ? 'Logged' : 'Not Logged'); - // }, - // ), \ No newline at end of file diff --git a/lib/screens/settings_screen/setting_screen_data.dart b/lib/screens/settings_screen/setting_screen_data.dart index cd405b6..92c7add 100644 --- a/lib/screens/settings_screen/setting_screen_data.dart +++ b/lib/screens/settings_screen/setting_screen_data.dart @@ -10,13 +10,13 @@ import 'playback/audio_and_playback_screen_data.dart'; import 'setting_item.dart'; List settingScreenData(BuildContext context) => [ - SettingItem( - title: S.of(context).Google_Account, - icon: CupertinoIcons.person, - color: Colors.accents[6], - hasNavigation: true, - location: '/settings/account', - ), + // SettingItem( + // title: S.of(context).Google_Account, + // icon: CupertinoIcons.person, + // color: Colors.accents[6], + // hasNavigation: true, + // location: '/settings/account', + // ), SettingItem( title: S.of(context).Appearence, icon: Icons.looks, diff --git a/lib/screens/ytmusic_screen/albums_screen.dart b/lib/screens/ytmusic_screen/albums_screen.dart index 2e8e79c..915414d 100644 --- a/lib/screens/ytmusic_screen/albums_screen.dart +++ b/lib/screens/ytmusic_screen/albums_screen.dart @@ -1,117 +1,117 @@ -import 'package:flutter/material.dart'; -import 'package:get_it/get_it.dart'; +// import 'package:flutter/material.dart'; +// import 'package:get_it/get_it.dart'; -import '../../utils/adaptive_widgets/adaptive_widgets.dart'; -import '../../ytmusic/ytmusic.dart'; -import 'song_tile.dart'; +// import '../../utils/adaptive_widgets/adaptive_widgets.dart'; +// import '../../ytmusic/ytmusic.dart'; +// import 'song_tile.dart'; -class AlbumsScreen extends StatefulWidget { - const AlbumsScreen({super.key}); +// class AlbumsScreen extends StatefulWidget { +// const AlbumsScreen({super.key}); - @override - State createState() => _AlbumsScreenState(); -} +// @override +// State createState() => _AlbumsScreenState(); +// } -class _AlbumsScreenState extends State - with AutomaticKeepAliveClientMixin { - late ScrollController _scrollController; - List items = []; - bool initialLoading = true; - bool nextLoading = false; - String? continuation; - @override - void initState() { - super.initState(); - _scrollController = ScrollController(); - _scrollController.addListener(_scrollListener); - fetchData(); - } +// class _AlbumsScreenState extends State +// with AutomaticKeepAliveClientMixin { +// late ScrollController _scrollController; +// List items = []; +// bool initialLoading = true; +// bool nextLoading = false; +// String? continuation; +// @override +// void initState() { +// super.initState(); +// _scrollController = ScrollController(); +// _scrollController.addListener(_scrollListener); +// fetchData(); +// } - _scrollListener() async { - if (initialLoading || nextLoading || continuation == null) { - return; - } +// _scrollListener() async { +// if (initialLoading || nextLoading || continuation == null) { +// return; +// } - if (_scrollController.position.pixels == - _scrollController.position.maxScrollExtent) { - await fetchNext(); - } - } +// if (_scrollController.position.pixels == +// _scrollController.position.maxScrollExtent) { +// await fetchNext(); +// } +// } - Future fetchData() async { - setState(() { - initialLoading = true; - }); - Map data = await GetIt.I().getLibraryAlbums(); - if (mounted) { - setState(() { - items = data['contents']; - continuation = data['continuation']; - initialLoading = false; - }); - } - } +// Future fetchData() async { +// setState(() { +// initialLoading = true; +// }); +// Map data = await GetIt.I().getLibraryAlbums(); +// if (mounted) { +// setState(() { +// items = data['contents']; +// continuation = data['continuation']; +// initialLoading = false; +// }); +// } +// } - fetchNext() async { - if (continuation == null) return; - setState(() { - nextLoading = true; - }); - Map data = await GetIt.I() - .getLibraryAlbums(continuationParams: continuation); - if (mounted) { - setState(() { - items.addAll(data['contents']); - continuation = data['continuation']; - nextLoading = false; - }); - } - setState(() { - nextLoading = false; - }); - } +// fetchNext() async { +// if (continuation == null) return; +// setState(() { +// nextLoading = true; +// }); +// Map data = await GetIt.I() +// .getLibraryAlbums(continuationParams: continuation); +// if (mounted) { +// setState(() { +// items.addAll(data['contents']); +// continuation = data['continuation']; +// nextLoading = false; +// }); +// } +// setState(() { +// nextLoading = false; +// }); +// } - @override - Widget build(BuildContext context) { - super.build(context); - return AdaptiveScaffold( - body: initialLoading - ? const Center(child: AdaptiveProgressRing()) - : RefreshIndicator( - onRefresh: () => fetchData(), - child: SingleChildScrollView( - controller: _scrollController, - child: Center( - child: Container( - constraints: const BoxConstraints(maxWidth: 1000), - padding: const EdgeInsets.symmetric(horizontal: 8), - child: Column( - children: [ - ...items.indexed.map((indexedItem) { - return YTMSongTile( - items: items, - index: indexedItem.$1, - mainBrowse: true, - ); - }), - if (!nextLoading && continuation != null) - const SizedBox(height: 64), - if (nextLoading) - const Center( - child: Padding( - padding: EdgeInsets.all(8.0), - child: AdaptiveProgressRing(), - ), - ), - ], - ), - ), - ), - ), - ), - ); - } +// @override +// Widget build(BuildContext context) { +// super.build(context); +// return AdaptiveScaffold( +// body: initialLoading +// ? const Center(child: AdaptiveProgressRing()) +// : RefreshIndicator( +// onRefresh: () => fetchData(), +// child: SingleChildScrollView( +// controller: _scrollController, +// child: Center( +// child: Container( +// constraints: const BoxConstraints(maxWidth: 1000), +// padding: const EdgeInsets.symmetric(horizontal: 8), +// child: Column( +// children: [ +// ...items.indexed.map((indexedItem) { +// return YTMSongTile( +// items: items, +// index: indexedItem.$1, +// mainBrowse: true, +// ); +// }), +// if (!nextLoading && continuation != null) +// const SizedBox(height: 64), +// if (nextLoading) +// const Center( +// child: Padding( +// padding: EdgeInsets.all(8.0), +// child: AdaptiveProgressRing(), +// ), +// ), +// ], +// ), +// ), +// ), +// ), +// ), +// ); +// } - @override - bool get wantKeepAlive => true; -} +// @override +// bool get wantKeepAlive => true; +// } diff --git a/lib/screens/ytmusic_screen/artists_screen.dart b/lib/screens/ytmusic_screen/artists_screen.dart index 89df8cb..5adea72 100644 --- a/lib/screens/ytmusic_screen/artists_screen.dart +++ b/lib/screens/ytmusic_screen/artists_screen.dart @@ -1,117 +1,117 @@ -import 'package:flutter/material.dart'; -import 'package:get_it/get_it.dart'; +// import 'package:flutter/material.dart'; +// import 'package:get_it/get_it.dart'; -import '../../utils/adaptive_widgets/adaptive_widgets.dart'; -import '../../ytmusic/ytmusic.dart'; -import 'song_tile.dart'; +// import '../../utils/adaptive_widgets/adaptive_widgets.dart'; +// import '../../ytmusic/ytmusic.dart'; +// import 'song_tile.dart'; -class ArtistsScreen extends StatefulWidget { - const ArtistsScreen({super.key}); +// class ArtistsScreen extends StatefulWidget { +// const ArtistsScreen({super.key}); - @override - State createState() => _ArtistsScreenState(); -} +// // @override +// State createState() => _ArtistsScreenState(); +// } -class _ArtistsScreenState extends State - with AutomaticKeepAliveClientMixin { - late ScrollController _scrollController; - List items = []; - bool initialLoading = true; - bool nextLoading = false; - String? continuation; - @override - void initState() { - super.initState(); - _scrollController = ScrollController(); - _scrollController.addListener(_scrollListener); - fetchData(); - } +// class _ArtistsScreenState extends State +// with AutomaticKeepAliveClientMixin { +// late ScrollController _scrollController; +// List items = []; +// bool initialLoading = true; +// bool nextLoading = false; +// String? continuation; +// @override +// void initState() { +// super.initState(); +// _scrollController = ScrollController(); +// _scrollController.addListener(_scrollListener); +// fetchData(); +// } - _scrollListener() async { - if (initialLoading || nextLoading || continuation == null) { - return; - } +// _scrollListener() async { +// if (initialLoading || nextLoading || continuation == null) { +// return; +// } - if (_scrollController.position.pixels == - _scrollController.position.maxScrollExtent) { - await fetchNext(); - } - } +// if (_scrollController.position.pixels == +// _scrollController.position.maxScrollExtent) { +// await fetchNext(); +// } +// } - Future fetchData() async { - setState(() { - initialLoading = true; - }); - Map data = await GetIt.I().getLibraryArtists(); - if (mounted) { - setState(() { - items = data['contents']; - continuation = data['continuation']; - initialLoading = false; - }); - } - } +// Future fetchData() async { +// setState(() { +// initialLoading = true; +// }); +// Map data = await GetIt.I().getLibraryArtists(); +// if (mounted) { +// setState(() { +// items = data['contents']; +// continuation = data['continuation']; +// initialLoading = false; +// }); +// } +// } - fetchNext() async { - if (continuation == null) return; - setState(() { - nextLoading = true; - }); - Map data = await GetIt.I() - .getLibraryArtists(continuationParams: continuation); - if (mounted) { - setState(() { - items.addAll(data['contents']); - continuation = data['continuation']; - nextLoading = false; - }); - } - setState(() { - nextLoading = false; - }); - } +// fetchNext() async { +// if (continuation == null) return; +// setState(() { +// nextLoading = true; +// }); +// Map data = await GetIt.I() +// .getLibraryArtists(continuationParams: continuation); +// if (mounted) { +// setState(() { +// items.addAll(data['contents']); +// continuation = data['continuation']; +// nextLoading = false; +// }); +// } +// setState(() { +// nextLoading = false; +// }); +// } - @override - Widget build(BuildContext context) { - super.build(context); - return AdaptiveScaffold( - body: initialLoading - ? const Center(child: AdaptiveProgressRing()) - : RefreshIndicator( - onRefresh: () => fetchData(), - child: SingleChildScrollView( - controller: _scrollController, - child: Center( - child: Container( - constraints: const BoxConstraints(maxWidth: 1000), - padding: const EdgeInsets.symmetric(horizontal: 8), - child: Column( - children: [ - ...items.indexed.map((indexedItem) { - return YTMSongTile( - items: items, - index: indexedItem.$1, - mainBrowse: true, - ); - }), - if (!nextLoading && continuation != null) - const SizedBox(height: 64), - if (nextLoading) - const Center( - child: Padding( - padding: EdgeInsets.all(8.0), - child: AdaptiveProgressRing(), - ), - ), - ], - ), - ), - ), - ), - ), - ); - } +// @override +// Widget build(BuildContext context) { +// super.build(context); +// return AdaptiveScaffold( +// body: initialLoading +// ? const Center(child: AdaptiveProgressRing()) +// : RefreshIndicator( +// onRefresh: () => fetchData(), +// child: SingleChildScrollView( +// controller: _scrollController, +// child: Center( +// child: Container( +// constraints: const BoxConstraints(maxWidth: 1000), +// padding: const EdgeInsets.symmetric(horizontal: 8), +// child: Column( +// children: [ +// ...items.indexed.map((indexedItem) { +// return YTMSongTile( +// items: items, +// index: indexedItem.$1, +// mainBrowse: true, +// ); +// }), +// if (!nextLoading && continuation != null) +// const SizedBox(height: 64), +// if (nextLoading) +// const Center( +// child: Padding( +// padding: EdgeInsets.all(8.0), +// child: AdaptiveProgressRing(), +// ), +// ), +// ], +// ), +// ), +// ), +// ), +// ), +// ); +// } - @override - bool get wantKeepAlive => true; -} +// @override +// bool get wantKeepAlive => true; +// } diff --git a/lib/screens/ytmusic_screen/playlists_screen.dart b/lib/screens/ytmusic_screen/playlists_screen.dart index 9280530..ade8221 100644 --- a/lib/screens/ytmusic_screen/playlists_screen.dart +++ b/lib/screens/ytmusic_screen/playlists_screen.dart @@ -1,116 +1,116 @@ -import 'package:flutter/material.dart'; -import 'package:get_it/get_it.dart'; -import '../../utils/adaptive_widgets/adaptive_widgets.dart'; -import '../../ytmusic/ytmusic.dart'; -import 'song_tile.dart'; +// import 'package:flutter/material.dart'; +// import 'package:get_it/get_it.dart'; +// import '../../utils/adaptive_widgets/adaptive_widgets.dart'; +// import '../../ytmusic/ytmusic.dart'; +// import 'song_tile.dart'; -class PlaylistsScreen extends StatefulWidget { - const PlaylistsScreen({super.key}); +// class PlaylistsScreen extends StatefulWidget { +// const PlaylistsScreen({super.key}); - @override - State createState() => _PlaylistsScreenState(); -} +// @override +// State createState() => _PlaylistsScreenState(); +// } -class _PlaylistsScreenState extends State - with AutomaticKeepAliveClientMixin { - late ScrollController _scrollController; - List items = []; - bool initialLoading = true; - bool nextLoading = false; - String? continuation; - @override - void initState() { - super.initState(); - _scrollController = ScrollController(); - _scrollController.addListener(_scrollListener); - fetchData(); - } +// class _PlaylistsScreenState extends State +// with AutomaticKeepAliveClientMixin { +// late ScrollController _scrollController; +// List items = []; +// bool initialLoading = true; +// bool nextLoading = false; +// String? continuation; +// @override +// void initState() { +// super.initState(); +// _scrollController = ScrollController(); +// _scrollController.addListener(_scrollListener); +// fetchData(); +// } - _scrollListener() async { - if (initialLoading || nextLoading || continuation == null) { - return; - } +// _scrollListener() async { +// if (initialLoading || nextLoading || continuation == null) { +// return; +// } - if (_scrollController.position.pixels == - _scrollController.position.maxScrollExtent) { - await fetchNext(); - } - } +// if (_scrollController.position.pixels == +// _scrollController.position.maxScrollExtent) { +// await fetchNext(); +// } +// } - Future fetchData() async { - setState(() { - initialLoading = true; - }); - Map data = await GetIt.I().getLibraryPlaylists(); - if (mounted) { - setState(() { - items = data['contents']; - continuation = data['continuation']; - initialLoading = false; - }); - } - } +// Future fetchData() async { +// setState(() { +// initialLoading = true; +// }); +// Map data = await GetIt.I().getLibraryPlaylists(); +// if (mounted) { +// setState(() { +// items = data['contents']; +// continuation = data['continuation']; +// initialLoading = false; +// }); +// } +// } - fetchNext() async { - if (continuation == null) return; - setState(() { - nextLoading = true; - }); - Map data = await GetIt.I() - .getLibraryPlaylists(continuationParams: continuation); - if (mounted) { - setState(() { - items.addAll(data['contents']); - continuation = data['continuation']; - nextLoading = false; - }); - } - setState(() { - nextLoading = false; - }); - } +// fetchNext() async { +// if (continuation == null) return; +// setState(() { +// nextLoading = true; +// }); +// Map data = await GetIt.I() +// .getLibraryPlaylists(continuationParams: continuation); +// if (mounted) { +// setState(() { +// items.addAll(data['contents']); +// continuation = data['continuation']; +// nextLoading = false; +// }); +// } +// setState(() { +// nextLoading = false; +// }); +// } - @override - Widget build(BuildContext context) { - super.build(context); - return AdaptiveScaffold( - body: initialLoading - ? const Center(child: AdaptiveProgressRing()) - : RefreshIndicator( - onRefresh: () => fetchData(), - child: SingleChildScrollView( - controller: _scrollController, - child: Center( - child: Container( - constraints: const BoxConstraints(maxWidth: 1000), - padding: const EdgeInsets.symmetric(horizontal: 8), - child: Column( - children: [ - ...items.indexed.map((playlist) { - return YTMSongTile( - items: items, - index: playlist.$1, - mainBrowse: true, - ); - }), - if (!nextLoading && continuation != null) - const SizedBox(height: 64), - if (nextLoading) - const Center( - child: Padding( - padding: EdgeInsets.all(8.0), - child: AdaptiveProgressRing(), - ), - ), - ], - ), - ), - ), - ), - ), - ); - } +// @override +// Widget build(BuildContext context) { +// super.build(context); +// return AdaptiveScaffold( +// body: initialLoading +// ? const Center(child: AdaptiveProgressRing()) +// : RefreshIndicator( +// onRefresh: () => fetchData(), +// child: SingleChildScrollView( +// controller: _scrollController, +// child: Center( +// child: Container( +// constraints: const BoxConstraints(maxWidth: 1000), +// padding: const EdgeInsets.symmetric(horizontal: 8), +// child: Column( +// children: [ +// ...items.indexed.map((playlist) { +// return YTMSongTile( +// items: items, +// index: playlist.$1, +// mainBrowse: true, +// ); +// }), +// if (!nextLoading && continuation != null) +// const SizedBox(height: 64), +// if (nextLoading) +// const Center( +// child: Padding( +// padding: EdgeInsets.all(8.0), +// child: AdaptiveProgressRing(), +// ), +// ), +// ], +// ), +// ), +// ), +// ), +// ), +// ); +// } - @override - bool get wantKeepAlive => true; -} +// @override +// bool get wantKeepAlive => true; +// } diff --git a/lib/screens/ytmusic_screen/songs_screen.dart b/lib/screens/ytmusic_screen/songs_screen.dart index ec84d65..7322e6d 100644 --- a/lib/screens/ytmusic_screen/songs_screen.dart +++ b/lib/screens/ytmusic_screen/songs_screen.dart @@ -1,113 +1,113 @@ -import 'package:flutter/material.dart'; -import 'package:get_it/get_it.dart'; -import '../../utils/adaptive_widgets/adaptive_widgets.dart'; -import '../../ytmusic/ytmusic.dart'; -import 'song_tile.dart'; +// import 'package:flutter/material.dart'; +// import 'package:get_it/get_it.dart'; +// import '../../utils/adaptive_widgets/adaptive_widgets.dart'; +// import '../../ytmusic/ytmusic.dart'; +// import 'song_tile.dart'; -class SongsScreen extends StatefulWidget { - const SongsScreen({super.key}); +// class SongsScreen extends StatefulWidget { +// const SongsScreen({super.key}); - @override - State createState() => _SongsScreenState(); -} +// @override +// State createState() => _SongsScreenState(); +// } -class _SongsScreenState extends State - with AutomaticKeepAliveClientMixin { - late ScrollController _scrollController; - List items = []; - bool initialLoading = true; - bool nextLoading = false; - String? continuation; - @override - void initState() { - super.initState(); - _scrollController = ScrollController(); - _scrollController.addListener(_scrollListener); - fetchData(); - } +// class _SongsScreenState extends State +// with AutomaticKeepAliveClientMixin { +// late ScrollController _scrollController; +// List items = []; +// bool initialLoading = true; +// bool nextLoading = false; +// String? continuation; +// @override +// void initState() { +// super.initState(); +// _scrollController = ScrollController(); +// _scrollController.addListener(_scrollListener); +// fetchData(); +// } - _scrollListener() async { - if (initialLoading || nextLoading || continuation == null) { - return; - } +// _scrollListener() async { +// if (initialLoading || nextLoading || continuation == null) { +// return; +// } - if (_scrollController.position.pixels == - _scrollController.position.maxScrollExtent) { - await fetchNext(); - } - } +// if (_scrollController.position.pixels == +// _scrollController.position.maxScrollExtent) { +// await fetchNext(); +// } +// } - Future fetchData() async { - setState(() { - initialLoading = true; - }); - Map data = await GetIt.I().getLibrarySongs(); - if (mounted) { - setState(() { - items = data['contents']; - continuation = data['continuation']; - initialLoading = false; - }); - } - } +// Future fetchData() async { +// setState(() { +// initialLoading = true; +// }); +// Map data = await GetIt.I().getLibrarySongs(); +// if (mounted) { +// setState(() { +// items = data['contents']; +// continuation = data['continuation']; +// initialLoading = false; +// }); +// } +// } - fetchNext() async { - if (continuation == null) return; - setState(() { - nextLoading = true; - }); - Map data = await GetIt.I() - .getLibrarySongs(continuationParams: continuation); - if (mounted) { - setState(() { - items.addAll(data['contents']); - continuation = data['continuation']; - nextLoading = false; - }); - } - setState(() { - nextLoading = false; - }); - } +// fetchNext() async { +// if (continuation == null) return; +// setState(() { +// nextLoading = true; +// }); +// Map data = await GetIt.I() +// .getLibrarySongs(continuationParams: continuation); +// if (mounted) { +// setState(() { +// items.addAll(data['contents']); +// continuation = data['continuation']; +// nextLoading = false; +// }); +// } +// setState(() { +// nextLoading = false; +// }); +// } - @override - Widget build(BuildContext context) { - super.build(context); - return AdaptiveScaffold( - body: initialLoading - ? const Center(child: AdaptiveProgressRing()) - : RefreshIndicator( - onRefresh: () => fetchData(), - child: SingleChildScrollView( - controller: _scrollController, - child: Center( - child: Container( - constraints: const BoxConstraints(maxWidth: 1000), - padding: const EdgeInsets.symmetric(horizontal: 8), - child: Column( - children: [ - ...items.indexed.map((indexedItem) { - return YTMSongTile( - items: items, index: indexedItem.$1); - }), - if (!nextLoading && continuation != null) - const SizedBox(height: 64), - if (nextLoading) - const Center( - child: Padding( - padding: EdgeInsets.all(8.0), - child: AdaptiveProgressRing(), - ), - ), - ], - ), - ), - ), - ), - ), - ); - } +// @override +// Widget build(BuildContext context) { +// super.build(context); +// return AdaptiveScaffold( +// body: initialLoading +// ? const Center(child: AdaptiveProgressRing()) +// : RefreshIndicator( +// onRefresh: () => fetchData(), +// child: SingleChildScrollView( +// controller: _scrollController, +// child: Center( +// child: Container( +// constraints: const BoxConstraints(maxWidth: 1000), +// padding: const EdgeInsets.symmetric(horizontal: 8), +// child: Column( +// children: [ +// ...items.indexed.map((indexedItem) { +// return YTMSongTile( +// items: items, index: indexedItem.$1); +// }), +// if (!nextLoading && continuation != null) +// const SizedBox(height: 64), +// if (nextLoading) +// const Center( +// child: Padding( +// padding: EdgeInsets.all(8.0), +// child: AdaptiveProgressRing(), +// ), +// ), +// ], +// ), +// ), +// ), +// ), +// ), +// ); +// } - @override - bool get wantKeepAlive => true; -} +// @override +// bool get wantKeepAlive => true; +// } diff --git a/lib/screens/ytmusic_screen/subscriptions_screen.dart b/lib/screens/ytmusic_screen/subscriptions_screen.dart index eb82023..8d92e53 100644 --- a/lib/screens/ytmusic_screen/subscriptions_screen.dart +++ b/lib/screens/ytmusic_screen/subscriptions_screen.dart @@ -1,117 +1,117 @@ -import 'package:flutter/material.dart'; -import 'package:get_it/get_it.dart'; -import 'song_tile.dart'; +// import 'package:flutter/material.dart'; +// import 'package:get_it/get_it.dart'; +// import 'song_tile.dart'; -import '../../utils/adaptive_widgets/adaptive_widgets.dart'; -import '../../ytmusic/ytmusic.dart'; +// import '../../utils/adaptive_widgets/adaptive_widgets.dart'; +// import '../../ytmusic/ytmusic.dart'; -class SubscriptionsScreen extends StatefulWidget { - const SubscriptionsScreen({super.key}); +// class SubscriptionsScreen extends StatefulWidget { +// const SubscriptionsScreen({super.key}); - @override - State createState() => _SubscriptionsScreenState(); -} +// @override +// State createState() => _SubscriptionsScreenState(); +// } -class _SubscriptionsScreenState extends State - with AutomaticKeepAliveClientMixin { - late ScrollController _scrollController; - List items = []; - bool initialLoading = true; - bool nextLoading = false; - String? continuation; - @override - void initState() { - super.initState(); - _scrollController = ScrollController(); - _scrollController.addListener(_scrollListener); - fetchData(); - } +// class _SubscriptionsScreenState extends State +// with AutomaticKeepAliveClientMixin { +// late ScrollController _scrollController; +// List items = []; +// bool initialLoading = true; +// bool nextLoading = false; +// String? continuation; +// @override +// void initState() { +// super.initState(); +// _scrollController = ScrollController(); +// _scrollController.addListener(_scrollListener); +// fetchData(); +// } - _scrollListener() async { - if (initialLoading || nextLoading || continuation == null) { - return; - } +// _scrollListener() async { +// if (initialLoading || nextLoading || continuation == null) { +// return; +// } - if (_scrollController.position.pixels == - _scrollController.position.maxScrollExtent) { - await fetchNext(); - } - } +// if (_scrollController.position.pixels == +// _scrollController.position.maxScrollExtent) { +// await fetchNext(); +// } +// } - Future fetchData() async { - setState(() { - initialLoading = true; - }); - Map data = await GetIt.I().getLibrarySubscriptions(); - if (mounted) { - setState(() { - items = data['contents']; - continuation = data['continuation']; - initialLoading = false; - }); - } - } +// Future fetchData() async { +// setState(() { +// initialLoading = true; +// }); +// Map data = await GetIt.I().getLibrarySubscriptions(); +// if (mounted) { +// setState(() { +// items = data['contents']; +// continuation = data['continuation']; +// initialLoading = false; +// }); +// } +// } - fetchNext() async { - if (continuation == null) return; - setState(() { - nextLoading = true; - }); - Map data = await GetIt.I() - .getLibrarySubscriptions(continuationParams: continuation); - if (mounted) { - setState(() { - items.addAll(data['contents']); - continuation = data['continuation']; - nextLoading = false; - }); - } - setState(() { - nextLoading = false; - }); - } +// fetchNext() async { +// if (continuation == null) return; +// setState(() { +// nextLoading = true; +// }); +// Map data = await GetIt.I() +// .getLibrarySubscriptions(continuationParams: continuation); +// if (mounted) { +// setState(() { +// items.addAll(data['contents']); +// continuation = data['continuation']; +// nextLoading = false; +// }); +// } +// setState(() { +// nextLoading = false; +// }); +// } - @override - Widget build(BuildContext context) { - super.build(context); - return AdaptiveScaffold( - body: initialLoading - ? const Center(child: AdaptiveProgressRing()) - : RefreshIndicator( - onRefresh: () => fetchData(), - child: SingleChildScrollView( - controller: _scrollController, - child: Center( - child: Container( - constraints: const BoxConstraints(maxWidth: 1000), - padding: const EdgeInsets.symmetric(horizontal: 8), - child: Column( - children: [ - ...items.indexed.map((indexedItem) { - return YTMSongTile( - items: items, - index: indexedItem.$1, - mainBrowse: true, - ); - }), - if (!nextLoading && continuation != null) - const SizedBox(height: 64), - if (nextLoading) - const Center( - child: Padding( - padding: EdgeInsets.all(8.0), - child: AdaptiveProgressRing(), - ), - ), - ], - ), - ), - ), - ), - ), - ); - } +// @override +// Widget build(BuildContext context) { +// super.build(context); +// return AdaptiveScaffold( +// body: initialLoading +// ? const Center(child: AdaptiveProgressRing()) +// : RefreshIndicator( +// onRefresh: () => fetchData(), +// child: SingleChildScrollView( +// controller: _scrollController, +// child: Center( +// child: Container( +// constraints: const BoxConstraints(maxWidth: 1000), +// padding: const EdgeInsets.symmetric(horizontal: 8), +// child: Column( +// children: [ +// ...items.indexed.map((indexedItem) { +// return YTMSongTile( +// items: items, +// index: indexedItem.$1, +// mainBrowse: true, +// ); +// }), +// if (!nextLoading && continuation != null) +// const SizedBox(height: 64), +// if (nextLoading) +// const Center( +// child: Padding( +// padding: EdgeInsets.all(8.0), +// child: AdaptiveProgressRing(), +// ), +// ), +// ], +// ), +// ), +// ), +// ), +// ), +// ); +// } - @override - bool get wantKeepAlive => true; -} +// @override +// bool get wantKeepAlive => true; +// } diff --git a/lib/screens/ytmusic_screen/youtube_history.dart b/lib/screens/ytmusic_screen/youtube_history.dart index a6b2ba4..e035357 100644 --- a/lib/screens/ytmusic_screen/youtube_history.dart +++ b/lib/screens/ytmusic_screen/youtube_history.dart @@ -1,177 +1,177 @@ -import 'package:cached_network_image/cached_network_image.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_swipe_action_cell/core/cell.dart'; -import 'package:get_it/get_it.dart'; +// import 'package:cached_network_image/cached_network_image.dart'; +// import 'package:flutter/material.dart'; +// import 'package:flutter_swipe_action_cell/core/cell.dart'; +// import 'package:get_it/get_it.dart'; -import '../../generated/l10n.dart'; -import '../../services/media_player.dart'; -import '../../themes/text_styles.dart'; -import '../../utils/adaptive_widgets/adaptive_widgets.dart'; -import '../../utils/bottom_modals.dart'; -import '../../ytmusic/ytmusic.dart'; +// import '../../generated/l10n.dart'; +// import '../../services/media_player.dart'; +// import '../../themes/text_styles.dart'; +// import '../../utils/adaptive_widgets/adaptive_widgets.dart'; +// import '../../utils/bottom_modals.dart'; +// import '../../ytmusic/ytmusic.dart'; -class YoutubeHistory extends StatefulWidget { - const YoutubeHistory({super.key}); +// class YoutubeHistory extends StatefulWidget { +// const YoutubeHistory({super.key}); - @override - State createState() => _YoutubeHistoryState(); -} +// @override +// State createState() => _YoutubeHistoryState(); +// } -class _YoutubeHistoryState extends State { - List sections = []; - bool loading = true; - @override - void initState() { - super.initState(); - fetchHistory(); - } +// class _YoutubeHistoryState extends State { +// List sections = []; +// bool loading = true; +// @override +// void initState() { +// super.initState(); +// fetchHistory(); +// } - fetchHistory() async { - setState(() { - loading = true; - }); - sections = await GetIt.I().getHistory(); - setState(() { - loading = false; - }); - } +// fetchHistory() async { +// setState(() { +// loading = true; +// }); +// sections = await GetIt.I().getHistory(); +// setState(() { +// loading = false; +// }); +// } - @override - Widget build(BuildContext context) { - return AdaptiveScaffold( - appBar: AdaptiveAppBar( - title: Text(S.of(context).History), - centerTitle: true, - actions: [ - if (sections.isNotEmpty) - AdaptiveIconButton( - icon: Icon(AdaptiveIcons.delete), - onPressed: () { - Modals.showConfirmBottomModal(context, - message: S.of(context).Remove_All_History_Message, - isDanger: true) - .then((bool confirm) async { - if (confirm) { - Modals.showCenterLoadingModal(context); - List ids = []; - for (var section in sections) { - ids.addAll(section['contents'] - .map((content) => content['feedbackToken']) - .toList()); - } +// @override +// Widget build(BuildContext context) { +// return AdaptiveScaffold( +// appBar: AdaptiveAppBar( +// title: Text(S.of(context).History), +// centerTitle: true, +// actions: [ +// if (sections.isNotEmpty) +// AdaptiveIconButton( +// icon: Icon(AdaptiveIcons.delete), +// onPressed: () { +// Modals.showConfirmBottomModal(context, +// message: S.of(context).Remove_All_History_Message, +// isDanger: true) +// .then((bool confirm) async { +// if (confirm) { +// Modals.showCenterLoadingModal(context); +// List ids = []; +// for (var section in sections) { +// ids.addAll(section['contents'] +// .map((content) => content['feedbackToken']) +// .toList()); +// } - bool deleted = - await GetIt.I().removeHistoryItem(ids); - if (deleted) { - setState(() { - sections = []; - }); - } - if (context.mounted) { - Navigator.pop(context); - fetchHistory(); - } - } - }); - }, - ) - ], - ), - body: loading - ? const Center(child: AdaptiveProgressRing()) - : SingleChildScrollView( - child: Center( - child: Container( - constraints: const BoxConstraints(maxWidth: 1000), - padding: const EdgeInsets.symmetric( - horizontal: 8, vertical: 8), - child: Column( - children: sections.indexed.map((section) { - int index = section.$1; - Map history = section.$2; - return Column( - children: [ - if (history['title'] != null && - history['contents'].isNotEmpty) - AdaptiveListTile( - margin: - const EdgeInsets.symmetric(vertical: 4), - title: Text( - history['title']!, - style: mediumTextStyle(context), - ), - ), - ...history['contents'].map((item) { - return SwipeActionCell( - key: Key(item['videoId']), - backgroundColor: Colors.transparent, - trailingActions: [ - SwipeAction( - title: S.of(context).Remove, - onTap: - (CompletionHandler handler) async { - Modals.showConfirmBottomModal(context, - message: S - .of(context) - .Remove_From_YTMusic_Message, - isDanger: true) - .then((bool confirm) async { - if (confirm) { - Modals.showCenterLoadingModal( - context); - bool deleted = - await GetIt.I() - .removeHistoryItem( - [item['feedbackToken']], - ); - if (deleted) { - setState(() { - sections[index]['contents'] - .remove(item); - }); - } - if (context.mounted) { - Navigator.pop(context); - } - } - }); - }, - color: Colors.red), - ], - child: AdaptiveListTile( - title: Text( - item['title'], - maxLines: 1, - ), - subtitle: Text(item['artists'] != null - ? item['artists'] - .map((artist) => artist['name']) - .join(',') - : item['subtitle'] ?? - item['album']?['name'] ?? - ''), - leading: ClipRRect( - borderRadius: BorderRadius.circular( - item['type'] == 'ARTIST' ? 50 : 3), - child: CachedNetworkImage( - imageUrl: - item['thumbnails'].first['url'], - height: 50, - width: 50, - fit: BoxFit.cover, - ), - ), - onTap: () { - GetIt.I().playSong(item); - }, - ), - ); - }), - ], - ); - }).toList(), - )), - ), - )); - } -} +// bool deleted = +// await GetIt.I().removeHistoryItem(ids); +// if (deleted) { +// setState(() { +// sections = []; +// }); +// } +// if (context.mounted) { +// Navigator.pop(context); +// fetchHistory(); +// } +// } +// }); +// }, +// ) +// ], +// ), +// body: loading +// ? const Center(child: AdaptiveProgressRing()) +// : SingleChildScrollView( +// child: Center( +// child: Container( +// constraints: const BoxConstraints(maxWidth: 1000), +// padding: const EdgeInsets.symmetric( +// horizontal: 8, vertical: 8), +// child: Column( +// children: sections.indexed.map((section) { +// int index = section.$1; +// Map history = section.$2; +// return Column( +// children: [ +// if (history['title'] != null && +// history['contents'].isNotEmpty) +// AdaptiveListTile( +// margin: +// const EdgeInsets.symmetric(vertical: 4), +// title: Text( +// history['title']!, +// style: mediumTextStyle(context), +// ), +// ), +// ...history['contents'].map((item) { +// return SwipeActionCell( +// key: Key(item['videoId']), +// backgroundColor: Colors.transparent, +// trailingActions: [ +// SwipeAction( +// title: S.of(context).Remove, +// onTap: +// (CompletionHandler handler) async { +// Modals.showConfirmBottomModal(context, +// message: S +// .of(context) +// .Remove_From_YTMusic_Message, +// isDanger: true) +// .then((bool confirm) async { +// if (confirm) { +// Modals.showCenterLoadingModal( +// context); +// bool deleted = +// await GetIt.I() +// .removeHistoryItem( +// [item['feedbackToken']], +// ); +// if (deleted) { +// setState(() { +// sections[index]['contents'] +// .remove(item); +// }); +// } +// if (context.mounted) { +// Navigator.pop(context); +// } +// } +// }); +// }, +// color: Colors.red), +// ], +// child: AdaptiveListTile( +// title: Text( +// item['title'], +// maxLines: 1, +// ), +// subtitle: Text(item['artists'] != null +// ? item['artists'] +// .map((artist) => artist['name']) +// .join(',') +// : item['subtitle'] ?? +// item['album']?['name'] ?? +// ''), +// leading: ClipRRect( +// borderRadius: BorderRadius.circular( +// item['type'] == 'ARTIST' ? 50 : 3), +// child: CachedNetworkImage( +// imageUrl: +// item['thumbnails'].first['url'], +// height: 50, +// width: 50, +// fit: BoxFit.cover, +// ), +// ), +// onTap: () { +// GetIt.I().playSong(item); +// }, +// ), +// ); +// }), +// ], +// ); +// }).toList(), +// )), +// ), +// )); +// } +// } diff --git a/lib/screens/ytmusic_screen/ytmusic_screen.dart b/lib/screens/ytmusic_screen/ytmusic_screen.dart index fc5c0a9..3029f4b 100644 --- a/lib/screens/ytmusic_screen/ytmusic_screen.dart +++ b/lib/screens/ytmusic_screen/ytmusic_screen.dart @@ -1,82 +1,82 @@ -import 'package:flutter/material.dart'; +// import 'package:flutter/material.dart'; -import '../../generated/l10n.dart'; -import '../../utils/adaptive_widgets/adaptive_widgets.dart'; -import 'albums_screen.dart'; -import 'artists_screen.dart'; -import 'playlists_screen.dart'; -import 'songs_screen.dart'; -import 'subscriptions_screen.dart'; -import 'youtube_history.dart'; +// import '../../generated/l10n.dart'; +// import '../../utils/adaptive_widgets/adaptive_widgets.dart'; +// import 'albums_screen.dart'; +// import 'artists_screen.dart'; +// import 'playlists_screen.dart'; +// import 'songs_screen.dart'; +// import 'subscriptions_screen.dart'; +// import 'youtube_history.dart'; -class YTMScreen extends StatefulWidget { - const YTMScreen({super.key}); +// class YTMScreen extends StatefulWidget { +// const YTMScreen({super.key}); - @override - State createState() => _YTMScreenState(); -} +// @override +// State createState() => _YTMScreenState(); +// } -class _YTMScreenState extends State with TickerProviderStateMixin { - @override - void initState() { - super.initState(); - } +// class _YTMScreenState extends State with TickerProviderStateMixin { +// @override +// void initState() { +// super.initState(); +// } - @override - Widget build(BuildContext context) { - return DefaultTabController( - length: 5, - child: AdaptiveScaffold( - appBar: AdaptiveAppBar( - title: Text(S.of(context).YTMusic), - centerTitle: true, - automaticallyImplyLeading: false, - actions: [ - AdaptiveIconButton( - icon: const Icon( - Icons.history, - size: 25, - ), - onPressed: () { - Navigator.push( - context, - AdaptivePageRoute.create( - (context) => const YoutubeHistory()), - ); - }) - ], - bottom: PreferredSize( - preferredSize: const Size.fromHeight(48), - child: Material( - color: Colors.transparent, - elevation: 0, - child: TabBar( - labelColor: AdaptiveTheme.of(context).primaryColor, - labelStyle: const TextStyle(fontWeight: FontWeight.bold), - unselectedLabelStyle: - const TextStyle(fontWeight: FontWeight.normal), - isScrollable: true, - tabs: [ - Tab(text: S.of(context).Songs), - Tab(text: S.of(context).Albums), - Tab(text: S.of(context).Playlists), - Tab(text: S.of(context).Artists), - Tab(text: S.of(context).Subscriptions) - ], - ), - ), - ), - ), - body: const TabBarView( - children: [ - SongsScreen(), - AlbumsScreen(), - PlaylistsScreen(), - ArtistsScreen(), - SubscriptionsScreen() - ], - ), - ), - ); - } -} +// @override +// Widget build(BuildContext context) { +// return DefaultTabController( +// length: 5, +// child: AdaptiveScaffold( +// appBar: AdaptiveAppBar( +// title: Text(S.of(context).YTMusic), +// centerTitle: true, +// automaticallyImplyLeading: false, +// actions: [ +// AdaptiveIconButton( +// icon: const Icon( +// Icons.history, +// size: 25, +// ), +// onPressed: () { +// Navigator.push( +// context, +// AdaptivePageRoute.create( +// (context) => const YoutubeHistory()), +// ); +// }) +// ], +// bottom: PreferredSize( +// preferredSize: const Size.fromHeight(48), +// child: Material( +// color: Colors.transparent, +// elevation: 0, +// child: TabBar( +// labelColor: AdaptiveTheme.of(context).primaryColor, +// labelStyle: const TextStyle(fontWeight: FontWeight.bold), +// unselectedLabelStyle: +// const TextStyle(fontWeight: FontWeight.normal), +// isScrollable: true, +// tabs: [ +// Tab(text: S.of(context).Songs), +// Tab(text: S.of(context).Albums), +// Tab(text: S.of(context).Playlists), +// Tab(text: S.of(context).Artists), +// Tab(text: S.of(context).Subscriptions) +// ], +// ), +// ), +// ), +// ), +// body: const TabBarView( +// children: [ +// SongsScreen(), +// AlbumsScreen(), +// PlaylistsScreen(), +// ArtistsScreen(), +// SubscriptionsScreen() +// ], +// ), +// ), +// ); +// } +// } diff --git a/lib/services/download_manager.dart b/lib/services/download_manager.dart index 3b0cb7a..7ebbc02 100644 --- a/lib/services/download_manager.dart +++ b/lib/services/download_manager.dart @@ -127,8 +127,11 @@ class DownloadManager { try { StreamManifest manifest = await ytExplode.videos.streamsClient.getManifest(videoId); - List streamInfos = - manifest.audioOnly.sortByBitrate().reversed.toList(); + List streamInfos = manifest.audioOnly + .where((a) => a.container == StreamContainer.mp4) + .sortByBitrate() + .reversed + .toList(); return quality == 'low' ? streamInfos.first : streamInfos.last; } catch (e) { rethrow; diff --git a/lib/services/yt_account.dart b/lib/services/yt_account.dart deleted file mode 100644 index 8d7b824..0000000 --- a/lib/services/yt_account.dart +++ /dev/null @@ -1,33 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter/widgets.dart'; -import 'package:get_it/get_it.dart'; - -import '../ytmusic/modals/user.dart'; -import '../ytmusic/ytmusic.dart'; - -class YTAccount { - ValueNotifier isLogged = GetIt.I().isLogged; - ValueNotifier user = ValueNotifier(null); - - YTAccount() { - _initialize(); - } - _initialize() async { - user.value = await GetIt.I().getUserInfo(); - GetIt.I().isLogged.addListener(() async { - await GetIt.I().refreshHeaders(); - isLogged.value = GetIt.I().isLogged.value; - user.value = await GetIt.I().getUserInfo(); - }); - } - - login(context) async { - await GetIt.I().toggleLogin(context); - await GetIt.I().refreshHeaders(); - } - - logOut(context) async { - await GetIt.I().toggleLogin(context); - await GetIt.I().refreshHeaders(); - } -} diff --git a/lib/utils/router.dart b/lib/utils/router.dart index 5af4b53..d2d433c 100644 --- a/lib/utils/router.dart +++ b/lib/utils/router.dart @@ -2,7 +2,6 @@ import 'dart:io'; import 'package:fluent_ui/fluent_ui.dart'; import 'package:flutter/cupertino.dart'; -import 'package:get_it/get_it.dart'; import 'package:go_router/go_router.dart'; import '../screens/home_screen/chip_screen.dart'; @@ -13,15 +12,12 @@ import '../screens/main_screen/main_screen.dart'; import '../screens/main_screen/player_screen.dart'; import '../screens/browse_screen/browse_screen.dart'; import '../screens/settings_screen/about/about_screen.dart'; -import '../screens/settings_screen/account/account_screen.dart'; import '../screens/settings_screen/appearence/appearence_screen.dart'; import '../screens/settings_screen/backup_restore/backup_restore_screen.dart'; import '../screens/settings_screen/content/content_screen.dart'; import '../screens/settings_screen/playback/audio_and_playback_screen.dart'; import '../screens/settings_screen/playback/equalizer_screen.dart'; import '../screens/settings_screen/settings_screen.dart'; -import '../screens/ytmusic_screen/ytmusic_screen.dart'; -import '../services/yt_account.dart'; GoRouter router = GoRouter( initialLocation: '/', @@ -35,14 +31,10 @@ GoRouter router = GoRouter( navigationShell: navigationShell, ), navigatorContainerBuilder: (context, navigationShell, children) => - ValueListenableBuilder( - valueListenable: GetIt.I().isLogged, - builder: (context, isLogged, child) { - return MyPageView( - currentIndex: navigationShell.currentIndex, - children: children, - ); - }), + MyPageView( + currentIndex: navigationShell.currentIndex, + children: children, + ), ), ], ), @@ -96,23 +88,23 @@ List branches = [ builder: (context, state) => const SavedScreen(), ), ]), - StatefulShellBranch(routes: [ - GoRoute( - path: '/ytmusic', - builder: (context, state) => const YTMScreen(), - ), - ]), + // StatefulShellBranch(routes: [ + // GoRoute( + // path: '/ytmusic', + // builder: (context, state) => const YTMScreen(), + // ), + // ]), StatefulShellBranch(routes: [ GoRoute( path: '/settings', builder: (context, state) => const SettingsScreen(), routes: [ - GoRoute( - path: 'account', - pageBuilder: (context, state) => Platform.isWindows - ? const FluentPage(child: AccountScreen()) - : const CupertinoPage(child: AccountScreen()), - ), + // GoRoute( + // path: 'account', + // pageBuilder: (context, state) => Platform.isWindows + // ? const FluentPage(child: AccountScreen()) + // : const CupertinoPage(child: AccountScreen()), + // ), GoRoute( path: 'appearence', pageBuilder: (context, state) => Platform.isWindows diff --git a/lib/ytmusic/auth/auth.dart b/lib/ytmusic/auth/auth.dart deleted file mode 100644 index 8efa841..0000000 --- a/lib/ytmusic/auth/auth.dart +++ /dev/null @@ -1,168 +0,0 @@ -// ignore_for_file: constant_identifier_names - -import 'dart:convert'; -import 'package:flutter/material.dart'; -import 'package:hive_flutter/hive_flutter.dart'; -import 'package:http/http.dart' as http; -import 'package:url_launcher/url_launcher.dart'; - -import '../../utils/bottom_modals.dart'; -import '../helpers.dart'; - -const USER_AGENT = - 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0'; -const OAUTH_CLIENT_ID = - "861556708454-d6dlm3lh05idd8npek18k6be8ba3oc68.apps.googleusercontent.com"; -const OAUTH_CLIENT_SECRET = "SboVhoG9s0rNafixCSGGKXAT"; -const OAUTH_SCOPE = "https://www.googleapis.com/auth/youtube"; -const OAUTH_CODE_URL = "https://www.youtube.com/o/oauth2/device/code"; -const OAUTH_TOKEN_URL = "https://oauth2.googleapis.com/token"; -const OAUTH_USER_AGENT = "$USER_AGENT Cobalt/Version"; - -bool isOAuth() { - Map headers = Hive.box('SETTINGS').get('YTMUSIC_AUTH', defaultValue: {}); - - var oauthStructure = { - "access_token", - "expires_at", - "expires_in", - "token_type", - "refresh_token", - }; - return oauthStructure.every((key) => headers.containsKey(key)); -} - -class AuthMixin { - ValueNotifier isLogged = ValueNotifier(false); - Future login(BuildContext context) async { - Modals.showCenterLoadingModal(context); - var code = await getCode(); - var url = "${code['verification_url']}?user_code=${code['user_code']}"; - if (context.mounted) { - Navigator.pop(context); - } - if (context.mounted) { - bool confirm1 = await Modals.showConfirmBottomModal( - context, - message: 'Login via youtube music. your code is:\n${code["user_code"]}', - doneText: 'Proceed', - cancelText: 'Cancel', - ); - if (confirm1 == true) { - await launchUrl(Uri.parse(url), mode: LaunchMode.inAppBrowserView); - await Future.delayed(const Duration(milliseconds: 1000)); - if (context.mounted) { - bool confirm2 = await Modals.showConfirmBottomModal(context, - message: 'Did you logged in successfully'); - - if (confirm2 == true) { - if (context.mounted) { - Modals.showCenterLoadingModal(context); - } - var token = await getTokenFromCode(code["device_code"]); - await saveToken(token); - await checkLogged(); - if (context.mounted) { - Navigator.pop(context); - } - } - } - } - } - return isLogged.value; - } - - Future _sendRequest( - String url, Map data) async { - data["client_id"] = OAUTH_CLIENT_ID; - var headers = {"User-Agent": OAUTH_USER_AGENT}; - return await http.post(Uri.parse(url), body: data, headers: headers); - } - - checkLogged() async { - if (isOAuth()) { - await checkToken(); - isLogged.value = isOAuth(); - } - } - - Future> getCode() async { - var codeResponse = - await _sendRequest(OAUTH_CODE_URL, {"scope": OAUTH_SCOPE}); - var responseJson = jsonDecode(codeResponse.body); - return responseJson; - } - - Map _parseToken(Map token) { - token["expires_at"] = token["expires_in"] != null - ? (DateTime.now().millisecondsSinceEpoch / 1000).round() + - int.parse(token["expires_in"].toString()) - : null; - return token; - } - - Future> getTokenFromCode(String deviceCode) async { - var response = await _sendRequest( - OAUTH_TOKEN_URL, - { - "client_secret": OAUTH_CLIENT_SECRET, - "grant_type": "http://oauth.net/grant_type/device/1.0", - "code": deviceCode, - }, - ); - return _parseToken(jsonDecode(response.body)); - } - - Future> refreshToken(String refreshToken) async { - var response = await _sendRequest( - OAUTH_TOKEN_URL, - { - "client_secret": OAUTH_CLIENT_SECRET, - "grant_type": "refresh_token", - "refresh_token": refreshToken, - }, - ); - return _parseToken(jsonDecode(response.body)); - } - - Future saveToken(Map token) async { - await Hive.box('SETTINGS').put('YTMUSIC_AUTH', token); - } - - Future checkToken() async { - Map headers = Hive.box('SETTINGS').get('YTMUSIC_AUTH', defaultValue: {}); - if ((DateTime.now().millisecondsSinceEpoch / 1000).round() > - (headers["expires_at"] - 3600)) { - Map rToken = - await refreshToken(headers["refresh_token"]); - headers.updateAll((key, value) => rToken[key] ?? value); - await saveToken(headers); - } - return headers; - } - - Future toggleLogin(BuildContext context) async { - if (isLogged.value) { - await Hive.box('SETTINGS').delete('YTMUSIC_AUTH'); - isLogged.value = false; - } else { - await login(context); - } - return isLogged.value; - } - - Future> loadHeaders() async { - var headers = initializeHeaders(); - await checkLogged(); - if (isLogged.value) { - Map token = await checkToken(); - - headers["Authorization"] = - "${token['token_type']} ${token['access_token']}"; - headers["Content-Type"] = "application/json"; - headers["X-Goog-Request-Time"] = - ((DateTime.now().millisecondsSinceEpoch / 1000).round()).toString(); - } - return headers; - } -} diff --git a/lib/ytmusic/auth/login_screen.dart b/lib/ytmusic/auth/login_screen.dart deleted file mode 100644 index 1c2b68f..0000000 --- a/lib/ytmusic/auth/login_screen.dart +++ /dev/null @@ -1,18 +0,0 @@ -// import 'package:flutter/material.dart'; -// import 'package:flutter_inappwebview/flutter_inappwebview.dart'; - -// class LoginScreen extends StatelessWidget { -// const LoginScreen({required this.url, super.key}); -// final String url; -// @override -// Widget build(BuildContext context) { -// return Scaffold( -// appBar: AppBar(), -// body: InAppWebView( -// initialUrlRequest: URLRequest( -// url: WebUri(url), -// ), -// ), -// ); -// } -// } diff --git a/lib/ytmusic/mixins/library.dart b/lib/ytmusic/mixins/library.dart index 4a39aa4..2c8acd9 100644 --- a/lib/ytmusic/mixins/library.dart +++ b/lib/ytmusic/mixins/library.dart @@ -5,10 +5,10 @@ import 'utils.dart'; mixin LibraryMixin on YTMusicServices { Future getLibrarySongs({String? continuationParams}) async { Map body = {'browseId': 'FEmusic_liked_videos'}; - + final response = await sendRequest('browse', body, additionalParams: continuationParams ?? ''); - + Map outerContents = {}; if (continuationParams != null) { outerContents = @@ -25,12 +25,8 @@ mixin LibraryMixin on YTMusicServices { 'contents', 0, ]); - outerContents = nav(contents, [ - 'musicShelfRenderer' - ])??nav(contents, [ - 'itemSectionRenderer' - ]); - + outerContents = nav(contents, ['musicShelfRenderer']) ?? + nav(contents, ['itemSectionRenderer']); } String? continuation = nav(outerContents, @@ -54,7 +50,8 @@ mixin LibraryMixin on YTMusicServices { outerContents = nav(response, ['continuationContents', 'gridContinuation']); } else { - Map contents = nav(response, ['contents', + Map contents = nav(response, [ + 'contents', 'singleColumnBrowseResultsRenderer', 'tabs', 0, @@ -62,19 +59,22 @@ mixin LibraryMixin on YTMusicServices { 'content', 'sectionListRenderer', 'contents', - 0,]); - outerContents = nav(contents, [ - 'gridRenderer', - ])??nav(contents, [ - 'itemSectionRenderer', + 0, ]); + outerContents = nav(contents, [ + 'gridRenderer', + ]) ?? + nav(contents, [ + 'itemSectionRenderer', + ]); } String? continuation = nav(outerContents, ['continuations', 0, 'nextContinuationData', 'continuation']); if (continuation != null) { continuation = getContinuationString(continuation); } - List contents = nav(outerContents, ['items'])??nav(outerContents, ['contents']); + List contents = + nav(outerContents, ['items']) ?? nav(outerContents, ['contents']); return { 'contents': handleContents(contents), @@ -94,7 +94,8 @@ mixin LibraryMixin on YTMusicServices { outerContents = nav(response, ['continuationContents', 'musicShelfContinuation']); } else { - Map contents = nav(response,['contents', + Map contents = nav(response, [ + 'contents', 'singleColumnBrowseResultsRenderer', 'tabs', 0, @@ -102,12 +103,14 @@ mixin LibraryMixin on YTMusicServices { 'content', 'sectionListRenderer', 'contents', - 0,]); - outerContents = nav(contents, [ - 'musicShelfRenderer', - ])??nav(contents,[ - 'itemSectionRenderer', + 0, ]); + outerContents = nav(contents, [ + 'musicShelfRenderer', + ]) ?? + nav(contents, [ + 'itemSectionRenderer', + ]); } String? continuation = nav(outerContents, ['continuations', 0, 'nextContinuationData', 'continuation']); @@ -131,7 +134,8 @@ mixin LibraryMixin on YTMusicServices { outerContents = nav(response, ['continuationContents', 'gridContinuation']); } else { - Map contents = nav(response,[ 'contents', + Map contents = nav(response, [ + 'contents', 'singleColumnBrowseResultsRenderer', 'tabs', 0, @@ -139,14 +143,12 @@ mixin LibraryMixin on YTMusicServices { 'content', 'sectionListRenderer', 'contents', - 0,]); - outerContents = nav(contents, [ - 'gridRenderer' - ])?? - nav(contents, [ - 'itemSectionRenderer', + 0, ]); - + outerContents = nav(contents, ['gridRenderer']) ?? + nav(contents, [ + 'itemSectionRenderer', + ]); } String? continuation = nav(outerContents, ['continuations', 0, 'nextContinuationData', 'continuation']); @@ -173,7 +175,7 @@ mixin LibraryMixin on YTMusicServices { outerContents = outerContents = nav(response, ['continuationContents', 'musicShelfContinuation']); } else { - Map contents = nav(response,[ + Map contents = nav(response, [ 'contents', 'singleColumnBrowseResultsRenderer', 'tabs', @@ -185,10 +187,11 @@ mixin LibraryMixin on YTMusicServices { 0, ]); outerContents = nav(contents, [ - 'musicShelfRenderer', - ])??nav(contents, [ - 'itemSectionRenderer', - ]); + 'musicShelfRenderer', + ]) ?? + nav(contents, [ + 'itemSectionRenderer', + ]); } String? continuation = nav(outerContents, ['continuations', 0, 'nextContinuationData', 'continuation']); @@ -252,12 +255,12 @@ mixin LibraryMixin on YTMusicServices { return result; } - Future removeHistoryItem(List feedbackTokens) async { - if (!isLogged.value) return false; - Map body = {'feedbackTokens': feedbackTokens}; - final response = await sendRequest('feedback', body); - return nav(response, ['feedbackResponses', 0, 'isProcessed']) == true; - } + // Future removeHistoryItem(List feedbackTokens) async { + // if (!isLogged.value) return false; + // Map body = {'feedbackTokens': feedbackTokens}; + // final response = await sendRequest('feedback', body); + // return nav(response, ['feedbackResponses', 0, 'isProcessed']) == true; + // } // def get_library_songs(self, // limit: int = 25, diff --git a/lib/ytmusic/mixins/user.dart b/lib/ytmusic/mixins/user.dart deleted file mode 100644 index 422270c..0000000 --- a/lib/ytmusic/mixins/user.dart +++ /dev/null @@ -1,29 +0,0 @@ -import '../helpers.dart'; -import '../modals/user.dart'; -import '../yt_service_provider.dart'; - -mixin UserMixin on YTMusicServices { - Future getUserInfo() async { - if (isLogged.value == false) return null; - - String endpoint = 'account/account_menu'; - var response = await sendRequest(endpoint, {}); - // pprint(response); - Map? header = nav(response, [ - 'actions', - 0, - 'openPopupAction', - 'popup', - 'multiPageMenuRenderer', - 'header', - 'activeAccountHeaderRenderer' - ]); - - User user = User( - name: nav(header, ['accountName', 'runs', 0, 'text']), - photos: nav(header, ['accountPhoto', 'thumbnails']), - channelHandle: nav(header, ['channelHandle', 'runs', 0, 'text']), - ); - return user; - } -} diff --git a/lib/ytmusic/yt_service_provider.dart b/lib/ytmusic/yt_service_provider.dart index e9f8b51..eb1827a 100644 --- a/lib/ytmusic/yt_service_provider.dart +++ b/lib/ytmusic/yt_service_provider.dart @@ -2,15 +2,14 @@ import 'dart:convert'; import 'package:hive_flutter/hive_flutter.dart'; import 'package:http/http.dart'; -import 'auth/auth.dart'; import 'helpers.dart'; -abstract class YTMusicServices extends AuthMixin { +abstract class YTMusicServices { YTMusicServices() : super() { init(); } Future init() async { - headers = await loadHeaders(); + headers = initializeHeaders(); context = initializeContext(); if (!headers.containsKey('X-Goog-Visitor-Id')) { @@ -23,7 +22,7 @@ abstract class YTMusicServices extends AuthMixin { } Future refreshHeaders() async { - headers = await loadHeaders(); + headers = initializeHeaders(); } Future resetVisitorId() async { diff --git a/lib/ytmusic/ytmusic.dart b/lib/ytmusic/ytmusic.dart index 848ab07..187c06f 100644 --- a/lib/ytmusic/ytmusic.dart +++ b/lib/ytmusic/ytmusic.dart @@ -1,10 +1,10 @@ library ytmusic; +import 'package:gyawun/ytmusic/mixins/library.dart'; + import 'mixins/browsing.dart'; -import 'mixins/library.dart'; import 'mixins/search.dart'; -import 'mixins/user.dart'; import 'yt_service_provider.dart'; class YTMusic extends YTMusicServices - with BrowsingMixin, SearchMixin, LibraryMixin, UserMixin {} + with BrowsingMixin, LibraryMixin, SearchMixin {} diff --git a/pubspec.yaml b/pubspec.yaml index 602aedb..b8ea428 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: gyawun description: "A new Flutter project." publish_to: 'none' -version: 2.0.7+32 +version: 2.0.8+33 environment: sdk: '>=3.4.1 <4.0.0'