Skip to content

Commit

Permalink
fix: navigation to settings not working
Browse files Browse the repository at this point in the history
  • Loading branch information
Kingkor Roy Tirtho committed Apr 30, 2023
1 parent 6d836bd commit ce10aa1
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 48 deletions.
28 changes: 19 additions & 9 deletions lib/collections/side_bar_tiles.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,29 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
class SideBarTiles {
final IconData icon;
final String title;
SideBarTiles({required this.icon, required this.title});
final String id;
SideBarTiles({required this.icon, required this.title, required this.id});
}

List<SideBarTiles> getSidebarTileList(AppLocalizations l10n) => [
SideBarTiles(icon: SpotubeIcons.home, title: l10n.browse),
SideBarTiles(icon: SpotubeIcons.search, title: l10n.search),
SideBarTiles(icon: SpotubeIcons.library, title: l10n.library),
SideBarTiles(icon: SpotubeIcons.music, title: l10n.lyrics),
SideBarTiles(id: "browse", icon: SpotubeIcons.home, title: l10n.browse),
SideBarTiles(id: "search", icon: SpotubeIcons.search, title: l10n.search),
SideBarTiles(
id: "library", icon: SpotubeIcons.library, title: l10n.library),
SideBarTiles(id: "lyrics", icon: SpotubeIcons.music, title: l10n.lyrics),
];

List<SideBarTiles> getNavbarTileList(AppLocalizations l10n) => [
SideBarTiles(icon: SpotubeIcons.home, title: l10n.browse),
SideBarTiles(icon: SpotubeIcons.search, title: l10n.search),
SideBarTiles(icon: SpotubeIcons.library, title: l10n.library),
SideBarTiles(icon: SpotubeIcons.settings, title: l10n.settings)
SideBarTiles(id: "browse", icon: SpotubeIcons.home, title: l10n.browse),
SideBarTiles(id: "search", icon: SpotubeIcons.search, title: l10n.search),
SideBarTiles(
id: "library",
icon: SpotubeIcons.library,
title: l10n.library,
),
SideBarTiles(
id: "settings",
icon: SpotubeIcons.settings,
title: l10n.settings,
)
];
4 changes: 2 additions & 2 deletions lib/components/root/spotube_navigation_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class SpotubeNavigationBar extends HookConsumerWidget {
return MouseRegion(
cursor: SystemMouseCursors.click,
child: Badge(
isLabelVisible: e.title == "Library" && downloadCount > 0,
isLabelVisible: e.id == "library" && downloadCount > 0,
label: Text(downloadCount.toString()),
child: Icon(
e.icon,
Expand All @@ -84,7 +84,7 @@ class SpotubeNavigationBar extends HookConsumerWidget {
index: insideSelectedIndex.value,
onTap: (i) {
insideSelectedIndex.value = i;
if (navbarTileList[i].title == "Settings") {
if (navbarTileList[i].id == "settings") {
Sidebar.goToSettings(context);
return;
}
Expand Down
13 changes: 6 additions & 7 deletions lib/provider/playlist_queue_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class PlaylistQueue {
class PlaylistQueueNotifier extends PersistedStateNotifier<PlaylistQueue?> {
final Ref ref;

AudioServices? audioServices;
late AudioServices audioServices;

static final provider =
StateNotifierProvider<PlaylistQueueNotifier, PlaylistQueue?>(
Expand All @@ -150,7 +150,7 @@ class PlaylistQueueNotifier extends PersistedStateNotifier<PlaylistQueue?> {
}

void configure() async {
audioServices = await AudioServices.create(ref, this);
audioServices = AudioServices(ref, this);

audioPlayer.onPlayerComplete.listen((event) async {
if (!isLoaded) return;
Expand Down Expand Up @@ -337,8 +337,7 @@ class PlaylistQueueNotifier extends PersistedStateNotifier<PlaylistQueue?> {
Future<void> play() async {
if (!isLoaded) return;
await pause();
audioServices?.activateSession();
await audioServices?.addTrack(state!.activeTrack);
await audioServices.addTrack(state!.activeTrack);
if (state!.activeTrack is LocalTrack) {
await audioPlayer.play(
DeviceFileSource((state!.activeTrack as LocalTrack).path),
Expand All @@ -363,7 +362,7 @@ class PlaylistQueueNotifier extends PersistedStateNotifier<PlaylistQueue?> {
);
}

audioServices?.addTrack(state!.activeTrack);
audioServices.addTrack(state!.activeTrack);

final cached =
await DefaultCacheManager().getFileFromCache(state!.activeTrack.id!);
Expand Down Expand Up @@ -415,7 +414,7 @@ class PlaylistQueueNotifier extends PersistedStateNotifier<PlaylistQueue?> {
}

Future<void> stop() async {
audioServices?.deactivateSession();
audioServices.deactivateSession();
state = null;

return audioPlayer.stop();
Expand Down Expand Up @@ -528,7 +527,7 @@ class PlaylistQueueNotifier extends PersistedStateNotifier<PlaylistQueue?> {

@override
void dispose() {
audioServices?.dispose();
audioServices.dispose();
super.dispose();
}
}
Expand Down
24 changes: 23 additions & 1 deletion lib/services/audio_player.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
import 'package:audioplayers/audioplayers.dart';

final audioPlayer = AudioPlayer();
final audioPlayer = (() {
AudioPlayer.global.setAudioContext(
const AudioContext(
android: AudioContextAndroid(
audioFocus: AndroidAudioFocus.gain,
audioMode: AndroidAudioMode.inCall,
contentType: AndroidContentType.music,
stayAwake: true,
usageType: AndroidUsageType.media,
),
iOS: AudioContextIOS(
category: AVAudioSessionCategory.playback,
options: [
AVAudioSessionOptions.allowBluetooth,
AVAudioSessionOptions.allowBluetoothA2DP,
AVAudioSessionOptions.defaultToSpeaker,
AVAudioSessionOptions.mixWithOthers,
],
),
),
);
return AudioPlayer();
})();
27 changes: 13 additions & 14 deletions lib/services/audio_services/audio_services.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,24 @@ class AudioServices {
final WindowsAudioService? smtc;
final LinuxAudioService? mpris;

AudioServices(this.mobile, this.smtc, this.mpris);
AudioServices._(this.mobile, this.smtc, this.mpris);

static Future<AudioServices> create(
Ref ref, PlaylistQueueNotifier playlistQueueNotifier) async {
factory AudioServices(Ref ref, PlaylistQueueNotifier playlistQueueNotifier) {
final mobile =
!DesktopTools.platform.isMobile && !!DesktopTools.platform.isMacOS
? null
: MobileAudioService(
DesktopTools.platform.isMobile || DesktopTools.platform.isMacOS
? MobileAudioService(
playlistQueueNotifier,
ref.read(VolumeProvider.provider.notifier),
);
final smtc = !DesktopTools.platform.isWindows
? null
: WindowsAudioService(ref, playlistQueueNotifier);
final mpris = !DesktopTools.platform.isLinux
? null
: LinuxAudioService(ref, playlistQueueNotifier);
)
: null;
final smtc = DesktopTools.platform.isWindows
? WindowsAudioService(ref, playlistQueueNotifier)
: null;
final mpris = DesktopTools.platform.isLinux
? LinuxAudioService(ref, playlistQueueNotifier)
: null;

return AudioServices(mobile, smtc, mpris);
return AudioServices._(mobile, smtc, mpris);
}

Future<void> addTrack(Track track) async {
Expand Down
28 changes: 14 additions & 14 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -141,58 +141,58 @@ packages:
dependency: "direct main"
description:
name: audioplayers
sha256: "16451eab798b23ad9307aef6f9ca62bb8fb06542af8810eead0d236d3fd40a42"
sha256: "6063c05f987596ba7a3dad9bb9a5d8adfa5e7c07b9bae5301b27c11d0b3a239f"
url: "https://pub.dev"
source: hosted
version: "3.0.1"
version: "4.0.1"
audioplayers_android:
dependency: transitive
description:
name: audioplayers_android
sha256: b2c833e6f718b6b030454e329931229afafe9327fdb002874dd544dc8bf2484d
sha256: fb6bca878ad175d8f6ddc0e0a2d4226d81fa7c10747c12db420e96c7a096b2cc
url: "https://pub.dev"
source: hosted
version: "2.0.0"
version: "3.0.1"
audioplayers_darwin:
dependency: transitive
description:
name: audioplayers_darwin
sha256: e7a3c8759bf11ecfe4b20df338bf9f3d37c7719a5761c46a3833aba0ceeaacff
sha256: c4a56c49347b2e85ac4e1efea218948ca0fba87f04d2a3d3de07ce2410037038
url: "https://pub.dev"
source: hosted
version: "3.0.1"
version: "4.0.1"
audioplayers_linux:
dependency: transitive
description:
name: audioplayers_linux
sha256: e95b65e1f4d4764601dac5e65f8d8186fc29401043ab020f1dacec483d708707
sha256: "897e24f190232a3fbb88134b062aa83a9240f55789b5e8d17c114283284ef56b"
url: "https://pub.dev"
source: hosted
version: "1.0.4"
version: "2.0.1"
audioplayers_platform_interface:
dependency: transitive
description:
name: audioplayers_platform_interface
sha256: "178581a44cb685fd798d2108111d2e98cca3400e30b9c3a05546f124fb37f600"
sha256: "3a90a46198d375fc7d47bc1d3070c8fd8863b6469b7d87ca80f953efb090f976"
url: "https://pub.dev"
source: hosted
version: "4.0.0"
version: "5.0.0"
audioplayers_web:
dependency: transitive
description:
name: audioplayers_web
sha256: "859ba09be2a57e57a787273f18c8cf0d9b61383870c5ee4b5632fe9adbc37edf"
sha256: "4f5dcbfec0bf98ea09e243d5f5b64ea43a4e6710a2f292724bed16cdba3c691e"
url: "https://pub.dev"
source: hosted
version: "2.2.0"
version: "3.0.1"
audioplayers_windows:
dependency: transitive
description:
name: audioplayers_windows
sha256: "622e01c4c357c2aaf1b956c3a0f89d97c3cb40315c03f16e3b6c2a31ff9c38bc"
sha256: "010f575653c01ccbe9756050b18df83d89426740e04b684f6438aa26c775a965"
url: "https://pub.dev"
source: hosted
version: "1.1.3"
version: "2.0.1"
auto_size_text:
dependency: "direct main"
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies:
async: ^2.9.0
audio_service: ^0.18.9
audio_session: ^0.1.13
audioplayers: ^3.0.1
audioplayers: ^4.0.1
auto_size_text: ^3.0.0
badges: ^2.0.3
buttons_tabbar: ^1.3.6
Expand Down

0 comments on commit ce10aa1

Please sign in to comment.