diff --git a/lib/frame/home.dart b/lib/frame/home.dart index 8d49ea0..587732d 100644 --- a/lib/frame/home.dart +++ b/lib/frame/home.dart @@ -6,21 +6,18 @@ import 'package:flutter_discord_rpc/flutter_discord_rpc.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:hotkey_manager/hotkey_manager.dart'; -import 'package:sangeet/core/widgets/blur_image_container.dart'; -import 'package:sangeet/functions/player/views/current_playing_view.dart'; +import 'package:sangeet/core/core.dart'; +import 'package:sangeet/functions/explore/controllers/explore_controller.dart'; +import 'package:sangeet/functions/explore/widgets/explore_list.dart'; +import 'package:sangeet/functions/explore/widgets/trend_card.dart'; import 'package:window_manager/window_manager.dart'; import 'package:tray_manager/tray_manager.dart'; import 'package:sangeet/core/constants.dart'; -import 'package:sangeet/functions/explore/views/explore_view.dart'; import 'package:sangeet/functions/player/controllers/player_controller.dart'; import 'package:sangeet/functions/player/widgets/base_audio_player.dart'; -import 'package:sangeet/functions/search/views/search_view.dart'; -import 'package:sangeet/functions/settings/views/settings_view.dart'; import 'package:sangeet/functions/shortcuts/actions.dart'; -import '../core/app_config.dart'; - class HomeFrame extends ConsumerStatefulWidget { const HomeFrame({super.key}); @@ -60,10 +57,8 @@ class _HomeFrameState extends ConsumerState @override Widget build(BuildContext context) { - final index = ref.watch(appScreenConfigProvider); - final config = ref.watch(appScreenConfigProvider.notifier); final player = ref.watch(playerControllerProvider.notifier).getPlayer; - + final currentWidth = MediaQuery.of(context).size.width; return Actions( actions: >{ BaseIntent: SongActions( @@ -83,91 +78,214 @@ class _HomeFrameState extends ConsumerState ), }, child: Scaffold( - backgroundColor: Colors.transparent, - body: BlurImageContainer( - child: Row( - children: [ - NavigationRail( - selectedIndex: index, - onDestinationSelected: (idx) => config.onIndex(idx), - destinations: const [ - NavigationRailDestination( - icon: Icon(Icons.home), - label: Text("Home"), - ), - NavigationRailDestination( - icon: Icon(Icons.search), - label: Text("Search"), - ), - NavigationRailDestination( - icon: Icon(Icons.music_note_rounded), - label: Text("Current Playing"), - ), - NavigationRailDestination( - icon: Icon(Icons.settings), - label: Text("Settings"), + body: Row( + mainAxisSize: MainAxisSize.max, + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Container( + decoration: BoxDecoration( + border: Border( + right: BorderSide( + width: 2, + color: Colors.teal.withOpacity(.09), + ))), + width: 430, + height: double.infinity, + child: Column( + children: [ + Flexible( + flex: 1, + child: SizedBox( + width: double.infinity, + height: double.maxFinite, + child: ref.watch(getExploreDataProvider).when( + data: (data) { + final trendings = data.trending; + + return Column( + children: [ + Row( + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + children: [ + const Padding( + padding: EdgeInsets.all(10.0), + child: Text( + 'Trending.', + style: TextStyle( + fontSize: 30, + fontWeight: FontWeight.bold, + ), + ), + ), + IconButton( + onPressed: () => ref + .read(playerControllerProvider + .notifier) + .reset(), + icon: const Icon(Icons + .disabled_by_default_rounded), + ) + ], + ), + SizedBox( + width: 430, + height: + MediaQuery.of(context).size.height - + 165, + child: ListView.builder( + itemCount: trendings.length, + scrollDirection: Axis.vertical, + itemBuilder: (context, index) { + final item = trendings[index]; + return TrendCard( + key: Key("trend_${item.id}"), + onTap: () => ref + .watch(playerControllerProvider + .notifier) + .runRadio( + radioId: item.id, + type: MediaType.fromString( + item.type), + redirect: () {}, + ), + onLike: () {}, + onPlay: () {}, + image: item.image, + accentColor: item.accentColor, + title: item.title, + subtitle: item.subtitle, + explicitContent: + item.explicitContent, + badgeIcon: item.type == "song" + ? Icons.music_note + : item.type == "playlist" + ? Icons + .playlist_play_rounded + : Icons.album_rounded, + ); + }, + ), + ), + ], + ); + }, + error: (error, stackTrace) { + return ErrorText( + error: error.toString(), + ); + }, + loading: () => const CircularProgressIndicator(), + ), + ), ), + const BaseAudioPlayer() ], - leading: Padding( - padding: const EdgeInsets.symmetric(vertical: 8.0), - child: Image.asset( - 'assets/app_icon.ico', - width: 35, - ), - ), - labelType: NavigationRailLabelType.none, - backgroundColor: Colors.black, - indicatorColor: Colors.grey.shade900, - unselectedIconTheme: const IconThemeData(color: Colors.grey), - selectedIconTheme: const IconThemeData(color: Colors.white), ), - Expanded( + ), + if (currentWidth > 450) + SizedBox( + width: currentWidth - 430, child: Column( children: [ - Expanded( - flex: 1, - child: IndexedStack( - index: index, - children: [ - _buildNavigator( - 0, - const ExploreView(), - ), - _buildNavigator( - 1, - const SearchView(), - ), - _buildNavigator( - 2, - const CurrentPlayingView(), - ), - _buildNavigator( - 3, - const SettingsView(), - ), - ], - ), - ), - const BaseAudioPlayer(), + SizedBox( + width: double.maxFinite, + height: MediaQuery.of(context).size.height, + child: const ExploreList(), + ) ], ), ), - ], - ), + ], ), ), + // child: Scaffold( + // backgroundColor: Colors.transparent, + // body: BlurImageContainer( + // child: Row( + // children: [ + // NavigationRail( + // selectedIndex: index, + // onDestinationSelected: (idx) => config.onIndex(idx), + // destinations: const [ + // NavigationRailDestination( + // icon: Icon(Icons.home), + // label: Text("Home"), + // ), + // NavigationRailDestination( + // icon: Icon(Icons.search), + // label: Text("Search"), + // ), + // NavigationRailDestination( + // icon: Icon(Icons.music_note_rounded), + // label: Text("Current Playing"), + // ), + // NavigationRailDestination( + // icon: Icon(Icons.settings), + // label: Text("Settings"), + // ), + // ], + // leading: Padding( + // padding: const EdgeInsets.symmetric(vertical: 8.0), + // child: Image.asset( + // 'assets/app_icon.ico', + // width: 35, + // ), + // ), + // labelType: NavigationRailLabelType.none, + // backgroundColor: Colors.black, + // indicatorColor: Colors.grey.shade900, + // unselectedIconTheme: const IconThemeData(color: Colors.grey), + // selectedIconTheme: const IconThemeData(color: Colors.white), + // ), + // Expanded( + // child: Column( + // children: [ + // Expanded( + // flex: 1, + // child: IndexedStack( + // index: index, + // children: [ + // _buildNavigator( + // 0, + // const ExploreView(), + // ), + // _buildNavigator( + // 1, + // const SearchView(), + // ), + // _buildNavigator( + // 2, + // const CurrentPlayingView(), + // ), + // _buildNavigator( + // 3, + // const SettingsView(), + // ), + // ], + // ), + // ), + // const BaseAudioPlayer(), + // ], + // ), + // ), + // ], + // ), + // ), + // ), ), ); } - Widget _buildNavigator(int index, Widget child) { - return Navigator( - key: GlobalKey(debugLabel: 'navigator$index'), - onGenerateRoute: (settings) => MaterialPageRoute( - builder: (context) => child, - ), - ); - } + // Widget _buildNavigator(int index, Widget child) { + // return Navigator( + // key: GlobalKey(debugLabel: 'navigator$index'), + // onGenerateRoute: (settings) => MaterialPageRoute( + // builder: (context) => child, + // ), + // ); + // } @override void onTrayIconRightMouseDown() async { diff --git a/lib/functions/explore/widgets/explore_list.dart b/lib/functions/explore/widgets/explore_list.dart index 7a114a5..7e96d43 100644 --- a/lib/functions/explore/widgets/explore_list.dart +++ b/lib/functions/explore/widgets/explore_list.dart @@ -5,7 +5,6 @@ import 'package:sangeet/core/core.dart'; import 'package:sangeet/core/skeletions/explore_loading_skeletion.dart'; import 'package:sangeet/functions/explore/widgets/browse_card.dart'; -import 'package:sangeet/functions/explore/widgets/trend_card.dart'; import 'package:sangeet/functions/explore/controllers/explore_controller.dart'; import 'package:sangeet/functions/player/controllers/player_controller.dart'; @@ -13,7 +12,6 @@ import 'package:sangeet/functions/player/controllers/player_controller.dart'; import 'package:sangeet/functions/charts/view/charts_view.dart'; import 'package:sangeet/functions/album/view/album_view.dart'; import 'package:sangeet/functions/playlist/view/playlist_view.dart'; -import 'package:sangeet/functions/song/view/song_view.dart'; class ExploreList extends ConsumerWidget { const ExploreList({super.key}); @@ -26,87 +24,12 @@ class ExploreList extends ConsumerWidget { final radios = data.radios; final albums = data.albums; final playlists = data.topPlaylists; - final trendings = data.trending; return SingleChildScrollView( physics: const BouncingScrollPhysics(), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - // TRENDINGS - const Padding( - padding: EdgeInsets.all(10.0), - child: Text( - 'Trendings.', - style: TextStyle( - fontSize: 30, - fontWeight: FontWeight.bold, - ), - ), - ), - Container( - margin: const EdgeInsets.symmetric(vertical: 20.0), - height: 290.0, - child: GridView.count( - crossAxisCount: 3, - childAspectRatio: 0.2, - scrollDirection: Axis.horizontal, - physics: const BouncingScrollPhysics(), - children: trendings - .map( - (item) => TrendCard( - key: Key("trend_${item.id}"), - onPlay: () => ref - .watch(playerControllerProvider.notifier) - .runRadio( - radioId: item.id, - type: MediaType.fromString(item.type), - redirect: () { - if (item.type == 'song') { - Navigator.of(context) - .push(SongView.route(item.id)); - } - if (item.type == 'album') { - Navigator.of(context) - .push(AlbumView.route(item.id)); - } - if (item.type == 'playlist') { - Navigator.of(context) - .push(PlaylistView.route(item.id)); - } - }, - ), - onLike: () {}, - onTap: () { - if (item.type == 'song') { - Navigator.of(context) - .push(SongView.route(item.id)); - } - if (item.type == 'album') { - Navigator.of(context) - .push(AlbumView.route(item.id)); - } - if (item.type == 'playlist') { - Navigator.of(context) - .push(PlaylistView.route(item.id)); - } - }, - image: item.image, - accentColor: item.accentColor, - title: item.title, - subtitle: item.subtitle, - explicitContent: item.explicitContent, - badgeIcon: item.type == "song" - ? Icons.music_note - : item.type == "playlist" - ? Icons.playlist_play_rounded - : Icons.album_rounded, - ), - ) - .toList(), - ), - ), - // ALBUMS // const Padding( padding: EdgeInsets.all(10.0), diff --git a/lib/functions/player/controllers/player_controller.dart b/lib/functions/player/controllers/player_controller.dart index 27dca0f..b3afbda 100644 --- a/lib/functions/player/controllers/player_controller.dart +++ b/lib/functions/player/controllers/player_controller.dart @@ -172,13 +172,15 @@ class PlayerController extends StateNotifier { await _player.play(); SongModel song = _player.audioSource?.sequence[_player.currentIndex!].tag; + await _smtc.enableSmtc(); await _smtc.updateMetadata(MusicMetadata( title: song.title, album: song.albumName, thumbnail: song.images[1].url, artist: song.artists[0].name, )); - FlutterDiscordRPC.instance.setActivity( + await _smtc.setPlaybackStatus(PlaybackStatus.playing); + await FlutterDiscordRPC.instance.setActivity( activity: RPCActivity( activityType: ActivityType.listening, state: "${song.title} - ${song.albumName}", @@ -361,10 +363,16 @@ class PlayerController extends StateNotifier { } } + Future reset() async { + await _player.stop(); + await playlist.clear(); + await _smtc.disableSmtc(); + } + @override void dispose() { - super.dispose(); _player.dispose(); _smtc.dispose(); + super.dispose(); } } diff --git a/lib/functions/player/widgets/base_audio_player.dart b/lib/functions/player/widgets/base_audio_player.dart index cbe57b1..8172d88 100644 --- a/lib/functions/player/widgets/base_audio_player.dart +++ b/lib/functions/player/widgets/base_audio_player.dart @@ -3,7 +3,6 @@ import 'package:flutter/material.dart'; import 'package:just_audio/just_audio.dart'; import 'package:audio_video_progress_bar/audio_video_progress_bar.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:sangeet/core/app_config.dart'; import 'package:sangeet/functions/player/controllers/player_controller.dart'; import 'package:sangeet/functions/player/widgets/common.dart'; import 'package:sangeet/functions/player/widgets/player_control_buttons.dart'; @@ -29,11 +28,43 @@ class _BaseAudioPlayerState extends ConsumerState { builder: (context, snapshot) { final state = snapshot.data; - if (snapshot.connectionState == ConnectionState.waiting) { - return Container(height: 0); - } if (state?.sequence.isEmpty ?? true) { - return const SizedBox(); + return Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(5), + border: Border.all( + color: Colors.teal.withOpacity(.09), + width: 2, + ), + ), + width: double.infinity, + height: 80, + child: const Center( + child: Text( + "Nothing Playing", + style: TextStyle( + fontSize: 18, + fontWeight: FontWeight.w500, + ), + ), + ), + ); + } + if (snapshot.connectionState == ConnectionState.waiting) { + return Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(5), + border: Border.all( + color: Colors.teal.withOpacity(.09), + width: 2, + ), + ), + width: double.infinity, + height: 80, + child: const Center( + child: LinearProgressIndicator(), + ), + ); } final metadata = state!.currentSource!.tag as SongModel; @@ -57,37 +88,37 @@ class _BaseAudioPlayerState extends ConsumerState { width: 70, ), ), - Flexible( - child: Padding( - padding: const EdgeInsets.all(8.0), - child: Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - metadata.title, - style: const TextStyle( - fontWeight: FontWeight.bold, - ), - maxLines: 1, - ), - Text( - metadata.albumName, - maxLines: 1, - ), - ], - ), - ), - ), + // Flexible( + // child: Padding( + // padding: const EdgeInsets.all(8.0), + // child: Column( + // mainAxisSize: MainAxisSize.min, + // crossAxisAlignment: CrossAxisAlignment.start, + // children: [ + // Text( + // metadata.title, + // style: const TextStyle( + // fontWeight: FontWeight.bold, + // ), + // maxLines: 1, + // ), + // Text( + // metadata.albumName, + // maxLines: 1, + // ), + // ], + // ), + // ), + // ), ], ), ), Expanded( - flex: 2, + flex: 4, child: Container( padding: const EdgeInsets.all(8.0), child: Column( - mainAxisSize: MainAxisSize.min, + mainAxisSize: MainAxisSize.max, crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: [ @@ -123,24 +154,24 @@ class _BaseAudioPlayerState extends ConsumerState { ), ), ), - Expanded( - flex: MediaQuery.of(context).size.width >= 880 ? 1 : 0, - child: Container( - padding: const EdgeInsets.all(8.0), - child: Row( - mainAxisSize: MainAxisSize.min, - mainAxisAlignment: MainAxisAlignment.end, - children: [ - IconButton( - onPressed: () => ref - .watch(appScreenConfigProvider.notifier) - .onIndex(2), - icon: const Icon(Icons.open_in_full_rounded), - ), - ], - ), - ), - ) + // Expanded( + // flex: MediaQuery.of(context).size.width >= 880 ? 1 : 0, + // child: Container( + // padding: const EdgeInsets.all(8.0), + // child: Row( + // mainAxisSize: MainAxisSize.min, + // mainAxisAlignment: MainAxisAlignment.end, + // children: [ + // IconButton( + // onPressed: () => ref + // .watch(appScreenConfigProvider.notifier) + // .onIndex(2), + // icon: const Icon(Icons.open_in_full_rounded), + // ), + // ], + // ), + // ), + // ) ], ), ); diff --git a/lib/initialization.dart b/lib/initialization.dart index 6b40e34..b3ccf71 100644 --- a/lib/initialization.dart +++ b/lib/initialization.dart @@ -32,7 +32,7 @@ Future initWindowManager() async { windowManager.waitUntilReadyToShow(windowOptions, () async { await windowManager.show(); await windowManager.focus(); - await windowManager.setMinimumSize(const Size(600, 800)); + await windowManager.setMinimumSize(const Size(450, 800)); await windowManager.setPreventClose(true); await trayManager.setIcon('assets/app_icon.ico');