Skip to content

Commit

Permalink
feat: jump to day inside yt history
Browse files Browse the repository at this point in the history
  • Loading branch information
MSOB7YY committed Nov 18, 2023
1 parent 4236835 commit 6903b32
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
10 changes: 7 additions & 3 deletions lib/core/functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -286,16 +287,19 @@ class NamidaOnTaps {
}
}

Future<void> showCalendarDialog({
Future<void> showCalendarDialog<T extends ItemWithDate, E>({
required String title,
required String buttonText,
CalendarDatePicker2Type calendarType = CalendarDatePicker2Type.range,
DateTime? firstDate,
DateTime? lastDate,
required bool useHistoryDates,
HistoryManager<T, E>? historyController,
void Function(List<DateTime> dates)? onChanged,
required void Function(List<DateTime> dates) onGenerate,
}) async {
historyController ??= HistoryController.inst as HistoryManager<T, E>;

final dates = <DateTime>[];

final RxInt daysNumber = 0.obs;
Expand Down Expand Up @@ -359,8 +363,8 @@ Future<void> 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 [],
),
Expand Down
6 changes: 5 additions & 1 deletion lib/core/namida_converter_ext.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(
Expand Down
14 changes: 8 additions & 6 deletions lib/ui/widgets/custom_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -2356,8 +2356,9 @@ class NamidaInkWell extends StatelessWidget {
}
}

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

@override
Widget build(BuildContext context) {
Expand All @@ -2366,19 +2367,20 @@ class HistoryJumpToDayIcon extends StatelessWidget {
tooltip: lang.JUMP_TO_DAY,
onPressed: () {
showCalendarDialog(
historyController: controller,
title: lang.JUMP_TO_DAY,
buttonText: lang.JUMP,
calendarType: CalendarDatePicker2Type.single,
useHistoryDates: true,
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);
},
);
},
Expand Down

0 comments on commit 6903b32

Please sign in to comment.