-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
history page implt. and limit set on home page
- Loading branch information
1 parent
90551b8
commit cc278a0
Showing
9 changed files
with
302 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import 'dart:async'; | ||
import 'dart:developer'; | ||
import 'package:Bloomee/services/db/bloomee_db_service.dart'; | ||
import 'package:bloc/bloc.dart'; | ||
import 'package:Bloomee/model/MediaPlaylistModel.dart'; | ||
part 'history_state.dart'; | ||
|
||
class HistoryCubit extends Cubit<HistoryState> { | ||
StreamSubscription<void>? watcher; | ||
HistoryCubit() : super(HistoryInitial()) { | ||
getRecentlyPlayed(); | ||
watchRecentlyPlayed(); | ||
} | ||
Future<void> watchRecentlyPlayed() async { | ||
watcher = (await BloomeeDBService.watchRecentlyPlayed()).listen((event) { | ||
getRecentlyPlayed(); | ||
log("History Updated"); | ||
}); | ||
} | ||
|
||
void getRecentlyPlayed() async { | ||
final mediaPlaylist = await BloomeeDBService.getRecentlyPlayed(); | ||
emit(state.copyWith(mediaPlaylist: mediaPlaylist)); | ||
} | ||
|
||
@override | ||
Future<void> close() { | ||
watcher?.cancel(); | ||
return super.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
part of 'history_cubit.dart'; | ||
|
||
class HistoryState { | ||
MediaPlaylist mediaPlaylist; | ||
HistoryState({ | ||
required this.mediaPlaylist, | ||
}); | ||
|
||
HistoryState copyWith({ | ||
MediaPlaylist? mediaPlaylist, | ||
}) { | ||
return HistoryState( | ||
mediaPlaylist: mediaPlaylist ?? this.mediaPlaylist, | ||
); | ||
} | ||
} | ||
|
||
class HistoryInitial extends HistoryState { | ||
HistoryInitial() | ||
: super(mediaPlaylist: MediaPlaylist(albumName: "", mediaItems: [])); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// ignore_for_file: public_member_api_docs, sort_constructors_first | ||
import 'package:Bloomee/blocs/history/cubit/history_cubit.dart'; | ||
import 'package:Bloomee/blocs/mediaPlayer/bloomee_player_cubit.dart'; | ||
import 'package:Bloomee/screens/widgets/more_bottom_sheet.dart'; | ||
import 'package:Bloomee/screens/widgets/song_card_widget.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:Bloomee/theme_data/default.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
|
||
class HistoryView extends StatelessWidget { | ||
const HistoryView({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
backgroundColor: Default_Theme.themeColor, | ||
appBar: AppBar( | ||
centerTitle: true, | ||
backgroundColor: Default_Theme.themeColor, | ||
surfaceTintColor: Default_Theme.themeColor, | ||
foregroundColor: Default_Theme.primaryColor1, | ||
title: Text( | ||
'History', | ||
style: const TextStyle( | ||
color: Default_Theme.primaryColor1, | ||
fontSize: 20, | ||
fontWeight: FontWeight.bold) | ||
.merge(Default_Theme.secondoryTextStyle), | ||
), | ||
), | ||
body: BlocProvider( | ||
create: (context) => HistoryCubit(), | ||
child: BlocBuilder<HistoryCubit, HistoryState>( | ||
builder: (context, state) { | ||
return (state is HistoryInitial) | ||
? const Center( | ||
child: CircularProgressIndicator(), | ||
) | ||
: ListView.builder( | ||
itemCount: state.mediaPlaylist.mediaItems.length, | ||
shrinkWrap: true, | ||
physics: const BouncingScrollPhysics(), | ||
itemBuilder: (context, index) { | ||
return SongCardWidget( | ||
song: state.mediaPlaylist.mediaItems[index], | ||
onTap: () { | ||
context | ||
.read<BloomeePlayerCubit>() | ||
.bloomeePlayer | ||
.addQueueItem( | ||
state.mediaPlaylist.mediaItems[index], | ||
); | ||
}, | ||
onOptionsTap: () => showMoreBottomSheet( | ||
context, state.mediaPlaylist.mediaItems[index]), | ||
); | ||
}, | ||
); | ||
}, | ||
), | ||
), | ||
); | ||
} | ||
|
||
ListTile settingListTile( | ||
{required String title, | ||
required String subtitle, | ||
required IconData icon, | ||
VoidCallback? onTap}) { | ||
return ListTile( | ||
leading: Icon( | ||
icon, | ||
size: 30, | ||
color: Default_Theme.primaryColor1, | ||
), | ||
title: Text( | ||
title, | ||
style: const TextStyle(color: Default_Theme.primaryColor1, fontSize: 17) | ||
.merge(Default_Theme.secondoryTextStyleMedium), | ||
), | ||
subtitle: Text( | ||
subtitle, | ||
style: TextStyle( | ||
color: Default_Theme.primaryColor1.withOpacity(0.5), | ||
fontSize: 12.5) | ||
.merge(Default_Theme.secondoryTextStyleMedium), | ||
), | ||
onTap: () { | ||
if (onTap != null) { | ||
onTap(); | ||
} | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
//credit goes to: https://stackoverflow.com/a/72817531/21571707 | ||
|
||
class PagingScrollPhysics extends ScrollPhysics { | ||
const PagingScrollPhysics( | ||
{required this.itemCount, required this.viewSize, super.parent}); | ||
|
||
final double viewSize; | ||
|
||
final int itemCount; | ||
|
||
@override | ||
PagingScrollPhysics applyTo(ScrollPhysics? ancestor) => PagingScrollPhysics( | ||
itemCount: itemCount, viewSize: viewSize, parent: buildParent(ancestor)); | ||
|
||
double _getPage(double current, double itemDimension) => | ||
current / itemDimension; | ||
|
||
double _getTargetPixels( | ||
ScrollMetrics position, Tolerance tolerance, double velocity) { | ||
// plus view size because the max scroll extent is about where the screen | ||
// starts not where the screen ends. | ||
final pixels = position.maxScrollExtent + viewSize; | ||
final itemDimension = pixels / itemCount; | ||
var page = _getPage(position.pixels, itemDimension); | ||
if (velocity < -tolerance.velocity) { | ||
page -= 0.5; | ||
} else if (velocity > tolerance.velocity) { | ||
page += 0.5; | ||
} | ||
final pageRound = page.round(); | ||
final itemsPerPage = viewSize ~/ itemDimension; | ||
final showingLastItem = pageRound == itemCount - itemsPerPage; | ||
if (showingLastItem) return pixels - viewSize; | ||
|
||
return pageRound * itemDimension; | ||
} | ||
|
||
@override | ||
Simulation? createBallisticSimulation( | ||
ScrollMetrics position, double velocity) { | ||
if ((velocity <= 0.0 && position.pixels <= position.minScrollExtent) || | ||
(velocity >= 0.0 && position.pixels >= position.maxScrollExtent)) { | ||
return super.createBallisticSimulation(position, velocity); | ||
} | ||
final Tolerance tolerance = this.tolerance; | ||
final double target = _getTargetPixels(position, tolerance, velocity); | ||
if (target != position.pixels) { | ||
return ScrollSpringSimulation(spring, position.pixels, target, velocity, | ||
tolerance: tolerance); | ||
} | ||
return null; | ||
} | ||
|
||
@override | ||
bool get allowImplicitScrolling => false; | ||
} |
Oops, something went wrong.