Skip to content

Commit

Permalink
feat: pressing "jump to day" icon will open with the current day at s…
Browse files Browse the repository at this point in the history
…croll position
  • Loading branch information
MSOB7YY committed Oct 10, 2024
1 parent 30d9cc1 commit e0cdb64
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
3 changes: 3 additions & 0 deletions lib/core/functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ Future<void> showCalendarDialog<T extends ItemWithDate, E>({
HistoryManager<T, E>? historyController,
void Function(List<DateTime> dates)? onChanged,
required void Function(List<DateTime> dates) onGenerate,
DateTime? initialDate,
}) async {
historyController ??= HistoryController.inst as HistoryManager<T, E>;

Expand Down Expand Up @@ -668,6 +669,7 @@ Future<void> showCalendarDialog<T extends ItemWithDate, E>({
),
],
child: CalendarDatePicker2(
displayedMonthDate: initialDate,
onValueChanged: (value) {
final dts = value.whereType<DateTime>().toList();
dates.assignAll(dts);
Expand All @@ -679,6 +681,7 @@ Future<void> showCalendarDialog<T extends ItemWithDate, E>({
},
config: CalendarDatePicker2Config(
calendarType: calendarType,
currentDate: initialDate,
firstDate: useHistoryDates ? historyController.oldestTrack?.dateTimeAdded : firstDate,
lastDate: useHistoryDates ? historyController.newestTrack?.dateTimeAdded : lastDate,
),
Expand Down
23 changes: 21 additions & 2 deletions lib/core/namida_converter_ext.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import 'package:namida/controller/search_sort_controller.dart';
import 'package:namida/controller/selected_tracks_controller.dart';
import 'package:namida/controller/settings_controller.dart';
import 'package:namida/core/constants.dart';
import 'package:namida/core/dimensions.dart';
import 'package:namida/core/enums.dart';
import 'package:namida/core/extensions.dart';
import 'package:namida/core/functions.dart';
Expand Down Expand Up @@ -902,9 +903,27 @@ extension RouteUtils on NamidaRoute {
route == RouteType.SUBPAGE_queueTracks,
),

getAnimatedCrossFade(child: HistoryJumpToDayIcon(controller: HistoryController.inst), shouldShow: route == RouteType.SUBPAGE_historyTracks),
getAnimatedCrossFade(
child: HistoryJumpToDayIcon(
controller: HistoryController.inst,
itemExtentAndDayHeaderExtent: () => (
itemExtent: Dimensions.inst.trackTileItemExtent,
dayHeaderExtent: kHistoryDayHeaderHeightWithPadding,
),
),
shouldShow: route == RouteType.SUBPAGE_historyTracks,
),

getAnimatedCrossFade(child: HistoryJumpToDayIcon(controller: YoutubeHistoryController.inst), shouldShow: route == RouteType.YOUTUBE_HISTORY_SUBPAGE),
getAnimatedCrossFade(
child: HistoryJumpToDayIcon(
controller: YoutubeHistoryController.inst,
itemExtentAndDayHeaderExtent: () => (
itemExtent: Dimensions.youtubeCardItemExtent,
dayHeaderExtent: kYoutubeHistoryDayHeaderHeightWithPadding,
),
),
shouldShow: route == RouteType.YOUTUBE_HISTORY_SUBPAGE,
),

// ---- Playlist Tracks ----
getAnimatedCrossFade(
Expand Down
6 changes: 5 additions & 1 deletion lib/ui/widgets/custom_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2985,20 +2985,24 @@ class NamidaInkWellButton extends StatelessWidget {

class HistoryJumpToDayIcon<T extends ItemWithDate, E> extends StatelessWidget {
final HistoryManager<T, E> controller;
const HistoryJumpToDayIcon({super.key, required this.controller});
final ({double itemExtent, double dayHeaderExtent}) Function() itemExtentAndDayHeaderExtent;
const HistoryJumpToDayIcon({super.key, required this.controller, required this.itemExtentAndDayHeaderExtent});

@override
Widget build(BuildContext context) {
return NamidaAppBarIcon(
icon: Broken.calendar,
tooltip: () => lang.JUMP_TO_DAY,
onPressed: () {
final info = itemExtentAndDayHeaderExtent();
final currentScrolledDay = controller.currentScrollPositionToDay(info.itemExtent, info.dayHeaderExtent);
showCalendarDialog(
historyController: controller,
title: lang.JUMP_TO_DAY,
buttonText: lang.JUMP,
calendarType: CalendarDatePicker2Type.single,
useHistoryDates: true,
initialDate: currentScrolledDay == null ? null : DateTime(1970, 0, currentScrolledDay),
onGenerate: (dates) {
NamidaNavigator.inst.closeDialog();
final dayToScrollTo = dates.firstOrNull?.toDaysSince1970() ?? 0;
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.35-beta+241010221
version: 4.5.37-beta+241010226

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

0 comments on commit e0cdb64

Please sign in to comment.