From 66c0fee808034f9644f23fec84405d7c581ae04f Mon Sep 17 00:00:00 2001 From: nixos script Date: Sun, 10 Dec 2023 17:35:30 +0800 Subject: [PATCH] add more freezed states --- lib/main.dart | 4 +- lib/player/models/mediaCommand.dart | 6 +- lib/player/models/mediaEvent.dart | 8 +- lib/player/states/player.dart | 453 ++++----- lib/player/states/player.freezed.dart | 928 ++++++++++++++++++ lib/player/states/player.g.dart | 438 --------- lib/player/states/player_controls.dart | 59 +- .../states/player_controls.freezed.dart | 418 ++++++++ lib/player/states/player_controls.g.dart | 204 ---- lib/player/states/tv_player_controls.dart | 83 +- .../states/tv_player_controls.freezed.dart | 232 +++++ lib/player/states/tv_player_controls.g.dart | 105 -- lib/player/states/tv_player_settings.dart | 61 +- .../states/tv_player_settings.freezed.dart | 139 +++ lib/player/states/tv_player_settings.g.dart | 58 -- .../views/components/player_controls.dart | 13 +- lib/player/views/tv/screens/tvPlayerView.dart | 2 +- lib/settings/states/settings.dart | 4 +- lib/utils/models/pair.dart | 12 +- lib/utils/states/item_list.dart | 62 +- lib/utils/states/item_list.freezed.dart | 209 ++++ lib/utils/states/item_list.g.dart | 115 --- lib/utils/states/paginated_list_view.dart | 46 +- .../states/paginated_list_view.freezed.dart | 192 ++++ lib/utils/states/paginated_list_view.g.dart | 99 -- lib/utils/states/select_list.dart | 20 +- lib/utils/states/select_list.freezed.dart | 163 +++ lib/utils/states/select_list.g.dart | 69 -- .../searchable_dynamic_select_from_list.dart | 20 +- ...able_dynamic_select_from_list.freezed.dart | 188 ++++ ...searchable_dynamic_select_from_list.g.dart | 84 -- .../views/components/paginated_list_view.dart | 36 +- .../views/components/select_list_dialog.dart | 2 +- .../components/tv_horizontal_item_list.dart | 4 +- .../tv_horizontal_paginated_list.dart | 6 +- lib/videos/states/add_to_playlist.dart | 26 +- .../states/add_to_playlist.freezed.dart | 261 +++++ lib/videos/states/add_to_playlist.g.dart | 117 --- lib/videos/states/compact_video.dart | 22 +- lib/videos/states/compact_video.freezed.dart | 156 +++ lib/videos/states/compact_video.g.dart | 72 -- lib/videos/states/download_modal_sheet.dart | 23 +- .../states/download_modal_sheet.freezed.dart | 159 +++ lib/videos/states/download_modal_sheet.g.dart | 70 -- lib/videos/states/history.dart | 29 +- lib/videos/states/history.freezed.dart | 171 ++++ lib/videos/states/history.g.dart | 79 -- lib/videos/states/tv_video.dart | 31 +- lib/videos/states/tv_video.freezed.dart | 134 +++ lib/videos/states/tv_video.g.dart | 68 -- lib/videos/states/video.dart | 98 +- lib/videos/states/video.freezed.dart | 361 +++++++ lib/videos/states/video.g.dart | 184 ---- lib/videos/states/video_in_list.dart | 25 +- lib/videos/states/video_in_list.freezed.dart | 174 ++++ lib/videos/states/video_in_list.g.dart | 79 -- .../components/add_to_playlist_button.dart | 2 +- lib/videos/views/components/history.dart | 6 +- .../views/components/inner_view_tablet.dart | 2 +- lib/videos/views/components/innter_view.dart | 29 +- lib/videos/views/components/video_list.dart | 2 +- lib/videos/views/screens/video.dart | 2 +- lib/videos/views/tv/screens/video.dart | 6 +- .../views/tv/screens/video_grid_view.dart | 4 +- 64 files changed, 4371 insertions(+), 2563 deletions(-) create mode 100644 lib/player/states/player.freezed.dart delete mode 100644 lib/player/states/player.g.dart create mode 100644 lib/player/states/player_controls.freezed.dart delete mode 100644 lib/player/states/player_controls.g.dart create mode 100644 lib/player/states/tv_player_controls.freezed.dart delete mode 100644 lib/player/states/tv_player_controls.g.dart create mode 100644 lib/player/states/tv_player_settings.freezed.dart delete mode 100644 lib/player/states/tv_player_settings.g.dart create mode 100644 lib/utils/states/item_list.freezed.dart delete mode 100644 lib/utils/states/item_list.g.dart create mode 100644 lib/utils/states/paginated_list_view.freezed.dart delete mode 100644 lib/utils/states/paginated_list_view.g.dart create mode 100644 lib/utils/states/select_list.freezed.dart delete mode 100644 lib/utils/states/select_list.g.dart create mode 100644 lib/utils/states/tv/searchable_dynamic_select_from_list.freezed.dart delete mode 100644 lib/utils/states/tv/searchable_dynamic_select_from_list.g.dart create mode 100644 lib/videos/states/add_to_playlist.freezed.dart delete mode 100644 lib/videos/states/add_to_playlist.g.dart create mode 100644 lib/videos/states/compact_video.freezed.dart delete mode 100644 lib/videos/states/compact_video.g.dart create mode 100644 lib/videos/states/download_modal_sheet.freezed.dart delete mode 100644 lib/videos/states/download_modal_sheet.g.dart create mode 100644 lib/videos/states/history.freezed.dart delete mode 100644 lib/videos/states/history.g.dart create mode 100644 lib/videos/states/tv_video.freezed.dart delete mode 100644 lib/videos/states/tv_video.g.dart create mode 100644 lib/videos/states/video.freezed.dart delete mode 100644 lib/videos/states/video.g.dart create mode 100644 lib/videos/states/video_in_list.freezed.dart delete mode 100644 lib/videos/states/video_in_list.g.dart diff --git a/lib/main.dart b/lib/main.dart index 021004d0..affb1870 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -79,10 +79,10 @@ Future main() async { }, ), BlocProvider( - create: (context) => PlayerCubit(PlayerState(), context.read()), + create: (context) => PlayerCubit(PlayerState.init(null), context.read()), ), BlocProvider( - create: (context) => DownloadManagerCubit(DownloadManagerState(), context.read()), + create: (context) => DownloadManagerCubit(const DownloadManagerState(), context.read()), ) ], child: const MyApp())); } diff --git a/lib/player/models/mediaCommand.dart b/lib/player/models/mediaCommand.dart index 0af168ed..ca357b42 100644 --- a/lib/player/models/mediaCommand.dart +++ b/lib/player/models/mediaCommand.dart @@ -15,10 +15,10 @@ enum MediaCommandType { } class MediaCommand { - MediaCommandType type; - T? value; + final MediaCommandType type; + final T? value; - MediaCommand(this.type, {this.value}); + const MediaCommand(this.type, {this.value}); } class SwitchVideoValue { diff --git a/lib/player/models/mediaEvent.dart b/lib/player/models/mediaEvent.dart index 827b31da..5d4e7f2e 100644 --- a/lib/player/models/mediaEvent.dart +++ b/lib/player/models/mediaEvent.dart @@ -1,9 +1,9 @@ class MediaEvent { - MediaEventType? type; - MediaState state; - T? value; + final MediaEventType? type; + final MediaState state; + final T? value; - MediaEvent({this.type, required this.state, this.value}); + const MediaEvent({this.type, required this.state, this.value}); } enum MediaEventType { diff --git a/lib/player/states/player.dart b/lib/player/states/player.dart index 15b7b3af..67b3054f 100644 --- a/lib/player/states/player.dart +++ b/lib/player/states/player.dart @@ -4,11 +4,11 @@ import 'dart:collection'; import 'package:audio_service/audio_service.dart'; import 'package:back_button_interceptor/back_button_interceptor.dart'; import 'package:bloc/bloc.dart'; -import 'package:copy_with_extension/copy_with_extension.dart'; import 'package:easy_debounce/easy_debounce.dart'; import 'package:easy_debounce/easy_throttle.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:invidious/globals.dart'; import 'package:invidious/player/models/mediaCommand.dart'; import 'package:invidious/player/models/mediaEvent.dart'; @@ -24,12 +24,12 @@ import '../../mediaHander.dart'; import '../../settings/states/settings.dart'; import '../../utils/models/pair.dart'; import '../../videos/models/base_video.dart'; -import '../../videos/models/db/progress.dart' as dbProgress; +import '../../videos/models/db/progress.dart' as db_progress; import '../../videos/models/sponsor_segment.dart'; import '../../videos/models/sponsor_segment_types.dart'; import '../../videos/models/video.dart'; -part 'player.g.dart'; +part 'player.freezed.dart'; const double targetHeight = 69; const double miniPlayerThreshold = 300; @@ -54,9 +54,8 @@ class PlayerCubit extends Cubit with WidgetsBindingObserver { setEvent(MediaEvent event) { handleMediaEvent(event); mapMediaEventToMediaHandler(event); - var state = this.state.copyWith(); - state.mediaEvent = event; - emit(state); + + emit(state.copyWith(mediaEvent: event)); } @@ -81,13 +80,7 @@ class PlayerCubit extends Cubit with WidgetsBindingObserver { MediaControl.stop, state.hasQueue ? MediaControl.skipToNext : MediaControl.fastForward, ], - systemActions: const { - MediaAction.seek, - MediaAction.seekForward, - MediaAction.seekBackward, - MediaAction.setShuffleMode, - MediaAction.setRepeatMode - }, + systemActions: const {MediaAction.seek, MediaAction.seekForward, MediaAction.seekBackward, MediaAction.setShuffleMode, MediaAction.setRepeatMode}, androidCompactActionIndices: const [0, 1, 3], processingState: const { MediaState.idle: AudioProcessingState.idle, @@ -111,8 +104,7 @@ class PlayerCubit extends Cubit with WidgetsBindingObserver { int get currentIndex { String? currentVideoId = state.currentlyPlaying?.videoId ?? state.offlineCurrentlyPlaying?.videoId; - return (state.videos.isNotEmpty ? state.videos : state.offlineVideos) - .indexWhere((element) => element.videoId == currentVideoId); + return (state.videos.isNotEmpty ? state.videos : state.offlineVideos).indexWhere((element) => element.videoId == currentVideoId); } onReady() async { @@ -175,9 +167,7 @@ class PlayerCubit extends Cubit with WidgetsBindingObserver { } _setPip(bool pip) { - var state = this.state.copyWith(); - state.isPip = pip; - emit(state); + emit(state.copyWith(isPip: pip)); } _setMuted(bool muted) { @@ -205,42 +195,34 @@ class PlayerCubit extends Cubit with WidgetsBindingObserver { } setVideos(List videos) { - var state = this.state.copyWith(); - state.videos = videos.where((element) => !element.filtered).toList(); - state.offlineVideos = []; - emit(state); + var newVideos = videos.where((element) => !element.filtered).toList(); + emit(state.copyWith(videos: newVideos, offlineVideos: [])); } selectTab(int index) { - var state = this.state.copyWith(); - state.selectedFullScreenIndex = index; - emit(state); + emit(state.copyWith(selectedFullScreenIndex: index)); } setAudio(bool? newValue) { - var state = this.state.copyWith(); - newValue ??= false; - - state.isAudio = newValue; - emit(state); + emit(state.copyWith(isAudio: newValue ?? false)); } hide() { - var state = this.state.copyWith(); - state.isMini = true; - state.mediaEvent = - MediaEvent(state: MediaState.playing, type: MediaEventType.miniDisplayChanged, value: state.isMini); - state.top = null; - state.height = targetHeight; - state.isHidden = true; - state.videos = []; - state.playedVideos = []; - state.currentlyPlaying = null; - state.offlineCurrentlyPlaying = null; - state.offlineVideos = []; - state.opacity = 0; - emit(state); - setEvent(MediaEvent(state: MediaState.idle)); + var mediaEvent = MediaEvent(state: MediaState.playing, type: MediaEventType.miniDisplayChanged, value: state.isMini); + + emit(state.copyWith( + isMini: true, + mediaEvent: mediaEvent, + top: null, + height: targetHeight, + isHidden: true, + videos: [], + playedVideos: [], + currentlyPlaying: null, + offlineCurrentlyPlaying: null, + offlineVideos: [], + opacity: 0)); + setEvent(const MediaEvent(state: MediaState.idle)); } double get getBottom => state.isHidden ? -targetHeight : 0; @@ -259,7 +241,7 @@ class PlayerCubit extends Cubit with WidgetsBindingObserver { // saving progress var currentProgress = currentPosition / state.currentlyPlaying!.lengthSeconds; if (currentProgress >= 0.9) currentProgress = 1; // we consider a video with 90%+ progress as watched - var progress = dbProgress.Progress.named(progress: currentProgress, videoId: state.currentlyPlaying!.videoId); + var progress = db_progress.Progress.named(progress: currentProgress, videoId: state.currentlyPlaying!.videoId); db.saveProgress(progress); @@ -274,61 +256,45 @@ class PlayerCubit extends Cubit with WidgetsBindingObserver { } queueVideos(List videos) { - var state = this.state.copyWith(); - state.offlineVideos = []; + var stateVideos = List.from(state.videos); if (videos.isNotEmpty) { //removing videos that are already in the queue - state.videos.addAll(videos - .where((v) => state.videos.indexWhere((v2) => v2.videoId == v.videoId) == -1) - .where((element) => !element.filtered)); + stateVideos.addAll(videos.where((v) => state.videos.indexWhere((v2) => v2.videoId == v.videoId) == -1).where((element) => !element.filtered)); } else { playVideo(videos); } log.fine('Videos in queue ${videos.length}'); - emit(state); + emit(state.copyWith(offlineVideos: [], videos: stateVideos)); generatePlayQueue(); } showBigPlayer() { - var state = this.state.copyWith(); - state.isMini = false; - state.mediaEvent = - MediaEvent(state: MediaState.playing, type: MediaEventType.miniDisplayChanged, value: state.isMini); - state.top = 0; - state.opacity = 1; - state.isHidden = false; - emit(state); + var mediaEvent = MediaEvent(state: MediaState.playing, type: MediaEventType.miniDisplayChanged, value: state.isMini); + + emit(state.copyWith(isMini: false, mediaEvent: mediaEvent, top: 0, opacity: 1, isHidden: false)); onOrientationChange(); } showMiniPlayer() { if (state.currentlyPlaying != null || state.offlineCurrentlyPlaying != null) { - var state = this.state.copyWith(); - state.isMini = true; - state.mediaEvent = - MediaEvent(state: MediaState.playing, type: MediaEventType.miniDisplayChanged, value: state.isMini); - state.top = null; - state.isHidden = false; - state.opacity = 1; - emit(state); + var mediaEvent = MediaEvent(state: MediaState.playing, type: MediaEventType.miniDisplayChanged, value: state.isMini); + emit(state.copyWith(isMini: true, mediaEvent: mediaEvent, top: null, isHidden: false, opacity: 1)); } } onProgress(Duration? position) { - var state = this.state.copyWith(); - state.position = position ?? Duration.zero; - int currentPosition = state.position.inSeconds; + var newPosition = position ?? Duration.zero; + int currentPosition = newPosition.inSeconds; saveProgress(currentPosition); log.fine("video event"); - emit(state); + emit(state.copyWith(position: newPosition)); if (state.sponsorSegments.isNotEmpty) { double positionInMs = currentPosition * 1000; - Pair nextSegment = state.sponsorSegments - .firstWhere((e) => e.first <= positionInMs && positionInMs <= e.last, orElse: () => Pair(-1, -1)); + Pair nextSegment = state.sponsorSegments.firstWhere((e) => e.first <= positionInMs && positionInMs <= e.last, orElse: () => const Pair(-1, -1)); if (nextSegment.first != -1) { - emit(state.copyWith(mediaEvent: MediaEvent(state: MediaState.playing, type: MediaEventType.sponsorSkipped))); + emit(state.copyWith(mediaEvent: const MediaEvent(state: MediaState.playing, type: MediaEventType.sponsorSkipped))); //for some reasons this needs to be last seek(Duration(milliseconds: nextSegment.last + 1000)); /* @@ -358,7 +324,8 @@ class PlayerCubit extends Cubit with WidgetsBindingObserver { String? currentVideoId = state.currentlyPlaying?.videoId ?? state.offlineCurrentlyPlaying?.videoId; if (currentVideoId != null) { // state.playedVideos.remove(currentVideoId); - state.playedVideos.add(currentVideoId); + var newPlayedVideos = List.from(state.playedVideos)..add(currentVideoId); + emit(state.copyWith(playedVideos: newPlayedVideos)); } if (state.playQueue.isNotEmpty) { @@ -369,8 +336,7 @@ class PlayerCubit extends Cubit with WidgetsBindingObserver { await switchToOfflineVideo(state.offlineVideos.firstWhere((element) => element.videoId == toPlay)); } } else if (settings.state.playerRepeatMode == PlayerRepeat.repeatAll) { - state.playedVideos = []; - state.playQueue = ListQueue.from([]); + emit(state.copyWith(playedVideos: [], playQueue: ListQueue.from([]))); if (state.videos.isNotEmpty) { await switchToVideo(state.videos[0]); } else { @@ -390,17 +356,20 @@ class PlayerCubit extends Cubit with WidgetsBindingObserver { if (state.playedVideos.isNotEmpty) { // putting back current video in play queue String? currentVideoId = state.currentlyPlaying?.videoId ?? state.offlineCurrentlyPlaying?.videoId; + var playQueue = ListQueue.from(state.playQueue); if (currentVideoId != null) { // state.playQueue.remove(currentVideoId); - state.playQueue.addFirst(currentVideoId); + playQueue.addFirst(currentVideoId); } - String toPlay = state.playedVideos.removeLast(); + var playedVideos = List.from(state.playedVideos); + String toPlay = playedVideos.removeLast(); if (state.videos.isNotEmpty) { await switchToVideo(state.videos.firstWhere((element) => element.videoId == toPlay)); } else { await switchToOfflineVideo(state.offlineVideos.firstWhere((element) => element.videoId == toPlay)); } + emit(state.copyWith(playQueue: playQueue, playedVideos: playedVideos)); } else { // if there's nothing to go back to, we just repeat the last video seek(Duration.zero); @@ -410,35 +379,32 @@ class PlayerCubit extends Cubit with WidgetsBindingObserver { } _setPlaying(bool playing) { - var state = this.state.copyWith(); - state.isPlaying = playing; - emit(state); + emit(state.copyWith(isPlaying: playing)); } _playVideos(List vids, {Duration? startAt}) async { if (vids.isNotEmpty) { - var state = this.state.copyWith(); - state.startAt = startAt; bool isOffline = vids[0] is DownloadedVideo; - state.mediaEvent = MediaEvent(state: MediaState.loading); + const mediaEvent = MediaEvent(state: MediaState.loading); + late List videos; + late List offlineVideos; if (isOffline) { - state.videos = []; - state.offlineVideos = List.from(vids, growable: true); + videos = []; + offlineVideos = List.from(vids, growable: true).cast(); } else { - state.offlineVideos = []; - state.videos = List.from(vids, growable: true); + offlineVideos = []; + videos = List.from(vids, growable: true).cast(); } - state.playedVideos = []; - state.selectedFullScreenIndex = 0; + var selectedFullScreenIndex = 0; if (vids.length > 1) { - state.selectedFullScreenIndex = 3; + selectedFullScreenIndex = 3; } - state.opacity = 0; - state.top = 500; - emit(state); + emit(state.copyWith( + offlineVideos: offlineVideos, videos: videos, startAt: startAt, mediaEvent: mediaEvent, playedVideos: [], selectedFullScreenIndex: selectedFullScreenIndex, opacity: 0, top: 500)); + showBigPlayer(); if (isOffline) { await switchToOfflineVideo(state.offlineVideos[0]); @@ -475,7 +441,6 @@ class PlayerCubit extends Cubit with WidgetsBindingObserver { /// Switches to a video without changing the queue _switchToVideo(IdedVideo video, {Duration? startAt}) async { - var state = this.state.copyWith(); try { // we move the existing video to the stack of played video @@ -485,21 +450,27 @@ class PlayerCubit extends Cubit with WidgetsBindingObserver { setAudio(video.audioOnly); } - state.mediaEvent = MediaEvent(state: MediaState.loading); + const mediaEvent = MediaEvent(state: MediaState.loading); + List videos = List.from(state.videos); + List offlineVideos = List.from(state.offlineVideos); + var currentlyPlaying = state.currentlyPlaying; + var offlineCurrentlyPlaying = state.offlineCurrentlyPlaying; if (isOffline) { - state.videos = []; - state.currentlyPlaying = null; + videos = []; + currentlyPlaying = null; } else { - state.offlineVideos = []; - state.offlineCurrentlyPlaying = null; + offlineVideos = []; + offlineCurrentlyPlaying = null; } - List toCheck = isOffline ? state.offlineVideos : state.videos; + // List toCheck = isOffline ? state.offlineVideos : state.videos; - emit(state); - state = this.state.copyWith(); + emit(state.copyWith(mediaEvent: mediaEvent, videos: videos, currentlyPlaying: currentlyPlaying, offlineVideos: offlineVideos, offlineCurrentlyPlaying: offlineCurrentlyPlaying)); + late MediaCommand mediaCommand; + currentlyPlaying = state.currentlyPlaying; + offlineCurrentlyPlaying = state.offlineCurrentlyPlaying; if (!isOffline) { late Video v; if (video is Video) { @@ -507,19 +478,20 @@ class PlayerCubit extends Cubit with WidgetsBindingObserver { } else { v = await service.getVideo(video.videoId); } - state.currentlyPlaying = v; - state.mediaCommand = - MediaCommand(MediaCommandType.switchVideo, value: SwitchVideoValue(video: v, startAt: startAt)); + currentlyPlaying = v; + mediaCommand = MediaCommand(MediaCommandType.switchVideo, value: SwitchVideoValue(video: v, startAt: startAt)); } else { - state.offlineCurrentlyPlaying = video; - state.mediaCommand = MediaCommand(MediaCommandType.switchToOfflineVideo, value: video); + offlineCurrentlyPlaying = video; + mediaCommand = MediaCommand(MediaCommandType.switchToOfflineVideo, value: video); } - state.position = Duration.zero; - state.forwardStep = defaultStep; - state.rewindStep = defaultStep; - - emit(state); + emit(state.copyWith( + position: Duration.zero, + forwardStep: defaultStep, + rewindStep: defaultStep, + mediaCommand: mediaCommand, + currentlyPlaying: currentlyPlaying, + offlineCurrentlyPlaying: offlineCurrentlyPlaying)); await setSponsorBlock(); @@ -527,7 +499,6 @@ class PlayerCubit extends Cubit with WidgetsBindingObserver { mediaHandler.skipToQueueItem(currentIndex); } } catch (err) { - emit(state); if (state.videos.length == 1) { // if we can't get video details, we need to stop everything log.severe("Couldn't play video '${video.videoId}', stopping player to avoid app crash"); @@ -570,44 +541,38 @@ class PlayerCubit extends Cubit with WidgetsBindingObserver { } play() { - var state = this.state.copyWith(); - state.mediaCommand = MediaCommand(MediaCommandType.play); - emit(state); + emit(state.copyWith(mediaCommand: const MediaCommand(MediaCommandType.play))); } pause() { - var state = this.state.copyWith(); - state.mediaCommand = MediaCommand(MediaCommandType.pause); - emit(state); + emit(state.copyWith(mediaCommand: const MediaCommand(MediaCommandType.pause))); } removeVideoFromQueue(String videoId) { - var state = this.state.copyWith(); - var listToUpdate = state.videos.isNotEmpty ? state.videos : state.offlineVideos; + var videos = List.from(state.videos); + var offlineVideos = List.from(state.offlineVideos); + var listToUpdate = videos.isNotEmpty ? videos : offlineVideos; if (listToUpdate.length == 1) { hide(); } else { - state.playQueue.removeWhere((element) => element == videoId); - state.playedVideos.removeWhere((element) => element == videoId); + var playQueue = ListQueue.from(state.playQueue)..removeWhere((element) => element == videoId); + var playedVideos = List.from(state.playedVideos)..removeWhere((element) => element == videoId); listToUpdate.removeWhere((element) => element.videoId == videoId); + emit(state.copyWith(videos: videos, offlineVideos: offlineVideos, playQueue: playQueue, playedVideos: playedVideos)); } - emit(state); } void videoDragged(DragUpdateDetails details) { - var state = this.state.copyWith(); - // log.info('delta: ${details.delta.dy}, local: ${details.localPosition.dy}, global: ${details.globalPosition.dy}'); - state.isDragging = true; - state.top = details.globalPosition.dy; // we change the display mode if there's a big enough drag movement to avoid jittery behavior when dragging slow + var isMini = state.isMini; + var mediaEvent = state.mediaEvent; if (details.delta.dy.abs() > 3) { - state.isMini = details.delta.dy > 0; - state.mediaEvent = - MediaEvent(state: MediaState.playing, type: MediaEventType.miniDisplayChanged, value: state.isMini); + isMini = details.delta.dy > 0; + mediaEvent = MediaEvent(state: MediaState.playing, type: MediaEventType.miniDisplayChanged, value: state.isMini); } - state.dragDistance += details.delta.dy; + var dragDistance = state.dragDistance + details.delta.dy; // we're going down, putting threshold high easier to switch to mini player - emit(state); + emit(state.copyWith(isDragging: true, top: details.globalPosition.dy, dragDistance: dragDistance, isMini: isMini, mediaEvent: mediaEvent)); } void videoDraggedEnd(DragEndDetails details) { @@ -620,8 +585,7 @@ class PlayerCubit extends Cubit with WidgetsBindingObserver { } void videoDragStarted(DragStartDetails details) { - state.dragDistance = 0; - state.dragStartMini = state.isMini; + emit(state.copyWith(dragDistance: 0, dragStartMini: state.isMini)); } bool isVideoInQueue(Video video) { @@ -629,14 +593,17 @@ class PlayerCubit extends Cubit with WidgetsBindingObserver { } onQueueReorder(int oldItemIndex, int newItemIndex) { - var state = this.state.copyWith(); log.fine('Dragged video'); - var listToUpdate = state.videos.isNotEmpty ? state.videos : state.offlineVideos; + var videos = List.from(state.videos); + var offlineVideos = List.from(state.offlineVideos); + var listToUpdate = videos.isNotEmpty ? videos : offlineVideos; var movedItem = listToUpdate.removeAt(oldItemIndex); + listToUpdate.insert(newItemIndex, movedItem); log.fine('Reordered list: $oldItemIndex new index: ${listToUpdate.indexOf(movedItem)}'); + var playedVideos = List.from(state.playedVideos); if (newItemIndex <= currentIndex) { - state.playedVideos.add(listToUpdate[newItemIndex].videoId); + playedVideos.add(listToUpdate[newItemIndex].videoId); } /* if (oldItemIndex == state.currentIndex) { @@ -648,7 +615,7 @@ class PlayerCubit extends Cubit with WidgetsBindingObserver { } */ - emit(state); + emit(state.copyWith(playedVideos: playedVideos, videos: videos, offlineVideos: offlineVideos)); generatePlayQueue(); } @@ -656,18 +623,16 @@ class PlayerCubit extends Cubit with WidgetsBindingObserver { if (state.videos.isEmpty) { playVideo([video]); } else { - var state = this.state.copyWith(); - state.videos.add(video); - state.playQueue.addFirst(video.videoId); - emit(state); + var videos = List.from(state.videos)..add(video); + var playQueue = ListQueue.from(state.playQueue)..addFirst(video.videoId); + emit(state.copyWith(videos: videos, playQueue: playQueue)); } } setSponsorBlock() async { List> newSegments = []; if (state.currentlyPlaying != null) { - List types = - SponsorSegmentType.values.where((e) => db.getSettings(e.settingsName())?.value == 'true').toList(); + List types = SponsorSegmentType.values.where((e) => db.getSettings(e.settingsName())?.value == 'true').toList(); if (types.isNotEmpty) { List sponsorSegments = await service.getSponsorSegments(state.currentlyPlaying!.videoId, types); @@ -690,16 +655,12 @@ class PlayerCubit extends Cubit with WidgetsBindingObserver { duration = Duration.zero; } - var videoLength = - this.state.currentlyPlaying?.lengthSeconds ?? this.state.offlineCurrentlyPlaying?.lengthSeconds ?? 1; + var videoLength = state.currentlyPlaying?.lengthSeconds ?? state.offlineCurrentlyPlaying?.lengthSeconds ?? 1; if (duration.inSeconds > (videoLength)) { duration = Duration(seconds: videoLength); } - var state = this.state.copyWith(); - state.position = duration; - state.mediaCommand = MediaCommand(MediaCommandType.seek, value: duration); - emit(state); + emit(state.copyWith(position: duration, mediaCommand: MediaCommand(MediaCommandType.seek, value: duration))); } void fastForward() { @@ -736,39 +697,24 @@ class PlayerCubit extends Cubit with WidgetsBindingObserver { if (state.videos.isNotEmpty) { var e = state.videos[index]; return MediaItem( - id: e.videoId, - title: e.title, - artist: e.author, - duration: Duration(seconds: e.lengthSeconds), - album: '', - artUri: Uri.parse(ImageObject.getBestThumbnail(e.videoThumbnails)?.url ?? '')); + id: e.videoId, title: e.title, artist: e.author, duration: Duration(seconds: e.lengthSeconds), album: '', artUri: Uri.parse(ImageObject.getBestThumbnail(e.videoThumbnails)?.url ?? '')); } else if (state.offlineVideos.isNotEmpty) { var e = state.offlineVideos[index]; var path = await e.thumbnailPath; - return MediaItem( - id: e.videoId, - title: e.title, - artist: e.author, - duration: Duration(seconds: e.lengthSeconds), - album: '', - artUri: Uri.file(path)); + return MediaItem(id: e.videoId, title: e.title, artist: e.author, duration: Duration(seconds: e.lengthSeconds), album: '', artUri: Uri.file(path)); } return null; } void setSpeed(double d) { - var state = this.state.copyWith(); - state.mediaCommand = MediaCommand(MediaCommandType.speed, value: d); - emit(state); + emit(state.copyWith(mediaCommand: MediaCommand(MediaCommandType.speed, value: d))); } void setFullScreen(FullScreenState fsState) { // emit(state.copyWith(mediaCommand: MediaCommand(MediaCommandType.fullScreen, value: fsState))); emit(state.copyWith( fullScreenState: fsState, - mediaCommand: MediaCommand(fsState == FullScreenState.notFullScreen - ? MediaCommandType.exitFullScreen - : MediaCommandType.enterFullScreen), + mediaCommand: MediaCommand(fsState == FullScreenState.notFullScreen ? MediaCommandType.exitFullScreen : MediaCommandType.enterFullScreen), mediaEvent: MediaEvent(state: state.mediaEvent.state, type: MediaEventType.fullScreenChanged, value: fsState))); switch (fsState) { @@ -811,8 +757,7 @@ class PlayerCubit extends Cubit with WidgetsBindingObserver { } } - Duration get duration => - Duration(seconds: (state.currentlyPlaying?.lengthSeconds ?? state.offlineCurrentlyPlaying?.lengthSeconds ?? 1)); + Duration get duration => Duration(seconds: (state.currentlyPlaying?.lengthSeconds ?? state.offlineCurrentlyPlaying?.lengthSeconds ?? 1)); double get progress => state.position.inMilliseconds / duration.inMilliseconds; @@ -827,8 +772,7 @@ class PlayerCubit extends Cubit with WidgetsBindingObserver { // get videos minus the one we already played and the currently playing video List videos = (state.videos.isNotEmpty ? state.videos : state.offlineVideos) .where((element) => !state.playedVideos.contains(element.videoId)) - .where( - (element) => element.videoId != (state.currentlyPlaying?.videoId ?? state.offlineCurrentlyPlaying?.videoId)) + .where((element) => element.videoId != (state.currentlyPlaying?.videoId ?? state.offlineCurrentlyPlaying?.videoId)) .map((e) => e.videoId) .toList(); @@ -842,108 +786,75 @@ class PlayerCubit extends Cubit with WidgetsBindingObserver { } void onOrientationChange() { - if (getDeviceType() == DeviceType.phone && - (orientation == Orientation.landscape) && - !state.isMini) { + if (getDeviceType() == DeviceType.phone && (orientation == Orientation.landscape) && !state.isMini) { setFullScreen(FullScreenState.fullScreen); } } } -@CopyWith(constructor: "_") -class PlayerState { - // player display properties - bool isMini = true; - double? top; - bool isDragging = false; - int selectedFullScreenIndex = 0; - bool isHidden = true; - double opacity = 0; - double dragDistance = 0; - bool dragStartMini = true; - double height = targetHeight; - FullScreenState fullScreenState = FullScreenState.notFullScreen; - bool muted = false; - double aspectRatio = 16 / 9; - - // videos to play - Video? currentlyPlaying; +@freezed +class PlayerState with _$PlayerState { + const factory PlayerState({ + // player display properties + @Default(true) bool isMini, + double? top, + @Default(false) bool isDragging, + @Default(0) int selectedFullScreenIndex, + @Default(true) bool isHidden, + @Default(0) double opacity, + @Default(0) double dragDistance, + @Default(true) bool dragStartMini, + @Default(targetHeight) double height, + @Default(FullScreenState.notFullScreen) FullScreenState fullScreenState, + @Default(false) bool muted, + @Default(16 / 9) double aspectRatio, + + // videos to play + Video? currentlyPlaying, + DownloadedVideo? offlineCurrentlyPlaying, + @Default([]) List videos, + @Default([]) List offlineVideos, + + // playlist controls + @Default([]) List playedVideos, + required ListQueue playQueue, + @Default(false) bool isAudio, + + // playing video data + @Default(false) bool isPip, + @Default(Offset.zero) Offset offset, + Duration? startAt, + @Default(Duration.zero) Duration position, + @Default(Duration.zero) Duration bufferedPosition, + @Default(false) bool isPlaying, + @Default(1.0) double speed, + + // events + // command we send down the stack, namely video / audio player + MediaCommand? mediaCommand, + + // events we receive from bottom of stack + @Default(MediaEvent(state: MediaState.idle)) MediaEvent mediaEvent, + + // sponsor block variables + @Default([]) List> sponsorSegments, + @Default(Pair(0, 0)) Pair nextSegment, + + // step in seconds when fast forawrd or fast rewind + @Default(defaultStep) int forwardStep, + @Default(defaultStep) rewindStep, + @Default(0) int totalFastForward, + @Default(0) totalRewind, + }) = _PlayerState; bool get hasVideo => currentlyPlaying != null || offlineCurrentlyPlaying != null; - DownloadedVideo? offlineCurrentlyPlaying; - List videos = List.empty(growable: true); - List offlineVideos = []; - - // playlist controls - List playedVideos = []; - ListQueue playQueue = ListQueue.from([]); - bool isAudio = false; - - // playing video data - // int currentIndex = 0; - bool isPip = false; - Offset offset = Offset.zero; - Duration? startAt; - Duration position = Duration.zero; - Duration bufferedPosition = Duration.zero; - bool isPlaying = false; bool get hasQueue => offlineVideos.length > 1 || videos.length > 1; - double speed = 1.0; - - // events - // command we send down the stack, namely video / audio player - MediaCommand? mediaCommand; - - // events we receive from bottom of stack - MediaEvent mediaEvent = MediaEvent(state: MediaState.idle); - - // sponsor block variables - List> sponsorSegments = List.of([]); - Pair nextSegment = Pair(0, 0); - - // step in seconds when fast forawrd or fast rewind - int forwardStep = defaultStep, rewindStep = defaultStep; - int totalFastForward = 0, totalRewind = 0; - - PlayerState(); - - PlayerState.withVideos(this.videos); - - PlayerState._( - this.videos, - this.height, - this.isMini, - this.top, - this.isDragging, - this.selectedFullScreenIndex, - this.isPip, - this.isHidden, - this.speed, - this.currentlyPlaying, - this.offlineCurrentlyPlaying, - this.opacity, - this.aspectRatio, - this.dragDistance, - this.dragStartMini, - this.bufferedPosition, - this.playedVideos, - this.offset, - this.isAudio, - this.startAt, - this.isPlaying, - this.sponsorSegments, - this.nextSegment, - this.offlineVideos, - this.position, - this.mediaCommand, - this.fullScreenState, - this.muted, - this.forwardStep, - this.rewindStep, - this.totalRewind, - this.totalFastForward, - this.mediaEvent, - this.playQueue); + const PlayerState._(); + +// + static PlayerState init(List? videos) { + return PlayerState(videos: videos ?? [], playQueue: ListQueue.from([])); + } } diff --git a/lib/player/states/player.freezed.dart b/lib/player/states/player.freezed.dart new file mode 100644 index 00000000..0949acdc --- /dev/null +++ b/lib/player/states/player.freezed.dart @@ -0,0 +1,928 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'player.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +mixin _$PlayerState { +// player display properties + bool get isMini => throw _privateConstructorUsedError; + double? get top => throw _privateConstructorUsedError; + bool get isDragging => throw _privateConstructorUsedError; + int get selectedFullScreenIndex => throw _privateConstructorUsedError; + bool get isHidden => throw _privateConstructorUsedError; + double get opacity => throw _privateConstructorUsedError; + double get dragDistance => throw _privateConstructorUsedError; + bool get dragStartMini => throw _privateConstructorUsedError; + double get height => throw _privateConstructorUsedError; + FullScreenState get fullScreenState => throw _privateConstructorUsedError; + bool get muted => throw _privateConstructorUsedError; + double get aspectRatio => + throw _privateConstructorUsedError; // videos to play + Video? get currentlyPlaying => throw _privateConstructorUsedError; + DownloadedVideo? get offlineCurrentlyPlaying => + throw _privateConstructorUsedError; + List get videos => throw _privateConstructorUsedError; + List get offlineVideos => + throw _privateConstructorUsedError; // playlist controls + List get playedVideos => throw _privateConstructorUsedError; + ListQueue get playQueue => throw _privateConstructorUsedError; + bool get isAudio => throw _privateConstructorUsedError; // playing video data + bool get isPip => throw _privateConstructorUsedError; + Offset get offset => throw _privateConstructorUsedError; + Duration? get startAt => throw _privateConstructorUsedError; + Duration get position => throw _privateConstructorUsedError; + Duration get bufferedPosition => throw _privateConstructorUsedError; + bool get isPlaying => throw _privateConstructorUsedError; + double get speed => throw _privateConstructorUsedError; // events +// command we send down the stack, namely video / audio player + MediaCommand? get mediaCommand => + throw _privateConstructorUsedError; // events we receive from bottom of stack + MediaEvent get mediaEvent => + throw _privateConstructorUsedError; // sponsor block variables + List> get sponsorSegments => throw _privateConstructorUsedError; + Pair get nextSegment => + throw _privateConstructorUsedError; // step in seconds when fast forawrd or fast rewind + int get forwardStep => throw _privateConstructorUsedError; + dynamic get rewindStep => throw _privateConstructorUsedError; + int get totalFastForward => throw _privateConstructorUsedError; + dynamic get totalRewind => throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + $PlayerStateCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $PlayerStateCopyWith<$Res> { + factory $PlayerStateCopyWith( + PlayerState value, $Res Function(PlayerState) then) = + _$PlayerStateCopyWithImpl<$Res, PlayerState>; + @useResult + $Res call( + {bool isMini, + double? top, + bool isDragging, + int selectedFullScreenIndex, + bool isHidden, + double opacity, + double dragDistance, + bool dragStartMini, + double height, + FullScreenState fullScreenState, + bool muted, + double aspectRatio, + Video? currentlyPlaying, + DownloadedVideo? offlineCurrentlyPlaying, + List videos, + List offlineVideos, + List playedVideos, + ListQueue playQueue, + bool isAudio, + bool isPip, + Offset offset, + Duration? startAt, + Duration position, + Duration bufferedPosition, + bool isPlaying, + double speed, + MediaCommand? mediaCommand, + MediaEvent mediaEvent, + List> sponsorSegments, + Pair nextSegment, + int forwardStep, + dynamic rewindStep, + int totalFastForward, + dynamic totalRewind}); +} + +/// @nodoc +class _$PlayerStateCopyWithImpl<$Res, $Val extends PlayerState> + implements $PlayerStateCopyWith<$Res> { + _$PlayerStateCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? isMini = null, + Object? top = freezed, + Object? isDragging = null, + Object? selectedFullScreenIndex = null, + Object? isHidden = null, + Object? opacity = null, + Object? dragDistance = null, + Object? dragStartMini = null, + Object? height = null, + Object? fullScreenState = null, + Object? muted = null, + Object? aspectRatio = null, + Object? currentlyPlaying = freezed, + Object? offlineCurrentlyPlaying = freezed, + Object? videos = null, + Object? offlineVideos = null, + Object? playedVideos = null, + Object? playQueue = null, + Object? isAudio = null, + Object? isPip = null, + Object? offset = null, + Object? startAt = freezed, + Object? position = null, + Object? bufferedPosition = null, + Object? isPlaying = null, + Object? speed = null, + Object? mediaCommand = freezed, + Object? mediaEvent = null, + Object? sponsorSegments = null, + Object? nextSegment = null, + Object? forwardStep = null, + Object? rewindStep = freezed, + Object? totalFastForward = null, + Object? totalRewind = freezed, + }) { + return _then(_value.copyWith( + isMini: null == isMini + ? _value.isMini + : isMini // ignore: cast_nullable_to_non_nullable + as bool, + top: freezed == top + ? _value.top + : top // ignore: cast_nullable_to_non_nullable + as double?, + isDragging: null == isDragging + ? _value.isDragging + : isDragging // ignore: cast_nullable_to_non_nullable + as bool, + selectedFullScreenIndex: null == selectedFullScreenIndex + ? _value.selectedFullScreenIndex + : selectedFullScreenIndex // ignore: cast_nullable_to_non_nullable + as int, + isHidden: null == isHidden + ? _value.isHidden + : isHidden // ignore: cast_nullable_to_non_nullable + as bool, + opacity: null == opacity + ? _value.opacity + : opacity // ignore: cast_nullable_to_non_nullable + as double, + dragDistance: null == dragDistance + ? _value.dragDistance + : dragDistance // ignore: cast_nullable_to_non_nullable + as double, + dragStartMini: null == dragStartMini + ? _value.dragStartMini + : dragStartMini // ignore: cast_nullable_to_non_nullable + as bool, + height: null == height + ? _value.height + : height // ignore: cast_nullable_to_non_nullable + as double, + fullScreenState: null == fullScreenState + ? _value.fullScreenState + : fullScreenState // ignore: cast_nullable_to_non_nullable + as FullScreenState, + muted: null == muted + ? _value.muted + : muted // ignore: cast_nullable_to_non_nullable + as bool, + aspectRatio: null == aspectRatio + ? _value.aspectRatio + : aspectRatio // ignore: cast_nullable_to_non_nullable + as double, + currentlyPlaying: freezed == currentlyPlaying + ? _value.currentlyPlaying + : currentlyPlaying // ignore: cast_nullable_to_non_nullable + as Video?, + offlineCurrentlyPlaying: freezed == offlineCurrentlyPlaying + ? _value.offlineCurrentlyPlaying + : offlineCurrentlyPlaying // ignore: cast_nullable_to_non_nullable + as DownloadedVideo?, + videos: null == videos + ? _value.videos + : videos // ignore: cast_nullable_to_non_nullable + as List, + offlineVideos: null == offlineVideos + ? _value.offlineVideos + : offlineVideos // ignore: cast_nullable_to_non_nullable + as List, + playedVideos: null == playedVideos + ? _value.playedVideos + : playedVideos // ignore: cast_nullable_to_non_nullable + as List, + playQueue: null == playQueue + ? _value.playQueue + : playQueue // ignore: cast_nullable_to_non_nullable + as ListQueue, + isAudio: null == isAudio + ? _value.isAudio + : isAudio // ignore: cast_nullable_to_non_nullable + as bool, + isPip: null == isPip + ? _value.isPip + : isPip // ignore: cast_nullable_to_non_nullable + as bool, + offset: null == offset + ? _value.offset + : offset // ignore: cast_nullable_to_non_nullable + as Offset, + startAt: freezed == startAt + ? _value.startAt + : startAt // ignore: cast_nullable_to_non_nullable + as Duration?, + position: null == position + ? _value.position + : position // ignore: cast_nullable_to_non_nullable + as Duration, + bufferedPosition: null == bufferedPosition + ? _value.bufferedPosition + : bufferedPosition // ignore: cast_nullable_to_non_nullable + as Duration, + isPlaying: null == isPlaying + ? _value.isPlaying + : isPlaying // ignore: cast_nullable_to_non_nullable + as bool, + speed: null == speed + ? _value.speed + : speed // ignore: cast_nullable_to_non_nullable + as double, + mediaCommand: freezed == mediaCommand + ? _value.mediaCommand + : mediaCommand // ignore: cast_nullable_to_non_nullable + as MediaCommand?, + mediaEvent: null == mediaEvent + ? _value.mediaEvent + : mediaEvent // ignore: cast_nullable_to_non_nullable + as MediaEvent, + sponsorSegments: null == sponsorSegments + ? _value.sponsorSegments + : sponsorSegments // ignore: cast_nullable_to_non_nullable + as List>, + nextSegment: null == nextSegment + ? _value.nextSegment + : nextSegment // ignore: cast_nullable_to_non_nullable + as Pair, + forwardStep: null == forwardStep + ? _value.forwardStep + : forwardStep // ignore: cast_nullable_to_non_nullable + as int, + rewindStep: freezed == rewindStep + ? _value.rewindStep + : rewindStep // ignore: cast_nullable_to_non_nullable + as dynamic, + totalFastForward: null == totalFastForward + ? _value.totalFastForward + : totalFastForward // ignore: cast_nullable_to_non_nullable + as int, + totalRewind: freezed == totalRewind + ? _value.totalRewind + : totalRewind // ignore: cast_nullable_to_non_nullable + as dynamic, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$PlayerStateImplCopyWith<$Res> + implements $PlayerStateCopyWith<$Res> { + factory _$$PlayerStateImplCopyWith( + _$PlayerStateImpl value, $Res Function(_$PlayerStateImpl) then) = + __$$PlayerStateImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {bool isMini, + double? top, + bool isDragging, + int selectedFullScreenIndex, + bool isHidden, + double opacity, + double dragDistance, + bool dragStartMini, + double height, + FullScreenState fullScreenState, + bool muted, + double aspectRatio, + Video? currentlyPlaying, + DownloadedVideo? offlineCurrentlyPlaying, + List videos, + List offlineVideos, + List playedVideos, + ListQueue playQueue, + bool isAudio, + bool isPip, + Offset offset, + Duration? startAt, + Duration position, + Duration bufferedPosition, + bool isPlaying, + double speed, + MediaCommand? mediaCommand, + MediaEvent mediaEvent, + List> sponsorSegments, + Pair nextSegment, + int forwardStep, + dynamic rewindStep, + int totalFastForward, + dynamic totalRewind}); +} + +/// @nodoc +class __$$PlayerStateImplCopyWithImpl<$Res> + extends _$PlayerStateCopyWithImpl<$Res, _$PlayerStateImpl> + implements _$$PlayerStateImplCopyWith<$Res> { + __$$PlayerStateImplCopyWithImpl( + _$PlayerStateImpl _value, $Res Function(_$PlayerStateImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? isMini = null, + Object? top = freezed, + Object? isDragging = null, + Object? selectedFullScreenIndex = null, + Object? isHidden = null, + Object? opacity = null, + Object? dragDistance = null, + Object? dragStartMini = null, + Object? height = null, + Object? fullScreenState = null, + Object? muted = null, + Object? aspectRatio = null, + Object? currentlyPlaying = freezed, + Object? offlineCurrentlyPlaying = freezed, + Object? videos = null, + Object? offlineVideos = null, + Object? playedVideos = null, + Object? playQueue = null, + Object? isAudio = null, + Object? isPip = null, + Object? offset = null, + Object? startAt = freezed, + Object? position = null, + Object? bufferedPosition = null, + Object? isPlaying = null, + Object? speed = null, + Object? mediaCommand = freezed, + Object? mediaEvent = null, + Object? sponsorSegments = null, + Object? nextSegment = null, + Object? forwardStep = null, + Object? rewindStep = freezed, + Object? totalFastForward = null, + Object? totalRewind = freezed, + }) { + return _then(_$PlayerStateImpl( + isMini: null == isMini + ? _value.isMini + : isMini // ignore: cast_nullable_to_non_nullable + as bool, + top: freezed == top + ? _value.top + : top // ignore: cast_nullable_to_non_nullable + as double?, + isDragging: null == isDragging + ? _value.isDragging + : isDragging // ignore: cast_nullable_to_non_nullable + as bool, + selectedFullScreenIndex: null == selectedFullScreenIndex + ? _value.selectedFullScreenIndex + : selectedFullScreenIndex // ignore: cast_nullable_to_non_nullable + as int, + isHidden: null == isHidden + ? _value.isHidden + : isHidden // ignore: cast_nullable_to_non_nullable + as bool, + opacity: null == opacity + ? _value.opacity + : opacity // ignore: cast_nullable_to_non_nullable + as double, + dragDistance: null == dragDistance + ? _value.dragDistance + : dragDistance // ignore: cast_nullable_to_non_nullable + as double, + dragStartMini: null == dragStartMini + ? _value.dragStartMini + : dragStartMini // ignore: cast_nullable_to_non_nullable + as bool, + height: null == height + ? _value.height + : height // ignore: cast_nullable_to_non_nullable + as double, + fullScreenState: null == fullScreenState + ? _value.fullScreenState + : fullScreenState // ignore: cast_nullable_to_non_nullable + as FullScreenState, + muted: null == muted + ? _value.muted + : muted // ignore: cast_nullable_to_non_nullable + as bool, + aspectRatio: null == aspectRatio + ? _value.aspectRatio + : aspectRatio // ignore: cast_nullable_to_non_nullable + as double, + currentlyPlaying: freezed == currentlyPlaying + ? _value.currentlyPlaying + : currentlyPlaying // ignore: cast_nullable_to_non_nullable + as Video?, + offlineCurrentlyPlaying: freezed == offlineCurrentlyPlaying + ? _value.offlineCurrentlyPlaying + : offlineCurrentlyPlaying // ignore: cast_nullable_to_non_nullable + as DownloadedVideo?, + videos: null == videos + ? _value._videos + : videos // ignore: cast_nullable_to_non_nullable + as List, + offlineVideos: null == offlineVideos + ? _value._offlineVideos + : offlineVideos // ignore: cast_nullable_to_non_nullable + as List, + playedVideos: null == playedVideos + ? _value._playedVideos + : playedVideos // ignore: cast_nullable_to_non_nullable + as List, + playQueue: null == playQueue + ? _value.playQueue + : playQueue // ignore: cast_nullable_to_non_nullable + as ListQueue, + isAudio: null == isAudio + ? _value.isAudio + : isAudio // ignore: cast_nullable_to_non_nullable + as bool, + isPip: null == isPip + ? _value.isPip + : isPip // ignore: cast_nullable_to_non_nullable + as bool, + offset: null == offset + ? _value.offset + : offset // ignore: cast_nullable_to_non_nullable + as Offset, + startAt: freezed == startAt + ? _value.startAt + : startAt // ignore: cast_nullable_to_non_nullable + as Duration?, + position: null == position + ? _value.position + : position // ignore: cast_nullable_to_non_nullable + as Duration, + bufferedPosition: null == bufferedPosition + ? _value.bufferedPosition + : bufferedPosition // ignore: cast_nullable_to_non_nullable + as Duration, + isPlaying: null == isPlaying + ? _value.isPlaying + : isPlaying // ignore: cast_nullable_to_non_nullable + as bool, + speed: null == speed + ? _value.speed + : speed // ignore: cast_nullable_to_non_nullable + as double, + mediaCommand: freezed == mediaCommand + ? _value.mediaCommand + : mediaCommand // ignore: cast_nullable_to_non_nullable + as MediaCommand?, + mediaEvent: null == mediaEvent + ? _value.mediaEvent + : mediaEvent // ignore: cast_nullable_to_non_nullable + as MediaEvent, + sponsorSegments: null == sponsorSegments + ? _value._sponsorSegments + : sponsorSegments // ignore: cast_nullable_to_non_nullable + as List>, + nextSegment: null == nextSegment + ? _value.nextSegment + : nextSegment // ignore: cast_nullable_to_non_nullable + as Pair, + forwardStep: null == forwardStep + ? _value.forwardStep + : forwardStep // ignore: cast_nullable_to_non_nullable + as int, + rewindStep: freezed == rewindStep ? _value.rewindStep! : rewindStep, + totalFastForward: null == totalFastForward + ? _value.totalFastForward + : totalFastForward // ignore: cast_nullable_to_non_nullable + as int, + totalRewind: freezed == totalRewind ? _value.totalRewind! : totalRewind, + )); + } +} + +/// @nodoc + +class _$PlayerStateImpl extends _PlayerState { + const _$PlayerStateImpl( + {this.isMini = true, + this.top, + this.isDragging = false, + this.selectedFullScreenIndex = 0, + this.isHidden = true, + this.opacity = 0, + this.dragDistance = 0, + this.dragStartMini = true, + this.height = targetHeight, + this.fullScreenState = FullScreenState.notFullScreen, + this.muted = false, + this.aspectRatio = 16 / 9, + this.currentlyPlaying, + this.offlineCurrentlyPlaying, + final List videos = const [], + final List offlineVideos = const [], + final List playedVideos = const [], + required this.playQueue, + this.isAudio = false, + this.isPip = false, + this.offset = Offset.zero, + this.startAt, + this.position = Duration.zero, + this.bufferedPosition = Duration.zero, + this.isPlaying = false, + this.speed = 1.0, + this.mediaCommand, + this.mediaEvent = const MediaEvent(state: MediaState.idle), + final List> sponsorSegments = const [], + this.nextSegment = const Pair(0, 0), + this.forwardStep = defaultStep, + this.rewindStep = defaultStep, + this.totalFastForward = 0, + this.totalRewind = 0}) + : _videos = videos, + _offlineVideos = offlineVideos, + _playedVideos = playedVideos, + _sponsorSegments = sponsorSegments, + super._(); + +// player display properties + @override + @JsonKey() + final bool isMini; + @override + final double? top; + @override + @JsonKey() + final bool isDragging; + @override + @JsonKey() + final int selectedFullScreenIndex; + @override + @JsonKey() + final bool isHidden; + @override + @JsonKey() + final double opacity; + @override + @JsonKey() + final double dragDistance; + @override + @JsonKey() + final bool dragStartMini; + @override + @JsonKey() + final double height; + @override + @JsonKey() + final FullScreenState fullScreenState; + @override + @JsonKey() + final bool muted; + @override + @JsonKey() + final double aspectRatio; +// videos to play + @override + final Video? currentlyPlaying; + @override + final DownloadedVideo? offlineCurrentlyPlaying; + final List _videos; + @override + @JsonKey() + List get videos { + if (_videos is EqualUnmodifiableListView) return _videos; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_videos); + } + + final List _offlineVideos; + @override + @JsonKey() + List get offlineVideos { + if (_offlineVideos is EqualUnmodifiableListView) return _offlineVideos; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_offlineVideos); + } + +// playlist controls + final List _playedVideos; +// playlist controls + @override + @JsonKey() + List get playedVideos { + if (_playedVideos is EqualUnmodifiableListView) return _playedVideos; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_playedVideos); + } + + @override + final ListQueue playQueue; + @override + @JsonKey() + final bool isAudio; +// playing video data + @override + @JsonKey() + final bool isPip; + @override + @JsonKey() + final Offset offset; + @override + final Duration? startAt; + @override + @JsonKey() + final Duration position; + @override + @JsonKey() + final Duration bufferedPosition; + @override + @JsonKey() + final bool isPlaying; + @override + @JsonKey() + final double speed; +// events +// command we send down the stack, namely video / audio player + @override + final MediaCommand? mediaCommand; +// events we receive from bottom of stack + @override + @JsonKey() + final MediaEvent mediaEvent; +// sponsor block variables + final List> _sponsorSegments; +// sponsor block variables + @override + @JsonKey() + List> get sponsorSegments { + if (_sponsorSegments is EqualUnmodifiableListView) return _sponsorSegments; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_sponsorSegments); + } + + @override + @JsonKey() + final Pair nextSegment; +// step in seconds when fast forawrd or fast rewind + @override + @JsonKey() + final int forwardStep; + @override + @JsonKey() + final dynamic rewindStep; + @override + @JsonKey() + final int totalFastForward; + @override + @JsonKey() + final dynamic totalRewind; + + @override + String toString() { + return 'PlayerState(isMini: $isMini, top: $top, isDragging: $isDragging, selectedFullScreenIndex: $selectedFullScreenIndex, isHidden: $isHidden, opacity: $opacity, dragDistance: $dragDistance, dragStartMini: $dragStartMini, height: $height, fullScreenState: $fullScreenState, muted: $muted, aspectRatio: $aspectRatio, currentlyPlaying: $currentlyPlaying, offlineCurrentlyPlaying: $offlineCurrentlyPlaying, videos: $videos, offlineVideos: $offlineVideos, playedVideos: $playedVideos, playQueue: $playQueue, isAudio: $isAudio, isPip: $isPip, offset: $offset, startAt: $startAt, position: $position, bufferedPosition: $bufferedPosition, isPlaying: $isPlaying, speed: $speed, mediaCommand: $mediaCommand, mediaEvent: $mediaEvent, sponsorSegments: $sponsorSegments, nextSegment: $nextSegment, forwardStep: $forwardStep, rewindStep: $rewindStep, totalFastForward: $totalFastForward, totalRewind: $totalRewind)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$PlayerStateImpl && + (identical(other.isMini, isMini) || other.isMini == isMini) && + (identical(other.top, top) || other.top == top) && + (identical(other.isDragging, isDragging) || + other.isDragging == isDragging) && + (identical( + other.selectedFullScreenIndex, selectedFullScreenIndex) || + other.selectedFullScreenIndex == selectedFullScreenIndex) && + (identical(other.isHidden, isHidden) || + other.isHidden == isHidden) && + (identical(other.opacity, opacity) || other.opacity == opacity) && + (identical(other.dragDistance, dragDistance) || + other.dragDistance == dragDistance) && + (identical(other.dragStartMini, dragStartMini) || + other.dragStartMini == dragStartMini) && + (identical(other.height, height) || other.height == height) && + (identical(other.fullScreenState, fullScreenState) || + other.fullScreenState == fullScreenState) && + (identical(other.muted, muted) || other.muted == muted) && + (identical(other.aspectRatio, aspectRatio) || + other.aspectRatio == aspectRatio) && + (identical(other.currentlyPlaying, currentlyPlaying) || + other.currentlyPlaying == currentlyPlaying) && + (identical( + other.offlineCurrentlyPlaying, offlineCurrentlyPlaying) || + other.offlineCurrentlyPlaying == offlineCurrentlyPlaying) && + const DeepCollectionEquality().equals(other._videos, _videos) && + const DeepCollectionEquality() + .equals(other._offlineVideos, _offlineVideos) && + const DeepCollectionEquality() + .equals(other._playedVideos, _playedVideos) && + const DeepCollectionEquality().equals(other.playQueue, playQueue) && + (identical(other.isAudio, isAudio) || other.isAudio == isAudio) && + (identical(other.isPip, isPip) || other.isPip == isPip) && + (identical(other.offset, offset) || other.offset == offset) && + (identical(other.startAt, startAt) || other.startAt == startAt) && + (identical(other.position, position) || + other.position == position) && + (identical(other.bufferedPosition, bufferedPosition) || + other.bufferedPosition == bufferedPosition) && + (identical(other.isPlaying, isPlaying) || + other.isPlaying == isPlaying) && + (identical(other.speed, speed) || other.speed == speed) && + (identical(other.mediaCommand, mediaCommand) || + other.mediaCommand == mediaCommand) && + (identical(other.mediaEvent, mediaEvent) || + other.mediaEvent == mediaEvent) && + const DeepCollectionEquality() + .equals(other._sponsorSegments, _sponsorSegments) && + (identical(other.nextSegment, nextSegment) || + other.nextSegment == nextSegment) && + (identical(other.forwardStep, forwardStep) || + other.forwardStep == forwardStep) && + const DeepCollectionEquality() + .equals(other.rewindStep, rewindStep) && + (identical(other.totalFastForward, totalFastForward) || + other.totalFastForward == totalFastForward) && + const DeepCollectionEquality() + .equals(other.totalRewind, totalRewind)); + } + + @override + int get hashCode => Object.hashAll([ + runtimeType, + isMini, + top, + isDragging, + selectedFullScreenIndex, + isHidden, + opacity, + dragDistance, + dragStartMini, + height, + fullScreenState, + muted, + aspectRatio, + currentlyPlaying, + offlineCurrentlyPlaying, + const DeepCollectionEquality().hash(_videos), + const DeepCollectionEquality().hash(_offlineVideos), + const DeepCollectionEquality().hash(_playedVideos), + const DeepCollectionEquality().hash(playQueue), + isAudio, + isPip, + offset, + startAt, + position, + bufferedPosition, + isPlaying, + speed, + mediaCommand, + mediaEvent, + const DeepCollectionEquality().hash(_sponsorSegments), + nextSegment, + forwardStep, + const DeepCollectionEquality().hash(rewindStep), + totalFastForward, + const DeepCollectionEquality().hash(totalRewind) + ]); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$PlayerStateImplCopyWith<_$PlayerStateImpl> get copyWith => + __$$PlayerStateImplCopyWithImpl<_$PlayerStateImpl>(this, _$identity); +} + +abstract class _PlayerState extends PlayerState { + const factory _PlayerState( + {final bool isMini, + final double? top, + final bool isDragging, + final int selectedFullScreenIndex, + final bool isHidden, + final double opacity, + final double dragDistance, + final bool dragStartMini, + final double height, + final FullScreenState fullScreenState, + final bool muted, + final double aspectRatio, + final Video? currentlyPlaying, + final DownloadedVideo? offlineCurrentlyPlaying, + final List videos, + final List offlineVideos, + final List playedVideos, + required final ListQueue playQueue, + final bool isAudio, + final bool isPip, + final Offset offset, + final Duration? startAt, + final Duration position, + final Duration bufferedPosition, + final bool isPlaying, + final double speed, + final MediaCommand? mediaCommand, + final MediaEvent mediaEvent, + final List> sponsorSegments, + final Pair nextSegment, + final int forwardStep, + final dynamic rewindStep, + final int totalFastForward, + final dynamic totalRewind}) = _$PlayerStateImpl; + const _PlayerState._() : super._(); + + @override // player display properties + bool get isMini; + @override + double? get top; + @override + bool get isDragging; + @override + int get selectedFullScreenIndex; + @override + bool get isHidden; + @override + double get opacity; + @override + double get dragDistance; + @override + bool get dragStartMini; + @override + double get height; + @override + FullScreenState get fullScreenState; + @override + bool get muted; + @override + double get aspectRatio; + @override // videos to play + Video? get currentlyPlaying; + @override + DownloadedVideo? get offlineCurrentlyPlaying; + @override + List get videos; + @override + List get offlineVideos; + @override // playlist controls + List get playedVideos; + @override + ListQueue get playQueue; + @override + bool get isAudio; + @override // playing video data + bool get isPip; + @override + Offset get offset; + @override + Duration? get startAt; + @override + Duration get position; + @override + Duration get bufferedPosition; + @override + bool get isPlaying; + @override + double get speed; + @override // events +// command we send down the stack, namely video / audio player + MediaCommand? get mediaCommand; + @override // events we receive from bottom of stack + MediaEvent get mediaEvent; + @override // sponsor block variables + List> get sponsorSegments; + @override + Pair get nextSegment; + @override // step in seconds when fast forawrd or fast rewind + int get forwardStep; + @override + dynamic get rewindStep; + @override + int get totalFastForward; + @override + dynamic get totalRewind; + @override + @JsonKey(ignore: true) + _$$PlayerStateImplCopyWith<_$PlayerStateImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/player/states/player.g.dart b/lib/player/states/player.g.dart deleted file mode 100644 index c6b024fe..00000000 --- a/lib/player/states/player.g.dart +++ /dev/null @@ -1,438 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'player.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$PlayerStateCWProxy { - PlayerState videos(List videos); - - PlayerState height(double height); - - PlayerState isMini(bool isMini); - - PlayerState top(double? top); - - PlayerState isDragging(bool isDragging); - - PlayerState selectedFullScreenIndex(int selectedFullScreenIndex); - - PlayerState isPip(bool isPip); - - PlayerState isHidden(bool isHidden); - - PlayerState speed(double speed); - - PlayerState currentlyPlaying(Video? currentlyPlaying); - - PlayerState offlineCurrentlyPlaying(DownloadedVideo? offlineCurrentlyPlaying); - - PlayerState opacity(double opacity); - - PlayerState aspectRatio(double aspectRatio); - - PlayerState dragDistance(double dragDistance); - - PlayerState dragStartMini(bool dragStartMini); - - PlayerState bufferedPosition(Duration bufferedPosition); - - PlayerState playedVideos(List playedVideos); - - PlayerState offset(Offset offset); - - PlayerState isAudio(bool isAudio); - - PlayerState startAt(Duration? startAt); - - PlayerState isPlaying(bool isPlaying); - - PlayerState sponsorSegments(List> sponsorSegments); - - PlayerState nextSegment(Pair nextSegment); - - PlayerState offlineVideos(List offlineVideos); - - PlayerState position(Duration position); - - PlayerState mediaCommand(MediaCommand? mediaCommand); - - PlayerState fullScreenState(FullScreenState fullScreenState); - - PlayerState muted(bool muted); - - PlayerState forwardStep(int forwardStep); - - PlayerState rewindStep(int rewindStep); - - PlayerState totalRewind(int totalRewind); - - PlayerState totalFastForward(int totalFastForward); - - PlayerState mediaEvent(MediaEvent mediaEvent); - - PlayerState playQueue(ListQueue playQueue); - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `PlayerState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// PlayerState(...).copyWith(id: 12, name: "My name") - /// ```` - PlayerState call({ - List? videos, - double? height, - bool? isMini, - double? top, - bool? isDragging, - int? selectedFullScreenIndex, - bool? isPip, - bool? isHidden, - double? speed, - Video? currentlyPlaying, - DownloadedVideo? offlineCurrentlyPlaying, - double? opacity, - double? aspectRatio, - double? dragDistance, - bool? dragStartMini, - Duration? bufferedPosition, - List? playedVideos, - Offset? offset, - bool? isAudio, - Duration? startAt, - bool? isPlaying, - List>? sponsorSegments, - Pair? nextSegment, - List? offlineVideos, - Duration? position, - MediaCommand? mediaCommand, - FullScreenState? fullScreenState, - bool? muted, - int? forwardStep, - int? rewindStep, - int? totalRewind, - int? totalFastForward, - MediaEvent? mediaEvent, - ListQueue? playQueue, - }); -} - -/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfPlayerState.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfPlayerState.copyWith.fieldName(...)` -class _$PlayerStateCWProxyImpl implements _$PlayerStateCWProxy { - const _$PlayerStateCWProxyImpl(this._value); - - final PlayerState _value; - - @override - PlayerState videos(List videos) => this(videos: videos); - - @override - PlayerState height(double height) => this(height: height); - - @override - PlayerState isMini(bool isMini) => this(isMini: isMini); - - @override - PlayerState top(double? top) => this(top: top); - - @override - PlayerState isDragging(bool isDragging) => this(isDragging: isDragging); - - @override - PlayerState selectedFullScreenIndex(int selectedFullScreenIndex) => - this(selectedFullScreenIndex: selectedFullScreenIndex); - - @override - PlayerState isPip(bool isPip) => this(isPip: isPip); - - @override - PlayerState isHidden(bool isHidden) => this(isHidden: isHidden); - - @override - PlayerState speed(double speed) => this(speed: speed); - - @override - PlayerState currentlyPlaying(Video? currentlyPlaying) => - this(currentlyPlaying: currentlyPlaying); - - @override - PlayerState offlineCurrentlyPlaying( - DownloadedVideo? offlineCurrentlyPlaying) => - this(offlineCurrentlyPlaying: offlineCurrentlyPlaying); - - @override - PlayerState opacity(double opacity) => this(opacity: opacity); - - @override - PlayerState aspectRatio(double aspectRatio) => this(aspectRatio: aspectRatio); - - @override - PlayerState dragDistance(double dragDistance) => - this(dragDistance: dragDistance); - - @override - PlayerState dragStartMini(bool dragStartMini) => - this(dragStartMini: dragStartMini); - - @override - PlayerState bufferedPosition(Duration bufferedPosition) => - this(bufferedPosition: bufferedPosition); - - @override - PlayerState playedVideos(List playedVideos) => - this(playedVideos: playedVideos); - - @override - PlayerState offset(Offset offset) => this(offset: offset); - - @override - PlayerState isAudio(bool isAudio) => this(isAudio: isAudio); - - @override - PlayerState startAt(Duration? startAt) => this(startAt: startAt); - - @override - PlayerState isPlaying(bool isPlaying) => this(isPlaying: isPlaying); - - @override - PlayerState sponsorSegments(List> sponsorSegments) => - this(sponsorSegments: sponsorSegments); - - @override - PlayerState nextSegment(Pair nextSegment) => - this(nextSegment: nextSegment); - - @override - PlayerState offlineVideos(List offlineVideos) => - this(offlineVideos: offlineVideos); - - @override - PlayerState position(Duration position) => this(position: position); - - @override - PlayerState mediaCommand(MediaCommand? mediaCommand) => - this(mediaCommand: mediaCommand); - - @override - PlayerState fullScreenState(FullScreenState fullScreenState) => - this(fullScreenState: fullScreenState); - - @override - PlayerState muted(bool muted) => this(muted: muted); - - @override - PlayerState forwardStep(int forwardStep) => this(forwardStep: forwardStep); - - @override - PlayerState rewindStep(int rewindStep) => this(rewindStep: rewindStep); - - @override - PlayerState totalRewind(int totalRewind) => this(totalRewind: totalRewind); - - @override - PlayerState totalFastForward(int totalFastForward) => - this(totalFastForward: totalFastForward); - - @override - PlayerState mediaEvent(MediaEvent mediaEvent) => - this(mediaEvent: mediaEvent); - - @override - PlayerState playQueue(ListQueue playQueue) => - this(playQueue: playQueue); - - @override - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `PlayerState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// PlayerState(...).copyWith(id: 12, name: "My name") - /// ```` - PlayerState call({ - Object? videos = const $CopyWithPlaceholder(), - Object? height = const $CopyWithPlaceholder(), - Object? isMini = const $CopyWithPlaceholder(), - Object? top = const $CopyWithPlaceholder(), - Object? isDragging = const $CopyWithPlaceholder(), - Object? selectedFullScreenIndex = const $CopyWithPlaceholder(), - Object? isPip = const $CopyWithPlaceholder(), - Object? isHidden = const $CopyWithPlaceholder(), - Object? speed = const $CopyWithPlaceholder(), - Object? currentlyPlaying = const $CopyWithPlaceholder(), - Object? offlineCurrentlyPlaying = const $CopyWithPlaceholder(), - Object? opacity = const $CopyWithPlaceholder(), - Object? aspectRatio = const $CopyWithPlaceholder(), - Object? dragDistance = const $CopyWithPlaceholder(), - Object? dragStartMini = const $CopyWithPlaceholder(), - Object? bufferedPosition = const $CopyWithPlaceholder(), - Object? playedVideos = const $CopyWithPlaceholder(), - Object? offset = const $CopyWithPlaceholder(), - Object? isAudio = const $CopyWithPlaceholder(), - Object? startAt = const $CopyWithPlaceholder(), - Object? isPlaying = const $CopyWithPlaceholder(), - Object? sponsorSegments = const $CopyWithPlaceholder(), - Object? nextSegment = const $CopyWithPlaceholder(), - Object? offlineVideos = const $CopyWithPlaceholder(), - Object? position = const $CopyWithPlaceholder(), - Object? mediaCommand = const $CopyWithPlaceholder(), - Object? fullScreenState = const $CopyWithPlaceholder(), - Object? muted = const $CopyWithPlaceholder(), - Object? forwardStep = const $CopyWithPlaceholder(), - Object? rewindStep = const $CopyWithPlaceholder(), - Object? totalRewind = const $CopyWithPlaceholder(), - Object? totalFastForward = const $CopyWithPlaceholder(), - Object? mediaEvent = const $CopyWithPlaceholder(), - Object? playQueue = const $CopyWithPlaceholder(), - }) { - return PlayerState._( - videos == const $CopyWithPlaceholder() || videos == null - ? _value.videos - // ignore: cast_nullable_to_non_nullable - : videos as List, - height == const $CopyWithPlaceholder() || height == null - ? _value.height - // ignore: cast_nullable_to_non_nullable - : height as double, - isMini == const $CopyWithPlaceholder() || isMini == null - ? _value.isMini - // ignore: cast_nullable_to_non_nullable - : isMini as bool, - top == const $CopyWithPlaceholder() - ? _value.top - // ignore: cast_nullable_to_non_nullable - : top as double?, - isDragging == const $CopyWithPlaceholder() || isDragging == null - ? _value.isDragging - // ignore: cast_nullable_to_non_nullable - : isDragging as bool, - selectedFullScreenIndex == const $CopyWithPlaceholder() || - selectedFullScreenIndex == null - ? _value.selectedFullScreenIndex - // ignore: cast_nullable_to_non_nullable - : selectedFullScreenIndex as int, - isPip == const $CopyWithPlaceholder() || isPip == null - ? _value.isPip - // ignore: cast_nullable_to_non_nullable - : isPip as bool, - isHidden == const $CopyWithPlaceholder() || isHidden == null - ? _value.isHidden - // ignore: cast_nullable_to_non_nullable - : isHidden as bool, - speed == const $CopyWithPlaceholder() || speed == null - ? _value.speed - // ignore: cast_nullable_to_non_nullable - : speed as double, - currentlyPlaying == const $CopyWithPlaceholder() - ? _value.currentlyPlaying - // ignore: cast_nullable_to_non_nullable - : currentlyPlaying as Video?, - offlineCurrentlyPlaying == const $CopyWithPlaceholder() - ? _value.offlineCurrentlyPlaying - // ignore: cast_nullable_to_non_nullable - : offlineCurrentlyPlaying as DownloadedVideo?, - opacity == const $CopyWithPlaceholder() || opacity == null - ? _value.opacity - // ignore: cast_nullable_to_non_nullable - : opacity as double, - aspectRatio == const $CopyWithPlaceholder() || aspectRatio == null - ? _value.aspectRatio - // ignore: cast_nullable_to_non_nullable - : aspectRatio as double, - dragDistance == const $CopyWithPlaceholder() || dragDistance == null - ? _value.dragDistance - // ignore: cast_nullable_to_non_nullable - : dragDistance as double, - dragStartMini == const $CopyWithPlaceholder() || dragStartMini == null - ? _value.dragStartMini - // ignore: cast_nullable_to_non_nullable - : dragStartMini as bool, - bufferedPosition == const $CopyWithPlaceholder() || - bufferedPosition == null - ? _value.bufferedPosition - // ignore: cast_nullable_to_non_nullable - : bufferedPosition as Duration, - playedVideos == const $CopyWithPlaceholder() || playedVideos == null - ? _value.playedVideos - // ignore: cast_nullable_to_non_nullable - : playedVideos as List, - offset == const $CopyWithPlaceholder() || offset == null - ? _value.offset - // ignore: cast_nullable_to_non_nullable - : offset as Offset, - isAudio == const $CopyWithPlaceholder() || isAudio == null - ? _value.isAudio - // ignore: cast_nullable_to_non_nullable - : isAudio as bool, - startAt == const $CopyWithPlaceholder() - ? _value.startAt - // ignore: cast_nullable_to_non_nullable - : startAt as Duration?, - isPlaying == const $CopyWithPlaceholder() || isPlaying == null - ? _value.isPlaying - // ignore: cast_nullable_to_non_nullable - : isPlaying as bool, - sponsorSegments == const $CopyWithPlaceholder() || sponsorSegments == null - ? _value.sponsorSegments - // ignore: cast_nullable_to_non_nullable - : sponsorSegments as List>, - nextSegment == const $CopyWithPlaceholder() || nextSegment == null - ? _value.nextSegment - // ignore: cast_nullable_to_non_nullable - : nextSegment as Pair, - offlineVideos == const $CopyWithPlaceholder() || offlineVideos == null - ? _value.offlineVideos - // ignore: cast_nullable_to_non_nullable - : offlineVideos as List, - position == const $CopyWithPlaceholder() || position == null - ? _value.position - // ignore: cast_nullable_to_non_nullable - : position as Duration, - mediaCommand == const $CopyWithPlaceholder() - ? _value.mediaCommand - // ignore: cast_nullable_to_non_nullable - : mediaCommand as MediaCommand?, - fullScreenState == const $CopyWithPlaceholder() || fullScreenState == null - ? _value.fullScreenState - // ignore: cast_nullable_to_non_nullable - : fullScreenState as FullScreenState, - muted == const $CopyWithPlaceholder() || muted == null - ? _value.muted - // ignore: cast_nullable_to_non_nullable - : muted as bool, - forwardStep == const $CopyWithPlaceholder() || forwardStep == null - ? _value.forwardStep - // ignore: cast_nullable_to_non_nullable - : forwardStep as int, - rewindStep == const $CopyWithPlaceholder() || rewindStep == null - ? _value.rewindStep - // ignore: cast_nullable_to_non_nullable - : rewindStep as int, - totalRewind == const $CopyWithPlaceholder() || totalRewind == null - ? _value.totalRewind - // ignore: cast_nullable_to_non_nullable - : totalRewind as int, - totalFastForward == const $CopyWithPlaceholder() || - totalFastForward == null - ? _value.totalFastForward - // ignore: cast_nullable_to_non_nullable - : totalFastForward as int, - mediaEvent == const $CopyWithPlaceholder() || mediaEvent == null - ? _value.mediaEvent - // ignore: cast_nullable_to_non_nullable - : mediaEvent as MediaEvent, - playQueue == const $CopyWithPlaceholder() || playQueue == null - ? _value.playQueue - // ignore: cast_nullable_to_non_nullable - : playQueue as ListQueue, - ); - } -} - -extension $PlayerStateCopyWith on PlayerState { - /// Returns a callable class that can be used as follows: `instanceOfPlayerState.copyWith(...)` or like so:`instanceOfPlayerState.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$PlayerStateCWProxy get copyWith => _$PlayerStateCWProxyImpl(this); -} diff --git a/lib/player/states/player_controls.dart b/lib/player/states/player_controls.dart index 914d2dde..9ab3f677 100644 --- a/lib/player/states/player_controls.dart +++ b/lib/player/states/player_controls.dart @@ -1,6 +1,6 @@ import 'package:bloc/bloc.dart'; -import 'package:copy_with_extension/copy_with_extension.dart'; import 'package:easy_debounce/easy_debounce.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:invidious/player/models/mediaEvent.dart'; import 'package:invidious/player/states/interfaces/media_player.dart'; import 'package:logging/logging.dart'; @@ -9,7 +9,7 @@ import '../../globals.dart'; import '../../main.dart'; import 'player.dart'; -part 'player_controls.g.dart'; +part 'player_controls.freezed.dart'; final log = Logger('PlayerControlControllers'); @@ -23,8 +23,7 @@ class PlayerControlsCubit extends Cubit { void onReady() { log.fine("Controls ready!"); - emit(state.copyWith( - duration: player.duration, muted: player.state.muted, fullScreenState: player.state.fullScreenState)); + emit(state.copyWith(duration: player.duration, muted: player.state.muted, fullScreenState: player.state.fullScreenState)); showControls(); } @@ -174,44 +173,28 @@ class PlayerControlsCubit extends Cubit { EasyDebounce.debounce('fast-rewind', const Duration(milliseconds: 250), () { emit(state.copyWith(doubleTapRewindedOpacity: 0)); }); - EasyDebounce.debounce('preventControlsShowing', Duration(seconds: 1), () { + EasyDebounce.debounce('preventControlsShowing', const Duration(seconds: 1), () { // we prevent controls showing to avoid issues where if hte user taps 3 times it will show the controls right after emit(state.copyWith(justDoubleTappedSkip: false)); }); } } -@CopyWith(constructor: "_") -class PlayerControlsState { - PlayerControlsState(); - - bool errored = false; - - Duration position = Duration.zero; - Duration duration = const Duration(seconds: 1); - Duration buffer = Duration.zero; - FullScreenState fullScreenState = FullScreenState.notFullScreen; - bool displayControls = false; - bool muted = false; - bool buffering = false; - bool draggingPositionSlider = false; - double doubleTapFastForwardedOpacity = 0; - double doubleTapRewindedOpacity = 0; - bool justDoubleTappedSkip = false; - bool showSponsorBlocked = false; - - PlayerControlsState._( - this.buffering, - this.justDoubleTappedSkip, - this.position, - this.displayControls, - this.errored, - this.duration, - this.fullScreenState, - this.muted, - this.buffer, - this.draggingPositionSlider, - this.doubleTapFastForwardedOpacity, - this.doubleTapRewindedOpacity, - this.showSponsorBlocked); +@freezed +class PlayerControlsState with _$PlayerControlsState { + const factory PlayerControlsState({ + @Default(false) bool errored, + @Default(Duration.zero) Duration position, + @Default(Duration(seconds: 1)) Duration duration, + @Default(Duration.zero) Duration buffer, + @Default(FullScreenState.notFullScreen) FullScreenState fullScreenState, + @Default(false) bool displayControls, + @Default(false) bool muted, + @Default(false) bool buffering, + @Default(false) bool draggingPositionSlider, + @Default(0) double doubleTapFastForwardedOpacity, + @Default(0) double doubleTapRewindedOpacity, + @Default(false) bool justDoubleTappedSkip, + @Default(false) bool showSponsorBlocked, + }) = _PlayercontrolsState; } diff --git a/lib/player/states/player_controls.freezed.dart b/lib/player/states/player_controls.freezed.dart new file mode 100644 index 00000000..fcda59f7 --- /dev/null +++ b/lib/player/states/player_controls.freezed.dart @@ -0,0 +1,418 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'player_controls.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +mixin _$PlayerControlsState { + bool get errored => throw _privateConstructorUsedError; + Duration get position => throw _privateConstructorUsedError; + Duration get duration => throw _privateConstructorUsedError; + Duration get buffer => throw _privateConstructorUsedError; + FullScreenState get fullScreenState => throw _privateConstructorUsedError; + bool get displayControls => throw _privateConstructorUsedError; + bool get muted => throw _privateConstructorUsedError; + bool get buffering => throw _privateConstructorUsedError; + bool get draggingPositionSlider => throw _privateConstructorUsedError; + double get doubleTapFastForwardedOpacity => + throw _privateConstructorUsedError; + double get doubleTapRewindedOpacity => throw _privateConstructorUsedError; + bool get justDoubleTappedSkip => throw _privateConstructorUsedError; + bool get showSponsorBlocked => throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + $PlayerControlsStateCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $PlayerControlsStateCopyWith<$Res> { + factory $PlayerControlsStateCopyWith( + PlayerControlsState value, $Res Function(PlayerControlsState) then) = + _$PlayerControlsStateCopyWithImpl<$Res, PlayerControlsState>; + @useResult + $Res call( + {bool errored, + Duration position, + Duration duration, + Duration buffer, + FullScreenState fullScreenState, + bool displayControls, + bool muted, + bool buffering, + bool draggingPositionSlider, + double doubleTapFastForwardedOpacity, + double doubleTapRewindedOpacity, + bool justDoubleTappedSkip, + bool showSponsorBlocked}); +} + +/// @nodoc +class _$PlayerControlsStateCopyWithImpl<$Res, $Val extends PlayerControlsState> + implements $PlayerControlsStateCopyWith<$Res> { + _$PlayerControlsStateCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? errored = null, + Object? position = null, + Object? duration = null, + Object? buffer = null, + Object? fullScreenState = null, + Object? displayControls = null, + Object? muted = null, + Object? buffering = null, + Object? draggingPositionSlider = null, + Object? doubleTapFastForwardedOpacity = null, + Object? doubleTapRewindedOpacity = null, + Object? justDoubleTappedSkip = null, + Object? showSponsorBlocked = null, + }) { + return _then(_value.copyWith( + errored: null == errored + ? _value.errored + : errored // ignore: cast_nullable_to_non_nullable + as bool, + position: null == position + ? _value.position + : position // ignore: cast_nullable_to_non_nullable + as Duration, + duration: null == duration + ? _value.duration + : duration // ignore: cast_nullable_to_non_nullable + as Duration, + buffer: null == buffer + ? _value.buffer + : buffer // ignore: cast_nullable_to_non_nullable + as Duration, + fullScreenState: null == fullScreenState + ? _value.fullScreenState + : fullScreenState // ignore: cast_nullable_to_non_nullable + as FullScreenState, + displayControls: null == displayControls + ? _value.displayControls + : displayControls // ignore: cast_nullable_to_non_nullable + as bool, + muted: null == muted + ? _value.muted + : muted // ignore: cast_nullable_to_non_nullable + as bool, + buffering: null == buffering + ? _value.buffering + : buffering // ignore: cast_nullable_to_non_nullable + as bool, + draggingPositionSlider: null == draggingPositionSlider + ? _value.draggingPositionSlider + : draggingPositionSlider // ignore: cast_nullable_to_non_nullable + as bool, + doubleTapFastForwardedOpacity: null == doubleTapFastForwardedOpacity + ? _value.doubleTapFastForwardedOpacity + : doubleTapFastForwardedOpacity // ignore: cast_nullable_to_non_nullable + as double, + doubleTapRewindedOpacity: null == doubleTapRewindedOpacity + ? _value.doubleTapRewindedOpacity + : doubleTapRewindedOpacity // ignore: cast_nullable_to_non_nullable + as double, + justDoubleTappedSkip: null == justDoubleTappedSkip + ? _value.justDoubleTappedSkip + : justDoubleTappedSkip // ignore: cast_nullable_to_non_nullable + as bool, + showSponsorBlocked: null == showSponsorBlocked + ? _value.showSponsorBlocked + : showSponsorBlocked // ignore: cast_nullable_to_non_nullable + as bool, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$PlayercontrolsStateImplCopyWith<$Res> + implements $PlayerControlsStateCopyWith<$Res> { + factory _$$PlayercontrolsStateImplCopyWith(_$PlayercontrolsStateImpl value, + $Res Function(_$PlayercontrolsStateImpl) then) = + __$$PlayercontrolsStateImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {bool errored, + Duration position, + Duration duration, + Duration buffer, + FullScreenState fullScreenState, + bool displayControls, + bool muted, + bool buffering, + bool draggingPositionSlider, + double doubleTapFastForwardedOpacity, + double doubleTapRewindedOpacity, + bool justDoubleTappedSkip, + bool showSponsorBlocked}); +} + +/// @nodoc +class __$$PlayercontrolsStateImplCopyWithImpl<$Res> + extends _$PlayerControlsStateCopyWithImpl<$Res, _$PlayercontrolsStateImpl> + implements _$$PlayercontrolsStateImplCopyWith<$Res> { + __$$PlayercontrolsStateImplCopyWithImpl(_$PlayercontrolsStateImpl _value, + $Res Function(_$PlayercontrolsStateImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? errored = null, + Object? position = null, + Object? duration = null, + Object? buffer = null, + Object? fullScreenState = null, + Object? displayControls = null, + Object? muted = null, + Object? buffering = null, + Object? draggingPositionSlider = null, + Object? doubleTapFastForwardedOpacity = null, + Object? doubleTapRewindedOpacity = null, + Object? justDoubleTappedSkip = null, + Object? showSponsorBlocked = null, + }) { + return _then(_$PlayercontrolsStateImpl( + errored: null == errored + ? _value.errored + : errored // ignore: cast_nullable_to_non_nullable + as bool, + position: null == position + ? _value.position + : position // ignore: cast_nullable_to_non_nullable + as Duration, + duration: null == duration + ? _value.duration + : duration // ignore: cast_nullable_to_non_nullable + as Duration, + buffer: null == buffer + ? _value.buffer + : buffer // ignore: cast_nullable_to_non_nullable + as Duration, + fullScreenState: null == fullScreenState + ? _value.fullScreenState + : fullScreenState // ignore: cast_nullable_to_non_nullable + as FullScreenState, + displayControls: null == displayControls + ? _value.displayControls + : displayControls // ignore: cast_nullable_to_non_nullable + as bool, + muted: null == muted + ? _value.muted + : muted // ignore: cast_nullable_to_non_nullable + as bool, + buffering: null == buffering + ? _value.buffering + : buffering // ignore: cast_nullable_to_non_nullable + as bool, + draggingPositionSlider: null == draggingPositionSlider + ? _value.draggingPositionSlider + : draggingPositionSlider // ignore: cast_nullable_to_non_nullable + as bool, + doubleTapFastForwardedOpacity: null == doubleTapFastForwardedOpacity + ? _value.doubleTapFastForwardedOpacity + : doubleTapFastForwardedOpacity // ignore: cast_nullable_to_non_nullable + as double, + doubleTapRewindedOpacity: null == doubleTapRewindedOpacity + ? _value.doubleTapRewindedOpacity + : doubleTapRewindedOpacity // ignore: cast_nullable_to_non_nullable + as double, + justDoubleTappedSkip: null == justDoubleTappedSkip + ? _value.justDoubleTappedSkip + : justDoubleTappedSkip // ignore: cast_nullable_to_non_nullable + as bool, + showSponsorBlocked: null == showSponsorBlocked + ? _value.showSponsorBlocked + : showSponsorBlocked // ignore: cast_nullable_to_non_nullable + as bool, + )); + } +} + +/// @nodoc + +class _$PlayercontrolsStateImpl implements _PlayercontrolsState { + const _$PlayercontrolsStateImpl( + {this.errored = false, + this.position = Duration.zero, + this.duration = const Duration(seconds: 1), + this.buffer = Duration.zero, + this.fullScreenState = FullScreenState.notFullScreen, + this.displayControls = false, + this.muted = false, + this.buffering = false, + this.draggingPositionSlider = false, + this.doubleTapFastForwardedOpacity = 0, + this.doubleTapRewindedOpacity = 0, + this.justDoubleTappedSkip = false, + this.showSponsorBlocked = false}); + + @override + @JsonKey() + final bool errored; + @override + @JsonKey() + final Duration position; + @override + @JsonKey() + final Duration duration; + @override + @JsonKey() + final Duration buffer; + @override + @JsonKey() + final FullScreenState fullScreenState; + @override + @JsonKey() + final bool displayControls; + @override + @JsonKey() + final bool muted; + @override + @JsonKey() + final bool buffering; + @override + @JsonKey() + final bool draggingPositionSlider; + @override + @JsonKey() + final double doubleTapFastForwardedOpacity; + @override + @JsonKey() + final double doubleTapRewindedOpacity; + @override + @JsonKey() + final bool justDoubleTappedSkip; + @override + @JsonKey() + final bool showSponsorBlocked; + + @override + String toString() { + return 'PlayerControlsState(errored: $errored, position: $position, duration: $duration, buffer: $buffer, fullScreenState: $fullScreenState, displayControls: $displayControls, muted: $muted, buffering: $buffering, draggingPositionSlider: $draggingPositionSlider, doubleTapFastForwardedOpacity: $doubleTapFastForwardedOpacity, doubleTapRewindedOpacity: $doubleTapRewindedOpacity, justDoubleTappedSkip: $justDoubleTappedSkip, showSponsorBlocked: $showSponsorBlocked)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$PlayercontrolsStateImpl && + (identical(other.errored, errored) || other.errored == errored) && + (identical(other.position, position) || + other.position == position) && + (identical(other.duration, duration) || + other.duration == duration) && + (identical(other.buffer, buffer) || other.buffer == buffer) && + (identical(other.fullScreenState, fullScreenState) || + other.fullScreenState == fullScreenState) && + (identical(other.displayControls, displayControls) || + other.displayControls == displayControls) && + (identical(other.muted, muted) || other.muted == muted) && + (identical(other.buffering, buffering) || + other.buffering == buffering) && + (identical(other.draggingPositionSlider, draggingPositionSlider) || + other.draggingPositionSlider == draggingPositionSlider) && + (identical(other.doubleTapFastForwardedOpacity, + doubleTapFastForwardedOpacity) || + other.doubleTapFastForwardedOpacity == + doubleTapFastForwardedOpacity) && + (identical( + other.doubleTapRewindedOpacity, doubleTapRewindedOpacity) || + other.doubleTapRewindedOpacity == doubleTapRewindedOpacity) && + (identical(other.justDoubleTappedSkip, justDoubleTappedSkip) || + other.justDoubleTappedSkip == justDoubleTappedSkip) && + (identical(other.showSponsorBlocked, showSponsorBlocked) || + other.showSponsorBlocked == showSponsorBlocked)); + } + + @override + int get hashCode => Object.hash( + runtimeType, + errored, + position, + duration, + buffer, + fullScreenState, + displayControls, + muted, + buffering, + draggingPositionSlider, + doubleTapFastForwardedOpacity, + doubleTapRewindedOpacity, + justDoubleTappedSkip, + showSponsorBlocked); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$PlayercontrolsStateImplCopyWith<_$PlayercontrolsStateImpl> get copyWith => + __$$PlayercontrolsStateImplCopyWithImpl<_$PlayercontrolsStateImpl>( + this, _$identity); +} + +abstract class _PlayercontrolsState implements PlayerControlsState { + const factory _PlayercontrolsState( + {final bool errored, + final Duration position, + final Duration duration, + final Duration buffer, + final FullScreenState fullScreenState, + final bool displayControls, + final bool muted, + final bool buffering, + final bool draggingPositionSlider, + final double doubleTapFastForwardedOpacity, + final double doubleTapRewindedOpacity, + final bool justDoubleTappedSkip, + final bool showSponsorBlocked}) = _$PlayercontrolsStateImpl; + + @override + bool get errored; + @override + Duration get position; + @override + Duration get duration; + @override + Duration get buffer; + @override + FullScreenState get fullScreenState; + @override + bool get displayControls; + @override + bool get muted; + @override + bool get buffering; + @override + bool get draggingPositionSlider; + @override + double get doubleTapFastForwardedOpacity; + @override + double get doubleTapRewindedOpacity; + @override + bool get justDoubleTappedSkip; + @override + bool get showSponsorBlocked; + @override + @JsonKey(ignore: true) + _$$PlayercontrolsStateImplCopyWith<_$PlayercontrolsStateImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/player/states/player_controls.g.dart b/lib/player/states/player_controls.g.dart deleted file mode 100644 index 29ed8272..00000000 --- a/lib/player/states/player_controls.g.dart +++ /dev/null @@ -1,204 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'player_controls.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$PlayerControlsStateCWProxy { - PlayerControlsState buffering(bool buffering); - - PlayerControlsState justDoubleTappedSkip(bool justDoubleTappedSkip); - - PlayerControlsState position(Duration position); - - PlayerControlsState displayControls(bool displayControls); - - PlayerControlsState errored(bool errored); - - PlayerControlsState duration(Duration duration); - - PlayerControlsState fullScreenState(FullScreenState fullScreenState); - - PlayerControlsState muted(bool muted); - - PlayerControlsState buffer(Duration buffer); - - PlayerControlsState draggingPositionSlider(bool draggingPositionSlider); - - PlayerControlsState doubleTapFastForwardedOpacity( - double doubleTapFastForwardedOpacity); - - PlayerControlsState doubleTapRewindedOpacity(double doubleTapRewindedOpacity); - - PlayerControlsState showSponsorBlocked(bool showSponsorBlocked); - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `PlayerControlsState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// PlayerControlsState(...).copyWith(id: 12, name: "My name") - /// ```` - PlayerControlsState call({ - bool? buffering, - bool? justDoubleTappedSkip, - Duration? position, - bool? displayControls, - bool? errored, - Duration? duration, - FullScreenState? fullScreenState, - bool? muted, - Duration? buffer, - bool? draggingPositionSlider, - double? doubleTapFastForwardedOpacity, - double? doubleTapRewindedOpacity, - bool? showSponsorBlocked, - }); -} - -/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfPlayerControlsState.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfPlayerControlsState.copyWith.fieldName(...)` -class _$PlayerControlsStateCWProxyImpl implements _$PlayerControlsStateCWProxy { - const _$PlayerControlsStateCWProxyImpl(this._value); - - final PlayerControlsState _value; - - @override - PlayerControlsState buffering(bool buffering) => this(buffering: buffering); - - @override - PlayerControlsState justDoubleTappedSkip(bool justDoubleTappedSkip) => - this(justDoubleTappedSkip: justDoubleTappedSkip); - - @override - PlayerControlsState position(Duration position) => this(position: position); - - @override - PlayerControlsState displayControls(bool displayControls) => - this(displayControls: displayControls); - - @override - PlayerControlsState errored(bool errored) => this(errored: errored); - - @override - PlayerControlsState duration(Duration duration) => this(duration: duration); - - @override - PlayerControlsState fullScreenState(FullScreenState fullScreenState) => - this(fullScreenState: fullScreenState); - - @override - PlayerControlsState muted(bool muted) => this(muted: muted); - - @override - PlayerControlsState buffer(Duration buffer) => this(buffer: buffer); - - @override - PlayerControlsState draggingPositionSlider(bool draggingPositionSlider) => - this(draggingPositionSlider: draggingPositionSlider); - - @override - PlayerControlsState doubleTapFastForwardedOpacity( - double doubleTapFastForwardedOpacity) => - this(doubleTapFastForwardedOpacity: doubleTapFastForwardedOpacity); - - @override - PlayerControlsState doubleTapRewindedOpacity( - double doubleTapRewindedOpacity) => - this(doubleTapRewindedOpacity: doubleTapRewindedOpacity); - - @override - PlayerControlsState showSponsorBlocked(bool showSponsorBlocked) => - this(showSponsorBlocked: showSponsorBlocked); - - @override - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `PlayerControlsState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// PlayerControlsState(...).copyWith(id: 12, name: "My name") - /// ```` - PlayerControlsState call({ - Object? buffering = const $CopyWithPlaceholder(), - Object? justDoubleTappedSkip = const $CopyWithPlaceholder(), - Object? position = const $CopyWithPlaceholder(), - Object? displayControls = const $CopyWithPlaceholder(), - Object? errored = const $CopyWithPlaceholder(), - Object? duration = const $CopyWithPlaceholder(), - Object? fullScreenState = const $CopyWithPlaceholder(), - Object? muted = const $CopyWithPlaceholder(), - Object? buffer = const $CopyWithPlaceholder(), - Object? draggingPositionSlider = const $CopyWithPlaceholder(), - Object? doubleTapFastForwardedOpacity = const $CopyWithPlaceholder(), - Object? doubleTapRewindedOpacity = const $CopyWithPlaceholder(), - Object? showSponsorBlocked = const $CopyWithPlaceholder(), - }) { - return PlayerControlsState._( - buffering == const $CopyWithPlaceholder() || buffering == null - ? _value.buffering - // ignore: cast_nullable_to_non_nullable - : buffering as bool, - justDoubleTappedSkip == const $CopyWithPlaceholder() || - justDoubleTappedSkip == null - ? _value.justDoubleTappedSkip - // ignore: cast_nullable_to_non_nullable - : justDoubleTappedSkip as bool, - position == const $CopyWithPlaceholder() || position == null - ? _value.position - // ignore: cast_nullable_to_non_nullable - : position as Duration, - displayControls == const $CopyWithPlaceholder() || displayControls == null - ? _value.displayControls - // ignore: cast_nullable_to_non_nullable - : displayControls as bool, - errored == const $CopyWithPlaceholder() || errored == null - ? _value.errored - // ignore: cast_nullable_to_non_nullable - : errored as bool, - duration == const $CopyWithPlaceholder() || duration == null - ? _value.duration - // ignore: cast_nullable_to_non_nullable - : duration as Duration, - fullScreenState == const $CopyWithPlaceholder() || fullScreenState == null - ? _value.fullScreenState - // ignore: cast_nullable_to_non_nullable - : fullScreenState as FullScreenState, - muted == const $CopyWithPlaceholder() || muted == null - ? _value.muted - // ignore: cast_nullable_to_non_nullable - : muted as bool, - buffer == const $CopyWithPlaceholder() || buffer == null - ? _value.buffer - // ignore: cast_nullable_to_non_nullable - : buffer as Duration, - draggingPositionSlider == const $CopyWithPlaceholder() || - draggingPositionSlider == null - ? _value.draggingPositionSlider - // ignore: cast_nullable_to_non_nullable - : draggingPositionSlider as bool, - doubleTapFastForwardedOpacity == const $CopyWithPlaceholder() || - doubleTapFastForwardedOpacity == null - ? _value.doubleTapFastForwardedOpacity - // ignore: cast_nullable_to_non_nullable - : doubleTapFastForwardedOpacity as double, - doubleTapRewindedOpacity == const $CopyWithPlaceholder() || - doubleTapRewindedOpacity == null - ? _value.doubleTapRewindedOpacity - // ignore: cast_nullable_to_non_nullable - : doubleTapRewindedOpacity as double, - showSponsorBlocked == const $CopyWithPlaceholder() || - showSponsorBlocked == null - ? _value.showSponsorBlocked - // ignore: cast_nullable_to_non_nullable - : showSponsorBlocked as bool, - ); - } -} - -extension $PlayerControlsStateCopyWith on PlayerControlsState { - /// Returns a callable class that can be used as follows: `instanceOfPlayerControlsState.copyWith(...)` or like so:`instanceOfPlayerControlsState.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$PlayerControlsStateCWProxy get copyWith => - _$PlayerControlsStateCWProxyImpl(this); -} diff --git a/lib/player/states/tv_player_controls.dart b/lib/player/states/tv_player_controls.dart index 502a0752..64935cfe 100644 --- a/lib/player/states/tv_player_controls.dart +++ b/lib/player/states/tv_player_controls.dart @@ -1,9 +1,9 @@ import 'package:bloc/bloc.dart'; -import 'package:copy_with_extension/copy_with_extension.dart'; import 'package:easy_debounce/easy_debounce.dart'; import 'package:easy_debounce/easy_throttle.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:invidious/player/states/player.dart'; import 'package:logging/logging.dart'; @@ -11,7 +11,7 @@ import '../../utils.dart'; import '../../videos/models/video_in_list.dart'; import '../models/mediaEvent.dart'; -part 'tv_player_controls.g.dart'; +part 'tv_player_controls.freezed.dart'; const Duration controlFadeOut = Duration(seconds: 4); const Duration throttleDuration = Duration(milliseconds: 250); @@ -32,38 +32,22 @@ class TvPlayerControlsCubit extends Cubit { } displaySettings() { - var state = this.state.copyWith(); - state.showSettings = true; - state.displayControls = false; - emit(state); + emit(state.copyWith(showSettings: true, displayControls: false)); } showUi() { - var state = this.state.copyWith(); - state.controlsOpacity = 1; - emit(state); + emit(state.copyWith(controlsOpacity: 1)); hideControls(); } KeyEventResult handleRemoteEvents(FocusNode node, KeyEvent event) { bool timeLineControl = !state.showQueue && !state.showSettings && !state.displayControls; - log.fine( - 'Key: ${event.logicalKey}, Timeline control: $timeLineControl, showQueue: ${state.showQueue}, showSettings: ${state.showSettings}, showControls: ${state.displayControls}'); + log.fine('Key: ${event.logicalKey}, Timeline control: $timeLineControl, showQueue: ${state.showQueue}, showSettings: ${state.showSettings}, showControls: ${state.displayControls}'); showUi(); // looks like back is activate on pressdown and not press up if (event is KeyUpEvent && !timeLineControl && event.logicalKey == LogicalKeyboardKey.goBack) { - var state = this.state.copyWith(); - if (state.showQueue || state.showSettings) { - state.showQueue = false; - state.showSettings = false; - state.displayControls = true; - } else { - state.showQueue = false; - state.showSettings = false; - state.displayControls = false; - } - emit(state); + emit(state.copyWith(showQueue: false, showSettings: false, displayControls: state.showQueue || state.showSettings)); return KeyEventResult.handled; } else if (event is KeyUpEvent) { switch (event.logicalKey) { @@ -101,9 +85,7 @@ class TvPlayerControlsCubit extends Cubit { } else if (event.logicalKey == LogicalKeyboardKey.arrowLeft) { fastRewind(); } else if (isOk(event.logicalKey)) { - var state = this.state.copyWith(); - state.displayControls = true; - emit(state); + emit(state.copyWith(displayControls: true)); } } else {} } @@ -122,38 +104,24 @@ class TvPlayerControlsCubit extends Cubit { hideControls() { EasyDebounce.debounce('tv-controls', controlFadeOut, () { - var state = this.state.copyWith(); - state.controlsOpacity = 0; - state.showSettings = false; - state.showQueue = false; - state.displayControls = false; if (!isClosed) { - emit(state); + emit(state.copyWith(controlsOpacity: 0, showSettings: false, showQueue: false, displayControls: false)); } }); } displayQueue() { - var state = this.state.copyWith(); - state.showQueue = true; - state.displayControls = false; - emit(state); + emit(state.copyWith(showQueue: true, displayControls: false)); } Future playFromQueue(VideoInList video) async { - var state = this.state.copyWith(); - state.showQueue = false; - state.loading = true; - emit(state); - state = this.state.copyWith(); + emit(state.copyWith(showQueue: false, loading: true)); player.switchToVideo(video); - state.loading = false; - emit(state); + emit(state.copyWith(loading: false)); } onStreamEvent(MediaEvent event) { log.fine('Event: ${event.state}, ${event.type}'); - var state = this.state.copyWith(); switch (event.state) { case MediaState.buffering: // showControls(); @@ -161,33 +129,24 @@ class TvPlayerControlsCubit extends Cubit { case MediaState.loading: case MediaState.ready: showUi(); - state = this.state.copyWith(); - break; -/* - case MediaState.miniDisplayChanged: - hideControls(); - state = this.state.copyWith(); break; -*/ default: break; } - - emit(state); } } -@CopyWith(constructor: "_") -class TvPlayerControlsState { - TvPlayerControlsState(); - - double controlsOpacity = 0; - bool showSettings = false; - bool showQueue = false; - bool loading = false; - bool displayControls = false; +@freezed +class TvPlayerControlsState with _$TvPlayerControlsState { + const factory TvPlayerControlsState({ + @Default(0) double controlsOpacity, + @Default(false) bool showSettings, + @Default(false) bool showQueue, + @Default(false) bool loading, + @Default(false) bool displayControls, + }) = _TvPlayerControlsState; bool get isShowUi => controlsOpacity == 1; - TvPlayerControlsState._(this.controlsOpacity, this.showSettings, this.showQueue, this.loading, this.displayControls); + const TvPlayerControlsState._(); } diff --git a/lib/player/states/tv_player_controls.freezed.dart b/lib/player/states/tv_player_controls.freezed.dart new file mode 100644 index 00000000..5b2f7b0b --- /dev/null +++ b/lib/player/states/tv_player_controls.freezed.dart @@ -0,0 +1,232 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'tv_player_controls.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +mixin _$TvPlayerControlsState { + double get controlsOpacity => throw _privateConstructorUsedError; + bool get showSettings => throw _privateConstructorUsedError; + bool get showQueue => throw _privateConstructorUsedError; + bool get loading => throw _privateConstructorUsedError; + bool get displayControls => throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + $TvPlayerControlsStateCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $TvPlayerControlsStateCopyWith<$Res> { + factory $TvPlayerControlsStateCopyWith(TvPlayerControlsState value, + $Res Function(TvPlayerControlsState) then) = + _$TvPlayerControlsStateCopyWithImpl<$Res, TvPlayerControlsState>; + @useResult + $Res call( + {double controlsOpacity, + bool showSettings, + bool showQueue, + bool loading, + bool displayControls}); +} + +/// @nodoc +class _$TvPlayerControlsStateCopyWithImpl<$Res, + $Val extends TvPlayerControlsState> + implements $TvPlayerControlsStateCopyWith<$Res> { + _$TvPlayerControlsStateCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? controlsOpacity = null, + Object? showSettings = null, + Object? showQueue = null, + Object? loading = null, + Object? displayControls = null, + }) { + return _then(_value.copyWith( + controlsOpacity: null == controlsOpacity + ? _value.controlsOpacity + : controlsOpacity // ignore: cast_nullable_to_non_nullable + as double, + showSettings: null == showSettings + ? _value.showSettings + : showSettings // ignore: cast_nullable_to_non_nullable + as bool, + showQueue: null == showQueue + ? _value.showQueue + : showQueue // ignore: cast_nullable_to_non_nullable + as bool, + loading: null == loading + ? _value.loading + : loading // ignore: cast_nullable_to_non_nullable + as bool, + displayControls: null == displayControls + ? _value.displayControls + : displayControls // ignore: cast_nullable_to_non_nullable + as bool, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$TvPlayerControlsStateImplCopyWith<$Res> + implements $TvPlayerControlsStateCopyWith<$Res> { + factory _$$TvPlayerControlsStateImplCopyWith( + _$TvPlayerControlsStateImpl value, + $Res Function(_$TvPlayerControlsStateImpl) then) = + __$$TvPlayerControlsStateImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {double controlsOpacity, + bool showSettings, + bool showQueue, + bool loading, + bool displayControls}); +} + +/// @nodoc +class __$$TvPlayerControlsStateImplCopyWithImpl<$Res> + extends _$TvPlayerControlsStateCopyWithImpl<$Res, + _$TvPlayerControlsStateImpl> + implements _$$TvPlayerControlsStateImplCopyWith<$Res> { + __$$TvPlayerControlsStateImplCopyWithImpl(_$TvPlayerControlsStateImpl _value, + $Res Function(_$TvPlayerControlsStateImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? controlsOpacity = null, + Object? showSettings = null, + Object? showQueue = null, + Object? loading = null, + Object? displayControls = null, + }) { + return _then(_$TvPlayerControlsStateImpl( + controlsOpacity: null == controlsOpacity + ? _value.controlsOpacity + : controlsOpacity // ignore: cast_nullable_to_non_nullable + as double, + showSettings: null == showSettings + ? _value.showSettings + : showSettings // ignore: cast_nullable_to_non_nullable + as bool, + showQueue: null == showQueue + ? _value.showQueue + : showQueue // ignore: cast_nullable_to_non_nullable + as bool, + loading: null == loading + ? _value.loading + : loading // ignore: cast_nullable_to_non_nullable + as bool, + displayControls: null == displayControls + ? _value.displayControls + : displayControls // ignore: cast_nullable_to_non_nullable + as bool, + )); + } +} + +/// @nodoc + +class _$TvPlayerControlsStateImpl extends _TvPlayerControlsState { + const _$TvPlayerControlsStateImpl( + {this.controlsOpacity = 0, + this.showSettings = false, + this.showQueue = false, + this.loading = false, + this.displayControls = false}) + : super._(); + + @override + @JsonKey() + final double controlsOpacity; + @override + @JsonKey() + final bool showSettings; + @override + @JsonKey() + final bool showQueue; + @override + @JsonKey() + final bool loading; + @override + @JsonKey() + final bool displayControls; + + @override + String toString() { + return 'TvPlayerControlsState(controlsOpacity: $controlsOpacity, showSettings: $showSettings, showQueue: $showQueue, loading: $loading, displayControls: $displayControls)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$TvPlayerControlsStateImpl && + (identical(other.controlsOpacity, controlsOpacity) || + other.controlsOpacity == controlsOpacity) && + (identical(other.showSettings, showSettings) || + other.showSettings == showSettings) && + (identical(other.showQueue, showQueue) || + other.showQueue == showQueue) && + (identical(other.loading, loading) || other.loading == loading) && + (identical(other.displayControls, displayControls) || + other.displayControls == displayControls)); + } + + @override + int get hashCode => Object.hash(runtimeType, controlsOpacity, showSettings, + showQueue, loading, displayControls); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$TvPlayerControlsStateImplCopyWith<_$TvPlayerControlsStateImpl> + get copyWith => __$$TvPlayerControlsStateImplCopyWithImpl< + _$TvPlayerControlsStateImpl>(this, _$identity); +} + +abstract class _TvPlayerControlsState extends TvPlayerControlsState { + const factory _TvPlayerControlsState( + {final double controlsOpacity, + final bool showSettings, + final bool showQueue, + final bool loading, + final bool displayControls}) = _$TvPlayerControlsStateImpl; + const _TvPlayerControlsState._() : super._(); + + @override + double get controlsOpacity; + @override + bool get showSettings; + @override + bool get showQueue; + @override + bool get loading; + @override + bool get displayControls; + @override + @JsonKey(ignore: true) + _$$TvPlayerControlsStateImplCopyWith<_$TvPlayerControlsStateImpl> + get copyWith => throw _privateConstructorUsedError; +} diff --git a/lib/player/states/tv_player_controls.g.dart b/lib/player/states/tv_player_controls.g.dart deleted file mode 100644 index 5a380123..00000000 --- a/lib/player/states/tv_player_controls.g.dart +++ /dev/null @@ -1,105 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'tv_player_controls.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$TvPlayerControlsStateCWProxy { - TvPlayerControlsState controlsOpacity(double controlsOpacity); - - TvPlayerControlsState showSettings(bool showSettings); - - TvPlayerControlsState showQueue(bool showQueue); - - TvPlayerControlsState loading(bool loading); - - TvPlayerControlsState displayControls(bool displayControls); - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `TvPlayerControlsState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// TvPlayerControlsState(...).copyWith(id: 12, name: "My name") - /// ```` - TvPlayerControlsState call({ - double? controlsOpacity, - bool? showSettings, - bool? showQueue, - bool? loading, - bool? displayControls, - }); -} - -/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfTvPlayerControlsState.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfTvPlayerControlsState.copyWith.fieldName(...)` -class _$TvPlayerControlsStateCWProxyImpl - implements _$TvPlayerControlsStateCWProxy { - const _$TvPlayerControlsStateCWProxyImpl(this._value); - - final TvPlayerControlsState _value; - - @override - TvPlayerControlsState controlsOpacity(double controlsOpacity) => - this(controlsOpacity: controlsOpacity); - - @override - TvPlayerControlsState showSettings(bool showSettings) => - this(showSettings: showSettings); - - @override - TvPlayerControlsState showQueue(bool showQueue) => this(showQueue: showQueue); - - @override - TvPlayerControlsState loading(bool loading) => this(loading: loading); - - @override - TvPlayerControlsState displayControls(bool displayControls) => - this(displayControls: displayControls); - - @override - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `TvPlayerControlsState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// TvPlayerControlsState(...).copyWith(id: 12, name: "My name") - /// ```` - TvPlayerControlsState call({ - Object? controlsOpacity = const $CopyWithPlaceholder(), - Object? showSettings = const $CopyWithPlaceholder(), - Object? showQueue = const $CopyWithPlaceholder(), - Object? loading = const $CopyWithPlaceholder(), - Object? displayControls = const $CopyWithPlaceholder(), - }) { - return TvPlayerControlsState._( - controlsOpacity == const $CopyWithPlaceholder() || controlsOpacity == null - ? _value.controlsOpacity - // ignore: cast_nullable_to_non_nullable - : controlsOpacity as double, - showSettings == const $CopyWithPlaceholder() || showSettings == null - ? _value.showSettings - // ignore: cast_nullable_to_non_nullable - : showSettings as bool, - showQueue == const $CopyWithPlaceholder() || showQueue == null - ? _value.showQueue - // ignore: cast_nullable_to_non_nullable - : showQueue as bool, - loading == const $CopyWithPlaceholder() || loading == null - ? _value.loading - // ignore: cast_nullable_to_non_nullable - : loading as bool, - displayControls == const $CopyWithPlaceholder() || displayControls == null - ? _value.displayControls - // ignore: cast_nullable_to_non_nullable - : displayControls as bool, - ); - } -} - -extension $TvPlayerControlsStateCopyWith on TvPlayerControlsState { - /// Returns a callable class that can be used as follows: `instanceOfTvPlayerControlsState.copyWith(...)` or like so:`instanceOfTvPlayerControlsState.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$TvPlayerControlsStateCWProxy get copyWith => - _$TvPlayerControlsStateCWProxyImpl(this); -} diff --git a/lib/player/states/tv_player_settings.dart b/lib/player/states/tv_player_settings.dart index d95ccf67..e5cd5eaa 100644 --- a/lib/player/states/tv_player_settings.dart +++ b/lib/player/states/tv_player_settings.dart @@ -1,26 +1,15 @@ import 'package:better_player/better_player.dart'; import 'package:bloc/bloc.dart'; import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:invidious/player/states/video_player.dart'; import 'package:logging/logging.dart'; import '../../settings/states/settings.dart'; -part 'tv_player_settings.g.dart'; - -const List tvAvailablePlaybackSpeeds = [ - '0.5x', - '0.75x', - '1x', - '1.25x', - '1.5x', - '1.75x', - '2x', - '2.25x', - '2.5x', - '2.75x', - '3x' -]; +part 'tv_player_settings.freezed.dart'; + +const List tvAvailablePlaybackSpeeds = ['0.5x', '0.75x', '1x', '1.25x', '1.5x', '1.75x', '2x', '2.25x', '2.5x', '2.75x', '3x']; final Logger log = Logger('TvSettingsController'); enum Tabs { @@ -40,44 +29,33 @@ class TvPlayerSettingsCubit extends Cubit { ? player.state.videoController?.betterPlayerAsmsTracks.map((e) => '${e.height}p').toSet().toList() ?? [] : player.state.videoController?.betterPlayerDataSource?.resolutions?.keys.toList() ?? []; - List get audioTrackNames => settings.state.useDash - ? player.state.videoController?.betterPlayerAsmsAudioTracks?.map((e) => '${e.label}').toList() ?? [] - : []; + List get audioTrackNames => settings.state.useDash ? player.state.videoController?.betterPlayerAsmsAudioTracks?.map((e) => '${e.label}').toList() ?? [] : []; - List get availableCaptions => - player.state.videoController?.betterPlayerSubtitlesSourceList.map((e) => '${e.name}').toList() ?? []; + List get availableCaptions => player.state.videoController?.betterPlayerSubtitlesSourceList.map((e) => '${e.name}').toList() ?? []; BetterPlayerController? get videoController => player.state.videoController; videoButtonFocusChange(bool focus) { if (focus) { - var state = this.state.copyWith(); - state.selected = Tabs.video; - emit(state); + emit(state.copyWith(selected: Tabs.video)); } } audioButtonFocusChange(bool focus) { if (focus) { - var state = this.state.copyWith(); - state.selected = Tabs.audio; - emit(state); + emit(state.copyWith(selected: Tabs.audio)); } } captionsButtonFocusChange(bool focus) { if (focus) { - var state = this.state.copyWith(); - state.selected = Tabs.captions; - emit(state); + emit(state.copyWith(selected: Tabs.captions)); } } playbackSpeedButtonFocusChange(bool focus) { if (focus) { - var state = this.state.copyWith(); - state.selected = Tabs.playbackSpeed; - emit(state); + emit(state.copyWith(selected: Tabs.playbackSpeed)); } } @@ -85,8 +63,7 @@ class TvPlayerSettingsCubit extends Cubit { log.fine('Video quality selected $selected'); if (settings.state.useDash) { - BetterPlayerAsmsTrack? track = - videoController?.betterPlayerAsmsTracks.firstWhere((element) => '${element.height}p' == selected); + BetterPlayerAsmsTrack? track = videoController?.betterPlayerAsmsTracks.firstWhere((element) => '${element.height}p' == selected); if (track != null) { log.fine('Changing video track to $selected'); @@ -102,8 +79,7 @@ class TvPlayerSettingsCubit extends Cubit { changeChangeAudioTrack(String selected) { log.fine('Audio quality selected $selected'); - BetterPlayerAsmsAudioTrack? track = - videoController?.betterPlayerAsmsAudioTracks?.firstWhere((e) => '${e.label}' == selected); + BetterPlayerAsmsAudioTrack? track = videoController?.betterPlayerAsmsAudioTracks?.firstWhere((e) => '${e.label}' == selected); if (track != null) { log.fine('Changing audio track to $selected'); @@ -113,8 +89,7 @@ class TvPlayerSettingsCubit extends Cubit { changeSubtitles(String selected) { log.fine('Subtitles selected $selected'); - BetterPlayerSubtitlesSource? track = - videoController?.betterPlayerSubtitlesSourceList.firstWhere((e) => '${e.name}' == selected); + BetterPlayerSubtitlesSource? track = videoController?.betterPlayerSubtitlesSourceList.firstWhere((e) => '${e.name}' == selected); settings.setLastSubtitle(selected); @@ -130,11 +105,7 @@ class TvPlayerSettingsCubit extends Cubit { } } -@CopyWith(constructor: "_") -class TvPlayerSettingsState { - Tabs selected = Tabs.video; - - TvPlayerSettingsState(); - - TvPlayerSettingsState._(this.selected); +@freezed +class TvPlayerSettingsState with _$TvPlayerSettingsState { + const factory TvPlayerSettingsState({@Default(Tabs.video) Tabs selected}) = _TvPlayerSettingsState; } diff --git a/lib/player/states/tv_player_settings.freezed.dart b/lib/player/states/tv_player_settings.freezed.dart new file mode 100644 index 00000000..ff5100f7 --- /dev/null +++ b/lib/player/states/tv_player_settings.freezed.dart @@ -0,0 +1,139 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'tv_player_settings.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +mixin _$TvPlayerSettingsState { + Tabs get selected => throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + $TvPlayerSettingsStateCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $TvPlayerSettingsStateCopyWith<$Res> { + factory $TvPlayerSettingsStateCopyWith(TvPlayerSettingsState value, + $Res Function(TvPlayerSettingsState) then) = + _$TvPlayerSettingsStateCopyWithImpl<$Res, TvPlayerSettingsState>; + @useResult + $Res call({Tabs selected}); +} + +/// @nodoc +class _$TvPlayerSettingsStateCopyWithImpl<$Res, + $Val extends TvPlayerSettingsState> + implements $TvPlayerSettingsStateCopyWith<$Res> { + _$TvPlayerSettingsStateCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? selected = null, + }) { + return _then(_value.copyWith( + selected: null == selected + ? _value.selected + : selected // ignore: cast_nullable_to_non_nullable + as Tabs, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$TvPlayerSettingsStateImplCopyWith<$Res> + implements $TvPlayerSettingsStateCopyWith<$Res> { + factory _$$TvPlayerSettingsStateImplCopyWith( + _$TvPlayerSettingsStateImpl value, + $Res Function(_$TvPlayerSettingsStateImpl) then) = + __$$TvPlayerSettingsStateImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({Tabs selected}); +} + +/// @nodoc +class __$$TvPlayerSettingsStateImplCopyWithImpl<$Res> + extends _$TvPlayerSettingsStateCopyWithImpl<$Res, + _$TvPlayerSettingsStateImpl> + implements _$$TvPlayerSettingsStateImplCopyWith<$Res> { + __$$TvPlayerSettingsStateImplCopyWithImpl(_$TvPlayerSettingsStateImpl _value, + $Res Function(_$TvPlayerSettingsStateImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? selected = null, + }) { + return _then(_$TvPlayerSettingsStateImpl( + selected: null == selected + ? _value.selected + : selected // ignore: cast_nullable_to_non_nullable + as Tabs, + )); + } +} + +/// @nodoc + +class _$TvPlayerSettingsStateImpl implements _TvPlayerSettingsState { + const _$TvPlayerSettingsStateImpl({this.selected = Tabs.video}); + + @override + @JsonKey() + final Tabs selected; + + @override + String toString() { + return 'TvPlayerSettingsState(selected: $selected)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$TvPlayerSettingsStateImpl && + (identical(other.selected, selected) || + other.selected == selected)); + } + + @override + int get hashCode => Object.hash(runtimeType, selected); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$TvPlayerSettingsStateImplCopyWith<_$TvPlayerSettingsStateImpl> + get copyWith => __$$TvPlayerSettingsStateImplCopyWithImpl< + _$TvPlayerSettingsStateImpl>(this, _$identity); +} + +abstract class _TvPlayerSettingsState implements TvPlayerSettingsState { + const factory _TvPlayerSettingsState({final Tabs selected}) = + _$TvPlayerSettingsStateImpl; + + @override + Tabs get selected; + @override + @JsonKey(ignore: true) + _$$TvPlayerSettingsStateImplCopyWith<_$TvPlayerSettingsStateImpl> + get copyWith => throw _privateConstructorUsedError; +} diff --git a/lib/player/states/tv_player_settings.g.dart b/lib/player/states/tv_player_settings.g.dart deleted file mode 100644 index 01881e8f..00000000 --- a/lib/player/states/tv_player_settings.g.dart +++ /dev/null @@ -1,58 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'tv_player_settings.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$TvPlayerSettingsStateCWProxy { - TvPlayerSettingsState selected(Tabs selected); - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `TvPlayerSettingsState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// TvPlayerSettingsState(...).copyWith(id: 12, name: "My name") - /// ```` - TvPlayerSettingsState call({ - Tabs? selected, - }); -} - -/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfTvPlayerSettingsState.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfTvPlayerSettingsState.copyWith.fieldName(...)` -class _$TvPlayerSettingsStateCWProxyImpl - implements _$TvPlayerSettingsStateCWProxy { - const _$TvPlayerSettingsStateCWProxyImpl(this._value); - - final TvPlayerSettingsState _value; - - @override - TvPlayerSettingsState selected(Tabs selected) => this(selected: selected); - - @override - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `TvPlayerSettingsState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// TvPlayerSettingsState(...).copyWith(id: 12, name: "My name") - /// ```` - TvPlayerSettingsState call({ - Object? selected = const $CopyWithPlaceholder(), - }) { - return TvPlayerSettingsState._( - selected == const $CopyWithPlaceholder() || selected == null - ? _value.selected - // ignore: cast_nullable_to_non_nullable - : selected as Tabs, - ); - } -} - -extension $TvPlayerSettingsStateCopyWith on TvPlayerSettingsState { - /// Returns a callable class that can be used as follows: `instanceOfTvPlayerSettingsState.copyWith(...)` or like so:`instanceOfTvPlayerSettingsState.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$TvPlayerSettingsStateCWProxy get copyWith => - _$TvPlayerSettingsStateCWProxyImpl(this); -} diff --git a/lib/player/views/components/player_controls.dart b/lib/player/views/components/player_controls.dart index 8102918b..0ca44bb3 100644 --- a/lib/player/views/components/player_controls.dart +++ b/lib/player/views/components/player_controls.dart @@ -11,6 +11,7 @@ import 'package:invidious/player/states/player.dart'; import 'package:invidious/settings/states/settings.dart'; import '../../../utils.dart'; +import '../../../videos/models/video.dart'; import '../../states/audio_player.dart'; import '../../states/player_controls.dart'; import '../../states/video_player.dart'; @@ -185,15 +186,17 @@ class PlayerControls extends StatelessWidget { Widget build(BuildContext context) { var locals = AppLocalizations.of(context)!; var textTheme = Theme.of(context).textTheme; - var player = context.read(); var colors = Theme.of(context).colorScheme; + var player = context.read(); return Theme( data: ThemeData(useMaterial3: true, colorScheme: darkColorScheme, progressIndicatorTheme: ProgressIndicatorThemeData(circularTrackColor: darkColorScheme.secondaryContainer.withOpacity(0.8))), child: BlocProvider( - create: (context) => PlayerControlsCubit(PlayerControlsState(), player), + create: (context) => PlayerControlsCubit(const PlayerControlsState(), player), child: BlocBuilder( builder: (context, _) { bool isMini = context.select((PlayerCubit cubit) => cubit.state.isMini); + bool isPlaying = context.select((PlayerCubit cubit) => cubit.state.isPlaying); + Video? currentlyPlaying = context.select((PlayerCubit cubit) => cubit.state.currentlyPlaying); bool hasQueue = context.select((PlayerCubit cubit) => cubit.state.hasQueue); bool isPip = context.select((PlayerCubit cubit) => cubit.state.isPip); int totalFastForward = context.select((PlayerCubit cubit) => cubit.state.totalFastForward); @@ -352,7 +355,7 @@ class PlayerControls extends StatelessWidget { ) : const SizedBox.expand(), ), - if ((_.displayControls || _.justDoubleTappedSkip) && !(player.state.currentlyPlaying?.liveNow ?? false)) + if ((_.displayControls || _.justDoubleTappedSkip) && !(currentlyPlaying?.liveNow ?? false)) Positioned( bottom: 0, left: 0, @@ -419,7 +422,7 @@ class PlayerControls extends StatelessWidget { )), IconButton( onPressed: () { - if (player.state.isPlaying) { + if (isPlaying) { player.pause(); } else if (isPausedAndDone) { player.seek(Duration.zero); @@ -429,7 +432,7 @@ class PlayerControls extends StatelessWidget { } }, icon: Icon( - player.state.isPlaying + isPlaying ? Icons.pause : isPausedAndDone ? Icons.refresh diff --git a/lib/player/views/tv/screens/tvPlayerView.dart b/lib/player/views/tv/screens/tvPlayerView.dart index 1bf8a5a2..d4101386 100644 --- a/lib/player/views/tv/screens/tvPlayerView.dart +++ b/lib/player/views/tv/screens/tvPlayerView.dart @@ -24,7 +24,7 @@ class TvPlayerScreen extends StatelessWidget { return MultiBlocProvider( providers: [ BlocProvider( - create: (context) => PlayerCubit(PlayerState.withVideos(videos), settings), + create: (context) => PlayerCubit(PlayerState.init(videos), settings), ) ], child: Theme( diff --git a/lib/settings/states/settings.dart b/lib/settings/states/settings.dart index a716f687..cb8dcb42 100644 --- a/lib/settings/states/settings.dart +++ b/lib/settings/states/settings.dart @@ -269,7 +269,6 @@ class SettingsCubit extends Cubit { Future setBackgroundNotifications(bool b) async { if (!b) { - var state = this.state.copyWith(); await stopTasks(); backgroundNotifications = b; } else { @@ -281,10 +280,9 @@ class SettingsCubit extends Cubit { } } - var state = this.state.copyWith(); + backgroundNotifications = b; await configureBackgroundService(this); await setupTasks(this); - backgroundNotifications = b; return EnableBackGroundNotificationResponse.ok; } diff --git a/lib/utils/models/pair.dart b/lib/utils/models/pair.dart index 2eafe9e4..0e3082cb 100644 --- a/lib/utils/models/pair.dart +++ b/lib/utils/models/pair.dart @@ -1,13 +1,13 @@ class Pair { - E first; - E last; + final E first; + final E last; - Pair(this.first, this.last); + const Pair(this.first, this.last); } class Couple { - E first; - M last; + final E first; + final M last; - Couple(this.first, this.last); + const Couple(this.first, this.last); } diff --git a/lib/utils/states/item_list.dart b/lib/utils/states/item_list.dart index b5a00a7e..836616e0 100644 --- a/lib/utils/states/item_list.dart +++ b/lib/utils/states/item_list.dart @@ -2,36 +2,39 @@ import 'package:bloc/bloc.dart'; import 'package:copy_with_extension/copy_with_extension.dart'; import 'package:easy_debounce/easy_debounce.dart'; import 'package:flutter/material.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:invidious/settings/models/errors/invidiousServiceError.dart'; import 'package:logging/logging.dart'; import '../models/paginatedList.dart'; -part 'item_list.g.dart'; +part 'item_list.freezed.dart'; enum ItemListErrors { none, couldNotFetchItems, invalidScope } var log = Logger('ItemListCubit'); class ItemListCubit extends Cubit> { + ScrollController scrollController = ScrollController(); + ItemListCubit(super.initialState) { onReady(); } @override close() async { - state.scrollController.dispose(); + scrollController.dispose(); super.close(); } onReady() { getItems(); - state.scrollController.addListener(onScrollEvent); + scrollController.addListener(onScrollEvent); } onScrollEvent() { - if (state.scrollController.hasClients) { - if (state.scrollController.position.maxScrollExtent * 0.9 < state.scrollController.offset) { + if (scrollController.hasClients) { + if (scrollController.position.maxScrollExtent * 0.9 < scrollController.offset) { EasyDebounce.debounce('loading-more-videos', const Duration(milliseconds: 500), getMoreItems); } } @@ -41,8 +44,7 @@ class ItemListCubit extends Cubit> { if (!state.loading && state.itemList.getHasMore()) { loadItems(() async { List items = await state.itemList.getMoreItems(); - List currentItems = state.items; - currentItems.addAll(items); + List currentItems = List.from(state.items)..addAll(items); return currentItems; }); } @@ -57,29 +59,21 @@ class ItemListCubit extends Cubit> { } loadItems(Future> Function() refreshFunction) async { - var state = this.state.copyWith(); - // var locals = AppLocalizations.of(context)!; - state.error = ItemListErrors.none; - state.loading = true; - emit(state); + emit(state.copyWith(error: ItemListErrors.none, loading: true)); try { - state = this.state.copyWith(); - state.items = await refreshFunction(); - state.loading = false; - if(!isClosed) { - emit(state); + var items = await refreshFunction(); + if (!isClosed) { + emit(state.copyWith(loading: false, items: items)); } } catch (err) { - state = this.state.copyWith(); - state.items = []; - state.loading = false; + late ItemListErrors error; if (err is InvidiousServiceError && err.message == "Invalid scope") { - state.error = ItemListErrors.invalidScope; + error = ItemListErrors.invalidScope; } else { - state.error = ItemListErrors.couldNotFetchItems; + error = ItemListErrors.couldNotFetchItems; } - if(!isClosed) { - emit(state); + if (!isClosed) { + emit(state.copyWith(error: error, items: [], loading: false)); } rethrow; } @@ -89,16 +83,12 @@ class ItemListCubit extends Cubit> { focusChanged(bool value, int index) {} } -@CopyWith(constructor: "_") -class ItemListState { - PaginatedList itemList; - List items = []; - bool loading = true; - Map imageCache = {}; - ScrollController scrollController = ScrollController(); - ItemListErrors error = ItemListErrors.none; - - ItemListState({required this.itemList}) {} - - ItemListState._(this.itemList, this.items, this.loading, this.imageCache, this.scrollController, this.error); +@freezed +class ItemListState with _$ItemListState { + const factory ItemListState({ + required PaginatedList itemList, + @Default([]) List items, + @Default(true) bool loading, + @Default(ItemListErrors.none) ItemListErrors error, + }) = _ItemListState; } diff --git a/lib/utils/states/item_list.freezed.dart b/lib/utils/states/item_list.freezed.dart new file mode 100644 index 00000000..6304a842 --- /dev/null +++ b/lib/utils/states/item_list.freezed.dart @@ -0,0 +1,209 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'item_list.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +mixin _$ItemListState { + PaginatedList get itemList => throw _privateConstructorUsedError; + List get items => throw _privateConstructorUsedError; + bool get loading => throw _privateConstructorUsedError; + ItemListErrors get error => throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + $ItemListStateCopyWith> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $ItemListStateCopyWith { + factory $ItemListStateCopyWith( + ItemListState value, $Res Function(ItemListState) then) = + _$ItemListStateCopyWithImpl>; + @useResult + $Res call( + {PaginatedList itemList, + List items, + bool loading, + ItemListErrors error}); +} + +/// @nodoc +class _$ItemListStateCopyWithImpl> + implements $ItemListStateCopyWith { + _$ItemListStateCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? itemList = null, + Object? items = null, + Object? loading = null, + Object? error = null, + }) { + return _then(_value.copyWith( + itemList: null == itemList + ? _value.itemList + : itemList // ignore: cast_nullable_to_non_nullable + as PaginatedList, + items: null == items + ? _value.items + : items // ignore: cast_nullable_to_non_nullable + as List, + loading: null == loading + ? _value.loading + : loading // ignore: cast_nullable_to_non_nullable + as bool, + error: null == error + ? _value.error + : error // ignore: cast_nullable_to_non_nullable + as ItemListErrors, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$ItemListStateImplCopyWith + implements $ItemListStateCopyWith { + factory _$$ItemListStateImplCopyWith(_$ItemListStateImpl value, + $Res Function(_$ItemListStateImpl) then) = + __$$ItemListStateImplCopyWithImpl; + @override + @useResult + $Res call( + {PaginatedList itemList, + List items, + bool loading, + ItemListErrors error}); +} + +/// @nodoc +class __$$ItemListStateImplCopyWithImpl + extends _$ItemListStateCopyWithImpl> + implements _$$ItemListStateImplCopyWith { + __$$ItemListStateImplCopyWithImpl(_$ItemListStateImpl _value, + $Res Function(_$ItemListStateImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? itemList = null, + Object? items = null, + Object? loading = null, + Object? error = null, + }) { + return _then(_$ItemListStateImpl( + itemList: null == itemList + ? _value.itemList + : itemList // ignore: cast_nullable_to_non_nullable + as PaginatedList, + items: null == items + ? _value._items + : items // ignore: cast_nullable_to_non_nullable + as List, + loading: null == loading + ? _value.loading + : loading // ignore: cast_nullable_to_non_nullable + as bool, + error: null == error + ? _value.error + : error // ignore: cast_nullable_to_non_nullable + as ItemListErrors, + )); + } +} + +/// @nodoc + +class _$ItemListStateImpl implements _ItemListState { + const _$ItemListStateImpl( + {required this.itemList, + final List items = const [], + this.loading = true, + this.error = ItemListErrors.none}) + : _items = items; + + @override + final PaginatedList itemList; + final List _items; + @override + @JsonKey() + List get items { + if (_items is EqualUnmodifiableListView) return _items; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_items); + } + + @override + @JsonKey() + final bool loading; + @override + @JsonKey() + final ItemListErrors error; + + @override + String toString() { + return 'ItemListState<$T>(itemList: $itemList, items: $items, loading: $loading, error: $error)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$ItemListStateImpl && + (identical(other.itemList, itemList) || + other.itemList == itemList) && + const DeepCollectionEquality().equals(other._items, _items) && + (identical(other.loading, loading) || other.loading == loading) && + (identical(other.error, error) || other.error == error)); + } + + @override + int get hashCode => Object.hash(runtimeType, itemList, + const DeepCollectionEquality().hash(_items), loading, error); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$ItemListStateImplCopyWith> get copyWith => + __$$ItemListStateImplCopyWithImpl>( + this, _$identity); +} + +abstract class _ItemListState implements ItemListState { + const factory _ItemListState( + {required final PaginatedList itemList, + final List items, + final bool loading, + final ItemListErrors error}) = _$ItemListStateImpl; + + @override + PaginatedList get itemList; + @override + List get items; + @override + bool get loading; + @override + ItemListErrors get error; + @override + @JsonKey(ignore: true) + _$$ItemListStateImplCopyWith> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/utils/states/item_list.g.dart b/lib/utils/states/item_list.g.dart deleted file mode 100644 index 79c6c4a1..00000000 --- a/lib/utils/states/item_list.g.dart +++ /dev/null @@ -1,115 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'item_list.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$ItemListStateCWProxy { - ItemListState itemList(PaginatedList itemList); - - ItemListState items(List items); - - ItemListState loading(bool loading); - - ItemListState imageCache(Map imageCache); - - ItemListState scrollController(ScrollController scrollController); - - ItemListState error(ItemListErrors error); - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `ItemListState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// ItemListState(...).copyWith(id: 12, name: "My name") - /// ```` - ItemListState call({ - PaginatedList? itemList, - List? items, - bool? loading, - Map? imageCache, - ScrollController? scrollController, - ItemListErrors? error, - }); -} - -/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfItemListState.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfItemListState.copyWith.fieldName(...)` -class _$ItemListStateCWProxyImpl implements _$ItemListStateCWProxy { - const _$ItemListStateCWProxyImpl(this._value); - - final ItemListState _value; - - @override - ItemListState itemList(PaginatedList itemList) => - this(itemList: itemList); - - @override - ItemListState items(List items) => this(items: items); - - @override - ItemListState loading(bool loading) => this(loading: loading); - - @override - ItemListState imageCache(Map imageCache) => - this(imageCache: imageCache); - - @override - ItemListState scrollController(ScrollController scrollController) => - this(scrollController: scrollController); - - @override - ItemListState error(ItemListErrors error) => this(error: error); - - @override - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `ItemListState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// ItemListState(...).copyWith(id: 12, name: "My name") - /// ```` - ItemListState call({ - Object? itemList = const $CopyWithPlaceholder(), - Object? items = const $CopyWithPlaceholder(), - Object? loading = const $CopyWithPlaceholder(), - Object? imageCache = const $CopyWithPlaceholder(), - Object? scrollController = const $CopyWithPlaceholder(), - Object? error = const $CopyWithPlaceholder(), - }) { - return ItemListState._( - itemList == const $CopyWithPlaceholder() || itemList == null - ? _value.itemList - // ignore: cast_nullable_to_non_nullable - : itemList as PaginatedList, - items == const $CopyWithPlaceholder() || items == null - ? _value.items - // ignore: cast_nullable_to_non_nullable - : items as List, - loading == const $CopyWithPlaceholder() || loading == null - ? _value.loading - // ignore: cast_nullable_to_non_nullable - : loading as bool, - imageCache == const $CopyWithPlaceholder() || imageCache == null - ? _value.imageCache - // ignore: cast_nullable_to_non_nullable - : imageCache as Map, - scrollController == const $CopyWithPlaceholder() || - scrollController == null - ? _value.scrollController - // ignore: cast_nullable_to_non_nullable - : scrollController as ScrollController, - error == const $CopyWithPlaceholder() || error == null - ? _value.error - // ignore: cast_nullable_to_non_nullable - : error as ItemListErrors, - ); - } -} - -extension $ItemListStateCopyWith on ItemListState { - /// Returns a callable class that can be used as follows: `instanceOfItemListState.copyWith(...)` or like so:`instanceOfItemListState.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$ItemListStateCWProxy get copyWith => _$ItemListStateCWProxyImpl(this); -} diff --git a/lib/utils/states/paginated_list_view.dart b/lib/utils/states/paginated_list_view.dart index 831cb905..9ba8d738 100644 --- a/lib/utils/states/paginated_list_view.dart +++ b/lib/utils/states/paginated_list_view.dart @@ -2,23 +2,26 @@ import 'package:bloc/bloc.dart'; import 'package:copy_with_extension/copy_with_extension.dart'; import 'package:easy_debounce/easy_debounce.dart'; import 'package:flutter/material.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:invidious/utils/models/paginatedList.dart'; -part 'paginated_list_view.g.dart'; +part 'paginated_list_view.freezed.dart'; class PaginatedListCubit extends Cubit> { + final ScrollController scrollController = ScrollController(); + PaginatedListCubit(super.initialState) { onInit(); } void onInit() { - state.scrollController.addListener(getMore); + scrollController.addListener(getMore); getItems(); } @override close() async { - state.scrollController.dispose(); + scrollController.dispose(); super.close(); } @@ -31,18 +34,15 @@ class PaginatedListCubit extends Cubit> { getMore() { if (state.paginatedList.getHasMore()) { - if (state.scrollController.hasClients) { - if (state.scrollController.position.maxScrollExtent * 0.9 < state.scrollController.offset) { + if (scrollController.hasClients) { + if (scrollController.position.maxScrollExtent * 0.9 < scrollController.offset) { EasyDebounce.debounce('get-more-playlists', const Duration(milliseconds: 250), () async { - var state = this.state.copyWith(); - state.loading = true; - emit(state); + emit(state.copyWith(loading: true)); List i = await state.paginatedList.getMoreItems(); - state = this.state.copyWith(); - state.items.addAll(i); - state.loading = false; - emit(state); + var items = List.from(state.items) + ..addAll(i); + emit(state.copyWith(items: items, loading: false)); }); } } @@ -50,18 +50,16 @@ class PaginatedListCubit extends Cubit> { } } -@CopyWith(constructor: "_") -class PaginatedListViewController { - ScrollController scrollController = ScrollController(); - PaginatedList paginatedList; - List items = []; - bool loading = false; - - PaginatedListViewController._(this.scrollController, this.paginatedList, this.items, this.loading); +@freezed +class PaginatedListViewController with _$PaginatedListViewController { + const factory PaginatedListViewController({ + required PaginatedList paginatedList, + @Default([]) List items, + @Default(false) bool loading + }) = _PaginatedListViewController; - PaginatedListViewController({required this.paginatedList, List? startItems}) { - if (startItems != null) { - items.addAll(startItems); - } + static PaginatedListViewController init({required PaginatedList paginatedList, List? startItems}) { + return PaginatedListViewController(paginatedList: paginatedList, items: startItems ?? []); } + } diff --git a/lib/utils/states/paginated_list_view.freezed.dart b/lib/utils/states/paginated_list_view.freezed.dart new file mode 100644 index 00000000..ca769e4e --- /dev/null +++ b/lib/utils/states/paginated_list_view.freezed.dart @@ -0,0 +1,192 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'paginated_list_view.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +mixin _$PaginatedListViewController { + PaginatedList get paginatedList => throw _privateConstructorUsedError; + List get items => throw _privateConstructorUsedError; + bool get loading => throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + $PaginatedListViewControllerCopyWith> + get copyWith => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $PaginatedListViewControllerCopyWith { + factory $PaginatedListViewControllerCopyWith( + PaginatedListViewController value, + $Res Function(PaginatedListViewController) then) = + _$PaginatedListViewControllerCopyWithImpl>; + @useResult + $Res call({PaginatedList paginatedList, List items, bool loading}); +} + +/// @nodoc +class _$PaginatedListViewControllerCopyWithImpl> + implements $PaginatedListViewControllerCopyWith { + _$PaginatedListViewControllerCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? paginatedList = null, + Object? items = null, + Object? loading = null, + }) { + return _then(_value.copyWith( + paginatedList: null == paginatedList + ? _value.paginatedList + : paginatedList // ignore: cast_nullable_to_non_nullable + as PaginatedList, + items: null == items + ? _value.items + : items // ignore: cast_nullable_to_non_nullable + as List, + loading: null == loading + ? _value.loading + : loading // ignore: cast_nullable_to_non_nullable + as bool, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$PaginatedListViewControllerImplCopyWith + implements $PaginatedListViewControllerCopyWith { + factory _$$PaginatedListViewControllerImplCopyWith( + _$PaginatedListViewControllerImpl value, + $Res Function(_$PaginatedListViewControllerImpl) then) = + __$$PaginatedListViewControllerImplCopyWithImpl; + @override + @useResult + $Res call({PaginatedList paginatedList, List items, bool loading}); +} + +/// @nodoc +class __$$PaginatedListViewControllerImplCopyWithImpl + extends _$PaginatedListViewControllerCopyWithImpl> + implements _$$PaginatedListViewControllerImplCopyWith { + __$$PaginatedListViewControllerImplCopyWithImpl( + _$PaginatedListViewControllerImpl _value, + $Res Function(_$PaginatedListViewControllerImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? paginatedList = null, + Object? items = null, + Object? loading = null, + }) { + return _then(_$PaginatedListViewControllerImpl( + paginatedList: null == paginatedList + ? _value.paginatedList + : paginatedList // ignore: cast_nullable_to_non_nullable + as PaginatedList, + items: null == items + ? _value._items + : items // ignore: cast_nullable_to_non_nullable + as List, + loading: null == loading + ? _value.loading + : loading // ignore: cast_nullable_to_non_nullable + as bool, + )); + } +} + +/// @nodoc + +class _$PaginatedListViewControllerImpl + implements _PaginatedListViewController { + const _$PaginatedListViewControllerImpl( + {required this.paginatedList, + final List items = const [], + this.loading = false}) + : _items = items; + + @override + final PaginatedList paginatedList; + final List _items; + @override + @JsonKey() + List get items { + if (_items is EqualUnmodifiableListView) return _items; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_items); + } + + @override + @JsonKey() + final bool loading; + + @override + String toString() { + return 'PaginatedListViewController<$T>(paginatedList: $paginatedList, items: $items, loading: $loading)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$PaginatedListViewControllerImpl && + (identical(other.paginatedList, paginatedList) || + other.paginatedList == paginatedList) && + const DeepCollectionEquality().equals(other._items, _items) && + (identical(other.loading, loading) || other.loading == loading)); + } + + @override + int get hashCode => Object.hash(runtimeType, paginatedList, + const DeepCollectionEquality().hash(_items), loading); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$PaginatedListViewControllerImplCopyWith> + get copyWith => __$$PaginatedListViewControllerImplCopyWithImpl>(this, _$identity); +} + +abstract class _PaginatedListViewController + implements PaginatedListViewController { + const factory _PaginatedListViewController( + {required final PaginatedList paginatedList, + final List items, + final bool loading}) = _$PaginatedListViewControllerImpl; + + @override + PaginatedList get paginatedList; + @override + List get items; + @override + bool get loading; + @override + @JsonKey(ignore: true) + _$$PaginatedListViewControllerImplCopyWith> + get copyWith => throw _privateConstructorUsedError; +} diff --git a/lib/utils/states/paginated_list_view.g.dart b/lib/utils/states/paginated_list_view.g.dart deleted file mode 100644 index 44682049..00000000 --- a/lib/utils/states/paginated_list_view.g.dart +++ /dev/null @@ -1,99 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'paginated_list_view.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$PaginatedListViewControllerCWProxy { - PaginatedListViewController scrollController( - ScrollController scrollController); - - PaginatedListViewController paginatedList(PaginatedList paginatedList); - - PaginatedListViewController items(List items); - - PaginatedListViewController loading(bool loading); - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `PaginatedListViewController(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// PaginatedListViewController(...).copyWith(id: 12, name: "My name") - /// ```` - PaginatedListViewController call({ - ScrollController? scrollController, - PaginatedList? paginatedList, - List? items, - bool? loading, - }); -} - -/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfPaginatedListViewController.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfPaginatedListViewController.copyWith.fieldName(...)` -class _$PaginatedListViewControllerCWProxyImpl - implements _$PaginatedListViewControllerCWProxy { - const _$PaginatedListViewControllerCWProxyImpl(this._value); - - final PaginatedListViewController _value; - - @override - PaginatedListViewController scrollController( - ScrollController scrollController) => - this(scrollController: scrollController); - - @override - PaginatedListViewController paginatedList( - PaginatedList paginatedList) => - this(paginatedList: paginatedList); - - @override - PaginatedListViewController items(List items) => this(items: items); - - @override - PaginatedListViewController loading(bool loading) => - this(loading: loading); - - @override - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `PaginatedListViewController(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// PaginatedListViewController(...).copyWith(id: 12, name: "My name") - /// ```` - PaginatedListViewController call({ - Object? scrollController = const $CopyWithPlaceholder(), - Object? paginatedList = const $CopyWithPlaceholder(), - Object? items = const $CopyWithPlaceholder(), - Object? loading = const $CopyWithPlaceholder(), - }) { - return PaginatedListViewController._( - scrollController == const $CopyWithPlaceholder() || - scrollController == null - ? _value.scrollController - // ignore: cast_nullable_to_non_nullable - : scrollController as ScrollController, - paginatedList == const $CopyWithPlaceholder() || paginatedList == null - ? _value.paginatedList - // ignore: cast_nullable_to_non_nullable - : paginatedList as PaginatedList, - items == const $CopyWithPlaceholder() || items == null - ? _value.items - // ignore: cast_nullable_to_non_nullable - : items as List, - loading == const $CopyWithPlaceholder() || loading == null - ? _value.loading - // ignore: cast_nullable_to_non_nullable - : loading as bool, - ); - } -} - -extension $PaginatedListViewControllerCopyWith - on PaginatedListViewController { - /// Returns a callable class that can be used as follows: `instanceOfPaginatedListViewController.copyWith(...)` or like so:`instanceOfPaginatedListViewController.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$PaginatedListViewControllerCWProxy get copyWith => - _$PaginatedListViewControllerCWProxyImpl(this); -} diff --git a/lib/utils/states/select_list.dart b/lib/utils/states/select_list.dart index 18177178..97d7a496 100644 --- a/lib/utils/states/select_list.dart +++ b/lib/utils/states/select_list.dart @@ -1,7 +1,8 @@ import 'package:bloc/bloc.dart'; import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; -part 'select_list.g.dart'; +part 'select_list.freezed.dart'; class SelectListCubit extends Cubit> { SelectListCubit(super.initialState); @@ -23,16 +24,11 @@ class SelectListCubit extends Cubit> { } } -@CopyWith(constructor: "_") -class SelectListState { - List filteredItems = []; - bool loading = false; +@freezed +class SelectListState with _$SelectListState{ - SelectListState(List? values) { - if (values != null) { - filteredItems = values; - } - } - - SelectListState._(this.filteredItems, this.loading); + const factory SelectListState({ + @Default([]) List filteredItems, + @Default(false) bool loading +}) = _SelectListState; } diff --git a/lib/utils/states/select_list.freezed.dart b/lib/utils/states/select_list.freezed.dart new file mode 100644 index 00000000..a6820610 --- /dev/null +++ b/lib/utils/states/select_list.freezed.dart @@ -0,0 +1,163 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'select_list.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +mixin _$SelectListState { + List get filteredItems => throw _privateConstructorUsedError; + bool get loading => throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + $SelectListStateCopyWith> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $SelectListStateCopyWith { + factory $SelectListStateCopyWith( + SelectListState value, $Res Function(SelectListState) then) = + _$SelectListStateCopyWithImpl>; + @useResult + $Res call({List filteredItems, bool loading}); +} + +/// @nodoc +class _$SelectListStateCopyWithImpl> + implements $SelectListStateCopyWith { + _$SelectListStateCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? filteredItems = null, + Object? loading = null, + }) { + return _then(_value.copyWith( + filteredItems: null == filteredItems + ? _value.filteredItems + : filteredItems // ignore: cast_nullable_to_non_nullable + as List, + loading: null == loading + ? _value.loading + : loading // ignore: cast_nullable_to_non_nullable + as bool, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$SelectListStateImplCopyWith + implements $SelectListStateCopyWith { + factory _$$SelectListStateImplCopyWith(_$SelectListStateImpl value, + $Res Function(_$SelectListStateImpl) then) = + __$$SelectListStateImplCopyWithImpl; + @override + @useResult + $Res call({List filteredItems, bool loading}); +} + +/// @nodoc +class __$$SelectListStateImplCopyWithImpl + extends _$SelectListStateCopyWithImpl> + implements _$$SelectListStateImplCopyWith { + __$$SelectListStateImplCopyWithImpl(_$SelectListStateImpl _value, + $Res Function(_$SelectListStateImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? filteredItems = null, + Object? loading = null, + }) { + return _then(_$SelectListStateImpl( + filteredItems: null == filteredItems + ? _value._filteredItems + : filteredItems // ignore: cast_nullable_to_non_nullable + as List, + loading: null == loading + ? _value.loading + : loading // ignore: cast_nullable_to_non_nullable + as bool, + )); + } +} + +/// @nodoc + +class _$SelectListStateImpl implements _SelectListState { + const _$SelectListStateImpl( + {final List filteredItems = const [], this.loading = false}) + : _filteredItems = filteredItems; + + final List _filteredItems; + @override + @JsonKey() + List get filteredItems { + if (_filteredItems is EqualUnmodifiableListView) return _filteredItems; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_filteredItems); + } + + @override + @JsonKey() + final bool loading; + + @override + String toString() { + return 'SelectListState<$T>(filteredItems: $filteredItems, loading: $loading)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$SelectListStateImpl && + const DeepCollectionEquality() + .equals(other._filteredItems, _filteredItems) && + (identical(other.loading, loading) || other.loading == loading)); + } + + @override + int get hashCode => Object.hash(runtimeType, + const DeepCollectionEquality().hash(_filteredItems), loading); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$SelectListStateImplCopyWith> get copyWith => + __$$SelectListStateImplCopyWithImpl>( + this, _$identity); +} + +abstract class _SelectListState implements SelectListState { + const factory _SelectListState( + {final List filteredItems, + final bool loading}) = _$SelectListStateImpl; + + @override + List get filteredItems; + @override + bool get loading; + @override + @JsonKey(ignore: true) + _$$SelectListStateImplCopyWith> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/utils/states/select_list.g.dart b/lib/utils/states/select_list.g.dart deleted file mode 100644 index b284f523..00000000 --- a/lib/utils/states/select_list.g.dart +++ /dev/null @@ -1,69 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'select_list.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$SelectListStateCWProxy { - SelectListState filteredItems(List filteredItems); - - SelectListState loading(bool loading); - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `SelectListState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// SelectListState(...).copyWith(id: 12, name: "My name") - /// ```` - SelectListState call({ - List? filteredItems, - bool? loading, - }); -} - -/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfSelectListState.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfSelectListState.copyWith.fieldName(...)` -class _$SelectListStateCWProxyImpl implements _$SelectListStateCWProxy { - const _$SelectListStateCWProxyImpl(this._value); - - final SelectListState _value; - - @override - SelectListState filteredItems(List filteredItems) => - this(filteredItems: filteredItems); - - @override - SelectListState loading(bool loading) => this(loading: loading); - - @override - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `SelectListState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// SelectListState(...).copyWith(id: 12, name: "My name") - /// ```` - SelectListState call({ - Object? filteredItems = const $CopyWithPlaceholder(), - Object? loading = const $CopyWithPlaceholder(), - }) { - return SelectListState._( - filteredItems == const $CopyWithPlaceholder() || filteredItems == null - ? _value.filteredItems - // ignore: cast_nullable_to_non_nullable - : filteredItems as List, - loading == const $CopyWithPlaceholder() || loading == null - ? _value.loading - // ignore: cast_nullable_to_non_nullable - : loading as bool, - ); - } -} - -extension $SelectListStateCopyWith on SelectListState { - /// Returns a callable class that can be used as follows: `instanceOfSelectListState.copyWith(...)` or like so:`instanceOfSelectListState.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$SelectListStateCWProxy get copyWith => - _$SelectListStateCWProxyImpl(this); -} diff --git a/lib/utils/states/tv/searchable_dynamic_select_from_list.dart b/lib/utils/states/tv/searchable_dynamic_select_from_list.dart index 18bc2210..c00e080c 100644 --- a/lib/utils/states/tv/searchable_dynamic_select_from_list.dart +++ b/lib/utils/states/tv/searchable_dynamic_select_from_list.dart @@ -1,10 +1,10 @@ import 'dart:core'; import 'package:bloc/bloc.dart'; -import 'package:copy_with_extension/copy_with_extension.dart'; import 'package:flutter/cupertino.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; -part 'searchable_dynamic_select_from_list.g.dart'; +part 'searchable_dynamic_select_from_list.freezed.dart'; class SearchableSelectFromListCubit extends Cubit> { final Future> Function(String query) fetchItems; @@ -17,13 +17,11 @@ class SearchableSelectFromListCubit extends Cubit { - final List items; - final TextEditingController controller; - final bool loading; - - SearchableSelectFromListState(this.items, {this.loading = false, required this.controller}); - - SearchableSelectFromListState._(this.items, this.controller, this.loading); +@freezed +class SearchableSelectFromListState with _$SearchableSelectFromListState { + const factory SearchableSelectFromListState( + List items, { + required TextEditingController controller, + @Default(false) bool loading, + }) = _SearchableSelectFromListState; } diff --git a/lib/utils/states/tv/searchable_dynamic_select_from_list.freezed.dart b/lib/utils/states/tv/searchable_dynamic_select_from_list.freezed.dart new file mode 100644 index 00000000..c42a4e40 --- /dev/null +++ b/lib/utils/states/tv/searchable_dynamic_select_from_list.freezed.dart @@ -0,0 +1,188 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'searchable_dynamic_select_from_list.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +mixin _$SearchableSelectFromListState { + List get items => throw _privateConstructorUsedError; + TextEditingController get controller => throw _privateConstructorUsedError; + bool get loading => throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + $SearchableSelectFromListStateCopyWith> + get copyWith => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $SearchableSelectFromListStateCopyWith { + factory $SearchableSelectFromListStateCopyWith( + SearchableSelectFromListState value, + $Res Function(SearchableSelectFromListState) then) = + _$SearchableSelectFromListStateCopyWithImpl>; + @useResult + $Res call({List items, TextEditingController controller, bool loading}); +} + +/// @nodoc +class _$SearchableSelectFromListStateCopyWithImpl> + implements $SearchableSelectFromListStateCopyWith { + _$SearchableSelectFromListStateCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? items = null, + Object? controller = null, + Object? loading = null, + }) { + return _then(_value.copyWith( + items: null == items + ? _value.items + : items // ignore: cast_nullable_to_non_nullable + as List, + controller: null == controller + ? _value.controller + : controller // ignore: cast_nullable_to_non_nullable + as TextEditingController, + loading: null == loading + ? _value.loading + : loading // ignore: cast_nullable_to_non_nullable + as bool, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$SearchableSelectFromListStateImplCopyWith + implements $SearchableSelectFromListStateCopyWith { + factory _$$SearchableSelectFromListStateImplCopyWith( + _$SearchableSelectFromListStateImpl value, + $Res Function(_$SearchableSelectFromListStateImpl) then) = + __$$SearchableSelectFromListStateImplCopyWithImpl; + @override + @useResult + $Res call({List items, TextEditingController controller, bool loading}); +} + +/// @nodoc +class __$$SearchableSelectFromListStateImplCopyWithImpl + extends _$SearchableSelectFromListStateCopyWithImpl> + implements _$$SearchableSelectFromListStateImplCopyWith { + __$$SearchableSelectFromListStateImplCopyWithImpl( + _$SearchableSelectFromListStateImpl _value, + $Res Function(_$SearchableSelectFromListStateImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? items = null, + Object? controller = null, + Object? loading = null, + }) { + return _then(_$SearchableSelectFromListStateImpl( + null == items + ? _value._items + : items // ignore: cast_nullable_to_non_nullable + as List, + controller: null == controller + ? _value.controller + : controller // ignore: cast_nullable_to_non_nullable + as TextEditingController, + loading: null == loading + ? _value.loading + : loading // ignore: cast_nullable_to_non_nullable + as bool, + )); + } +} + +/// @nodoc + +class _$SearchableSelectFromListStateImpl + implements _SearchableSelectFromListState { + const _$SearchableSelectFromListStateImpl(final List items, + {required this.controller, this.loading = false}) + : _items = items; + + final List _items; + @override + List get items { + if (_items is EqualUnmodifiableListView) return _items; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_items); + } + + @override + final TextEditingController controller; + @override + @JsonKey() + final bool loading; + + @override + String toString() { + return 'SearchableSelectFromListState<$T>(items: $items, controller: $controller, loading: $loading)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$SearchableSelectFromListStateImpl && + const DeepCollectionEquality().equals(other._items, _items) && + (identical(other.controller, controller) || + other.controller == controller) && + (identical(other.loading, loading) || other.loading == loading)); + } + + @override + int get hashCode => Object.hash(runtimeType, + const DeepCollectionEquality().hash(_items), controller, loading); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$SearchableSelectFromListStateImplCopyWith> + get copyWith => __$$SearchableSelectFromListStateImplCopyWithImpl>(this, _$identity); +} + +abstract class _SearchableSelectFromListState + implements SearchableSelectFromListState { + const factory _SearchableSelectFromListState(final List items, + {required final TextEditingController controller, + final bool loading}) = _$SearchableSelectFromListStateImpl; + + @override + List get items; + @override + TextEditingController get controller; + @override + bool get loading; + @override + @JsonKey(ignore: true) + _$$SearchableSelectFromListStateImplCopyWith> + get copyWith => throw _privateConstructorUsedError; +} diff --git a/lib/utils/states/tv/searchable_dynamic_select_from_list.g.dart b/lib/utils/states/tv/searchable_dynamic_select_from_list.g.dart deleted file mode 100644 index 30adaffb..00000000 --- a/lib/utils/states/tv/searchable_dynamic_select_from_list.g.dart +++ /dev/null @@ -1,84 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'searchable_dynamic_select_from_list.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$SearchableSelectFromListStateCWProxy { - SearchableSelectFromListState items(List items); - - SearchableSelectFromListState controller(TextEditingController controller); - - SearchableSelectFromListState loading(bool loading); - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `SearchableSelectFromListState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// SearchableSelectFromListState(...).copyWith(id: 12, name: "My name") - /// ```` - SearchableSelectFromListState call({ - List? items, - TextEditingController? controller, - bool? loading, - }); -} - -/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfSearchableSelectFromListState.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfSearchableSelectFromListState.copyWith.fieldName(...)` -class _$SearchableSelectFromListStateCWProxyImpl - implements _$SearchableSelectFromListStateCWProxy { - const _$SearchableSelectFromListStateCWProxyImpl(this._value); - - final SearchableSelectFromListState _value; - - @override - SearchableSelectFromListState items(List items) => this(items: items); - - @override - SearchableSelectFromListState controller( - TextEditingController controller) => - this(controller: controller); - - @override - SearchableSelectFromListState loading(bool loading) => - this(loading: loading); - - @override - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `SearchableSelectFromListState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// SearchableSelectFromListState(...).copyWith(id: 12, name: "My name") - /// ```` - SearchableSelectFromListState call({ - Object? items = const $CopyWithPlaceholder(), - Object? controller = const $CopyWithPlaceholder(), - Object? loading = const $CopyWithPlaceholder(), - }) { - return SearchableSelectFromListState._( - items == const $CopyWithPlaceholder() || items == null - ? _value.items - // ignore: cast_nullable_to_non_nullable - : items as List, - controller == const $CopyWithPlaceholder() || controller == null - ? _value.controller - // ignore: cast_nullable_to_non_nullable - : controller as TextEditingController, - loading == const $CopyWithPlaceholder() || loading == null - ? _value.loading - // ignore: cast_nullable_to_non_nullable - : loading as bool, - ); - } -} - -extension $SearchableSelectFromListStateCopyWith - on SearchableSelectFromListState { - /// Returns a callable class that can be used as follows: `instanceOfSearchableSelectFromListState.copyWith(...)` or like so:`instanceOfSearchableSelectFromListState.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$SearchableSelectFromListStateCWProxy get copyWith => - _$SearchableSelectFromListStateCWProxyImpl(this); -} diff --git a/lib/utils/views/components/paginated_list_view.dart b/lib/utils/views/components/paginated_list_view.dart index 5debf733..b27cef28 100644 --- a/lib/utils/views/components/paginated_list_view.dart +++ b/lib/utils/views/components/paginated_list_view.dart @@ -10,28 +10,28 @@ class PaginatedListView extends StatelessWidget { final List? startItems; final Widget Function(T item) itemBuilder; - const PaginatedListView({Key? key, required this.paginatedList, required this.itemBuilder, this.startItems}) - : super(key: key); + const PaginatedListView({Key? key, required this.paginatedList, required this.itemBuilder, this.startItems}) : super(key: key); @override Widget build(BuildContext context) { return BlocProvider( - create: (context) => PaginatedListCubit( - PaginatedListViewController(paginatedList: this.paginatedList, startItems: this.startItems)), - child: BlocBuilder, PaginatedListViewController>( - builder: (context, _) => Stack( - children: [ - if(_.loading) const TopListLoading(), - ListView.builder( - controller: _.scrollController, - itemCount: _.items.length, - itemBuilder: (BuildContext context, int index) { - T item = _.items[index]; - return itemBuilder(item); - }, - ), - ], - )), + create: (context) => PaginatedListCubit(PaginatedListViewController.init(paginatedList: this.paginatedList, startItems: this.startItems)), + child: BlocBuilder, PaginatedListViewController>(builder: (context, _) { + var cubit = context.read>(); + return Stack( + children: [ + if (_.loading) const TopListLoading(), + ListView.builder( + controller: cubit.scrollController, + itemCount: _.items.length, + itemBuilder: (BuildContext context, int index) { + T item = _.items[index]; + return itemBuilder(item); + }, + ), + ], + ); + }), ); } } diff --git a/lib/utils/views/components/select_list_dialog.dart b/lib/utils/views/components/select_list_dialog.dart index c4af7f74..674209f7 100644 --- a/lib/utils/views/components/select_list_dialog.dart +++ b/lib/utils/views/components/select_list_dialog.dart @@ -60,7 +60,7 @@ class SelectList extends StatelessWidget { content: SizedBox( width: 300, child: BlocProvider( - create: (BuildContext context) => SelectListCubit(SelectListState(values)), + create: (BuildContext context) => SelectListCubit(SelectListState(filteredItems: values ?? [])), child: BlocBuilder, SelectListState>(builder: (context, state) { var cubit = context.read>(); return Column( diff --git a/lib/utils/views/tv/components/tv_horizontal_item_list.dart b/lib/utils/views/tv/components/tv_horizontal_item_list.dart index fa21bac5..fb3d02f4 100644 --- a/lib/utils/views/tv/components/tv_horizontal_item_list.dart +++ b/lib/utils/views/tv/components/tv_horizontal_item_list.dart @@ -24,7 +24,7 @@ class TvHorizontalItemList extends StatelessWidget { create: (context) => ItemListCubit(ItemListState(itemList: paginatedList)), child: BlocBuilder, ItemListState>( builder: (context, _) { - + var cubit = context.read>(); // filter items if possible List items = _.items; if (items.isNotEmpty && items[0] is BaseVideo) { @@ -43,7 +43,7 @@ class TvHorizontalItemList extends StatelessWidget { height: 250, child: ListView.builder( scrollDirection: Axis.horizontal, - controller: _.scrollController, + controller: cubit.scrollController, itemCount: items.length + (_.loading ? 10 : 0), itemBuilder: (context, index) { if (index >= items.length) { diff --git a/lib/utils/views/tv/components/tv_horizontal_paginated_list.dart b/lib/utils/views/tv/components/tv_horizontal_paginated_list.dart index 053dffac..cc117296 100644 --- a/lib/utils/views/tv/components/tv_horizontal_paginated_list.dart +++ b/lib/utils/views/tv/components/tv_horizontal_paginated_list.dart @@ -20,10 +20,10 @@ class TvHorizontalPaginatedListView extends StatelessWidget { Widget build(BuildContext context) { return BlocProvider( create: (context) => PaginatedListCubit( - PaginatedListViewController(paginatedList: this.paginatedList, startItems: this.startItems)), + PaginatedListViewController.init(paginatedList: this.paginatedList, startItems: this.startItems)), child: BlocBuilder, PaginatedListViewController>( builder: (context, _) { - + var cubit = context.read>(); // filter items if possible List items = _.items; if (items.isNotEmpty && items[0] is BaseVideo) { @@ -37,7 +37,7 @@ class TvHorizontalPaginatedListView extends StatelessWidget { ) : const SizedBox.shrink(), ListView.builder( - controller: _.scrollController, + controller: cubit.scrollController, scrollDirection: Axis.horizontal, itemCount: items.length + (_.loading ? 10 : 0), itemBuilder: (BuildContext context, int index) => diff --git a/lib/videos/states/add_to_playlist.dart b/lib/videos/states/add_to_playlist.dart index 0d39ee5d..c7c242fc 100644 --- a/lib/videos/states/add_to_playlist.dart +++ b/lib/videos/states/add_to_playlist.dart @@ -1,5 +1,6 @@ import 'package:bloc/bloc.dart'; import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:invidious/extensions.dart'; import 'package:invidious/videos/models/video_in_list.dart'; import 'package:logging/logging.dart'; @@ -7,7 +8,7 @@ import 'package:logging/logging.dart'; import '../../globals.dart'; import '../../playlists/models/playlist.dart'; -part 'add_to_playlist.g.dart'; +part 'add_to_playlist.freezed.dart'; const String likePlaylistName = '❤️'; @@ -109,18 +110,19 @@ class AddToPlaylistCubit extends Cubit { } } -@CopyWith(constructor: "_") -class AddToPlaylistController { - List playlists = []; - int playListCount = 0; - String videoId; - bool isVideoLiked = false; +@freezed +class AddToPlaylistController with _$AddToPlaylistController{ + const factory AddToPlaylistController(String videoId, { + @Default([]) List playlists, + @Default(0) int playListCount, + @Default(false) bool isVideoLiked, + @Default(true) bool loading, + required bool isLoggedIn - bool loading = true; - bool isLoggedIn = service.isLoggedIn(); + }) = _AddToPlaylistController; - AddToPlaylistController(this.videoId); + static AddToPlaylistController init(String videoId){ + return AddToPlaylistController(videoId, isLoggedIn: service.isLoggedIn()); + } - AddToPlaylistController._( - this.playlists, this.playListCount, this.videoId, this.loading, this.isLoggedIn, this.isVideoLiked); } diff --git a/lib/videos/states/add_to_playlist.freezed.dart b/lib/videos/states/add_to_playlist.freezed.dart new file mode 100644 index 00000000..68dbe65f --- /dev/null +++ b/lib/videos/states/add_to_playlist.freezed.dart @@ -0,0 +1,261 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'add_to_playlist.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +mixin _$AddToPlaylistController { + String get videoId => throw _privateConstructorUsedError; + List get playlists => throw _privateConstructorUsedError; + int get playListCount => throw _privateConstructorUsedError; + bool get isVideoLiked => throw _privateConstructorUsedError; + bool get loading => throw _privateConstructorUsedError; + bool get isLoggedIn => throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + $AddToPlaylistControllerCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $AddToPlaylistControllerCopyWith<$Res> { + factory $AddToPlaylistControllerCopyWith(AddToPlaylistController value, + $Res Function(AddToPlaylistController) then) = + _$AddToPlaylistControllerCopyWithImpl<$Res, AddToPlaylistController>; + @useResult + $Res call( + {String videoId, + List playlists, + int playListCount, + bool isVideoLiked, + bool loading, + bool isLoggedIn}); +} + +/// @nodoc +class _$AddToPlaylistControllerCopyWithImpl<$Res, + $Val extends AddToPlaylistController> + implements $AddToPlaylistControllerCopyWith<$Res> { + _$AddToPlaylistControllerCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? videoId = null, + Object? playlists = null, + Object? playListCount = null, + Object? isVideoLiked = null, + Object? loading = null, + Object? isLoggedIn = null, + }) { + return _then(_value.copyWith( + videoId: null == videoId + ? _value.videoId + : videoId // ignore: cast_nullable_to_non_nullable + as String, + playlists: null == playlists + ? _value.playlists + : playlists // ignore: cast_nullable_to_non_nullable + as List, + playListCount: null == playListCount + ? _value.playListCount + : playListCount // ignore: cast_nullable_to_non_nullable + as int, + isVideoLiked: null == isVideoLiked + ? _value.isVideoLiked + : isVideoLiked // ignore: cast_nullable_to_non_nullable + as bool, + loading: null == loading + ? _value.loading + : loading // ignore: cast_nullable_to_non_nullable + as bool, + isLoggedIn: null == isLoggedIn + ? _value.isLoggedIn + : isLoggedIn // ignore: cast_nullable_to_non_nullable + as bool, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$AddToPlaylistControllerImplCopyWith<$Res> + implements $AddToPlaylistControllerCopyWith<$Res> { + factory _$$AddToPlaylistControllerImplCopyWith( + _$AddToPlaylistControllerImpl value, + $Res Function(_$AddToPlaylistControllerImpl) then) = + __$$AddToPlaylistControllerImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {String videoId, + List playlists, + int playListCount, + bool isVideoLiked, + bool loading, + bool isLoggedIn}); +} + +/// @nodoc +class __$$AddToPlaylistControllerImplCopyWithImpl<$Res> + extends _$AddToPlaylistControllerCopyWithImpl<$Res, + _$AddToPlaylistControllerImpl> + implements _$$AddToPlaylistControllerImplCopyWith<$Res> { + __$$AddToPlaylistControllerImplCopyWithImpl( + _$AddToPlaylistControllerImpl _value, + $Res Function(_$AddToPlaylistControllerImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? videoId = null, + Object? playlists = null, + Object? playListCount = null, + Object? isVideoLiked = null, + Object? loading = null, + Object? isLoggedIn = null, + }) { + return _then(_$AddToPlaylistControllerImpl( + null == videoId + ? _value.videoId + : videoId // ignore: cast_nullable_to_non_nullable + as String, + playlists: null == playlists + ? _value._playlists + : playlists // ignore: cast_nullable_to_non_nullable + as List, + playListCount: null == playListCount + ? _value.playListCount + : playListCount // ignore: cast_nullable_to_non_nullable + as int, + isVideoLiked: null == isVideoLiked + ? _value.isVideoLiked + : isVideoLiked // ignore: cast_nullable_to_non_nullable + as bool, + loading: null == loading + ? _value.loading + : loading // ignore: cast_nullable_to_non_nullable + as bool, + isLoggedIn: null == isLoggedIn + ? _value.isLoggedIn + : isLoggedIn // ignore: cast_nullable_to_non_nullable + as bool, + )); + } +} + +/// @nodoc + +class _$AddToPlaylistControllerImpl implements _AddToPlaylistController { + const _$AddToPlaylistControllerImpl(this.videoId, + {final List playlists = const [], + this.playListCount = 0, + this.isVideoLiked = false, + this.loading = true, + required this.isLoggedIn}) + : _playlists = playlists; + + @override + final String videoId; + final List _playlists; + @override + @JsonKey() + List get playlists { + if (_playlists is EqualUnmodifiableListView) return _playlists; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_playlists); + } + + @override + @JsonKey() + final int playListCount; + @override + @JsonKey() + final bool isVideoLiked; + @override + @JsonKey() + final bool loading; + @override + final bool isLoggedIn; + + @override + String toString() { + return 'AddToPlaylistController(videoId: $videoId, playlists: $playlists, playListCount: $playListCount, isVideoLiked: $isVideoLiked, loading: $loading, isLoggedIn: $isLoggedIn)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$AddToPlaylistControllerImpl && + (identical(other.videoId, videoId) || other.videoId == videoId) && + const DeepCollectionEquality() + .equals(other._playlists, _playlists) && + (identical(other.playListCount, playListCount) || + other.playListCount == playListCount) && + (identical(other.isVideoLiked, isVideoLiked) || + other.isVideoLiked == isVideoLiked) && + (identical(other.loading, loading) || other.loading == loading) && + (identical(other.isLoggedIn, isLoggedIn) || + other.isLoggedIn == isLoggedIn)); + } + + @override + int get hashCode => Object.hash( + runtimeType, + videoId, + const DeepCollectionEquality().hash(_playlists), + playListCount, + isVideoLiked, + loading, + isLoggedIn); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$AddToPlaylistControllerImplCopyWith<_$AddToPlaylistControllerImpl> + get copyWith => __$$AddToPlaylistControllerImplCopyWithImpl< + _$AddToPlaylistControllerImpl>(this, _$identity); +} + +abstract class _AddToPlaylistController implements AddToPlaylistController { + const factory _AddToPlaylistController(final String videoId, + {final List playlists, + final int playListCount, + final bool isVideoLiked, + final bool loading, + required final bool isLoggedIn}) = _$AddToPlaylistControllerImpl; + + @override + String get videoId; + @override + List get playlists; + @override + int get playListCount; + @override + bool get isVideoLiked; + @override + bool get loading; + @override + bool get isLoggedIn; + @override + @JsonKey(ignore: true) + _$$AddToPlaylistControllerImplCopyWith<_$AddToPlaylistControllerImpl> + get copyWith => throw _privateConstructorUsedError; +} diff --git a/lib/videos/states/add_to_playlist.g.dart b/lib/videos/states/add_to_playlist.g.dart deleted file mode 100644 index 0ce006dc..00000000 --- a/lib/videos/states/add_to_playlist.g.dart +++ /dev/null @@ -1,117 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'add_to_playlist.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$AddToPlaylistControllerCWProxy { - AddToPlaylistController playlists(List playlists); - - AddToPlaylistController playListCount(int playListCount); - - AddToPlaylistController videoId(String videoId); - - AddToPlaylistController loading(bool loading); - - AddToPlaylistController isLoggedIn(bool isLoggedIn); - - AddToPlaylistController isVideoLiked(bool isVideoLiked); - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `AddToPlaylistController(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// AddToPlaylistController(...).copyWith(id: 12, name: "My name") - /// ```` - AddToPlaylistController call({ - List? playlists, - int? playListCount, - String? videoId, - bool? loading, - bool? isLoggedIn, - bool? isVideoLiked, - }); -} - -/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfAddToPlaylistController.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfAddToPlaylistController.copyWith.fieldName(...)` -class _$AddToPlaylistControllerCWProxyImpl - implements _$AddToPlaylistControllerCWProxy { - const _$AddToPlaylistControllerCWProxyImpl(this._value); - - final AddToPlaylistController _value; - - @override - AddToPlaylistController playlists(List playlists) => - this(playlists: playlists); - - @override - AddToPlaylistController playListCount(int playListCount) => - this(playListCount: playListCount); - - @override - AddToPlaylistController videoId(String videoId) => this(videoId: videoId); - - @override - AddToPlaylistController loading(bool loading) => this(loading: loading); - - @override - AddToPlaylistController isLoggedIn(bool isLoggedIn) => - this(isLoggedIn: isLoggedIn); - - @override - AddToPlaylistController isVideoLiked(bool isVideoLiked) => - this(isVideoLiked: isVideoLiked); - - @override - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `AddToPlaylistController(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// AddToPlaylistController(...).copyWith(id: 12, name: "My name") - /// ```` - AddToPlaylistController call({ - Object? playlists = const $CopyWithPlaceholder(), - Object? playListCount = const $CopyWithPlaceholder(), - Object? videoId = const $CopyWithPlaceholder(), - Object? loading = const $CopyWithPlaceholder(), - Object? isLoggedIn = const $CopyWithPlaceholder(), - Object? isVideoLiked = const $CopyWithPlaceholder(), - }) { - return AddToPlaylistController._( - playlists == const $CopyWithPlaceholder() || playlists == null - ? _value.playlists - // ignore: cast_nullable_to_non_nullable - : playlists as List, - playListCount == const $CopyWithPlaceholder() || playListCount == null - ? _value.playListCount - // ignore: cast_nullable_to_non_nullable - : playListCount as int, - videoId == const $CopyWithPlaceholder() || videoId == null - ? _value.videoId - // ignore: cast_nullable_to_non_nullable - : videoId as String, - loading == const $CopyWithPlaceholder() || loading == null - ? _value.loading - // ignore: cast_nullable_to_non_nullable - : loading as bool, - isLoggedIn == const $CopyWithPlaceholder() || isLoggedIn == null - ? _value.isLoggedIn - // ignore: cast_nullable_to_non_nullable - : isLoggedIn as bool, - isVideoLiked == const $CopyWithPlaceholder() || isVideoLiked == null - ? _value.isVideoLiked - // ignore: cast_nullable_to_non_nullable - : isVideoLiked as bool, - ); - } -} - -extension $AddToPlaylistControllerCopyWith on AddToPlaylistController { - /// Returns a callable class that can be used as follows: `instanceOfAddToPlaylistController.copyWith(...)` or like so:`instanceOfAddToPlaylistController.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$AddToPlaylistControllerCWProxy get copyWith => - _$AddToPlaylistControllerCWProxyImpl(this); -} diff --git a/lib/videos/states/compact_video.dart b/lib/videos/states/compact_video.dart index c909113b..72e035a1 100644 --- a/lib/videos/states/compact_video.dart +++ b/lib/videos/states/compact_video.dart @@ -1,11 +1,11 @@ import 'dart:io'; import 'package:bloc/bloc.dart'; -import 'package:copy_with_extension/copy_with_extension.dart'; import 'package:easy_debounce/easy_debounce.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:invidious/downloads/models/downloaded_video.dart'; -part 'compact_video.g.dart'; +part 'compact_video.freezed.dart'; class CompactVideoCubit extends Cubit { CompactVideoCubit(super.initialState) { @@ -24,9 +24,7 @@ class CompactVideoCubit extends Cubit { var exists = await file.exists(); var hasSize = await file.length() > 0; if (exists && hasSize) { - var state = this.state.copyWith(); - state.offlineVideoThumbnailPath = path; - emit(state); + emit(state.copyWith(offlineVideoThumbnailPath: path)); } else { EasyDebounce.debounce( '${state.offlineVideo?.videoId}-compact-view-thumbnail', const Duration(seconds: 1), getThumbnail); @@ -39,12 +37,10 @@ class CompactVideoCubit extends Cubit { } } -@CopyWith(constructor: "_") -class CompactVideoState { - final DownloadedVideo? offlineVideo; - String? offlineVideoThumbnailPath; - - CompactVideoState({this.offlineVideo}); - - CompactVideoState._(this.offlineVideo, this.offlineVideoThumbnailPath); +@freezed +class CompactVideoState with _$CompactVideoState { + const factory CompactVideoState({ + DownloadedVideo? offlineVideo, + String? offlineVideoThumbnailPath + }) = _CompactVideoState; } diff --git a/lib/videos/states/compact_video.freezed.dart b/lib/videos/states/compact_video.freezed.dart new file mode 100644 index 00000000..cdd04ec3 --- /dev/null +++ b/lib/videos/states/compact_video.freezed.dart @@ -0,0 +1,156 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'compact_video.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +mixin _$CompactVideoState { + DownloadedVideo? get offlineVideo => throw _privateConstructorUsedError; + String? get offlineVideoThumbnailPath => throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + $CompactVideoStateCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $CompactVideoStateCopyWith<$Res> { + factory $CompactVideoStateCopyWith( + CompactVideoState value, $Res Function(CompactVideoState) then) = + _$CompactVideoStateCopyWithImpl<$Res, CompactVideoState>; + @useResult + $Res call({DownloadedVideo? offlineVideo, String? offlineVideoThumbnailPath}); +} + +/// @nodoc +class _$CompactVideoStateCopyWithImpl<$Res, $Val extends CompactVideoState> + implements $CompactVideoStateCopyWith<$Res> { + _$CompactVideoStateCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? offlineVideo = freezed, + Object? offlineVideoThumbnailPath = freezed, + }) { + return _then(_value.copyWith( + offlineVideo: freezed == offlineVideo + ? _value.offlineVideo + : offlineVideo // ignore: cast_nullable_to_non_nullable + as DownloadedVideo?, + offlineVideoThumbnailPath: freezed == offlineVideoThumbnailPath + ? _value.offlineVideoThumbnailPath + : offlineVideoThumbnailPath // ignore: cast_nullable_to_non_nullable + as String?, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$CompactVideoStateImplCopyWith<$Res> + implements $CompactVideoStateCopyWith<$Res> { + factory _$$CompactVideoStateImplCopyWith(_$CompactVideoStateImpl value, + $Res Function(_$CompactVideoStateImpl) then) = + __$$CompactVideoStateImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({DownloadedVideo? offlineVideo, String? offlineVideoThumbnailPath}); +} + +/// @nodoc +class __$$CompactVideoStateImplCopyWithImpl<$Res> + extends _$CompactVideoStateCopyWithImpl<$Res, _$CompactVideoStateImpl> + implements _$$CompactVideoStateImplCopyWith<$Res> { + __$$CompactVideoStateImplCopyWithImpl(_$CompactVideoStateImpl _value, + $Res Function(_$CompactVideoStateImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? offlineVideo = freezed, + Object? offlineVideoThumbnailPath = freezed, + }) { + return _then(_$CompactVideoStateImpl( + offlineVideo: freezed == offlineVideo + ? _value.offlineVideo + : offlineVideo // ignore: cast_nullable_to_non_nullable + as DownloadedVideo?, + offlineVideoThumbnailPath: freezed == offlineVideoThumbnailPath + ? _value.offlineVideoThumbnailPath + : offlineVideoThumbnailPath // ignore: cast_nullable_to_non_nullable + as String?, + )); + } +} + +/// @nodoc + +class _$CompactVideoStateImpl implements _CompactVideoState { + const _$CompactVideoStateImpl( + {this.offlineVideo, this.offlineVideoThumbnailPath}); + + @override + final DownloadedVideo? offlineVideo; + @override + final String? offlineVideoThumbnailPath; + + @override + String toString() { + return 'CompactVideoState(offlineVideo: $offlineVideo, offlineVideoThumbnailPath: $offlineVideoThumbnailPath)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$CompactVideoStateImpl && + (identical(other.offlineVideo, offlineVideo) || + other.offlineVideo == offlineVideo) && + (identical(other.offlineVideoThumbnailPath, + offlineVideoThumbnailPath) || + other.offlineVideoThumbnailPath == offlineVideoThumbnailPath)); + } + + @override + int get hashCode => + Object.hash(runtimeType, offlineVideo, offlineVideoThumbnailPath); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$CompactVideoStateImplCopyWith<_$CompactVideoStateImpl> get copyWith => + __$$CompactVideoStateImplCopyWithImpl<_$CompactVideoStateImpl>( + this, _$identity); +} + +abstract class _CompactVideoState implements CompactVideoState { + const factory _CompactVideoState( + {final DownloadedVideo? offlineVideo, + final String? offlineVideoThumbnailPath}) = _$CompactVideoStateImpl; + + @override + DownloadedVideo? get offlineVideo; + @override + String? get offlineVideoThumbnailPath; + @override + @JsonKey(ignore: true) + _$$CompactVideoStateImplCopyWith<_$CompactVideoStateImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/videos/states/compact_video.g.dart b/lib/videos/states/compact_video.g.dart deleted file mode 100644 index 99329e31..00000000 --- a/lib/videos/states/compact_video.g.dart +++ /dev/null @@ -1,72 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'compact_video.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$CompactVideoStateCWProxy { - CompactVideoState offlineVideo(DownloadedVideo? offlineVideo); - - CompactVideoState offlineVideoThumbnailPath( - String? offlineVideoThumbnailPath); - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `CompactVideoState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// CompactVideoState(...).copyWith(id: 12, name: "My name") - /// ```` - CompactVideoState call({ - DownloadedVideo? offlineVideo, - String? offlineVideoThumbnailPath, - }); -} - -/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfCompactVideoState.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfCompactVideoState.copyWith.fieldName(...)` -class _$CompactVideoStateCWProxyImpl implements _$CompactVideoStateCWProxy { - const _$CompactVideoStateCWProxyImpl(this._value); - - final CompactVideoState _value; - - @override - CompactVideoState offlineVideo(DownloadedVideo? offlineVideo) => - this(offlineVideo: offlineVideo); - - @override - CompactVideoState offlineVideoThumbnailPath( - String? offlineVideoThumbnailPath) => - this(offlineVideoThumbnailPath: offlineVideoThumbnailPath); - - @override - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `CompactVideoState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// CompactVideoState(...).copyWith(id: 12, name: "My name") - /// ```` - CompactVideoState call({ - Object? offlineVideo = const $CopyWithPlaceholder(), - Object? offlineVideoThumbnailPath = const $CopyWithPlaceholder(), - }) { - return CompactVideoState._( - offlineVideo == const $CopyWithPlaceholder() - ? _value.offlineVideo - // ignore: cast_nullable_to_non_nullable - : offlineVideo as DownloadedVideo?, - offlineVideoThumbnailPath == const $CopyWithPlaceholder() - ? _value.offlineVideoThumbnailPath - // ignore: cast_nullable_to_non_nullable - : offlineVideoThumbnailPath as String?, - ); - } -} - -extension $CompactVideoStateCopyWith on CompactVideoState { - /// Returns a callable class that can be used as follows: `instanceOfCompactVideoState.copyWith(...)` or like so:`instanceOfCompactVideoState.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$CompactVideoStateCWProxy get copyWith => - _$CompactVideoStateCWProxyImpl(this); -} diff --git a/lib/videos/states/download_modal_sheet.dart b/lib/videos/states/download_modal_sheet.dart index 2426c6f3..fef2b985 100644 --- a/lib/videos/states/download_modal_sheet.dart +++ b/lib/videos/states/download_modal_sheet.dart @@ -1,30 +1,21 @@ import 'package:bloc/bloc.dart'; -import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; -part 'download_modal_sheet.g.dart'; +part 'download_modal_sheet.freezed.dart'; class DownloadModalSheetCubit extends Cubit { DownloadModalSheetCubit(super.initialState); setAudioOnly(bool value) { - var state = this.state.copyWith(); - state.audioOnly = value; - emit(state); + emit(state.copyWith(audioOnly: value)); } setQuality(String quality) { - var state = this.state.copyWith(); - state.quality = quality; - emit(state); + emit(state.copyWith(quality: quality)); } } -@CopyWith(constructor: "_") -class DownloadModalSheetState { - bool audioOnly = false; - String quality = '720p'; - - DownloadModalSheetState(); - - DownloadModalSheetState._(this.audioOnly, this.quality); +@freezed +class DownloadModalSheetState with _$DownloadModalSheetState { + const factory DownloadModalSheetState({@Default(false) bool audioOnly, @Default('720p') String quality}) = _DownloadModalSheetState; } diff --git a/lib/videos/states/download_modal_sheet.freezed.dart b/lib/videos/states/download_modal_sheet.freezed.dart new file mode 100644 index 00000000..61c49a24 --- /dev/null +++ b/lib/videos/states/download_modal_sheet.freezed.dart @@ -0,0 +1,159 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'download_modal_sheet.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +mixin _$DownloadModalSheetState { + bool get audioOnly => throw _privateConstructorUsedError; + String get quality => throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + $DownloadModalSheetStateCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $DownloadModalSheetStateCopyWith<$Res> { + factory $DownloadModalSheetStateCopyWith(DownloadModalSheetState value, + $Res Function(DownloadModalSheetState) then) = + _$DownloadModalSheetStateCopyWithImpl<$Res, DownloadModalSheetState>; + @useResult + $Res call({bool audioOnly, String quality}); +} + +/// @nodoc +class _$DownloadModalSheetStateCopyWithImpl<$Res, + $Val extends DownloadModalSheetState> + implements $DownloadModalSheetStateCopyWith<$Res> { + _$DownloadModalSheetStateCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? audioOnly = null, + Object? quality = null, + }) { + return _then(_value.copyWith( + audioOnly: null == audioOnly + ? _value.audioOnly + : audioOnly // ignore: cast_nullable_to_non_nullable + as bool, + quality: null == quality + ? _value.quality + : quality // ignore: cast_nullable_to_non_nullable + as String, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$DownloadModalSheetStateImplCopyWith<$Res> + implements $DownloadModalSheetStateCopyWith<$Res> { + factory _$$DownloadModalSheetStateImplCopyWith( + _$DownloadModalSheetStateImpl value, + $Res Function(_$DownloadModalSheetStateImpl) then) = + __$$DownloadModalSheetStateImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({bool audioOnly, String quality}); +} + +/// @nodoc +class __$$DownloadModalSheetStateImplCopyWithImpl<$Res> + extends _$DownloadModalSheetStateCopyWithImpl<$Res, + _$DownloadModalSheetStateImpl> + implements _$$DownloadModalSheetStateImplCopyWith<$Res> { + __$$DownloadModalSheetStateImplCopyWithImpl( + _$DownloadModalSheetStateImpl _value, + $Res Function(_$DownloadModalSheetStateImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? audioOnly = null, + Object? quality = null, + }) { + return _then(_$DownloadModalSheetStateImpl( + audioOnly: null == audioOnly + ? _value.audioOnly + : audioOnly // ignore: cast_nullable_to_non_nullable + as bool, + quality: null == quality + ? _value.quality + : quality // ignore: cast_nullable_to_non_nullable + as String, + )); + } +} + +/// @nodoc + +class _$DownloadModalSheetStateImpl implements _DownloadModalSheetState { + const _$DownloadModalSheetStateImpl( + {this.audioOnly = false, this.quality = '720p'}); + + @override + @JsonKey() + final bool audioOnly; + @override + @JsonKey() + final String quality; + + @override + String toString() { + return 'DownloadModalSheetState(audioOnly: $audioOnly, quality: $quality)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$DownloadModalSheetStateImpl && + (identical(other.audioOnly, audioOnly) || + other.audioOnly == audioOnly) && + (identical(other.quality, quality) || other.quality == quality)); + } + + @override + int get hashCode => Object.hash(runtimeType, audioOnly, quality); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$DownloadModalSheetStateImplCopyWith<_$DownloadModalSheetStateImpl> + get copyWith => __$$DownloadModalSheetStateImplCopyWithImpl< + _$DownloadModalSheetStateImpl>(this, _$identity); +} + +abstract class _DownloadModalSheetState implements DownloadModalSheetState { + const factory _DownloadModalSheetState( + {final bool audioOnly, + final String quality}) = _$DownloadModalSheetStateImpl; + + @override + bool get audioOnly; + @override + String get quality; + @override + @JsonKey(ignore: true) + _$$DownloadModalSheetStateImplCopyWith<_$DownloadModalSheetStateImpl> + get copyWith => throw _privateConstructorUsedError; +} diff --git a/lib/videos/states/download_modal_sheet.g.dart b/lib/videos/states/download_modal_sheet.g.dart deleted file mode 100644 index 798e37ec..00000000 --- a/lib/videos/states/download_modal_sheet.g.dart +++ /dev/null @@ -1,70 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'download_modal_sheet.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$DownloadModalSheetStateCWProxy { - DownloadModalSheetState audioOnly(bool audioOnly); - - DownloadModalSheetState quality(String quality); - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `DownloadModalSheetState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// DownloadModalSheetState(...).copyWith(id: 12, name: "My name") - /// ```` - DownloadModalSheetState call({ - bool? audioOnly, - String? quality, - }); -} - -/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfDownloadModalSheetState.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfDownloadModalSheetState.copyWith.fieldName(...)` -class _$DownloadModalSheetStateCWProxyImpl - implements _$DownloadModalSheetStateCWProxy { - const _$DownloadModalSheetStateCWProxyImpl(this._value); - - final DownloadModalSheetState _value; - - @override - DownloadModalSheetState audioOnly(bool audioOnly) => - this(audioOnly: audioOnly); - - @override - DownloadModalSheetState quality(String quality) => this(quality: quality); - - @override - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `DownloadModalSheetState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// DownloadModalSheetState(...).copyWith(id: 12, name: "My name") - /// ```` - DownloadModalSheetState call({ - Object? audioOnly = const $CopyWithPlaceholder(), - Object? quality = const $CopyWithPlaceholder(), - }) { - return DownloadModalSheetState._( - audioOnly == const $CopyWithPlaceholder() || audioOnly == null - ? _value.audioOnly - // ignore: cast_nullable_to_non_nullable - : audioOnly as bool, - quality == const $CopyWithPlaceholder() || quality == null - ? _value.quality - // ignore: cast_nullable_to_non_nullable - : quality as String, - ); - } -} - -extension $DownloadModalSheetStateCopyWith on DownloadModalSheetState { - /// Returns a callable class that can be used as follows: `instanceOfDownloadModalSheetState.copyWith(...)` or like so:`instanceOfDownloadModalSheetState.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$DownloadModalSheetStateCWProxy get copyWith => - _$DownloadModalSheetStateCWProxyImpl(this); -} diff --git a/lib/videos/states/history.dart b/lib/videos/states/history.dart index d1614d5d..dc7dcc9b 100644 --- a/lib/videos/states/history.dart +++ b/lib/videos/states/history.dart @@ -1,11 +1,12 @@ import 'package:bloc/bloc.dart'; import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:invidious/globals.dart'; import 'package:invidious/utils/states/item_list.dart'; import '../models/db/history_video_cache.dart'; -part 'history.g.dart'; +part 'history.freezed.dart'; class HistoryCubit extends Cubit { final ItemListCubit historyListCubit; @@ -33,29 +34,17 @@ class HistoryItemCubit extends Cubit { } getVideo() async { - var state = this.state.copyWith(); - state = this.state.copyWith(); - state.loading = true; - emit(state); + emit(state.copyWith(loading: true)); - state = state.copyWith(); + var cachedVid = await HistoryVideoCache.fromVideoIdToVideo(state.videoId); - state.cachedVid = await HistoryVideoCache.fromVideoIdToVideo(state.videoId); - - state.loading = false; - if(!isClosed) { - emit(state); + if (!isClosed) { + emit(state.copyWith(cachedVid: cachedVid, loading: false)); } } } -@CopyWith(constructor: "_") -class HistoryItemState { - final String videoId; - bool loading = true; - HistoryVideoCache? cachedVid; - - HistoryItemState({required this.videoId}); - - HistoryItemState._(this.videoId, this.loading, this.cachedVid); +@freezed +class HistoryItemState with _$HistoryItemState { + const factory HistoryItemState({required String videoId, @Default(true) bool loading, HistoryVideoCache? cachedVid}) = _HistoryItemState; } diff --git a/lib/videos/states/history.freezed.dart b/lib/videos/states/history.freezed.dart new file mode 100644 index 00000000..cb6c8cbd --- /dev/null +++ b/lib/videos/states/history.freezed.dart @@ -0,0 +1,171 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'history.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +mixin _$HistoryItemState { + String get videoId => throw _privateConstructorUsedError; + bool get loading => throw _privateConstructorUsedError; + HistoryVideoCache? get cachedVid => throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + $HistoryItemStateCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $HistoryItemStateCopyWith<$Res> { + factory $HistoryItemStateCopyWith( + HistoryItemState value, $Res Function(HistoryItemState) then) = + _$HistoryItemStateCopyWithImpl<$Res, HistoryItemState>; + @useResult + $Res call({String videoId, bool loading, HistoryVideoCache? cachedVid}); +} + +/// @nodoc +class _$HistoryItemStateCopyWithImpl<$Res, $Val extends HistoryItemState> + implements $HistoryItemStateCopyWith<$Res> { + _$HistoryItemStateCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? videoId = null, + Object? loading = null, + Object? cachedVid = freezed, + }) { + return _then(_value.copyWith( + videoId: null == videoId + ? _value.videoId + : videoId // ignore: cast_nullable_to_non_nullable + as String, + loading: null == loading + ? _value.loading + : loading // ignore: cast_nullable_to_non_nullable + as bool, + cachedVid: freezed == cachedVid + ? _value.cachedVid + : cachedVid // ignore: cast_nullable_to_non_nullable + as HistoryVideoCache?, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$HistoryItemStateImplCopyWith<$Res> + implements $HistoryItemStateCopyWith<$Res> { + factory _$$HistoryItemStateImplCopyWith(_$HistoryItemStateImpl value, + $Res Function(_$HistoryItemStateImpl) then) = + __$$HistoryItemStateImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({String videoId, bool loading, HistoryVideoCache? cachedVid}); +} + +/// @nodoc +class __$$HistoryItemStateImplCopyWithImpl<$Res> + extends _$HistoryItemStateCopyWithImpl<$Res, _$HistoryItemStateImpl> + implements _$$HistoryItemStateImplCopyWith<$Res> { + __$$HistoryItemStateImplCopyWithImpl(_$HistoryItemStateImpl _value, + $Res Function(_$HistoryItemStateImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? videoId = null, + Object? loading = null, + Object? cachedVid = freezed, + }) { + return _then(_$HistoryItemStateImpl( + videoId: null == videoId + ? _value.videoId + : videoId // ignore: cast_nullable_to_non_nullable + as String, + loading: null == loading + ? _value.loading + : loading // ignore: cast_nullable_to_non_nullable + as bool, + cachedVid: freezed == cachedVid + ? _value.cachedVid + : cachedVid // ignore: cast_nullable_to_non_nullable + as HistoryVideoCache?, + )); + } +} + +/// @nodoc + +class _$HistoryItemStateImpl implements _HistoryItemState { + const _$HistoryItemStateImpl( + {required this.videoId, this.loading = true, this.cachedVid}); + + @override + final String videoId; + @override + @JsonKey() + final bool loading; + @override + final HistoryVideoCache? cachedVid; + + @override + String toString() { + return 'HistoryItemState(videoId: $videoId, loading: $loading, cachedVid: $cachedVid)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$HistoryItemStateImpl && + (identical(other.videoId, videoId) || other.videoId == videoId) && + (identical(other.loading, loading) || other.loading == loading) && + (identical(other.cachedVid, cachedVid) || + other.cachedVid == cachedVid)); + } + + @override + int get hashCode => Object.hash(runtimeType, videoId, loading, cachedVid); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$HistoryItemStateImplCopyWith<_$HistoryItemStateImpl> get copyWith => + __$$HistoryItemStateImplCopyWithImpl<_$HistoryItemStateImpl>( + this, _$identity); +} + +abstract class _HistoryItemState implements HistoryItemState { + const factory _HistoryItemState( + {required final String videoId, + final bool loading, + final HistoryVideoCache? cachedVid}) = _$HistoryItemStateImpl; + + @override + String get videoId; + @override + bool get loading; + @override + HistoryVideoCache? get cachedVid; + @override + @JsonKey(ignore: true) + _$$HistoryItemStateImplCopyWith<_$HistoryItemStateImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/videos/states/history.g.dart b/lib/videos/states/history.g.dart deleted file mode 100644 index ff6a1a01..00000000 --- a/lib/videos/states/history.g.dart +++ /dev/null @@ -1,79 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'history.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$HistoryItemStateCWProxy { - HistoryItemState videoId(String videoId); - - HistoryItemState loading(bool loading); - - HistoryItemState cachedVid(HistoryVideoCache? cachedVid); - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `HistoryItemState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// HistoryItemState(...).copyWith(id: 12, name: "My name") - /// ```` - HistoryItemState call({ - String? videoId, - bool? loading, - HistoryVideoCache? cachedVid, - }); -} - -/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfHistoryItemState.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfHistoryItemState.copyWith.fieldName(...)` -class _$HistoryItemStateCWProxyImpl implements _$HistoryItemStateCWProxy { - const _$HistoryItemStateCWProxyImpl(this._value); - - final HistoryItemState _value; - - @override - HistoryItemState videoId(String videoId) => this(videoId: videoId); - - @override - HistoryItemState loading(bool loading) => this(loading: loading); - - @override - HistoryItemState cachedVid(HistoryVideoCache? cachedVid) => - this(cachedVid: cachedVid); - - @override - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `HistoryItemState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// HistoryItemState(...).copyWith(id: 12, name: "My name") - /// ```` - HistoryItemState call({ - Object? videoId = const $CopyWithPlaceholder(), - Object? loading = const $CopyWithPlaceholder(), - Object? cachedVid = const $CopyWithPlaceholder(), - }) { - return HistoryItemState._( - videoId == const $CopyWithPlaceholder() || videoId == null - ? _value.videoId - // ignore: cast_nullable_to_non_nullable - : videoId as String, - loading == const $CopyWithPlaceholder() || loading == null - ? _value.loading - // ignore: cast_nullable_to_non_nullable - : loading as bool, - cachedVid == const $CopyWithPlaceholder() - ? _value.cachedVid - // ignore: cast_nullable_to_non_nullable - : cachedVid as HistoryVideoCache?, - ); - } -} - -extension $HistoryItemStateCopyWith on HistoryItemState { - /// Returns a callable class that can be used as follows: `instanceOfHistoryItemState.copyWith(...)` or like so:`instanceOfHistoryItemState.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$HistoryItemStateCWProxy get copyWith => _$HistoryItemStateCWProxyImpl(this); -} diff --git a/lib/videos/states/tv_video.dart b/lib/videos/states/tv_video.dart index 257fa2b2..30cf888f 100644 --- a/lib/videos/states/tv_video.dart +++ b/lib/videos/states/tv_video.dart @@ -1,42 +1,35 @@ import 'package:bloc/bloc.dart'; -import 'package:copy_with_extension/copy_with_extension.dart'; import 'package:flutter/material.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:invidious/globals.dart'; -part 'tv_video.g.dart'; +part 'tv_video.freezed.dart'; double defaultBottomOffset = -400; class TvVideoCubit extends Cubit { - TvVideoCubit(super.initialState); + final ScrollController scrollController; + + TvVideoCubit(super.initialState, {ScrollController? scrollController}) : scrollController = scrollController ?? ScrollController(); @override close() async { - state.scrollController.dispose(); + scrollController.dispose(); super.close(); } scrollUp() { var state = this.state.copyWith(); - state.scrollController.animateTo(0, duration: animationDuration ~/ 2, curve: Curves.easeInOutQuad); - state.showImage = true; - emit(state); + scrollController.animateTo(0, duration: animationDuration ~/ 2, curve: Curves.easeInOutQuad); + emit(state.copyWith(showImage: true)); } scrollDown() { - var state = this.state.copyWith(); - state.showImage = false; - emit(state); + emit(state.copyWith(showImage: false)); } } -@CopyWith(constructor: "_") -class TvVideoState { - final ScrollController scrollController; - bool showImage = true; - - TvVideoState({ScrollController? scrollController}) : scrollController = scrollController ?? ScrollController(); - - TvVideoState._(ScrollController? scrollController, this.showImage) - : scrollController = scrollController ?? ScrollController(); +@freezed +class TvVideoState with _$TvVideoState { + const factory TvVideoState({@Default(true) bool showImage}) = _TvVideoState; } diff --git a/lib/videos/states/tv_video.freezed.dart b/lib/videos/states/tv_video.freezed.dart new file mode 100644 index 00000000..710688f4 --- /dev/null +++ b/lib/videos/states/tv_video.freezed.dart @@ -0,0 +1,134 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'tv_video.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +mixin _$TvVideoState { + bool get showImage => throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + $TvVideoStateCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $TvVideoStateCopyWith<$Res> { + factory $TvVideoStateCopyWith( + TvVideoState value, $Res Function(TvVideoState) then) = + _$TvVideoStateCopyWithImpl<$Res, TvVideoState>; + @useResult + $Res call({bool showImage}); +} + +/// @nodoc +class _$TvVideoStateCopyWithImpl<$Res, $Val extends TvVideoState> + implements $TvVideoStateCopyWith<$Res> { + _$TvVideoStateCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? showImage = null, + }) { + return _then(_value.copyWith( + showImage: null == showImage + ? _value.showImage + : showImage // ignore: cast_nullable_to_non_nullable + as bool, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$TvVideoStateImplCopyWith<$Res> + implements $TvVideoStateCopyWith<$Res> { + factory _$$TvVideoStateImplCopyWith( + _$TvVideoStateImpl value, $Res Function(_$TvVideoStateImpl) then) = + __$$TvVideoStateImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({bool showImage}); +} + +/// @nodoc +class __$$TvVideoStateImplCopyWithImpl<$Res> + extends _$TvVideoStateCopyWithImpl<$Res, _$TvVideoStateImpl> + implements _$$TvVideoStateImplCopyWith<$Res> { + __$$TvVideoStateImplCopyWithImpl( + _$TvVideoStateImpl _value, $Res Function(_$TvVideoStateImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? showImage = null, + }) { + return _then(_$TvVideoStateImpl( + showImage: null == showImage + ? _value.showImage + : showImage // ignore: cast_nullable_to_non_nullable + as bool, + )); + } +} + +/// @nodoc + +class _$TvVideoStateImpl implements _TvVideoState { + const _$TvVideoStateImpl({this.showImage = true}); + + @override + @JsonKey() + final bool showImage; + + @override + String toString() { + return 'TvVideoState(showImage: $showImage)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$TvVideoStateImpl && + (identical(other.showImage, showImage) || + other.showImage == showImage)); + } + + @override + int get hashCode => Object.hash(runtimeType, showImage); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$TvVideoStateImplCopyWith<_$TvVideoStateImpl> get copyWith => + __$$TvVideoStateImplCopyWithImpl<_$TvVideoStateImpl>(this, _$identity); +} + +abstract class _TvVideoState implements TvVideoState { + const factory _TvVideoState({final bool showImage}) = _$TvVideoStateImpl; + + @override + bool get showImage; + @override + @JsonKey(ignore: true) + _$$TvVideoStateImplCopyWith<_$TvVideoStateImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/videos/states/tv_video.g.dart b/lib/videos/states/tv_video.g.dart deleted file mode 100644 index ceb44603..00000000 --- a/lib/videos/states/tv_video.g.dart +++ /dev/null @@ -1,68 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'tv_video.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$TvVideoStateCWProxy { - TvVideoState scrollController(ScrollController? scrollController); - - TvVideoState showImage(bool showImage); - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `TvVideoState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// TvVideoState(...).copyWith(id: 12, name: "My name") - /// ```` - TvVideoState call({ - ScrollController? scrollController, - bool? showImage, - }); -} - -/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfTvVideoState.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfTvVideoState.copyWith.fieldName(...)` -class _$TvVideoStateCWProxyImpl implements _$TvVideoStateCWProxy { - const _$TvVideoStateCWProxyImpl(this._value); - - final TvVideoState _value; - - @override - TvVideoState scrollController(ScrollController? scrollController) => - this(scrollController: scrollController); - - @override - TvVideoState showImage(bool showImage) => this(showImage: showImage); - - @override - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `TvVideoState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// TvVideoState(...).copyWith(id: 12, name: "My name") - /// ```` - TvVideoState call({ - Object? scrollController = const $CopyWithPlaceholder(), - Object? showImage = const $CopyWithPlaceholder(), - }) { - return TvVideoState._( - scrollController == const $CopyWithPlaceholder() - ? _value.scrollController - // ignore: cast_nullable_to_non_nullable - : scrollController as ScrollController?, - showImage == const $CopyWithPlaceholder() || showImage == null - ? _value.showImage - // ignore: cast_nullable_to_non_nullable - : showImage as bool, - ); - } -} - -extension $TvVideoStateCopyWith on TvVideoState { - /// Returns a callable class that can be used as follows: `instanceOfTvVideoState.copyWith(...)` or like so:`instanceOfTvVideoState.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$TvVideoStateCWProxy get copyWith => _$TvVideoStateCWProxyImpl(this); -} diff --git a/lib/videos/states/video.dart b/lib/videos/states/video.dart index 64b666f6..e3b23b72 100644 --- a/lib/videos/states/video.dart +++ b/lib/videos/states/video.dart @@ -1,6 +1,7 @@ import 'package:copy_with_extension/copy_with_extension.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:invidious/downloads/models/downloaded_video.dart'; import 'package:invidious/videos/models/base_video.dart'; import 'package:invidious/videos/models/dislike.dart'; @@ -13,12 +14,13 @@ import '../../settings/models/errors/invidiousServiceError.dart'; import '../../settings/states/settings.dart'; import '../models/video.dart'; -part 'video.g.dart'; +part 'video.freezed.dart'; const String coulnotLoadVideos = 'cannot-load-videos'; final log = Logger('Video'); class VideoCubit extends Cubit { + final ScrollController scrollController = ScrollController(); final DownloadManagerCubit downloadManager; final PlayerCubit player; final SettingsCubit settings; @@ -29,45 +31,39 @@ class VideoCubit extends Cubit { Future onReady() async { try { - var state = this.state.copyWith(); Video video = await service.getVideo(state.videoId); - state.video = video; - state.loadingVideo = false; + var dislikes = state.dislikes; if (settings.state.useReturnYoutubeDislike) { Dislike dislike = await service.getDislikes(state.videoId); - state.dislikes = dislike.dislikes; + dislikes = dislike.dislikes; } - emit(state); + emit(state.copyWith(loadingVideo: false, video: video, dislikes: dislikes)); getDownloadStatus(); - } catch (err) { - var state = this.state.copyWith(); + late String error; if (err is InvidiousServiceError) { - state.error = (err).message; + error = (err).message; } else { - state.error = coulnotLoadVideos; + error = coulnotLoadVideos; } - state.loadingVideo = false; - emit(state); + emit(state.copyWith(error: error, loadingVideo: false)); rethrow; } } getDownloadStatus() { - var state = this.state.copyWith(); - state.downloadedVideo = db.getDownloadByVideoId(state.videoId); - + var downloadedVideo = db.getDownloadByVideoId(state.videoId); initStreamListener(); - if (!isClosed) emit(state); + if (!isClosed) emit(state.copyWith(downloadedVideo: downloadedVideo)); } @override close() async { var state = this.state.copyWith(); - state.scrollController.dispose(); + scrollController.dispose(); if (downloadManager.state.downloadProgresses.containsKey(state.videoId)) { downloadManager.removeListener(state.videoId, onDownloadProgress); } @@ -75,24 +71,19 @@ class VideoCubit extends Cubit { } onDownload() { - var state = this.state.copyWith(); - state.downloading = true; - state.downloadProgress = 0; - emit(state); + emit(state.copyWith(downloading: true, downloadProgress: 0)); } onDownloadProgress(double progress) { - var state = this.state.copyWith(); if (state.video != null) { - state.downloadProgress = progress; + late bool downloading; if (progress < 1) { - state.downloading = true; + downloading = true; } else { getDownloadStatus(); - state = this.state.copyWith(); - state.downloading = false; + downloading = false; } - emit(state); + emit(state.copyWith(downloadProgress: progress, downloading: downloading)); } } @@ -103,19 +94,15 @@ class VideoCubit extends Cubit { } togglePlayRecommendedNext(bool? value) { - var state = this.state.copyWith(); settings.setPlayRecommendedNext(value ?? false); - emit(state); } selectIndex(int index) { - var state = this.state.copyWith(); - state.selectedIndex = index; - emit(state); + emit(state.copyWith(selectedIndex: index)); scrollUp(); } - void restartVideo(bool? audio){ + void restartVideo(bool? audio) { if (state.video != null) { player.showBigPlayer(); player.seek(Duration.zero); @@ -129,34 +116,34 @@ class VideoCubit extends Cubit { videos.addAll(state.video?.recommendedVideos ?? []); } player.playVideo(videos, audio: audio); - } } scrollUp() { - state.scrollController.animateTo(0, duration: animationDuration, curve: Curves.easeInOutQuad); + scrollController.animateTo(0, duration: animationDuration, curve: Curves.easeInOutQuad); } } -@CopyWith(constructor: "_") -class VideoState { - Video? video; - int? dislikes; - bool loadingVideo = true; - - int selectedIndex = 0; - String videoId; - bool isLoggedIn = service.isLoggedIn(); - bool downloading = false; - double downloadProgress = 0; - DownloadedVideo? downloadedVideo; - ScrollController scrollController = ScrollController(); - - double opacity = 1; - - String error = ''; - - VideoState({required this.videoId}); +@freezed +class VideoState with _$VideoState { + const factory VideoState( + {Video? video, + int? dislikes, + @Default(true) loadingVideo, + @Default(0) int selectedIndex, + required String videoId, + required bool isLoggedIn, + @Default(false) bool downloading, + @Default(0) double downloadProgress, + DownloadedVideo? downloadedVideo, + @Default(1) double opacity, + @Default('') String error}) = _VideoState; + + const VideoState._(); + + static VideoState init({required String videoId}){ + return VideoState(videoId: videoId, isLoggedIn: service.isLoggedIn()); + } bool get downloadFailed => downloadedVideo?.downloadFailed ?? false; @@ -167,7 +154,4 @@ class VideoState { return false; } } - - VideoState._(this.scrollController, this.video, this.dislikes, this.loadingVideo, this.selectedIndex, this.videoId, - this.isLoggedIn, this.downloading, this.downloadProgress, this.downloadedVideo, this.opacity, this.error); } diff --git a/lib/videos/states/video.freezed.dart b/lib/videos/states/video.freezed.dart new file mode 100644 index 00000000..6edcdbb2 --- /dev/null +++ b/lib/videos/states/video.freezed.dart @@ -0,0 +1,361 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'video.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +mixin _$VideoState { + Video? get video => throw _privateConstructorUsedError; + int? get dislikes => throw _privateConstructorUsedError; + dynamic get loadingVideo => throw _privateConstructorUsedError; + int get selectedIndex => throw _privateConstructorUsedError; + String get videoId => throw _privateConstructorUsedError; + bool get isLoggedIn => throw _privateConstructorUsedError; + bool get downloading => throw _privateConstructorUsedError; + double get downloadProgress => throw _privateConstructorUsedError; + DownloadedVideo? get downloadedVideo => throw _privateConstructorUsedError; + double get opacity => throw _privateConstructorUsedError; + String get error => throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + $VideoStateCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $VideoStateCopyWith<$Res> { + factory $VideoStateCopyWith( + VideoState value, $Res Function(VideoState) then) = + _$VideoStateCopyWithImpl<$Res, VideoState>; + @useResult + $Res call( + {Video? video, + int? dislikes, + dynamic loadingVideo, + int selectedIndex, + String videoId, + bool isLoggedIn, + bool downloading, + double downloadProgress, + DownloadedVideo? downloadedVideo, + double opacity, + String error}); +} + +/// @nodoc +class _$VideoStateCopyWithImpl<$Res, $Val extends VideoState> + implements $VideoStateCopyWith<$Res> { + _$VideoStateCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? video = freezed, + Object? dislikes = freezed, + Object? loadingVideo = freezed, + Object? selectedIndex = null, + Object? videoId = null, + Object? isLoggedIn = null, + Object? downloading = null, + Object? downloadProgress = null, + Object? downloadedVideo = freezed, + Object? opacity = null, + Object? error = null, + }) { + return _then(_value.copyWith( + video: freezed == video + ? _value.video + : video // ignore: cast_nullable_to_non_nullable + as Video?, + dislikes: freezed == dislikes + ? _value.dislikes + : dislikes // ignore: cast_nullable_to_non_nullable + as int?, + loadingVideo: freezed == loadingVideo + ? _value.loadingVideo + : loadingVideo // ignore: cast_nullable_to_non_nullable + as dynamic, + selectedIndex: null == selectedIndex + ? _value.selectedIndex + : selectedIndex // ignore: cast_nullable_to_non_nullable + as int, + videoId: null == videoId + ? _value.videoId + : videoId // ignore: cast_nullable_to_non_nullable + as String, + isLoggedIn: null == isLoggedIn + ? _value.isLoggedIn + : isLoggedIn // ignore: cast_nullable_to_non_nullable + as bool, + downloading: null == downloading + ? _value.downloading + : downloading // ignore: cast_nullable_to_non_nullable + as bool, + downloadProgress: null == downloadProgress + ? _value.downloadProgress + : downloadProgress // ignore: cast_nullable_to_non_nullable + as double, + downloadedVideo: freezed == downloadedVideo + ? _value.downloadedVideo + : downloadedVideo // ignore: cast_nullable_to_non_nullable + as DownloadedVideo?, + opacity: null == opacity + ? _value.opacity + : opacity // ignore: cast_nullable_to_non_nullable + as double, + error: null == error + ? _value.error + : error // ignore: cast_nullable_to_non_nullable + as String, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$VideoStateImplCopyWith<$Res> + implements $VideoStateCopyWith<$Res> { + factory _$$VideoStateImplCopyWith( + _$VideoStateImpl value, $Res Function(_$VideoStateImpl) then) = + __$$VideoStateImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {Video? video, + int? dislikes, + dynamic loadingVideo, + int selectedIndex, + String videoId, + bool isLoggedIn, + bool downloading, + double downloadProgress, + DownloadedVideo? downloadedVideo, + double opacity, + String error}); +} + +/// @nodoc +class __$$VideoStateImplCopyWithImpl<$Res> + extends _$VideoStateCopyWithImpl<$Res, _$VideoStateImpl> + implements _$$VideoStateImplCopyWith<$Res> { + __$$VideoStateImplCopyWithImpl( + _$VideoStateImpl _value, $Res Function(_$VideoStateImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? video = freezed, + Object? dislikes = freezed, + Object? loadingVideo = freezed, + Object? selectedIndex = null, + Object? videoId = null, + Object? isLoggedIn = null, + Object? downloading = null, + Object? downloadProgress = null, + Object? downloadedVideo = freezed, + Object? opacity = null, + Object? error = null, + }) { + return _then(_$VideoStateImpl( + video: freezed == video + ? _value.video + : video // ignore: cast_nullable_to_non_nullable + as Video?, + dislikes: freezed == dislikes + ? _value.dislikes + : dislikes // ignore: cast_nullable_to_non_nullable + as int?, + loadingVideo: + freezed == loadingVideo ? _value.loadingVideo! : loadingVideo, + selectedIndex: null == selectedIndex + ? _value.selectedIndex + : selectedIndex // ignore: cast_nullable_to_non_nullable + as int, + videoId: null == videoId + ? _value.videoId + : videoId // ignore: cast_nullable_to_non_nullable + as String, + isLoggedIn: null == isLoggedIn + ? _value.isLoggedIn + : isLoggedIn // ignore: cast_nullable_to_non_nullable + as bool, + downloading: null == downloading + ? _value.downloading + : downloading // ignore: cast_nullable_to_non_nullable + as bool, + downloadProgress: null == downloadProgress + ? _value.downloadProgress + : downloadProgress // ignore: cast_nullable_to_non_nullable + as double, + downloadedVideo: freezed == downloadedVideo + ? _value.downloadedVideo + : downloadedVideo // ignore: cast_nullable_to_non_nullable + as DownloadedVideo?, + opacity: null == opacity + ? _value.opacity + : opacity // ignore: cast_nullable_to_non_nullable + as double, + error: null == error + ? _value.error + : error // ignore: cast_nullable_to_non_nullable + as String, + )); + } +} + +/// @nodoc + +class _$VideoStateImpl extends _VideoState { + const _$VideoStateImpl( + {this.video, + this.dislikes, + this.loadingVideo = true, + this.selectedIndex = 0, + required this.videoId, + required this.isLoggedIn, + this.downloading = false, + this.downloadProgress = 0, + this.downloadedVideo, + this.opacity = 1, + this.error = ''}) + : super._(); + + @override + final Video? video; + @override + final int? dislikes; + @override + @JsonKey() + final dynamic loadingVideo; + @override + @JsonKey() + final int selectedIndex; + @override + final String videoId; + @override + final bool isLoggedIn; + @override + @JsonKey() + final bool downloading; + @override + @JsonKey() + final double downloadProgress; + @override + final DownloadedVideo? downloadedVideo; + @override + @JsonKey() + final double opacity; + @override + @JsonKey() + final String error; + + @override + String toString() { + return 'VideoState(video: $video, dislikes: $dislikes, loadingVideo: $loadingVideo, selectedIndex: $selectedIndex, videoId: $videoId, isLoggedIn: $isLoggedIn, downloading: $downloading, downloadProgress: $downloadProgress, downloadedVideo: $downloadedVideo, opacity: $opacity, error: $error)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$VideoStateImpl && + (identical(other.video, video) || other.video == video) && + (identical(other.dislikes, dislikes) || + other.dislikes == dislikes) && + const DeepCollectionEquality() + .equals(other.loadingVideo, loadingVideo) && + (identical(other.selectedIndex, selectedIndex) || + other.selectedIndex == selectedIndex) && + (identical(other.videoId, videoId) || other.videoId == videoId) && + (identical(other.isLoggedIn, isLoggedIn) || + other.isLoggedIn == isLoggedIn) && + (identical(other.downloading, downloading) || + other.downloading == downloading) && + (identical(other.downloadProgress, downloadProgress) || + other.downloadProgress == downloadProgress) && + (identical(other.downloadedVideo, downloadedVideo) || + other.downloadedVideo == downloadedVideo) && + (identical(other.opacity, opacity) || other.opacity == opacity) && + (identical(other.error, error) || other.error == error)); + } + + @override + int get hashCode => Object.hash( + runtimeType, + video, + dislikes, + const DeepCollectionEquality().hash(loadingVideo), + selectedIndex, + videoId, + isLoggedIn, + downloading, + downloadProgress, + downloadedVideo, + opacity, + error); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$VideoStateImplCopyWith<_$VideoStateImpl> get copyWith => + __$$VideoStateImplCopyWithImpl<_$VideoStateImpl>(this, _$identity); +} + +abstract class _VideoState extends VideoState { + const factory _VideoState( + {final Video? video, + final int? dislikes, + final dynamic loadingVideo, + final int selectedIndex, + required final String videoId, + required final bool isLoggedIn, + final bool downloading, + final double downloadProgress, + final DownloadedVideo? downloadedVideo, + final double opacity, + final String error}) = _$VideoStateImpl; + const _VideoState._() : super._(); + + @override + Video? get video; + @override + int? get dislikes; + @override + dynamic get loadingVideo; + @override + int get selectedIndex; + @override + String get videoId; + @override + bool get isLoggedIn; + @override + bool get downloading; + @override + double get downloadProgress; + @override + DownloadedVideo? get downloadedVideo; + @override + double get opacity; + @override + String get error; + @override + @JsonKey(ignore: true) + _$$VideoStateImplCopyWith<_$VideoStateImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/videos/states/video.g.dart b/lib/videos/states/video.g.dart deleted file mode 100644 index f3a002a0..00000000 --- a/lib/videos/states/video.g.dart +++ /dev/null @@ -1,184 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'video.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$VideoStateCWProxy { - VideoState scrollController(ScrollController scrollController); - - VideoState video(Video? video); - - VideoState dislikes(int? dislikes); - - VideoState loadingVideo(bool loadingVideo); - - VideoState selectedIndex(int selectedIndex); - - VideoState videoId(String videoId); - - VideoState isLoggedIn(bool isLoggedIn); - - VideoState downloading(bool downloading); - - VideoState downloadProgress(double downloadProgress); - - VideoState downloadedVideo(DownloadedVideo? downloadedVideo); - - VideoState opacity(double opacity); - - VideoState error(String error); - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `VideoState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// VideoState(...).copyWith(id: 12, name: "My name") - /// ```` - VideoState call({ - ScrollController? scrollController, - Video? video, - int? dislikes, - bool? loadingVideo, - int? selectedIndex, - String? videoId, - bool? isLoggedIn, - bool? downloading, - double? downloadProgress, - DownloadedVideo? downloadedVideo, - double? opacity, - String? error, - }); -} - -/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfVideoState.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfVideoState.copyWith.fieldName(...)` -class _$VideoStateCWProxyImpl implements _$VideoStateCWProxy { - const _$VideoStateCWProxyImpl(this._value); - - final VideoState _value; - - @override - VideoState scrollController(ScrollController scrollController) => - this(scrollController: scrollController); - - @override - VideoState video(Video? video) => this(video: video); - - @override - VideoState dislikes(int? dislikes) => this(dislikes: dislikes); - - @override - VideoState loadingVideo(bool loadingVideo) => - this(loadingVideo: loadingVideo); - - @override - VideoState selectedIndex(int selectedIndex) => - this(selectedIndex: selectedIndex); - - @override - VideoState videoId(String videoId) => this(videoId: videoId); - - @override - VideoState isLoggedIn(bool isLoggedIn) => this(isLoggedIn: isLoggedIn); - - @override - VideoState downloading(bool downloading) => this(downloading: downloading); - - @override - VideoState downloadProgress(double downloadProgress) => - this(downloadProgress: downloadProgress); - - @override - VideoState downloadedVideo(DownloadedVideo? downloadedVideo) => - this(downloadedVideo: downloadedVideo); - - @override - VideoState opacity(double opacity) => this(opacity: opacity); - - @override - VideoState error(String error) => this(error: error); - - @override - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `VideoState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// VideoState(...).copyWith(id: 12, name: "My name") - /// ```` - VideoState call({ - Object? scrollController = const $CopyWithPlaceholder(), - Object? video = const $CopyWithPlaceholder(), - Object? dislikes = const $CopyWithPlaceholder(), - Object? loadingVideo = const $CopyWithPlaceholder(), - Object? selectedIndex = const $CopyWithPlaceholder(), - Object? videoId = const $CopyWithPlaceholder(), - Object? isLoggedIn = const $CopyWithPlaceholder(), - Object? downloading = const $CopyWithPlaceholder(), - Object? downloadProgress = const $CopyWithPlaceholder(), - Object? downloadedVideo = const $CopyWithPlaceholder(), - Object? opacity = const $CopyWithPlaceholder(), - Object? error = const $CopyWithPlaceholder(), - }) { - return VideoState._( - scrollController == const $CopyWithPlaceholder() || - scrollController == null - ? _value.scrollController - // ignore: cast_nullable_to_non_nullable - : scrollController as ScrollController, - video == const $CopyWithPlaceholder() - ? _value.video - // ignore: cast_nullable_to_non_nullable - : video as Video?, - dislikes == const $CopyWithPlaceholder() - ? _value.dislikes - // ignore: cast_nullable_to_non_nullable - : dislikes as int?, - loadingVideo == const $CopyWithPlaceholder() || loadingVideo == null - ? _value.loadingVideo - // ignore: cast_nullable_to_non_nullable - : loadingVideo as bool, - selectedIndex == const $CopyWithPlaceholder() || selectedIndex == null - ? _value.selectedIndex - // ignore: cast_nullable_to_non_nullable - : selectedIndex as int, - videoId == const $CopyWithPlaceholder() || videoId == null - ? _value.videoId - // ignore: cast_nullable_to_non_nullable - : videoId as String, - isLoggedIn == const $CopyWithPlaceholder() || isLoggedIn == null - ? _value.isLoggedIn - // ignore: cast_nullable_to_non_nullable - : isLoggedIn as bool, - downloading == const $CopyWithPlaceholder() || downloading == null - ? _value.downloading - // ignore: cast_nullable_to_non_nullable - : downloading as bool, - downloadProgress == const $CopyWithPlaceholder() || - downloadProgress == null - ? _value.downloadProgress - // ignore: cast_nullable_to_non_nullable - : downloadProgress as double, - downloadedVideo == const $CopyWithPlaceholder() - ? _value.downloadedVideo - // ignore: cast_nullable_to_non_nullable - : downloadedVideo as DownloadedVideo?, - opacity == const $CopyWithPlaceholder() || opacity == null - ? _value.opacity - // ignore: cast_nullable_to_non_nullable - : opacity as double, - error == const $CopyWithPlaceholder() || error == null - ? _value.error - // ignore: cast_nullable_to_non_nullable - : error as String, - ); - } -} - -extension $VideoStateCopyWith on VideoState { - /// Returns a callable class that can be used as follows: `instanceOfVideoState.copyWith(...)` or like so:`instanceOfVideoState.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$VideoStateCWProxy get copyWith => _$VideoStateCWProxyImpl(this); -} diff --git a/lib/videos/states/video_in_list.dart b/lib/videos/states/video_in_list.dart index 83dffbd5..bfcaaaa8 100644 --- a/lib/videos/states/video_in_list.dart +++ b/lib/videos/states/video_in_list.dart @@ -1,11 +1,12 @@ import 'package:bloc/bloc.dart'; import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:invidious/downloads/models/downloaded_video.dart'; import 'package:invidious/videos/models/base_video.dart'; import '../../globals.dart'; -part 'video_in_list.g.dart'; +part 'video_in_list.freezed.dart'; class VideoInListCubit extends Cubit { VideoInListCubit(super.initialState) { @@ -24,9 +25,7 @@ class VideoInListCubit extends Cubit { setProgress(double progress) { if (state.video != null) { - var state = this.state.copyWith(); - state.progress = progress; - emit(state); + emit(state.copyWith(progress: progress)); } } @@ -39,14 +38,12 @@ class VideoInListCubit extends Cubit { } } -@CopyWith(constructor: "_") -class VideoInListState { - double progress = 0; - BaseVideo? video; - DownloadedVideo? offlineVideo; - - VideoInListState({this.video, this.offlineVideo}) - : assert(video == null || offlineVideo == null, 'cannot provide both video and offline video\n'); - - VideoInListState._(this.progress, this.video, this.offlineVideo); +@freezed +class VideoInListState with _$VideoInListState{ + @Assert('video == null || offlineVideo == null', 'cannot provide both video and offline video') + const factory VideoInListState({ + @Default(0) double progress, + BaseVideo? video, + DownloadedVideo? offlineVideo +}) = _VideoInListState; } diff --git a/lib/videos/states/video_in_list.freezed.dart b/lib/videos/states/video_in_list.freezed.dart new file mode 100644 index 00000000..9efe3e9f --- /dev/null +++ b/lib/videos/states/video_in_list.freezed.dart @@ -0,0 +1,174 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'video_in_list.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +mixin _$VideoInListState { + double get progress => throw _privateConstructorUsedError; + BaseVideo? get video => throw _privateConstructorUsedError; + DownloadedVideo? get offlineVideo => throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + $VideoInListStateCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $VideoInListStateCopyWith<$Res> { + factory $VideoInListStateCopyWith( + VideoInListState value, $Res Function(VideoInListState) then) = + _$VideoInListStateCopyWithImpl<$Res, VideoInListState>; + @useResult + $Res call({double progress, BaseVideo? video, DownloadedVideo? offlineVideo}); +} + +/// @nodoc +class _$VideoInListStateCopyWithImpl<$Res, $Val extends VideoInListState> + implements $VideoInListStateCopyWith<$Res> { + _$VideoInListStateCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? progress = null, + Object? video = freezed, + Object? offlineVideo = freezed, + }) { + return _then(_value.copyWith( + progress: null == progress + ? _value.progress + : progress // ignore: cast_nullable_to_non_nullable + as double, + video: freezed == video + ? _value.video + : video // ignore: cast_nullable_to_non_nullable + as BaseVideo?, + offlineVideo: freezed == offlineVideo + ? _value.offlineVideo + : offlineVideo // ignore: cast_nullable_to_non_nullable + as DownloadedVideo?, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$VideoInListStateImplCopyWith<$Res> + implements $VideoInListStateCopyWith<$Res> { + factory _$$VideoInListStateImplCopyWith(_$VideoInListStateImpl value, + $Res Function(_$VideoInListStateImpl) then) = + __$$VideoInListStateImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({double progress, BaseVideo? video, DownloadedVideo? offlineVideo}); +} + +/// @nodoc +class __$$VideoInListStateImplCopyWithImpl<$Res> + extends _$VideoInListStateCopyWithImpl<$Res, _$VideoInListStateImpl> + implements _$$VideoInListStateImplCopyWith<$Res> { + __$$VideoInListStateImplCopyWithImpl(_$VideoInListStateImpl _value, + $Res Function(_$VideoInListStateImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? progress = null, + Object? video = freezed, + Object? offlineVideo = freezed, + }) { + return _then(_$VideoInListStateImpl( + progress: null == progress + ? _value.progress + : progress // ignore: cast_nullable_to_non_nullable + as double, + video: freezed == video + ? _value.video + : video // ignore: cast_nullable_to_non_nullable + as BaseVideo?, + offlineVideo: freezed == offlineVideo + ? _value.offlineVideo + : offlineVideo // ignore: cast_nullable_to_non_nullable + as DownloadedVideo?, + )); + } +} + +/// @nodoc + +class _$VideoInListStateImpl implements _VideoInListState { + const _$VideoInListStateImpl( + {this.progress = 0, this.video, this.offlineVideo}) + : assert(video == null || offlineVideo == null, + 'cannot provide both video and offline video'); + + @override + @JsonKey() + final double progress; + @override + final BaseVideo? video; + @override + final DownloadedVideo? offlineVideo; + + @override + String toString() { + return 'VideoInListState(progress: $progress, video: $video, offlineVideo: $offlineVideo)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$VideoInListStateImpl && + (identical(other.progress, progress) || + other.progress == progress) && + (identical(other.video, video) || other.video == video) && + (identical(other.offlineVideo, offlineVideo) || + other.offlineVideo == offlineVideo)); + } + + @override + int get hashCode => Object.hash(runtimeType, progress, video, offlineVideo); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$VideoInListStateImplCopyWith<_$VideoInListStateImpl> get copyWith => + __$$VideoInListStateImplCopyWithImpl<_$VideoInListStateImpl>( + this, _$identity); +} + +abstract class _VideoInListState implements VideoInListState { + const factory _VideoInListState( + {final double progress, + final BaseVideo? video, + final DownloadedVideo? offlineVideo}) = _$VideoInListStateImpl; + + @override + double get progress; + @override + BaseVideo? get video; + @override + DownloadedVideo? get offlineVideo; + @override + @JsonKey(ignore: true) + _$$VideoInListStateImplCopyWith<_$VideoInListStateImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/videos/states/video_in_list.g.dart b/lib/videos/states/video_in_list.g.dart deleted file mode 100644 index 1494b203..00000000 --- a/lib/videos/states/video_in_list.g.dart +++ /dev/null @@ -1,79 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'video_in_list.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$VideoInListStateCWProxy { - VideoInListState progress(double progress); - - VideoInListState video(BaseVideo? video); - - VideoInListState offlineVideo(DownloadedVideo? offlineVideo); - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `VideoInListState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// VideoInListState(...).copyWith(id: 12, name: "My name") - /// ```` - VideoInListState call({ - double? progress, - BaseVideo? video, - DownloadedVideo? offlineVideo, - }); -} - -/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfVideoInListState.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfVideoInListState.copyWith.fieldName(...)` -class _$VideoInListStateCWProxyImpl implements _$VideoInListStateCWProxy { - const _$VideoInListStateCWProxyImpl(this._value); - - final VideoInListState _value; - - @override - VideoInListState progress(double progress) => this(progress: progress); - - @override - VideoInListState video(BaseVideo? video) => this(video: video); - - @override - VideoInListState offlineVideo(DownloadedVideo? offlineVideo) => - this(offlineVideo: offlineVideo); - - @override - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `VideoInListState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// VideoInListState(...).copyWith(id: 12, name: "My name") - /// ```` - VideoInListState call({ - Object? progress = const $CopyWithPlaceholder(), - Object? video = const $CopyWithPlaceholder(), - Object? offlineVideo = const $CopyWithPlaceholder(), - }) { - return VideoInListState._( - progress == const $CopyWithPlaceholder() || progress == null - ? _value.progress - // ignore: cast_nullable_to_non_nullable - : progress as double, - video == const $CopyWithPlaceholder() - ? _value.video - // ignore: cast_nullable_to_non_nullable - : video as BaseVideo?, - offlineVideo == const $CopyWithPlaceholder() - ? _value.offlineVideo - // ignore: cast_nullable_to_non_nullable - : offlineVideo as DownloadedVideo?, - ); - } -} - -extension $VideoInListStateCopyWith on VideoInListState { - /// Returns a callable class that can be used as follows: `instanceOfVideoInListState.copyWith(...)` or like so:`instanceOfVideoInListState.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$VideoInListStateCWProxy get copyWith => _$VideoInListStateCWProxyImpl(this); -} diff --git a/lib/videos/views/components/add_to_playlist_button.dart b/lib/videos/views/components/add_to_playlist_button.dart index eaeca5f0..dc41c2be 100644 --- a/lib/videos/views/components/add_to_playlist_button.dart +++ b/lib/videos/views/components/add_to_playlist_button.dart @@ -50,7 +50,7 @@ class AddToPlayListButton extends StatelessWidget { var locals = AppLocalizations.of(context)!; return BlocProvider( - create: (BuildContext context) => AddToPlaylistCubit(AddToPlaylistController(videoId)), + create: (BuildContext context) => AddToPlaylistCubit(AddToPlaylistController.init(videoId)), child: BlocBuilder(builder: (context, _) { var cubit = context.read(); return switch (type) { diff --git a/lib/videos/views/components/history.dart b/lib/videos/views/components/history.dart index 34617d1e..49e23467 100644 --- a/lib/videos/views/components/history.dart +++ b/lib/videos/views/components/history.dart @@ -30,7 +30,7 @@ class HistoryView extends StatelessWidget { ) ], child: BlocBuilder, ItemListState>(builder: (context, _) { - var listcubit = context.read>(); + var listCubit = context.read>(); var historyCubit = context.read(); bool showPlaceholder = _.loading && _.items.isEmpty; return Stack( @@ -54,9 +54,9 @@ class HistoryView extends StatelessWidget { : Padding( padding: const EdgeInsets.only(top: 3), child: RefreshIndicator( - onRefresh: () => listcubit.refreshItems(), + onRefresh: () => listCubit.refreshItems(), child: ListView.builder( - controller: _.scrollController, + controller: listCubit.scrollController, scrollDirection: Axis.vertical, itemCount: _.items.length + (_.loading ? 5 : 0), itemBuilder: (context, index) => Padding( diff --git a/lib/videos/views/components/inner_view_tablet.dart b/lib/videos/views/components/inner_view_tablet.dart index 3eae2201..960c439f 100644 --- a/lib/videos/views/components/inner_view_tablet.dart +++ b/lib/videos/views/components/inner_view_tablet.dart @@ -94,7 +94,7 @@ class VideoTabletInnerView extends StatelessWidget { width: double.infinity, constraints: const BoxConstraints(maxWidth: 500), child: ListView( - controller: videoController.scrollController, + controller: cubit.scrollController, children: [ AnimatedSwitcher( duration: animationDuration, diff --git a/lib/videos/views/components/innter_view.dart b/lib/videos/views/components/innter_view.dart index a24094ea..385d80ce 100644 --- a/lib/videos/views/components/innter_view.dart +++ b/lib/videos/views/components/innter_view.dart @@ -54,23 +54,28 @@ class VideoInnerView extends StatelessWidget { ), ), if (!settings.state.distractionFreeMode) - Row( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - SizedBox(height: 25, child: Checkbox(value: settings.state.playRecommendedNext, onChanged: cubit.togglePlayRecommendedNext, visualDensity: VisualDensity.compact)), - InkWell( - onTap: () => cubit.togglePlayRecommendedNext(!settings.state.playRecommendedNext), - child: Text( - locals.addRecommendedToQueue, - style: textTheme.bodySmall, - )) - ], + BlocBuilder( + buildWhen: (previous, current) => previous.playRecommendedNext != current.playRecommendedNext, + builder: (context, settingsState) { + return Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + SizedBox(height: 25, child: Checkbox(value: settingsState.playRecommendedNext, onChanged: cubit.togglePlayRecommendedNext, visualDensity: VisualDensity.compact)), + InkWell( + onTap: () => cubit.togglePlayRecommendedNext(!settingsState.playRecommendedNext), + child: Text( + locals.addRecommendedToQueue, + style: textTheme.bodySmall, + )) + ], + ); + } ), Expanded( child: Padding( padding: const EdgeInsets.only(top: 0), child: ListView( - controller: videoController.scrollController, + controller: cubit.scrollController, children: [ AnimatedSwitcher( duration: animationDuration, diff --git a/lib/videos/views/components/video_list.dart b/lib/videos/views/components/video_list.dart index 92665ad3..0adae48e 100644 --- a/lib/videos/views/components/video_list.dart +++ b/lib/videos/views/components/video_list.dart @@ -82,7 +82,7 @@ class VideoList extends StatelessWidget { : Future.delayed(Duration.zero), child: GridView.count( crossAxisCount: gridCount, - controller: _.scrollController, + controller: cubit.scrollController, scrollDirection: scrollDirection, crossAxisSpacing: small ? 8 : 5, mainAxisSpacing: small ? 8 : 5, diff --git a/lib/videos/views/screens/video.dart b/lib/videos/views/screens/video.dart index 3774bf8d..ad962ea1 100644 --- a/lib/videos/views/screens/video.dart +++ b/lib/videos/views/screens/video.dart @@ -78,7 +78,7 @@ class VideoScreen extends StatelessWidget { providers: [ BlocProvider( create: (BuildContext context) => - VideoCubit(VideoState(videoId: videoId), downloadManager, player, settings)), + VideoCubit(VideoState.init(videoId: videoId), downloadManager, player, settings)), ], child: BlocConsumer( listenWhen: (previous, current) => settings.state.autoplayVideoOnLoad && previous.video != current.video, diff --git a/lib/videos/views/tv/screens/video.dart b/lib/videos/views/tv/screens/video.dart index 40b0e5a8..344d72f6 100644 --- a/lib/videos/views/tv/screens/video.dart +++ b/lib/videos/views/tv/screens/video.dart @@ -53,9 +53,9 @@ class TvVideoScreen extends StatelessWidget { var settings = context.read(); return MultiBlocProvider( providers: [ - BlocProvider(create: (context) => VideoCubit(VideoState(videoId: videoId), downloadManager, player, settings)), + BlocProvider(create: (context) => VideoCubit(VideoState.init(videoId: videoId), downloadManager, player, settings)), BlocProvider( - create: (context) => TvVideoCubit(TvVideoState()), + create: (context) => TvVideoCubit(const TvVideoState()), ) ], child: Scaffold(body: Builder(builder: (context) { @@ -113,7 +113,7 @@ class TvVideoScreen extends StatelessWidget { child: Padding( padding: const EdgeInsets.all(16.0), child: SingleChildScrollView( - controller: tvState.scrollController, + controller: tvCubit.scrollController, child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ diff --git a/lib/videos/views/tv/screens/video_grid_view.dart b/lib/videos/views/tv/screens/video_grid_view.dart index 6d926879..a009c7ca 100644 --- a/lib/videos/views/tv/screens/video_grid_view.dart +++ b/lib/videos/views/tv/screens/video_grid_view.dart @@ -25,7 +25,7 @@ class TvGridScreen extends StatelessWidget { child: Scaffold( body: TvOverscan( child: BlocBuilder, ItemListState>(builder: (context, _) { - + var cubit = context.read>(); return Column( children: [ Row( @@ -49,7 +49,7 @@ class TvGridScreen extends StatelessWidget { ), Expanded( child: GridView.count( - controller: _.scrollController, + controller: cubit.scrollController, childAspectRatio: 16 / 13, crossAxisCount: 3, children: [