Skip to content

Commit

Permalink
feat: in homepage, pressing top recents or lost memories will now ope…
Browse files Browse the repository at this point in the history
…n the most played page with the actual date range
  • Loading branch information
MSOB7YY committed Oct 11, 2024
1 parent 0ad1425 commit 4ec2636
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
45 changes: 37 additions & 8 deletions lib/ui/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,12 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin, Pull
final _lostMemoriesYears = <int>[];

int currentYearLostMemories = 0;
DateRange? currentYearLostMemoriesDateRange;
late final ScrollController _scrollController;
late final ScrollController _lostMemoriesScrollController;

final MostPlayedTimeRange _topRecentsTimeRange = MostPlayedTimeRange.day3;

@override
void initState() {
super.initState();
Expand Down Expand Up @@ -136,7 +139,7 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin, Pull
_topRecentListened.addAllIfEmpty(
HistoryController.inst
.getMostListensInTimeRange(
mptr: MostPlayedTimeRange.day3,
mptr: _topRecentsTimeRange,
isStartOfDay: false,
mainItemToSubItem: (item) => item.track,
)
Expand Down Expand Up @@ -210,19 +213,36 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin, Pull
}

void _updateSameTimeNYearsAgo(DateTime timeNow, int year) {
final dateRange = DateRange(
oldest: DateTime(year, timeNow.month, timeNow.day - 5),
newest: DateTime(year, timeNow.month, timeNow.day + 5),
);
currentYearLostMemories = year;
currentYearLostMemoriesDateRange = dateRange;
_sameTimeYearAgo = HistoryController.inst.getMostListensInTimeRange(
mptr: MostPlayedTimeRange.custom,
customDate: DateRange(
oldest: DateTime(year, timeNow.month, timeNow.day - 5),
newest: DateTime(year, timeNow.month, timeNow.day + 5),
),
customDate: dateRange,
isStartOfDay: false,
mainItemToSubItem: (item) => item.track,
);
currentYearLostMemories = year;
if (_lostMemoriesScrollController.hasClients) _lostMemoriesScrollController.jumpTo(0);
}

void _onGoingToMostPlayedPage({
required MostPlayedTimeRange mptr,
DateRange? dateCustom,
}) {
settings.save(
mostPlayedTimeRange: mptr,
mostPlayedCustomDateRange: dateCustom,
);
HistoryController.inst.updateTempMostPlayedPlaylist(
mptr: mptr,
customDateRange: dateCustom,
);
NamidaOnTaps.inst.onMostPlayedPlaylistTap();
}

List<E?> _listOrShimmer<E>(List<E> listy) {
return _isLoading ? _shimmerList : listy;
}
Expand Down Expand Up @@ -443,7 +463,11 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin, Pull
icon: Broken.crown_1,
listy: const [],
listWithListens: _topRecentListened,
onTap: NamidaOnTaps.inst.onMostPlayedPlaylistTap,
onTap: () {
_onGoingToMostPlayedPage(
mptr: _topRecentsTimeRange,
);
},
);

case HomePageItems.lostMemories:
Expand All @@ -459,7 +483,12 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin, Pull
icon: Broken.link_21,
listy: const [],
listWithListens: _sameTimeYearAgo,
onTap: NamidaOnTaps.inst.onMostPlayedPlaylistTap,
onTap: () {
_onGoingToMostPlayedPage(
mptr: MostPlayedTimeRange.custom,
dateCustom: currentYearLostMemoriesDateRange,
);
},
thirdWidget: SizedBox(
height: 32.0,
width: context.width,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: namida
description: A Beautiful and Feature-rich Music Player, With YouTube & Video Support Built in Flutter
publish_to: "none"
version: 4.5.47-beta+241011011
version: 4.5.5-beta+241011011

environment:
sdk: ">=3.4.0 <4.0.0"
Expand Down

0 comments on commit 4ec2636

Please sign in to comment.