@adelin-io/cli 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/README.md +76 -2
  2. package/authoring-release.json +174 -0
  3. package/package.json +30 -4
  4. package/runtime-integrity.json +9 -0
  5. package/scripts/adelin.mjs +7768 -0
  6. package/scripts/assemble-checkout.mjs +93 -0
  7. package/scripts/local-save.mjs +513 -0
  8. package/scripts/materialize.mjs +319 -0
  9. package/scripts/runtime.mjs +8950 -0
  10. package/scripts/typecheck.mjs +72 -0
  11. package/scripts/workspace-state.mjs +183 -0
  12. package/skill/README.md +77 -0
  13. package/skill/SKILL.md +100 -0
  14. package/skill/authoring/access.md +193 -0
  15. package/skill/authoring/analytics.md +20 -0
  16. package/skill/authoring/app-memory.md +128 -0
  17. package/skill/authoring/app-requirements.md +99 -0
  18. package/skill/authoring/app-structure.md +265 -0
  19. package/skill/authoring/assets.md +117 -0
  20. package/skill/authoring/auth.md +261 -0
  21. package/skill/authoring/content-binding.md +26 -0
  22. package/skill/authoring/i18n.md +184 -0
  23. package/skill/authoring/language.md +503 -0
  24. package/skill/authoring/local-workflow.md +1665 -0
  25. package/skill/authoring/offline/connectivity.md +50 -0
  26. package/skill/authoring/offline/example.md +102 -0
  27. package/skill/authoring/offline/history-sync.md +39 -0
  28. package/skill/authoring/offline/index.md +29 -0
  29. package/skill/authoring/offline/package-storage.md +37 -0
  30. package/skill/authoring/offline/platforms.md +35 -0
  31. package/skill/authoring/offline/startup-navigation.md +53 -0
  32. package/skill/authoring/platform-files.md +616 -0
  33. package/skill/authoring/player/casting.md +47 -0
  34. package/skill/authoring/player/controls.md +95 -0
  35. package/skill/authoring/player/downloads.md +90 -0
  36. package/skill/authoring/player/drm.md +31 -0
  37. package/skill/authoring/player/index.md +39 -0
  38. package/skill/authoring/player/live-dvr.md +33 -0
  39. package/skill/authoring/player/platforms.md +47 -0
  40. package/skill/authoring/player/playback.md +42 -0
  41. package/skill/authoring/player/tracks-subtitles.md +32 -0
  42. package/skill/authoring/profiles.md +213 -0
  43. package/skill/authoring/remote-keys.md +139 -0
  44. package/skill/authoring/search.md +27 -0
  45. package/skill/authoring/store.md +85 -0
  46. package/skill/authoring/tv-text-entry.md +146 -0
  47. package/skill/design/approved/README.md +14 -0
  48. package/skill/design/approved/vesper-phone-home.jpg +0 -0
  49. package/skill/design/approved/vesper-tv-detail.jpg +0 -0
  50. package/skill/design/approved/vesper-tv-home.jpg +0 -0
  51. package/skill/design/design-guide.md +610 -0
  52. package/skill/design/edge-to-edge.md +66 -0
  53. package/skill/design/icons.md +50 -0
  54. package/skill/design/responsive-layout.md +175 -0
  55. package/skill/design/safe-area.md +221 -0
  56. package/skill/design/streaming-playbook.md +131 -0
  57. package/skill/design/visual-review.md +150 -0
  58. package/skill/examples/README.md +24 -0
  59. package/skill/examples/cinema/DESIGN.md +58 -0
  60. package/skill/examples/cinema/app.tsx +17 -0
  61. package/skill/examples/cinema/assets/logo.png +0 -0
  62. package/skill/examples/cinema/components/Action.tsx +40 -0
  63. package/skill/examples/cinema/components/Action.tv.tsx +44 -0
  64. package/skill/examples/cinema/components/CatalogGrid.tsx +31 -0
  65. package/skill/examples/cinema/components/ContinueRail.tsx +98 -0
  66. package/skill/examples/cinema/components/Feedback.tsx +28 -0
  67. package/skill/examples/cinema/components/Field.tsx +41 -0
  68. package/skill/examples/cinema/components/LibraryRail.tsx +46 -0
  69. package/skill/examples/cinema/components/PlayAction.tsx +29 -0
  70. package/skill/examples/cinema/components/Root.tsx +59 -0
  71. package/skill/examples/cinema/components/Shell.tsx +70 -0
  72. package/skill/examples/cinema/components/Tab.tsx +22 -0
  73. package/skill/examples/cinema/components/TitleCard.tsx +68 -0
  74. package/skill/examples/cinema/components/TitleMeta.tsx +36 -0
  75. package/skill/examples/cinema/locales/en.ts +211 -0
  76. package/skill/examples/cinema/locales/lt.ts +211 -0
  77. package/skill/examples/cinema/preview/phone-home.jpg +0 -0
  78. package/skill/examples/cinema/preview/tv-detail.jpg +0 -0
  79. package/skill/examples/cinema/preview/tv-home.jpg +0 -0
  80. package/skill/examples/cinema/screens/portrait/Account.tsx +110 -0
  81. package/skill/examples/cinema/screens/portrait/Browse.tsx +73 -0
  82. package/skill/examples/cinema/screens/portrait/Detail.tsx +159 -0
  83. package/skill/examples/cinema/screens/portrait/Home.tsx +196 -0
  84. package/skill/examples/cinema/screens/portrait/Player.tsx +299 -0
  85. package/skill/examples/cinema/screens/portrait/Search.tsx +46 -0
  86. package/skill/examples/cinema/screens/portrait/Search.tv.tsx +55 -0
  87. package/skill/examples/cinema/screens/portrait/SignIn.tsx +101 -0
  88. package/skill/examples/cinema/screens/portrait/SignUp.tsx +106 -0
  89. package/skill/examples/cinema/store.tsx +132 -0
  90. package/skill/examples/cinema/theme.ts +32 -0
  91. package/skill/examples/documentary/DESIGN.md +33 -0
  92. package/skill/examples/documentary/app.tsx +17 -0
  93. package/skill/examples/documentary/components/Action.tsx +43 -0
  94. package/skill/examples/documentary/components/CatalogGrid.tsx +47 -0
  95. package/skill/examples/documentary/components/Feedback.tsx +27 -0
  96. package/skill/examples/documentary/components/Field.tsx +33 -0
  97. package/skill/examples/documentary/components/LibraryRail.tsx +47 -0
  98. package/skill/examples/documentary/components/Root.tsx +62 -0
  99. package/skill/examples/documentary/components/Shell.tsx +93 -0
  100. package/skill/examples/documentary/components/StoryCard.tsx +53 -0
  101. package/skill/examples/documentary/components/StoryMeta.tsx +22 -0
  102. package/skill/examples/documentary/preview/phone-home.jpg +0 -0
  103. package/skill/examples/documentary/preview/tv-detail.jpg +0 -0
  104. package/skill/examples/documentary/preview/tv-home.jpg +0 -0
  105. package/skill/examples/documentary/screens/portrait/Account.tsx +97 -0
  106. package/skill/examples/documentary/screens/portrait/Browse.tsx +71 -0
  107. package/skill/examples/documentary/screens/portrait/Detail.tsx +133 -0
  108. package/skill/examples/documentary/screens/portrait/Home.tsx +89 -0
  109. package/skill/examples/documentary/screens/portrait/Player.tsx +116 -0
  110. package/skill/examples/documentary/screens/portrait/Search.tsx +48 -0
  111. package/skill/examples/documentary/screens/portrait/SignIn.tsx +96 -0
  112. package/skill/examples/documentary/screens/portrait/SignUp.tsx +101 -0
  113. package/skill/examples/documentary/store.tsx +115 -0
  114. package/skill/examples/documentary/theme.ts +20 -0
  115. package/skill/examples/series/DESIGN.md +55 -0
  116. package/skill/examples/series/app.tsx +17 -0
  117. package/skill/examples/series/components/Action.tsx +42 -0
  118. package/skill/examples/series/components/CatalogGrid.tsx +43 -0
  119. package/skill/examples/series/components/ContinueRail.tsx +78 -0
  120. package/skill/examples/series/components/Feedback.tsx +26 -0
  121. package/skill/examples/series/components/Field.tsx +34 -0
  122. package/skill/examples/series/components/LibraryRail.tsx +38 -0
  123. package/skill/examples/series/components/OutcomeNote.tsx +28 -0
  124. package/skill/examples/series/components/PlayAction.tsx +29 -0
  125. package/skill/examples/series/components/RestoreAction.tsx +33 -0
  126. package/skill/examples/series/components/Root.tsx +75 -0
  127. package/skill/examples/series/components/SaveTitle.tsx +34 -0
  128. package/skill/examples/series/components/Shell.tsx +75 -0
  129. package/skill/examples/series/components/TitleCard.tsx +62 -0
  130. package/skill/examples/series/components/UnlockAction.tsx +10 -0
  131. package/skill/examples/series/preview/phone-home.jpg +0 -0
  132. package/skill/examples/series/preview/tv-detail.jpg +0 -0
  133. package/skill/examples/series/preview/tv-home.jpg +0 -0
  134. package/skill/examples/series/screens/portrait/Account.tsx +125 -0
  135. package/skill/examples/series/screens/portrait/Browse.tsx +61 -0
  136. package/skill/examples/series/screens/portrait/Detail.tsx +231 -0
  137. package/skill/examples/series/screens/portrait/Home.tsx +109 -0
  138. package/skill/examples/series/screens/portrait/MyList.tsx +44 -0
  139. package/skill/examples/series/screens/portrait/Plans.tsx +131 -0
  140. package/skill/examples/series/screens/portrait/Player.tsx +138 -0
  141. package/skill/examples/series/screens/portrait/Profiles.tsx +103 -0
  142. package/skill/examples/series/screens/portrait/Search.tsx +50 -0
  143. package/skill/examples/series/screens/portrait/SignIn.tsx +94 -0
  144. package/skill/examples/series/screens/portrait/SignUp.tsx +100 -0
  145. package/skill/examples/series/store.tsx +192 -0
  146. package/skill/examples/series/theme.ts +32 -0
  147. package/skill/guides/final-pricing-capabilities.md +13 -0
  148. package/skill/reference/api.md +842 -0
  149. package/skill/reference/components.md +1782 -0
  150. package/skill/reference/packages.md +24 -0
  151. package/skill/scripts/assemble-checkout.mjs +93 -0
  152. package/skill/scripts/local-save.mjs +513 -0
  153. package/skill/scripts/materialize.mjs +319 -0
  154. package/skill/scripts/workspace-state.mjs +183 -0
  155. package/types/adelin-access.d.ts +70 -0
  156. package/types/adelin-analytics.d.ts +5 -0
  157. package/types/adelin-assets.d.ts +26 -0
  158. package/types/adelin-auth.d.ts +37 -0
  159. package/types/adelin-content.d.ts +112 -0
  160. package/types/adelin-device.d.ts +195 -0
  161. package/types/adelin-downloads.d.ts +47 -0
  162. package/types/adelin-env.d.ts +8 -0
  163. package/types/adelin-globals.d.ts +19 -0
  164. package/types/adelin-i18n.d.ts +31 -0
  165. package/types/adelin-native-stack.d.ts +178 -0
  166. package/types/adelin-navigation.d.ts +264 -0
  167. package/types/adelin-profiles.d.ts +51 -0
  168. package/types/adelin-react.d.ts +49 -0
  169. package/types/adelin-reanimated.d.ts +376 -0
  170. package/types/adelin-storage.d.ts +9 -0
  171. package/types/adelin-store.d.ts +74 -0
  172. package/types/adelin-ui.d.ts +1518 -0
  173. package/types/adelin-utils.d.ts +7 -0
  174. package/types/adelin-worklets.d.ts +15 -0
  175. package/workspace-tsconfig.json +53 -0
@@ -0,0 +1,196 @@
1
+ import { useEffect } from '@adelin/react';
2
+ import { useAuth } from '@adelin/auth';
3
+ import type { ContentItem } from '@adelin/content';
4
+ import { useNavigation } from '@adelin/navigation';
5
+ import { useTranslation } from '@adelin/i18n';
6
+ import { useDispatch, useSelector } from '@adelin/store';
7
+ import { Platform } from '@adelin/device';
8
+ import { FocusGroup, Image, LinearGradient, ScrollTarget, ScrollView, StyleSheet, Text, View, theme, useSafeAreaInsets, useWindowDimensions, Screen } from '@adelin/ui';
9
+ import Animated, { Easing, useAnimatedStyle, useSharedValue, withSequence, withTiming } from '@adelin/reanimated';
10
+ import { feature, loadLibrary, loadProfiles, loadWatching, resetWatching, settle } from '../../store';
11
+ import Shell from '../../components/Shell';
12
+ import Feedback from '../../components/Feedback';
13
+ import Action from '../../components/Action';
14
+ import PlayAction from '../../components/PlayAction';
15
+ import LibraryRail from '../../components/LibraryRail';
16
+ import ContinueRail from '../../components/ContinueRail';
17
+ import TitleMeta from '../../components/TitleMeta';
18
+ import logo from '../../assets/logo.png';
19
+
20
+ export default function Home() {
21
+ const { t } = useTranslation();
22
+ const dispatch = useDispatch();
23
+ const auth = useAuth();
24
+ const profileStatus = useSelector(state => state.profiles.status);
25
+ const activeId = useSelector(state => state.profiles.activeId);
26
+ const entries = useSelector(state => state.library.entries);
27
+ const collections = useSelector(state => state.library.collections);
28
+ const status = useSelector(state => state.library.status);
29
+ const { width, height } = useWindowDimensions();
30
+ const wide = width >= 840 && height >= 480;
31
+ const filled = collections.filter(collection => entries.filter(entry => collection.entryIds.includes(entry.id)).length >= 3);
32
+ const leaves = filled.filter(collection => !filled.some(child => child.parentId === collection.id));
33
+ const holdsFolders = (collection: { entryIds: string[] }) => entries.find(entry => entry.id === collection.entryIds[0])?.kind === 'folder';
34
+ const playable = leaves.filter(collection => !holdsFolders(collection));
35
+ const shelves = [...playable.slice(0, 1), ...leaves.filter(collection => holdsFolders(collection)), ...playable.slice(1)];
36
+ const hero = entries.find(entry => entry.id === shelves[0]?.entryIds[0]) ?? entries.find(entry => !entry.parentId);
37
+ const rails = shelves.map((collection, index) => ({
38
+ id: collection.id,
39
+ name: collection.name,
40
+ note: collection.note ?? '',
41
+ poster: holdsFolders(collection),
42
+ entries: collection.entryIds.map(id => entries.find(entry => entry.id === id)).filter((entry): entry is ContentItem => !!entry && (index > 0 || entry.id !== hero?.id)),
43
+ }));
44
+ useEffect(() => { if (auth.status === 'signed-in' && profileStatus === 'idle') dispatch(loadProfiles()); }, [auth.status, profileStatus]);
45
+ useEffect(() => { dispatch(resetWatching(activeId)); if (activeId.length > 0) dispatch(loadWatching(activeId)); }, [activeId]);
46
+ return (
47
+ <Screen>
48
+ <Shell active="Home" overlay contentAutoFocus>
49
+ {status === 'idle' || status === 'loading' ? <Feedback title={t('common.loading')} message={t('library.loading')} loading /> : status === 'failed' ? <Feedback title={t('library.failed')} message={t('common.checkConnection')} onRetry={() => dispatch(loadLibrary())} /> : !hero ? <Feedback title={t('home.emptyTitle')} message={t('home.emptyMessage')} /> : wide ? <Billboard hero={hero} rails={rails} /> : <PosterHome hero={hero} rails={rails} />}
50
+ </Shell>
51
+ </Screen>
52
+ );
53
+ }
54
+
55
+ function Billboard({ hero, rails }: { hero: ContentItem; rails: { id: string; name: string; note: string; poster: boolean; entries: ContentItem[] }[] }) {
56
+ const dispatch = useDispatch();
57
+ const { width, height } = useWindowDimensions();
58
+ return (
59
+ <View style={styles.stage}>
60
+ <SettleFocus />
61
+ <View style={[styles.band, { height: Math.min(width / 2.39, height * 0.48) }]}>
62
+ <Backdrop hero={hero} />
63
+ <View style={styles.bandCopy}><Feature hero={hero} /></View>
64
+ </View>
65
+ <ScrollView style={styles.fillFlex} contentContainerStyle={styles.shelvesContent} showsVerticalScrollIndicator={false} viewportOffset={40} scrollPaddingTop={0}>
66
+ <ContinueRail onFocusItem={id => dispatch(feature(id))} />
67
+ {rails.map(rail => <LibraryRail key={rail.id} title={rail.name} entries={rail.entries} variant="scope" onFocusItem={id => dispatch(feature(id))} />)}
68
+ </ScrollView>
69
+ </View>
70
+ );
71
+ }
72
+
73
+ /** Features a card only once focus rests on it, so holding a direction key doesn't strobe the billboard. */
74
+ function SettleFocus() {
75
+ const dispatch = useDispatch();
76
+ const focusedId = useSelector(state => state.billboard.focusedId);
77
+ useEffect(() => {
78
+ const timer = setTimeout(() => dispatch(settle(focusedId)), 260);
79
+ return () => clearTimeout(timer);
80
+ }, [focusedId]);
81
+ return null;
82
+ }
83
+
84
+ function Backdrop({ hero }: { hero: ContentItem }) {
85
+ const entries = useSelector(state => state.library.entries);
86
+ const featuredId = useSelector(state => state.billboard.featuredId);
87
+ const previousId = useSelector(state => state.billboard.previousId);
88
+ const above = entries.find(entry => entry.id === featuredId) ?? hero;
89
+ const below = entries.find(entry => entry.id === previousId) ?? hero;
90
+ const changes = useSelector(state => state.billboard.changes);
91
+ const layers = changes > 0 ? [{ key: 'still-' + (changes - 1), item: below, fadeIn: false }, { key: 'still-' + changes, item: above, fadeIn: true }] : [{ key: 'still-0', item: above, fadeIn: true }];
92
+ return (
93
+ <View style={styles.backdrop}>
94
+ {layers.map(layer => <Still key={layer.key} item={layer.item} fadeIn={layer.fadeIn} />)}
95
+ <LinearGradient colors={[theme.gradients.heroDeep, theme.gradients.heroMiddle, theme.gradients.heroClear]} start={{ x: 0, y: 0 }} end={{ x: 1, y: 0 }} locations={[0, 0.3, 0.62]} style={styles.fill} pointerEvents="none" />
96
+ </View>
97
+ );
98
+ }
99
+
100
+ function Still({ item, fadeIn }: { item: ContentItem; fadeIn: boolean }) {
101
+ const opacity = useSharedValue(fadeIn ? 0 : 1);
102
+ const fadeStyle = useAnimatedStyle(() => ({ opacity: opacity.value }));
103
+ useEffect(() => { opacity.value = withTiming(1, { duration: 360, easing: Easing.out(Easing.cubic) }); }, []);
104
+ const uri = item.artwork.backdrop || item.artwork.poster;
105
+ return <Animated.View style={[styles.fill, fadeStyle]}>{uri ? <Image source={{ uri }} resizeMode="cover" style={styles.fill} /> : null}</Animated.View>;
106
+ }
107
+
108
+ function Feature({ hero }: { hero: ContentItem }) {
109
+ const navigation = useNavigation();
110
+ const entries = useSelector(state => state.library.entries);
111
+ const featuredId = useSelector(state => state.billboard.featuredId);
112
+ const featured = entries.find(entry => entry.id === featuredId) ?? hero;
113
+ const fade = useSharedValue(1);
114
+ const fadeStyle = useAnimatedStyle(() => ({ opacity: fade.value }));
115
+ useEffect(() => { fade.value = withSequence(withTiming(0.5, { duration: 0 }), withTiming(1, { duration: 220, easing: Easing.out(Easing.cubic) })); }, [featured.id]);
116
+ return (
117
+ <View>
118
+ <Animated.View style={fadeStyle}>
119
+ <Text style={styles.title} numberOfLines={2}>{featured.title}</Text>
120
+ <View style={styles.meta}><TitleMeta item={featured} /></View>
121
+ <Text style={styles.logline} numberOfLines={2}>{logline(featured)}</Text>
122
+ </Animated.View>
123
+ <HeroActions item={featured} onDetails={() => navigation.push('Detail', { id: featured.id })} />
124
+ </View>
125
+ );
126
+ }
127
+
128
+ /** Resume or play the title, and open its details. */
129
+ function HeroActions({ item, onDetails }: { item: ContentItem; onDetails: () => void }) {
130
+ const { t } = useTranslation();
131
+ const entries = useSelector(state => state.library.entries);
132
+ const seasons = entries.filter(entry => entry.parentId === item.id && entry.kind === 'folder');
133
+ const firstEpisode = seasons.length > 0 ? entries.find(entry => entry.parentId === seasons[0].id) : entries.find(entry => entry.parentId === item.id && entry.kind === 'item');
134
+ const playTarget = item.kind === 'item' ? item : firstEpisode;
135
+ const canPlay = playTarget?.playbackSource?.uri != null;
136
+ return (
137
+ <FocusGroup direction="horizontal" remember>
138
+ <View style={styles.actions}>
139
+ <View style={styles.action}><PlayAction item={item} focusKey="vesper-play" /></View>
140
+ <Action label={t('home.details')} primary={!canPlay} focusKey="vesper-details" onPress={onDetails} />
141
+ </View>
142
+ </FocusGroup>
143
+ );
144
+ }
145
+
146
+ function logline(item: ContentItem) {
147
+ const synopsis = item.description ?? '';
148
+ const sentenceEnd = synopsis.indexOf('. ');
149
+ return sentenceEnd >= 0 ? synopsis.slice(0, sentenceEnd + 1) : synopsis;
150
+ }
151
+
152
+ function PosterHome({ hero, rails }: { hero: ContentItem; rails: { id: string; name: string; note: string; poster: boolean; entries: ContentItem[] }[] }) {
153
+ const { t } = useTranslation();
154
+ const navigation = useNavigation();
155
+ const { width } = useWindowDimensions();
156
+ const insets = useSafeAreaInsets();
157
+ const uri = hero.artwork.backdrop || hero.artwork.poster;
158
+ return (
159
+ <ScrollView style={styles.fillFlex} contentContainerStyle={styles.phoneContent} showsVerticalScrollIndicator={false}>
160
+ <ScrollTarget y={0}>
161
+ <View>
162
+ <Image source={logo} accessibilityLabel={t('common.brand')} resizeMode="contain" style={[styles.phoneMark, { marginTop: insets.top + 16 }]} />
163
+ <View style={[styles.phoneBand, { height: width / 2.39 }]}>{uri ? <Image source={{ uri }} resizeMode="cover" style={styles.fill} /> : null}</View>
164
+ <View style={styles.posterCopy}>
165
+ <Text style={styles.phoneTitle} numberOfLines={2}>{hero.title}</Text>
166
+ <View style={styles.meta}><TitleMeta item={hero} /></View>
167
+ <Text style={styles.logline} numberOfLines={3}>{logline(hero)}</Text>
168
+ <HeroActions item={hero} onDetails={() => navigation.push('Detail', { id: hero.id })} />
169
+ </View>
170
+ </View>
171
+ </ScrollTarget>
172
+ <ContinueRail />
173
+ {rails.map(rail => <LibraryRail key={rail.id} title={rail.name} entries={rail.entries} variant={rail.poster ? 'poster' : 'scope'} />)}
174
+ </ScrollView>
175
+ );
176
+ }
177
+
178
+ const styles = StyleSheet.create({
179
+ stage: { flex: 1, backgroundColor: theme.colors.background },
180
+ fill: { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, width: '100%', height: '100%' },
181
+ fillFlex: { flex: 1 },
182
+ band: { marginTop: 52, justifyContent: 'flex-end', overflow: 'hidden', backgroundColor: theme.colors.surface, marginBottom: Platform.select({ tv: 12, default: theme.spacing.lg }) },
183
+ backdrop: { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 },
184
+ bandCopy: { paddingHorizontal: theme.spacing.xl, paddingBottom: Platform.select({ tv: 20, default: 36 }), width: Platform.select({ tv: 520, default: 640 }) },
185
+ title: { color: theme.colors.text, fontSize: Platform.select({ tv: 36, default: 48 }), lineHeight: Platform.select({ tv: 39, default: 52 }), fontWeight: '800', letterSpacing: -1.4 },
186
+ logline: { color: theme.colors.textSecondary, fontSize: Platform.select({ tv: 12, default: 15 }), lineHeight: Platform.select({ tv: 17, default: 21 }), fontWeight: '400', marginTop: Platform.select({ tv: 6, default: 8 }), maxWidth: Platform.select({ tv: 420, default: 520 }) },
187
+ meta: { marginTop: Platform.select({ tv: 8, default: 8 }) },
188
+ actions: { flexDirection: 'row', alignItems: 'center', marginTop: Platform.select({ tv: 14, default: 16 }) },
189
+ action: { marginRight: Platform.select({ tv: 10, default: 10 }) },
190
+ shelvesContent: { paddingBottom: Platform.select({ tv: 160, default: theme.spacing.xl }) },
191
+ phoneContent: { paddingBottom: theme.spacing.lg },
192
+ phoneMark: { width: 105, height: 16, marginLeft: theme.spacing.md, marginBottom: theme.spacing.md },
193
+ phoneBand: { width: '100%', backgroundColor: theme.colors.surface },
194
+ posterCopy: { paddingHorizontal: theme.spacing.md, paddingTop: theme.spacing.lg, marginBottom: theme.spacing.lg },
195
+ phoneTitle: { color: theme.colors.text, fontSize: 34, lineHeight: 37, fontWeight: '800', letterSpacing: -1.2 },
196
+ });
@@ -0,0 +1,299 @@
1
+ import { useEffect, useState } from '@adelin/react';
2
+ import type { VideoSource } from '@adelin/ui';
3
+ import { useNavigation, useRoute } from '@adelin/navigation';
4
+ import { useTranslation } from '@adelin/i18n';
5
+ import { useDispatch, useSelector } from '@adelin/store';
6
+ import { ActivityIndicator, FocusGroup, Icon, LinearGradient, Pressable, SafeAreaView, ScrollView, ScrubFilmstrip, ScrubThumbnail, Slider, StyleSheet, Text, VideoView, View, theme, useVideoPlayer, useWindowDimensions, Screen } from '@adelin/ui';
7
+ import Animated, { useAnimatedStyle, useSharedValue, withTiming } from '@adelin/reanimated';
8
+ import { Keys, Platform, capabilities, useBackHandler, useTVEventHandler } from '@adelin/device';
9
+ import Action from '../../components/Action';
10
+ import Feedback from '../../components/Feedback';
11
+ import { loadWatching } from '../../store';
12
+
13
+ export default function Player() {
14
+ const { t } = useTranslation();
15
+ const navigation = useNavigation();
16
+ const route = useRoute();
17
+ const entries = useSelector(state => state.library.entries);
18
+ const item = entries.find(entry => entry.id === route.params.id);
19
+ const parent = entries.find(entry => entry.id === item?.parentId);
20
+ const grandparent = entries.find(entry => entry.id === parent?.parentId);
21
+ const source = item?.playbackSource;
22
+ return (
23
+ <Screen>
24
+ <View style={styles.page}>
25
+ {source?.uri ? <Playback source={source} entryId={item?.id ?? ''} title={item?.title ?? ''} context={grandparent?.title ?? parent?.title ?? ''} onRetry={() => navigation.replace('Player', { id: item?.id })} onBack={() => navigation.goBack()} /> : <SafeAreaView style={styles.unavailable}><Feedback title={t('player.unavailable')} message={t('player.unavailableMessage')} /><View style={styles.centered}><Action label={t('player.backToTitle')} primary onPress={() => navigation.goBack()} preferred /></View></SafeAreaView>}
26
+ </View>
27
+ </Screen>
28
+ );
29
+ }
30
+
31
+ function Playback({ source, entryId, title, context, onRetry, onBack }: {
32
+ source: VideoSource;
33
+ entryId: string;
34
+ title: string;
35
+ context: string;
36
+ onRetry: () => void;
37
+ onBack: () => void;
38
+ }) {
39
+ const { t } = useTranslation();
40
+ const player = useVideoPlayer(source, { autoHideControls: true, entryId });
41
+ const dispatch = useDispatch();
42
+ const activeId = useSelector(state => state.profiles.activeId);
43
+ useEffect(() => () => { if (activeId.length > 0) dispatch(loadWatching(activeId)); }, [activeId]);
44
+ const { width, height } = useWindowDimensions();
45
+ const wide = width >= 840 && height >= 480;
46
+ const [timedOut, setTimedOut] = useState(false);
47
+ const [onBar, setOnBar] = useState(false);
48
+ const [fit, setFit] = useState<'contain' | 'cover' | 'stretch'>('contain');
49
+ const [settingsOpen, setSettingsOpen] = useState(false);
50
+ const [textSize, setTextSize] = useState<'small' | 'medium' | 'large'>('medium');
51
+ const [textLook, setTextLook] = useState<'shadow' | 'outline' | 'box'>('shadow');
52
+ const [textColor, setTextColor] = useState('#FFFFFF');
53
+ const chrome = useSharedValue(1);
54
+ const chromeStyle = useAnimatedStyle(() => ({ opacity: chrome.value }));
55
+ useEffect(() => {
56
+ const timer = setTimeout(() => { if (player.duration <= 0) setTimedOut(true); }, 15000);
57
+ return () => clearTimeout(timer);
58
+ }, [player.duration]);
59
+ useEffect(() => { chrome.value = withTiming(player.controlsVisible && !settingsOpen ? 1 : 0, { duration: player.controlsVisible && !settingsOpen ? 140 : 320 }); }, [player.controlsVisible, settingsOpen]);
60
+ const closeSettings = () => {
61
+ setSettingsOpen(false);
62
+ player.showControls();
63
+ };
64
+ useBackHandler(() => {
65
+ if (!settingsOpen) return false;
66
+ closeSettings();
67
+ return true;
68
+ });
69
+ useTVEventHandler(event => {
70
+ if (settingsOpen || event.eventKeyAction !== 'down' || event.eventType === Keys.Back) return false;
71
+ if (event.eventType === Keys.PlayPause) {
72
+ player.togglePlay();
73
+ return true;
74
+ }
75
+ if (event.eventType === Keys.Play) {
76
+ player.play();
77
+ return true;
78
+ }
79
+ if (event.eventType === Keys.Pause) {
80
+ player.pause();
81
+ return true;
82
+ }
83
+ if (event.eventType === Keys.Stop) {
84
+ player.stop();
85
+ return true;
86
+ }
87
+ if (!player.controlsVisible) {
88
+ player.showControls();
89
+ return true;
90
+ }
91
+ player.showControls();
92
+ if (event.eventType === Keys.Rewind || (onBar && event.eventType === Keys.Left)) {
93
+ player.scrubBackward();
94
+ return true;
95
+ }
96
+ if (event.eventType === Keys.FastForward || (onBar && event.eventType === Keys.Right)) {
97
+ player.scrubForward();
98
+ return true;
99
+ }
100
+ return false;
101
+ });
102
+ return (
103
+ <View style={styles.playerLayout}>
104
+ <VideoView player={player} style={styles.video} resizeMode={fit} subtitleStyle={{ fontSizeScale: (textSize === 'small' ? 0.8 : textSize === 'large' ? 1.3 : 1) * (wide ? 2.2 : 1.15), fontColor: textColor, edgeStyle: textLook === 'shadow' ? 'dropShadow' : textLook === 'outline' ? 'uniform' : 'none', edgeColor: '#000000', windowColor: textLook === 'box' ? 'rgba(0,0,0,0.75)' : 'rgba(0,0,0,0)', bottomInset: wide ? (player.controlsVisible && !settingsOpen ? 0.3 : 0.07) : 0.27 }} />
105
+ <Pressable focusable={false} onPress={() => player.toggleControls()} style={styles.video} accessibilityLabel={player.controlsVisible ? t('player.hideControls') : t('player.showControls')} />
106
+ {player.duration <= 0 && (
107
+ <View style={styles.loading} pointerEvents="box-none">
108
+ {timedOut ? <Feedback title={t('player.notLoaded')} message={t('common.checkConnection')} onRetry={onRetry} /> : <ActivityIndicator color={theme.colors.text} />}
109
+ </View>
110
+ )}
111
+ <Animated.View style={[styles.overlay, chromeStyle]} pointerEvents={player.controlsVisible && !settingsOpen ? 'box-none' : 'none'}>
112
+ <LinearGradient colors={[theme.gradients.heroClear, theme.gradients.playerChrome]} start={{ x: 0, y: 0 }} end={{ x: 0, y: 1 }} locations={[0.4, 1]} style={styles.shade} pointerEvents="none" />
113
+ {!wide && (
114
+ <SafeAreaView edges={['top', 'left']} style={styles.topSafe}>
115
+ <Pressable onPress={onBack} style={styles.back} accessibilityRole="button" accessibilityLabel={t('player.backToTitle')}>
116
+ <Icon icon="ph:caret-left" size={22} color={theme.colors.text} />
117
+ </Pressable>
118
+ </SafeAreaView>
119
+ )}
120
+ {wide && <ScrubFilmstrip player={player} count={5} style={styles.filmstrip} />}
121
+ <SafeAreaView edges={['left', 'right', 'bottom']} style={styles.bottomSafe}>
122
+ <View style={styles.chrome}>
123
+ {context.length > 0 && <Text style={styles.context} numberOfLines={1}>{context.toUpperCase()}</Text>}
124
+ <Text style={styles.title} numberOfLines={1}>{title}</Text>
125
+ <FocusGroup direction="vertical" remember>
126
+ <View style={styles.timeline}>
127
+ <Pressable onPress={() => { if (player.scrubbing) player.commitScrub(); else player.togglePlay(); }} onFocus={() => setOnBar(true)} onBlur={() => setOnBar(false)} style={styles.bar} accessibilityRole="adjustable" accessibilityLabel={t('player.position', { elapsed: player.elapsedText, duration: player.durationText })}>
128
+ <View style={[styles.track, onBar && styles.trackFocused]}><View style={[styles.fill, { width: player.progress * 100 + '%' }]} /></View>
129
+ {(onBar || player.scrubbing) && <View style={[styles.thumb, { left: player.progress * 100 + '%' }]} />}
130
+ {!wide && <ScrubThumbnail player={player} style={styles.preview} />}
131
+ {player.scrubbing && <View style={[styles.bubble, { left: player.progress * 100 + '%' }]}><Text style={styles.bubbleText} maxFontSizeMultiplier={1}>{player.elapsedText}</Text></View>}
132
+ <Slider value={player.displayPosition} minimumValue={0} maximumValue={player.duration > 0 ? player.duration : 1} onValueChange={value => player.scrubTo(value)} onSlidingComplete={() => player.commitScrub()} style={styles.drag} accessibilityLabel={t('player.drag')} />
133
+ </Pressable>
134
+ <Text style={styles.time} maxFontSizeMultiplier={1}>{player.elapsedText} / {player.durationText}</Text>
135
+ </View>
136
+ <FocusGroup direction="horizontal" remember autoFocus>
137
+ <View style={styles.controls}>
138
+ <Control icon={player.playing ? 'ph:pause-fill' : 'ph:play-fill'} label={player.playing ? t('player.pause') : t('player.play')} primary onPress={() => player.togglePlay()} />
139
+ <Control icon="ph:arrow-counter-clockwise" label={t('player.back10')} onPress={() => player.seekBy(-10)} />
140
+ <Control icon="ph:arrow-clockwise" label={t('player.forward10')} onPress={() => player.seekBy(10)} />
141
+ <Control icon="ph:skip-back" label={t('player.restart')} onPress={() => player.seekTo(0)} />
142
+ <View style={styles.spacer} />
143
+ <Control icon="ph:sliders-horizontal" label={t('player.settings')} onPress={() => setSettingsOpen(true)} />
144
+ </View>
145
+ </FocusGroup>
146
+ </FocusGroup>
147
+ </View>
148
+ </SafeAreaView>
149
+ </Animated.View>
150
+ {settingsOpen && (
151
+ <View style={styles.settings}>
152
+ <Pressable focusable={false} onPress={closeSettings} style={styles.video} accessibilityLabel={t('player.closeSettings')} />
153
+ <SafeAreaView style={styles.settingsSafe} pointerEvents="box-none">
154
+ <ScrollView style={styles.settingsScroll} contentContainerStyle={styles.settingsContent}>
155
+ <View style={styles.settingsHeader}>
156
+ <Text style={styles.settingsTitle}>{t('player.settingsTitle')}</Text>
157
+ {!wide && (
158
+ <Pressable onPress={closeSettings} style={styles.close} accessibilityRole="button" accessibilityLabel={t('player.closeSettings')}>
159
+ <Icon icon="ph:x-bold" size={18} color={theme.colors.text} />
160
+ </Pressable>
161
+ )}
162
+ </View>
163
+ <FocusGroup direction="vertical" trap autoFocus>
164
+ <View>
165
+ <FocusGroup direction="horizontal" remember>
166
+ <View style={wide ? styles.columns : styles.sections}>
167
+ {capabilities.player.resizeMode && (
168
+ <Section title={t('player.picture')} wide={wide}>
169
+ <Option label={t('player.fit')} selected={fit === 'contain'} wide={wide} onPress={() => setFit('contain')} />
170
+ <Option label={t('player.fill')} selected={fit === 'cover'} wide={wide} onPress={() => setFit('cover')} />
171
+ <Option label={t('player.stretch')} selected={fit === 'stretch'} wide={wide} onPress={() => setFit('stretch')} />
172
+ </Section>
173
+ )}
174
+ <Section title={t('player.subtitles')} wide={wide}>
175
+ <Option label={t('player.off')} selected={player.subtitleTrack === null} wide={wide} onPress={() => player.selectSubtitleTrack(null)} />
176
+ {player.subtitleTracks.map(track => <Option key={track.id} label={track.label} selected={player.subtitleTrack === track.id} wide={wide} onPress={() => player.selectSubtitleTrack(track.id)} />)}
177
+ </Section>
178
+ {player.audioTracks.length > 1 && (
179
+ <Section title={t('player.audio')} wide={wide}>
180
+ {player.audioTracks.map(track => <Option key={track.id} label={track.label} selected={player.audioTrack === track.id} wide={wide} onPress={() => player.selectAudioTrack(track.id)} />)}
181
+ </Section>
182
+ )}
183
+ {capabilities.player.rate && (
184
+ <Section title={t('player.speed')} wide={wide}>
185
+ {[0.5, 0.75, 1, 1.25, 1.5, 2].map(rate => <Option key={rate + 'x'} label={rate === 1 ? t('player.normal') : rate + '×'} selected={player.rate === rate} wide={wide} onPress={() => player.setRate(rate)} />)}
186
+ </Section>
187
+ )}
188
+ </View>
189
+ </FocusGroup>
190
+ <FocusGroup direction="horizontal" remember>
191
+ <View style={wide ? styles.secondRow : styles.sections}>
192
+ <Section title={t('player.textSize')} wide={wide}>
193
+ <Option label={t('player.small')} selected={textSize === 'small'} wide={wide} onPress={() => setTextSize('small')} />
194
+ <Option label={t('player.medium')} selected={textSize === 'medium'} wide={wide} onPress={() => setTextSize('medium')} />
195
+ <Option label={t('player.large')} selected={textSize === 'large'} wide={wide} onPress={() => setTextSize('large')} />
196
+ </Section>
197
+ <Section title={t('player.textStyle')} wide={wide}>
198
+ <Option label={t('player.shadow')} selected={textLook === 'shadow'} wide={wide} onPress={() => setTextLook('shadow')} />
199
+ <Option label={t('player.outline')} selected={textLook === 'outline'} wide={wide} onPress={() => setTextLook('outline')} />
200
+ <Option label={t('player.box')} selected={textLook === 'box'} wide={wide} onPress={() => setTextLook('box')} />
201
+ </Section>
202
+ <Section title={t('player.textColour')} wide={wide}>
203
+ <Option label={t('player.white')} selected={textColor === '#FFFFFF'} wide={wide} onPress={() => setTextColor('#FFFFFF')} />
204
+ <Option label={t('player.yellow')} selected={textColor === '#FFE14D'} wide={wide} onPress={() => setTextColor('#FFE14D')} />
205
+ </Section>
206
+ </View>
207
+ </FocusGroup>
208
+ </View>
209
+ </FocusGroup>
210
+ </ScrollView>
211
+ </SafeAreaView>
212
+ </View>
213
+ )}
214
+ </View>
215
+ );
216
+ }
217
+
218
+ function Section({ title, wide, children }: { title: string; wide: boolean; children?: {} | null }) {
219
+ return (
220
+ <View style={wide ? styles.column : styles.section}>
221
+ <Text style={styles.heading}>{title.toUpperCase()}</Text>
222
+ <FocusGroup direction={wide ? 'vertical' : 'horizontal'} remember>
223
+ <View style={wide ? styles.list : styles.chips}>{children}</View>
224
+ </FocusGroup>
225
+ </View>
226
+ );
227
+ }
228
+
229
+ function Option({ label, selected, wide, onPress }: { label: string; selected: boolean; wide: boolean; onPress: () => void }) {
230
+ return (
231
+ <Pressable onPress={onPress} style={[wide ? styles.option : styles.chip, selected && !wide && styles.chipSelected]} focusAnimation={{ backgroundColor: theme.gradients.ghostStrong, scale: 1.04 }} accessibilityRole="button" accessibilityState={{ selected }} accessibilityLabel={label}>
232
+ {wide && <View style={styles.check}>{selected && <Icon icon="ph:check-bold" size={12} color={theme.colors.text} />}</View>}
233
+ <Text style={[styles.optionText, selected && styles.optionSelected, !wide && selected && styles.chipTextSelected]} numberOfLines={1}>{label}</Text>
234
+ </Pressable>
235
+ );
236
+ }
237
+
238
+ function Control({ icon, label, onPress, primary = false }: { icon: string; label: string; onPress: () => void; primary?: boolean }) {
239
+ return (
240
+ <Pressable onPress={onPress} style={[styles.control, primary === true && styles.controlPrimary]} focusAnimation={{ border: { color: theme.colors.text, width: 2 }, scale: 1.06 }} accessibilityRole="button" accessibilityLabel={label}>
241
+ <Icon icon={icon} size={16} color={primary ? theme.colors.background : theme.colors.text} />
242
+ </Pressable>
243
+ );
244
+ }
245
+
246
+ const styles = StyleSheet.create({
247
+ page: { flex: 1, backgroundColor: theme.colors.background },
248
+ playerLayout: { flex: 1, backgroundColor: theme.colors.background },
249
+ video: { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 },
250
+ loading: { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, alignItems: 'center', justifyContent: 'center' },
251
+ shade: { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 },
252
+ topSafe: { position: 'absolute', top: 0, left: 0 },
253
+ back: { margin: theme.spacing.md, width: 40, height: 40, borderRadius: 20, alignItems: 'center', justifyContent: 'center', backgroundColor: theme.gradients.tag },
254
+ bottomSafe: { position: 'absolute', left: 0, right: 0, bottom: 0 },
255
+ chrome: { paddingHorizontal: Platform.select({ tv: theme.spacing.xl, default: theme.spacing.md }), paddingBottom: Platform.select({ tv: 36, default: theme.spacing.md }) },
256
+ context: { color: theme.colors.textSecondary, fontSize: Platform.select({ tv: 8, default: 11 }), lineHeight: Platform.select({ tv: 12, default: 16 }), fontWeight: '800', letterSpacing: 2 },
257
+ title: { color: theme.colors.text, fontSize: Platform.select({ tv: 20, default: 22 }), lineHeight: Platform.select({ tv: 25, default: 28 }), fontWeight: '800', letterSpacing: -0.5, marginTop: 4 },
258
+ overlay: { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, zIndex: 2 },
259
+ timeline: { flexDirection: 'row', alignItems: 'center', marginTop: Platform.select({ tv: 14, default: 26 }) },
260
+ bar: { flex: 1, height: Platform.select({ tv: 24, default: 32 }), justifyContent: 'center' },
261
+ track: { height: 4, backgroundColor: theme.gradients.ghost, borderRadius: 2, overflow: 'hidden' },
262
+ trackFocused: { backgroundColor: theme.gradients.ghostStrong },
263
+ fill: { height: 4, backgroundColor: theme.colors.text },
264
+ thumb: { position: 'absolute', top: Platform.select({ tv: 5, default: 9 }), width: 14, height: 14, marginLeft: -7, borderRadius: 7, backgroundColor: theme.colors.text },
265
+ bubble: { position: 'absolute', bottom: Platform.select({ tv: 22, default: 30 }), width: 56, marginLeft: -28, paddingVertical: 3, borderRadius: 2, alignItems: 'center', backgroundColor: theme.colors.text },
266
+ preview: { position: 'absolute', left: 0, right: 0, bottom: 58 },
267
+ filmstrip: { position: 'absolute', left: 0, right: 0, bottom: Platform.select({ tv: 156, default: 196 }) },
268
+ bubbleText: { color: theme.colors.background, fontSize: Platform.select({ tv: 10, default: 13 }), lineHeight: Platform.select({ tv: 14, default: 17 }), fontWeight: '800' },
269
+ drag: { position: 'absolute', top: 0, left: 0, right: 0, height: Platform.select({ tv: 24, default: 32 }), opacity: 0 },
270
+ time: { color: theme.colors.textSecondary, fontSize: Platform.select({ tv: 9, default: 12 }), lineHeight: Platform.select({ tv: 13, default: 16 }), fontWeight: '600', marginLeft: theme.spacing.md },
271
+ controls: { flexDirection: 'row', alignItems: 'center', marginTop: Platform.select({ tv: 14, default: 16 }) },
272
+ control: { width: Platform.select({ tv: 34, default: 46 }), height: Platform.select({ tv: 34, default: 46 }), borderRadius: 2, alignItems: 'center', justifyContent: 'center', backgroundColor: theme.gradients.ghost, marginRight: Platform.select({ tv: 10, default: 12 }) },
273
+ controlPrimary: { backgroundColor: theme.colors.primary },
274
+ spacer: { flex: 1 },
275
+ settings: { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, zIndex: 3, backgroundColor: theme.gradients.scrim },
276
+ settingsSafe: { flex: 1, zIndex: 2 },
277
+ settingsScroll: { flex: 1 },
278
+ settingsContent: { flexGrow: 1, justifyContent: Platform.select({ tv: 'center', default: 'flex-start' }), paddingHorizontal: Platform.select({ tv: 72, default: theme.spacing.md }), paddingVertical: Platform.select({ tv: theme.spacing.lg, default: 0 }) },
279
+ settingsHeader: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', marginTop: Platform.select({ tv: 0, default: theme.spacing.md }), marginBottom: Platform.select({ tv: 16, default: theme.spacing.lg }) },
280
+ settingsTitle: { color: theme.colors.text, fontSize: Platform.select({ tv: 22, default: 24 }), lineHeight: Platform.select({ tv: 28, default: 30 }), fontWeight: '800', letterSpacing: -0.5 },
281
+ close: { width: 40, height: 40, borderRadius: 20, alignItems: 'center', justifyContent: 'center', backgroundColor: theme.gradients.ghost },
282
+ columns: { flexDirection: 'row' },
283
+ sections: { flexDirection: 'column' },
284
+ column: { width: 128, marginRight: theme.spacing.md },
285
+ secondRow: { flexDirection: 'row', marginTop: 20 },
286
+ section: { marginBottom: theme.spacing.lg },
287
+ heading: { color: theme.colors.textSecondary, fontSize: Platform.select({ tv: 8, default: 11 }), lineHeight: Platform.select({ tv: 12, default: 16 }), fontWeight: '800', letterSpacing: 2, marginBottom: Platform.select({ tv: 8, default: 10 }) },
288
+ list: { flexDirection: 'column' },
289
+ chips: { flexDirection: 'row', flexWrap: 'wrap' },
290
+ option: { flexDirection: 'row', alignItems: 'center', height: 22, paddingHorizontal: 8, borderRadius: 2, marginBottom: 2 },
291
+ chip: { height: 38, paddingHorizontal: 16, borderRadius: 19, justifyContent: 'center', backgroundColor: theme.gradients.ghost, marginRight: 8, marginBottom: 8 },
292
+ chipSelected: { backgroundColor: theme.colors.text },
293
+ chipTextSelected: { color: theme.colors.background },
294
+ check: { width: 18 },
295
+ optionText: { color: theme.colors.textSecondary, fontSize: Platform.select({ tv: 11, default: 14 }), fontWeight: '600' },
296
+ optionSelected: { color: theme.colors.text, fontWeight: '800' },
297
+ unavailable: { flex: 1, justifyContent: 'center', padding: theme.spacing.lg },
298
+ centered: { alignItems: 'center' },
299
+ });
@@ -0,0 +1,46 @@
1
+ import { useState } from '@adelin/react';
2
+ import { useDispatch, useSelector } from '@adelin/store';
3
+ import { useSearch } from '@adelin/content';
4
+ import { useTranslation } from '@adelin/i18n';
5
+ import { StyleSheet, Text, View, theme, useWindowDimensions, Screen } from '@adelin/ui';
6
+ import { loadLibrary } from '../../store';
7
+ import Shell from '../../components/Shell';
8
+ import Field from '../../components/Field';
9
+ import Feedback from '../../components/Feedback';
10
+ import CatalogGrid from '../../components/CatalogGrid';
11
+
12
+ /** Phone and browser search: results follow the field once the viewer pauses. TVs use Search.tv.tsx. */
13
+ export default function Search() {
14
+ const { t } = useTranslation();
15
+ const dispatch = useDispatch();
16
+ const entries = useSelector(state => state.library.entries);
17
+ const status = useSelector(state => state.library.status);
18
+ const { width, height } = useWindowDimensions();
19
+ const gutter = width >= 840 && height >= 480 ? theme.spacing.xl : theme.spacing.md;
20
+ const [query, setQuery] = useState('');
21
+ const pool = entries.filter(item => item.parentId == null || (item.kind === 'item' && item.mediaType === 'video'));
22
+ const { results, active } = useSearch(pool, query);
23
+ const shown = active ? results : entries.filter(item => item.parentId == null);
24
+ return (
25
+ <Screen>
26
+ <Shell active="Search">
27
+ <View style={styles.body}>
28
+ <View style={[styles.form, { paddingHorizontal: gutter }]}>
29
+ <Text style={styles.heading}>{t('search.title')}</Text>
30
+ <View style={styles.field}><Field label="" placeholder={t('search.placeholder')} icon="ph:magnifying-glass" value={query} onChangeText={setQuery} /></View>
31
+ <Text style={styles.summary}>{active ? t(results.length === 1 ? 'search.oneResult' : 'search.results', { count: results.length }) : t('search.allTitles')}</Text>
32
+ </View>
33
+ {status === 'idle' || status === 'loading' ? <Feedback title={t('common.loading')} message={t('search.loading')} loading /> : status === 'failed' ? <Feedback title={t('search.failed')} message={t('common.checkConnection')} onRetry={() => dispatch(loadLibrary())} /> : <CatalogGrid entries={shown} emptyTitle={t('search.noMatch', { query: query.trim() })} emptyMessage={t('search.noMatchMessage')} />}
34
+ </View>
35
+ </Shell>
36
+ </Screen>
37
+ );
38
+ }
39
+
40
+ const styles = StyleSheet.create({
41
+ body: { flex: 1 },
42
+ form: { paddingTop: theme.spacing.md },
43
+ field: { maxWidth: 640 },
44
+ heading: { color: theme.colors.text, fontSize: 30, lineHeight: 36, fontWeight: '800', letterSpacing: -0.8, marginBottom: 14 },
45
+ summary: { color: theme.colors.textMuted, fontSize: 13, lineHeight: 18, fontWeight: '600', marginBottom: 6 },
46
+ });
@@ -0,0 +1,55 @@
1
+ import { useState } from '@adelin/react';
2
+ import { useDispatch, useSelector } from '@adelin/store';
3
+ import { useSearch } from '@adelin/content';
4
+ import { useTranslation } from '@adelin/i18n';
5
+ import { FocusGroup, StyleSheet, Text, TVKeyboard, View, theme, Screen } from '@adelin/ui';
6
+ import { loadLibrary } from '../../store';
7
+ import Shell from '../../components/Shell';
8
+ import Feedback from '../../components/Feedback';
9
+ import CatalogGrid from '../../components/CatalogGrid';
10
+
11
+ /** TV search: the keyboard sits beside the results, which follow the query once the viewer pauses. */
12
+ export default function Search() {
13
+ const { t } = useTranslation();
14
+ const dispatch = useDispatch();
15
+ const entries = useSelector(state => state.library.entries);
16
+ const status = useSelector(state => state.library.status);
17
+ const [query, setQuery] = useState('');
18
+ const pool = entries.filter(item => item.parentId == null || (item.kind === 'item' && item.mediaType === 'video'));
19
+ const { results, active } = useSearch(pool, query);
20
+ const shown = active ? results : entries.filter(item => item.parentId == null);
21
+ return (
22
+ <Screen>
23
+ <Shell active="Search">
24
+ {status === 'idle' || status === 'loading' ? <Feedback title={t('common.loading')} message={t('search.loading')} loading /> : status === 'failed' ? <Feedback title={t('search.failed')} message={t('common.checkConnection')} onRetry={() => dispatch(loadLibrary())} /> : (
25
+ <FocusGroup direction="horizontal" remember>
26
+ <View style={styles.row}>
27
+ <View style={styles.keys}>
28
+ <Text style={styles.heading}>{t('search.title')}</Text>
29
+ <TVKeyboard variant="search" value={query} onChangeText={setQuery} placeholder={t('search.tvPlaceholder')} echoStyle={styles.echo} echoTextStyle={styles.echoText} keyStyle={styles.key} keyFocusedStyle={styles.keyFocused} keyLabelStyle={styles.keyLabel} specialKeyLabelStyle={styles.keyLabel} keyLabelFocusedStyle={styles.keyLabelFocused} />
30
+ </View>
31
+ <View style={styles.results}>
32
+ <Text style={styles.summary}>{active ? t(results.length === 1 ? 'search.oneResult' : 'search.results', { count: results.length }) : t('search.allTitles')}</Text>
33
+ <CatalogGrid entries={shown} columns={3} inset={320} emptyTitle={t('search.noMatch', { query: query.trim() })} emptyMessage={t('search.noMatchMessage')} />
34
+ </View>
35
+ </View>
36
+ </FocusGroup>
37
+ )}
38
+ </Shell>
39
+ </Screen>
40
+ );
41
+ }
42
+
43
+ const styles = StyleSheet.create({
44
+ row: { flex: 1, flexDirection: 'row' },
45
+ keys: { width: 272, marginLeft: theme.spacing.xl, paddingTop: 10 },
46
+ results: { flex: 1, paddingTop: 41 },
47
+ heading: { color: theme.colors.text, fontSize: 24, lineHeight: 29, fontWeight: '800', letterSpacing: -0.8, marginBottom: 12 },
48
+ echo: { backgroundColor: theme.colors.surface, borderRadius: 2 },
49
+ echoText: { color: theme.colors.text, fontSize: 13 },
50
+ key: { backgroundColor: theme.colors.surfaceLight, borderRadius: 2 },
51
+ keyFocused: { backgroundColor: theme.colors.primary },
52
+ keyLabel: { color: theme.colors.text },
53
+ keyLabelFocused: { color: theme.colors.background },
54
+ summary: { color: theme.colors.textMuted, fontSize: 11, lineHeight: 15, fontWeight: '600', paddingHorizontal: theme.spacing.xl, marginBottom: 2 },
55
+ });