From 6903b323d56879ce35779589047f0694cf251386 Mon Sep 17 00:00:00 2001 From: MSOB7YY Date: Sat, 18 Nov 2023 03:06:33 +0200 Subject: [PATCH] feat: jump to day inside yt history --- lib/core/functions.dart | 10 +++++++--- lib/core/namida_converter_ext.dart | 6 +++++- lib/ui/widgets/custom_widgets.dart | 14 ++++++++------ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/lib/core/functions.dart b/lib/core/functions.dart index 69a1ca04..9e59c5c7 100644 --- a/lib/core/functions.dart +++ b/lib/core/functions.dart @@ -3,6 +3,7 @@ import 'dart:io'; import 'package:calendar_date_picker2/calendar_date_picker2.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; +import 'package:history_manager/history_manager.dart'; import 'package:namida/class/folder.dart'; import 'package:namida/class/queue.dart'; @@ -286,16 +287,19 @@ class NamidaOnTaps { } } -Future showCalendarDialog({ +Future showCalendarDialog({ required String title, required String buttonText, CalendarDatePicker2Type calendarType = CalendarDatePicker2Type.range, DateTime? firstDate, DateTime? lastDate, required bool useHistoryDates, + HistoryManager? historyController, void Function(List dates)? onChanged, required void Function(List dates) onGenerate, }) async { + historyController ??= HistoryController.inst as HistoryManager; + final dates = []; final RxInt daysNumber = 0.obs; @@ -359,8 +363,8 @@ Future showCalendarDialog({ }, config: CalendarDatePicker2Config( calendarType: calendarType, - firstDate: useHistoryDates ? HistoryController.inst.oldestTrack?.dateAdded.milliSecondsSinceEpoch : firstDate, - lastDate: useHistoryDates ? HistoryController.inst.newestTrack?.dateAdded.milliSecondsSinceEpoch : lastDate, + firstDate: useHistoryDates ? historyController.oldestTrack?.dateTimeAdded : firstDate, + lastDate: useHistoryDates ? historyController.newestTrack?.dateTimeAdded : lastDate, ), value: const [], ), diff --git a/lib/core/namida_converter_ext.dart b/lib/core/namida_converter_ext.dart index 23f56c6e..b5c24646 100644 --- a/lib/core/namida_converter_ext.dart +++ b/lib/core/namida_converter_ext.dart @@ -61,6 +61,7 @@ import 'package:namida/ui/widgets/custom_widgets.dart'; import 'package:namida/ui/widgets/stats.dart'; import 'package:namida/youtube/class/youtube_id.dart'; import 'package:namida/youtube/controller/youtube_controller.dart'; +import 'package:namida/youtube/controller/youtube_history_controller.dart'; import 'package:namida/youtube/functions/add_to_playlist_sheet.dart'; import 'package:namida/youtube/functions/download_sheet.dart'; import 'package:namida/youtube/pages/youtube_home_view.dart'; @@ -933,7 +934,10 @@ extension RouteUtils on NamidaRoute { shouldShow: route == RouteType.SUBPAGE_albumTracks || route == RouteType.SUBPAGE_artistTracks || route == RouteType.SUBPAGE_genreTracks || route == RouteType.SUBPAGE_queueTracks, ), - getAnimatedCrossFade(child: const HistoryJumpToDayIcon(), shouldShow: route == RouteType.SUBPAGE_historyTracks), + + getAnimatedCrossFade(child: HistoryJumpToDayIcon(controller: HistoryController.inst), shouldShow: route == RouteType.SUBPAGE_historyTracks), + + getAnimatedCrossFade(child: HistoryJumpToDayIcon(controller: YoutubeHistoryController.inst), shouldShow: route == RouteType.YOUTUBE_HISTORY_SUBPAGE), // ---- Playlist Tracks ---- getAnimatedCrossFade( diff --git a/lib/ui/widgets/custom_widgets.dart b/lib/ui/widgets/custom_widgets.dart index e16c35e4..21f10816 100644 --- a/lib/ui/widgets/custom_widgets.dart +++ b/lib/ui/widgets/custom_widgets.dart @@ -9,6 +9,7 @@ import 'package:flutter_animate/flutter_animate.dart'; import 'package:flutter_scrollbar_modified/flutter_scrollbar_modified.dart'; import 'package:flutter_staggered_animations/flutter_staggered_animations.dart'; import 'package:get/get.dart'; +import 'package:history_manager/history_manager.dart'; import 'package:known_extents_list_view_builder/known_extents_reorderable_list_view_builder.dart'; import 'package:known_extents_list_view_builder/known_extents_sliver_reorderable_list.dart'; import 'package:like_button/like_button.dart'; @@ -19,7 +20,6 @@ import 'package:wheel_slider/wheel_slider.dart'; import 'package:namida/class/track.dart'; import 'package:namida/controller/current_color.dart'; -import 'package:namida/controller/history_controller.dart'; import 'package:namida/controller/miniplayer_controller.dart'; import 'package:namida/controller/navigator_controller.dart'; import 'package:namida/controller/player_controller.dart'; @@ -2356,8 +2356,9 @@ class NamidaInkWell extends StatelessWidget { } } -class HistoryJumpToDayIcon extends StatelessWidget { - const HistoryJumpToDayIcon({super.key}); +class HistoryJumpToDayIcon extends StatelessWidget { + final HistoryManager controller; + const HistoryJumpToDayIcon({super.key, required this.controller}); @override Widget build(BuildContext context) { @@ -2366,6 +2367,7 @@ class HistoryJumpToDayIcon extends StatelessWidget { tooltip: lang.JUMP_TO_DAY, onPressed: () { showCalendarDialog( + historyController: controller, title: lang.JUMP_TO_DAY, buttonText: lang.JUMP, calendarType: CalendarDatePicker2Type.single, @@ -2373,12 +2375,12 @@ class HistoryJumpToDayIcon extends StatelessWidget { onGenerate: (dates) { NamidaNavigator.inst.closeDialog(); final dayToScrollTo = dates.firstOrNull?.toDaysSince1970() ?? 0; - final days = HistoryController.inst.historyDays.toList(); + final days = controller.historyDays.toList(); days.removeWhere((element) => element <= dayToScrollTo); - final itemExtents = HistoryController.inst.allItemsExtentsHistory; + final itemExtents = controller.allItemsExtentsHistory; double totalScrollOffset = 0; days.loop((e, index) => totalScrollOffset += itemExtents[index]); - HistoryController.inst.scrollController.jumpTo(totalScrollOffset + 100.0); + controller.scrollController.jumpTo(totalScrollOffset + 100.0); }, ); },