Skip to content

Commit

Permalink
Recently played songs fixed.
Browse files Browse the repository at this point in the history
Gray theme added.
Some themes updated.
Bug fixes and improvements.
  • Loading branch information
ShokhrukhbekYuldoshev committed May 19, 2024
1 parent 85f040b commit 1634386
Show file tree
Hide file tree
Showing 19 changed files with 177 additions and 109 deletions.
Binary file modified assets/images/earphones.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Future<void> main() async {
await Hive.openBox(HiveBox.boxName);

// initialize audio service
await sl<JustAudioPlayer>().init();
await sl<MusicPlayer>().init();

// run app
runApp(
Expand Down
2 changes: 1 addition & 1 deletion lib/src/bloc/player/player_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ part 'player_event.dart';
part 'player_state.dart';

class PlayerBloc extends Bloc<PlayerEvent, PlayerState> {
PlayerBloc({required JustAudioPlayer repository}) : super(PlayerInitial()) {
PlayerBloc({required MusicPlayer repository}) : super(PlayerInitial()) {
on<PlayerLoadSongs>((event, emit) async {
try {
emit(PlayerLoading());
Expand Down
4 changes: 2 additions & 2 deletions lib/src/core/di/service_locator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ void init() {
// Repository
sl.registerLazySingleton(() => ThemeRepository());
sl.registerLazySingleton(() => HomeRepository());
sl.registerLazySingleton<JustAudioPlayer>(
() => JustAudioPlayerImpl(),
sl.registerLazySingleton<MusicPlayer>(
() => JustAudioPlayer(),
);
sl.registerLazySingleton(() => SongRepository());
sl.registerLazySingleton(() => FavoritesRepository());
Expand Down
73 changes: 49 additions & 24 deletions lib/src/core/theme/themes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Themes {
RedTheme(),
BlackTheme(),
WhiteTheme(),
GrayTheme(),
];

static final List<String> _themeNames = [
Expand All @@ -25,6 +26,7 @@ class Themes {
'Red',
'Black',
'White',
'Gray',
];

static get themes => _themes;
Expand All @@ -50,6 +52,8 @@ class Themes {
return _themes[7];
case 'White':
return _themes[8];
case 'Gray':
return _themes[9];
default:
return _themes[0];
}
Expand Down Expand Up @@ -93,8 +97,8 @@ class PurpleTheme extends ThemeColor {
PurpleTheme()
: super(
themeName: 'Purple',
primaryColor: const Color(0xff21143d),
secondaryColor: const Color(0xff47210c),
primaryColor: const Color(0xff0e0725),
secondaryColor: const Color(0xff5c03bc),
colorScheme: ColorScheme.fromSwatch(
primarySwatch: Colors.purple,
brightness: Brightness.dark,
Expand All @@ -103,8 +107,8 @@ class PurpleTheme extends ThemeColor {
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color(0xff21143d),
Color(0xff47210c),
Color(0xff0e0725),
Color(0xff5c03bc),
],
),
);
Expand All @@ -114,8 +118,8 @@ class BlueTheme extends ThemeColor {
BlueTheme()
: super(
themeName: 'Blue',
primaryColor: const Color(0xff0c1a47),
secondaryColor: const Color(0xFF16488A),
primaryColor: const Color(0xff000328),
secondaryColor: const Color(0xFF00458e),
colorScheme: ColorScheme.fromSwatch(
primarySwatch: Colors.blue,
brightness: Brightness.dark,
Expand All @@ -124,8 +128,8 @@ class BlueTheme extends ThemeColor {
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color(0xff0c1a47),
Color(0xFF16488A),
Color(0xff000328),
Color(0xFF00458e),
],
),
);
Expand All @@ -135,8 +139,8 @@ class GreenTheme extends ThemeColor {
GreenTheme()
: super(
themeName: 'Green',
primaryColor: const Color(0xff0c471a),
secondaryColor: const Color(0xFF168A48),
primaryColor: const Color(0xff0c0c0c),
secondaryColor: const Color(0xFF0f971c),
colorScheme: ColorScheme.fromSwatch(
primarySwatch: Colors.green,
brightness: Brightness.dark,
Expand All @@ -145,8 +149,8 @@ class GreenTheme extends ThemeColor {
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color(0xff0c471a),
Color(0xFF168A48),
Color(0xff0c0c0c),
Color(0xFF0f971c),
],
),
);
Expand Down Expand Up @@ -177,8 +181,8 @@ class YellowTheme extends ThemeColor {
YellowTheme()
: super(
themeName: 'Yellow',
primaryColor: const Color(0xff47410c),
secondaryColor: const Color(0xFF8A7A16),
primaryColor: const Color(0xff161616),
secondaryColor: const Color(0xFFb79c05),
colorScheme: ColorScheme.fromSwatch(
primarySwatch: Colors.yellow,
brightness: Brightness.dark,
Expand All @@ -187,8 +191,8 @@ class YellowTheme extends ThemeColor {
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color(0xff47410c),
Color(0xFF8A7A16),
Color(0xff161616),
Color(0xFFb79c05),
],
),
);
Expand Down Expand Up @@ -219,8 +223,8 @@ class RedTheme extends ThemeColor {
RedTheme()
: super(
themeName: 'Red',
primaryColor: const Color(0xff470c1a),
secondaryColor: const Color(0xFF8A1648),
primaryColor: const Color(0xff1b0a07),
secondaryColor: const Color(0xFF7f0012),
colorScheme: ColorScheme.fromSwatch(
primarySwatch: Colors.red,
brightness: Brightness.dark,
Expand All @@ -229,8 +233,8 @@ class RedTheme extends ThemeColor {
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color(0xff470c1a),
Color(0xFF8A1648),
Color(0xff1b0a07),
Color(0xFF7f0012),
],
),
);
Expand Down Expand Up @@ -261,8 +265,8 @@ class WhiteTheme extends ThemeColor {
WhiteTheme()
: super(
themeName: 'White',
primaryColor: const Color(0XFFFFFFFF),
secondaryColor: const Color(0xFFC7C7C7),
primaryColor: const Color(0XFFD3CCE3),
secondaryColor: const Color(0xFFE9E4F0),
colorScheme: ColorScheme.fromSwatch(
primarySwatch: Colors.grey,
brightness: Brightness.light,
Expand All @@ -271,8 +275,29 @@ class WhiteTheme extends ThemeColor {
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color(0XFFFFFFFF),
Color(0xFFC7C7C7),
Color(0XFFD3CCE3),
Color(0xFFE9E4F0),
],
),
);
}

class GrayTheme extends ThemeColor {
GrayTheme()
: super(
themeName: 'Gray',
primaryColor: const Color(0xff232526),
secondaryColor: const Color(0xFF414345),
colorScheme: ColorScheme.fromSwatch(
primarySwatch: Colors.grey,
brightness: Brightness.dark,
),
linearGradient: const LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color(0xff232526),
Color(0xFF414345),
],
),
);
Expand Down
15 changes: 11 additions & 4 deletions lib/src/data/repositories/player_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import 'dart:io';

import 'package:just_audio/just_audio.dart';
import 'package:just_audio_background/just_audio_background.dart';
import 'package:meloplay/src/data/repositories/song_repository.dart';
import 'package:on_audio_query/on_audio_query.dart';

abstract class JustAudioPlayer {
abstract class MusicPlayer {
Future<void> init();
Future<void> load(
MediaItem mediaItem,
Expand Down Expand Up @@ -34,7 +35,7 @@ abstract class JustAudioPlayer {
Future<void> setLoopMode(LoopMode loopMode);
}

class JustAudioPlayerImpl implements JustAudioPlayer {
class JustAudioPlayer implements MusicPlayer {
final AudioPlayer _player = AudioPlayer();
List<SongModel> currentPlaylist = [];

Expand All @@ -46,6 +47,14 @@ class JustAudioPlayerImpl implements JustAudioPlayer {
androidNotificationOngoing: true,
androidStopForegroundOnPause: true,
);

// subscribe to changes in playback state to add to the recently played
_player.playbackEventStream.listen((event) {
if (event.currentIndex != null && currentPlaylist.isNotEmpty) {
String songId = currentPlaylist[event.currentIndex!].id.toString();
SongRepository().addToRecentlyPlayed(songId);
}
});
}

@override
Expand Down Expand Up @@ -156,11 +165,9 @@ class JustAudioPlayerImpl implements JustAudioPlayer {
Stream<Duration?> get duration => _player.durationStream;

@override
// shuffle mode enabled
Stream<bool> get shuffleModeEnabled => _player.shuffleModeEnabledStream;

@override
// loop mode
Stream<LoopMode> get loopMode => _player.loopModeStream;

@override
Expand Down
10 changes: 10 additions & 0 deletions lib/src/data/repositories/recents_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,14 @@ class RecentsRepository {
.where((song) => recentSongsIds.contains(song.id.toString()))
.toList();
}

Future<SongModel?> fetchLastPlayed() async {
var recents = await fetchRecents();

if (recents.isNotEmpty) {
return recents.first;
} else {
return null;
}
}
}
9 changes: 6 additions & 3 deletions lib/src/presentation/pages/home/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
? Column(
children: [
TabBar(
dividerColor:
Theme.of(context).colorScheme.onPrimary.withOpacity(
0.3,
),
tabAlignment: TabAlignment.start,
isScrollable: true,
controller: _tabController,
Expand Down Expand Up @@ -150,8 +154,7 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
decoration: BoxDecoration(
color: Themes.getTheme().primaryColor,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
child: Row(
children: [
Hero(
tag: 'logo',
Expand All @@ -162,7 +165,7 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
),
),
const SizedBox(
height: 8,
width: 8,
),
const Text(
'Meloplay',
Expand Down
20 changes: 16 additions & 4 deletions lib/src/presentation/pages/home/views/playlists_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class _PlaylistsViewState extends State<PlaylistsView>
image: Assets.earphones,
label: 'Recents',
icon: Icons.history_outlined,
color: const Color(0xFFF321D0),
color: Colors.yellow,
onTap: () {
Navigator.of(context).pushNamed(
AppRouter.recentsRoute,
Expand Down Expand Up @@ -186,11 +186,23 @@ class PlaylistCard extends StatelessWidget {
child: GestureDetector(
onTap: onTap,
child: Container(
color: Colors.grey.withOpacity(0.2),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16),
color: Colors.grey.withOpacity(0.2),
),
child: Column(
children: [
Image.asset(
image,
ClipRRect(
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(16),
topRight: Radius.circular(16),
),
child: Image.asset(
image,
height: 150,
width: double.infinity,
fit: BoxFit.cover,
),
),
const SizedBox(height: 8),
Row(
Expand Down
14 changes: 14 additions & 0 deletions lib/src/presentation/pages/home/views/songs_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class _SongsViewState extends State<SongsView>
final audioQuery = sl<OnAudioQuery>();
final songs = <SongModel>[];
bool isLoading = true;
final _scrollController = ScrollController();

@override
void initState() {
Expand Down Expand Up @@ -64,6 +65,7 @@ class _SongsViewState extends State<SongsView>
context.read<HomeBloc>().add(GetSongsEvent());
},
child: CustomScrollView(
controller: _scrollController,
slivers: [
SliverToBoxAdapter(
child: Padding(
Expand Down Expand Up @@ -185,6 +187,9 @@ class _SongsViewState extends State<SongsView>
),
),
),
const SliverToBoxAdapter(
child: SizedBox(height: 16),
),
AnimationLimiter(
child: SliverList(
delegate: SliverChildBuilderDelegate(
Expand Down Expand Up @@ -214,6 +219,15 @@ class _SongsViewState extends State<SongsView>
),
);
}

void scrollToTop() {
_scrollController.animateTo(
0.0, // Scroll to the top
duration:
const Duration(milliseconds: 500), // Duration of the scroll animation
curve: Curves.easeInOut, // Animation curve
);
}
}

class SortBottomSheet extends StatefulWidget {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/presentation/pages/player/player_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class PlayerPage extends StatefulWidget {
}

class _PlayerPageState extends State<PlayerPage> {
final player = sl<JustAudioPlayer>();
final player = sl<MusicPlayer>();
SequenceState? sequence;

@override
Expand Down
2 changes: 1 addition & 1 deletion lib/src/presentation/pages/player/queue_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class _QueuePageState extends State<QueuePage> {
}

Widget _buildBody() {
final playlist = sl<JustAudioPlayer>().playlist;
final playlist = sl<MusicPlayer>().playlist;

return ListView.builder(
padding: const EdgeInsets.only(bottom: 100),
Expand Down
Loading

0 comments on commit 1634386

Please sign in to comment.