diff --git a/lib/playlists/views/tv/screens/playlist.dart b/lib/playlists/views/tv/screens/playlist.dart index 4a36e0f6..8d93bcbd 100644 --- a/lib/playlists/views/tv/screens/playlist.dart +++ b/lib/playlists/views/tv/screens/playlist.dart @@ -1,6 +1,5 @@ import 'dart:ui'; -import 'package:auto_route/annotations.dart'; import 'package:auto_route/auto_route.dart'; import 'package:carousel_slider/carousel_slider.dart'; import 'package:flutter/material.dart'; @@ -8,7 +7,6 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:invidious/app/views/tv/screens/tv_home.dart'; import 'package:invidious/globals.dart'; -import 'package:invidious/player/views/tv/screens/tvPlayerView.dart'; import 'package:invidious/playlists/states/playlist.dart'; import 'package:invidious/playlists/views/screens/playlist.dart'; import 'package:invidious/router.dart'; @@ -27,7 +25,7 @@ class TvPlaylistScreen extends PlaylistViewScreen { const TvPlaylistScreen({super.key, required super.playlist, required super.canDeleteVideos}); playPlaylist(BuildContext context, PlaylistState _) { - AutoRouter.of(context).push(TvPlayerRoute(videos: _.playlist.videos)); + AutoRouter.of(context).push(TvPlayerRoute(videos: _.playlist.videos.where((element) => !element.filterHide).toList())); } @override @@ -52,7 +50,9 @@ class TvPlaylistScreen extends PlaylistViewScreen { return VideoThumbnailView( videoId: video.videoId, decoration: BoxDecoration(), - thumbnailUrl: video.deArrowThumbnailUrl ?? ImageObject.getBestThumbnail(video.videoThumbnails)?.url ?? ''); + thumbnailUrl: video.deArrowThumbnailUrl ?? + ImageObject.getBestThumbnail(video.videoThumbnails)?.url ?? + ''); }, options: CarouselOptions( autoPlayCurve: Curves.easeInOutQuad, @@ -162,6 +162,7 @@ class TvPlaylistScreen extends PlaylistViewScreen { crossAxisCount: 3, children: [ ..._.playlist.videos + .where((element) => !element.filterHide) .map((e) => TvVideoItem(video: e, autoFocus: false)) .toList(), if (_.loading) diff --git a/lib/settings/models/db/video_filter.dart b/lib/settings/models/db/video_filter.dart index 49136859..08b7737c 100644 --- a/lib/settings/models/db/video_filter.dart +++ b/lib/settings/models/db/video_filter.dart @@ -119,7 +119,9 @@ class VideoFilter { videos = videos?.map((v) => _innerFilterVideo(v, filters)).toList() ?? []; - videos.removeWhere((element) => element.filtered && element.filterHide); + // leaving this for future self. CANNOT remove videos from list, otherwise it will break pagination + // TODO: write test cases about this. + // videos.removeWhere((element) => element.filtered && element.filterHide); return videos; } diff --git a/lib/utils.dart b/lib/utils.dart index 6ec2183d..f3351bf6 100644 --- a/lib/utils.dart +++ b/lib/utils.dart @@ -301,7 +301,7 @@ SystemUiOverlayStyle getUiOverlayStyle(BuildContext context) { statusBarIconBrightness: colorScheme.brightness == Brightness.dark ? Brightness.light : Brightness.dark); } -//List filteredVideos(List videos) => videos.where((element) => !element.filterHide).toList(); +List filteredVideos(List videos) => videos.where((element) => !element.filterHide).toList(); String getWeekdayName(int weekday) { final DateTime now = DateTime.now().toLocal(); 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 41685f7a..fa21bac5 100644 --- a/lib/utils/views/tv/components/tv_horizontal_item_list.dart +++ b/lib/utils/views/tv/components/tv_horizontal_item_list.dart @@ -2,8 +2,10 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:invidious/utils/states/item_list.dart'; import 'package:invidious/utils/views/components/placeholders.dart'; +import 'package:invidious/videos/models/base_video.dart'; import 'package:invidious/videos/views/tv/components/video_item.dart'; +import '../../../../utils.dart'; import '../../../../videos/models/video_in_list.dart'; import '../../../models/paginatedList.dart'; @@ -14,39 +16,47 @@ class TvHorizontalItemList extends StatelessWidget { final Widget Function(BuildContext context, int index, T item) buildItem; const TvHorizontalItemList( - {Key? key, this.tags, required this.paginatedList, required this.buildItem, required this.getPlaceholder}) - : super(key: key); + {super.key, this.tags, required this.paginatedList, required this.buildItem, required this.getPlaceholder}); @override Widget build(BuildContext context) { return BlocProvider( create: (context) => ItemListCubit(ItemListState(itemList: paginatedList)), child: BlocBuilder, ItemListState>( - builder: (context, _) => Stack( + builder: (context, _) { + + // filter items if possible + List items = _.items; + if (items.isNotEmpty && items[0] is BaseVideo) { + items = filteredVideos(_.items.cast()).cast(); + } + + return Stack( children: [ if (_.loading) const LinearProgressIndicator( minHeight: 3, ), - !_.loading && _.items.isEmpty + !_.loading && items.isEmpty ? const SizedBox.shrink() : SizedBox( height: 250, child: ListView.builder( scrollDirection: Axis.horizontal, controller: _.scrollController, - itemCount: _.items.length + (_.loading ? 10 : 0), + itemCount: items.length + (_.loading ? 10 : 0), itemBuilder: (context, index) { - if (index >= _.items.length) { + if (index >= items.length) { return getPlaceholder(); } - T e = _.items[index]; + T e = items[index]; return buildItem(context, index, e); }, ), ), ], - ), + ); + }, ), ); } 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 3f24b23b..053dffac 100644 --- a/lib/utils/views/tv/components/tv_horizontal_paginated_list.dart +++ b/lib/utils/views/tv/components/tv_horizontal_paginated_list.dart @@ -1,6 +1,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import '../../../../utils.dart'; +import '../../../../videos/models/base_video.dart'; import '../../../models/paginatedList.dart'; import '../../../states/paginated_list_view.dart'; @@ -20,7 +22,14 @@ class TvHorizontalPaginatedListView extends StatelessWidget { create: (context) => PaginatedListCubit( PaginatedListViewController(paginatedList: this.paginatedList, startItems: this.startItems)), child: BlocBuilder, PaginatedListViewController>( - builder: (context, _) => Stack( + builder: (context, _) { + + // filter items if possible + List items = _.items; + if (items.isNotEmpty && items[0] is BaseVideo) { + items = filteredVideos(_.items.cast()).cast(); + } + return Stack( children: [ _.loading ? const LinearProgressIndicator( @@ -30,12 +39,13 @@ class TvHorizontalPaginatedListView extends StatelessWidget { ListView.builder( controller: _.scrollController, scrollDirection: Axis.horizontal, - itemCount: _.items.length + (_.loading ? 10 : 0), + itemCount: items.length + (_.loading ? 10 : 0), itemBuilder: (BuildContext context, int index) => - index >= _.items.length ? getPlaceHolder() : itemBuilder(_.items[index]), + index >= items.length ? getPlaceHolder() : itemBuilder(items[index]), ), ], - )), + ); + }), ); } } diff --git a/lib/videos/states/history.dart b/lib/videos/states/history.dart index 028cc93d..d1614d5d 100644 --- a/lib/videos/states/history.dart +++ b/lib/videos/states/history.dart @@ -43,7 +43,9 @@ class HistoryItemCubit extends Cubit { state.cachedVid = await HistoryVideoCache.fromVideoIdToVideo(state.videoId); state.loading = false; - emit(state); + if(!isClosed) { + emit(state); + } } } diff --git a/lib/videos/views/components/video_in_list.dart b/lib/videos/views/components/video_in_list.dart index 37bb5ee1..66c08bc5 100644 --- a/lib/videos/views/components/video_in_list.dart +++ b/lib/videos/views/components/video_in_list.dart @@ -44,6 +44,8 @@ class VideoListItem extends StatelessWidget { @override Widget build(BuildContext context) { + + ColorScheme colorScheme = Theme.of(context).colorScheme; var locals = AppLocalizations.of(context)!; diff --git a/lib/videos/views/components/video_list.dart b/lib/videos/views/components/video_list.dart index d16eca87..92665ad3 100644 --- a/lib/videos/views/components/video_list.dart +++ b/lib/videos/views/components/video_list.dart @@ -55,7 +55,7 @@ class VideoList extends StatelessWidget { List items = _.items; if (items.isNotEmpty && items[0] is VideoInList) { - // items = filteredVideos(_.items.cast()); + items = filteredVideos(_.items.cast()); } var gridCount = small ? 1 : getGridCount(context); diff --git a/lib/videos/views/tv/screens/video.dart b/lib/videos/views/tv/screens/video.dart index a5499279..40b0e5a8 100644 --- a/lib/videos/views/tv/screens/video.dart +++ b/lib/videos/views/tv/screens/video.dart @@ -35,7 +35,7 @@ class TvVideoScreen extends StatelessWidget { const TvVideoScreen({Key? key, required this.videoId}) : super(key: key); playVideo(BuildContext context, Video video) { - AutoRouter.of(context).push(TvPlayerRoute(videos: [video, ...video.recommendedVideos])); + AutoRouter.of(context).push(TvPlayerRoute(videos: [video, ...video.recommendedVideos.where((element) => !element.filterHide)])); } showChannel(BuildContext context, String channelId) { diff --git a/lib/videos/views/tv/screens/video_grid_view.dart b/lib/videos/views/tv/screens/video_grid_view.dart index fb406c0a..6d926879 100644 --- a/lib/videos/views/tv/screens/video_grid_view.dart +++ b/lib/videos/views/tv/screens/video_grid_view.dart @@ -25,6 +25,7 @@ class TvGridScreen extends StatelessWidget { child: Scaffold( body: TvOverscan( child: BlocBuilder, ItemListState>(builder: (context, _) { + return Column( children: [ Row( @@ -52,7 +53,7 @@ class TvGridScreen extends StatelessWidget { childAspectRatio: 16 / 13, crossAxisCount: 3, children: [ - ..._.items.map((e) => TvVideoItem(key: ValueKey(e.videoId), video: e, autoFocus: false)).toList(), + ..._.items.where((element) => !element.filterHide).map((e) => TvVideoItem(key: ValueKey(e.videoId), video: e, autoFocus: false)).toList(), if (_.loading) ...repeatWidget(() => const TvVideoItemPlaceHolder(), count: 10) ], ))