-
-
Notifications
You must be signed in to change notification settings - Fork 171
/
Copy pathyoutube_feed_page.dart
136 lines (131 loc) · 6.39 KB
/
youtube_feed_page.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import 'package:flutter/material.dart';
import 'package:youtipie/class/result_wrapper/feed_result.dart';
import 'package:youtipie/class/stream_info_item/stream_info_item.dart';
import 'package:youtipie/class/stream_info_item/stream_info_item_short.dart';
import 'package:youtipie/class/youtipie_feed/playlist_info_item.dart';
import 'package:youtipie/class/youtipie_feed/yt_feed_base.dart';
import 'package:youtipie/youtipie.dart';
import 'package:namida/controller/settings_controller.dart';
import 'package:namida/core/dimensions.dart';
import 'package:namida/core/enums.dart';
import 'package:namida/core/translations/language.dart';
import 'package:namida/core/utils.dart';
import 'package:namida/youtube/pages/youtube_main_page_fetcher_acc_base.dart';
import 'package:namida/youtube/widgets/yt_playlist_card.dart';
import 'package:namida/youtube/widgets/yt_video_card.dart';
class YoutubeHomeFeedPage extends StatelessWidget {
const YoutubeHomeFeedPage({super.key});
@override
Widget build(BuildContext context) {
const thumbnailHeight = Dimensions.youtubeThumbnailHeight;
const thumbnailWidth = Dimensions.youtubeThumbnailWidth;
const thumbnailItemExtent = thumbnailHeight + 8.0 * 2;
return ObxO(
rx: settings.youtube.ytVisibleShorts,
builder: (context, visibleShorts) {
final isShortsVisible = visibleShorts[YTVisibleShortPlaces.homeFeed] ?? true;
return ObxO(
rx: settings.youtube.ytVisibleMixes,
builder: (context, visibleMixes) {
final isMixesVisible = visibleMixes[YTVisibleMixesPlaces.homeFeed] ?? true;
return YoutubeMainPageFetcherAccBase<YoutiPieFeedResult, YoutubeFeed>(
showRefreshInsteadOfRefreshing: true,
transparentShimmer: false,
title: lang.HOME,
cacheReader: YoutiPie.cacheBuilder.forFeedItems(),
networkFetcher: (details) => YoutiPie.feed.fetchFeed(details: details),
itemExtent: thumbnailItemExtent,
dummyCard: const YoutubeVideoCardDummy(
shimmerEnabled: true,
thumbnailWidth: thumbnailWidth,
thumbnailHeight: thumbnailHeight,
),
sliverListBuilder: (feed, itemBuilder, dummyCard) {
return SliverVariedExtentList.builder(
itemExtentBuilder: (index, dimensions) {
if (isShortsVisible && feed.shortsSection.relatedItemsShortsData[index] != null) return 64.0 * 3 + 24.0 * 2;
final item = feed.items[index];
if (!isShortsVisible && item is StreamInfoItemShort) return 0;
if (!isMixesVisible && item is PlaylistInfoItem && item.isMix) return 0;
return thumbnailItemExtent;
},
itemCount: feed.items.length,
itemBuilder: (context, index) {
final shortSection = feed.shortsSection.relatedItemsShortsData[index];
if (shortSection != null) {
if (isShortsVisible == false) return const SizedBox();
const height = 64.0 * 3;
const width = height * (9 / 16 * 1.2);
const hPadding = 4.0;
return SizedBox(
height: height,
child: ListView.builder(
padding: const EdgeInsets.symmetric(vertical: 24.0 / 6, horizontal: 4.0),
scrollDirection: Axis.horizontal,
itemExtent: width + hPadding * 2,
itemCount: shortSection.length,
itemBuilder: (context, index) {
final shortIndex = shortSection[index];
final short = feed.items[shortIndex] as StreamInfoItemShort;
return Padding(
padding: const EdgeInsets.symmetric(horizontal: hPadding),
child: YoutubeShortVideoTallCard(
index: index,
short: short,
thumbnailWidth: width,
thumbnailHeight: height,
),
);
},
),
);
}
return itemBuilder(feed.items[index], index, feed);
},
);
},
itemBuilder: (item, i, _) {
return switch (item.runtimeType) {
const (StreamInfoItem) => YoutubeVideoCard(
key: Key((item as StreamInfoItem).id),
thumbnailWidth: thumbnailWidth,
thumbnailHeight: thumbnailHeight,
isImageImportantInCache: false,
video: item,
playlistID: null,
),
const (StreamInfoItemShort) => !isShortsVisible
? const SizedBox.shrink()
: YoutubeShortVideoCard(
key: Key("${(item as StreamInfoItemShort?)?.id}"),
thumbnailWidth: thumbnailWidth,
thumbnailHeight: thumbnailHeight,
short: item as StreamInfoItemShort,
playlistID: null,
),
const (PlaylistInfoItem) => (item as PlaylistInfoItem).isMix && !isMixesVisible
? const SizedBox.shrink()
: YoutubePlaylistCard(
key: Key(item.id),
playlist: item,
firstVideoID: item.initialVideos.firstOrNull?.id,
thumbnailWidth: thumbnailWidth,
thumbnailHeight: thumbnailHeight,
subtitle: item.subtitle,
playOnTap: true,
isMixPlaylist: item.isMix,
),
_ => const YoutubeVideoCardDummy(
shimmerEnabled: true,
thumbnailWidth: thumbnailWidth,
thumbnailHeight: thumbnailHeight,
),
};
},
);
},
);
},
);
}
}