Skip to content

Commit

Permalink
feat: remove youtube player, remove piped setting
Browse files Browse the repository at this point in the history
add a button to watch on youtube instead
  • Loading branch information
BrightDV committed Feb 26, 2025
1 parent fc2b63b commit 30e27b7
Show file tree
Hide file tree
Showing 25 changed files with 176 additions and 169 deletions.
2 changes: 1 addition & 1 deletion lib/Screens/free_practice_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class FreePracticeResultsList extends StatelessWidget {
FontAwesomeIcons.youtube,
),
title: Text(
AppLocalizations.of(context)!.watchOnYoutube,
AppLocalizations.of(context)!.watchHighlightsOnYoutube,
textAlign: TextAlign.center,
),
onTap: () async {
Expand Down
8 changes: 5 additions & 3 deletions lib/Screens/race_details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,8 @@ class _RaceResultsProviderState extends State<RaceResultsProvider> {
FontAwesomeIcons.youtube,
),
title: Text(
AppLocalizations.of(context)!.watchOnYoutube,
AppLocalizations.of(context)!
.watchHighlightsOnYoutube,
textAlign: TextAlign.center,
),
onTap: () async {
Expand Down Expand Up @@ -826,7 +827,8 @@ class _RaceResultsProviderState extends State<RaceResultsProvider> {
FontAwesomeIcons.youtube,
),
title: Text(
AppLocalizations.of(context)!.watchOnYoutube,
AppLocalizations.of(context)!
.watchHighlightsOnYoutube,
textAlign: TextAlign.center,
),
onTap: () async {
Expand Down Expand Up @@ -983,7 +985,7 @@ class _SprintResultsProviderState extends State<SprintResultsProvider> {
),
title: Text(
AppLocalizations.of(context)!
.watchOnYoutube,
.watchHighlightsOnYoutube,
textAlign: TextAlign.center,
),
onTap: () async {
Expand Down
46 changes: 0 additions & 46 deletions lib/Screens/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,6 @@ class _PlayerCardState extends State<PlayerCard> {
Widget build(BuildContext context) {
int playerQuality =
Hive.box('settings').get('playerQuality', defaultValue: 360) as int;
String pipedApiUrl = Hive.box('settings')
.get('pipedApiUrl', defaultValue: 'pipedapi.kavin.rocks') as String;
bool swipeUpToEnterFullScreen = Hive.box('settings')
.get('swipeUpToEnterFullScreen', defaultValue: false) as bool;
return Card(
Expand Down Expand Up @@ -498,50 +496,6 @@ class _PlayerCardState extends State<PlayerCard> {
).toList(),
),
),
ListTile(
title: Text(
'Piped Proxy URL',
),
subtitle: Text(
AppLocalizations.of(context)!.pipedApiUrlSub,
style: TextStyle(
fontSize: 12,
),
),
onTap: () {},
trailing: DropdownButton(
value: pipedApiUrl,
onChanged: (String? newValue) {
if (newValue != null) {
setState(
() {
pipedApiUrl = newValue;
Hive.box('settings').put('pipedApiUrl', newValue);
},
);
}
},
items: <String>[
'pipedapi.kavin.rocks',
'pipedapi.syncpundit.io',
'pipedapi.adminforge.de',
'watchapi.whatever.social',
'api.piped.privacydev.net',
].map<DropdownMenuItem<String>>(
(String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(
value,
style: TextStyle(
fontSize: 12,
),
),
);
},
).toList(),
),
),
if (!kIsWeb)
SwitchListTile(
title: Text(
Expand Down
4 changes: 2 additions & 2 deletions lib/Screens/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class TestScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const ArticleScreen(
'2H7KjYuyfv7tSQ24RH47wM',
'circuit',
'1AbyIc0y5jDaRudNv2Mc5s',
'youtube video',
true,
);
}
Expand Down
5 changes: 5 additions & 0 deletions lib/api/article_parts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class ArticleParts extends StatelessWidget {
youtubeId: article.articleHero['fields']
['youTubeVideoId'] ??
'',
youtubeThumbnail:
article.articleHero['fields']['image']['url'] ?? '',
player: article.articleHero['fields']['player'],
articleChampionship: articleChampionship,
),
Expand Down Expand Up @@ -266,6 +268,9 @@ class WidgetsList extends StatelessWidget {
? VideoRenderer(
'',
youtubeId: element['fields']['youTubeVideoId'],
youtubeThumbnail: article.articleHero['fields']
['image']['url'] ??
'',
)
: element['contentType'] == 'atomImage'
? ImageRenderer(
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/driver_result_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ class QualificationDriversResultsList extends StatelessWidget {
FontAwesomeIcons.youtube,
),
title: Text(
AppLocalizations.of(context)!.watchOnYoutube,
AppLocalizations.of(context)!.watchHighlightsOnYoutube,
textAlign: TextAlign.center,
),
onTap: () async {
Expand Down
168 changes: 106 additions & 62 deletions lib/helpers/news.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:go_router/go_router.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:http/http.dart';
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
import 'package:loading_indicator/loading_indicator.dart';
import 'package:river_player/river_player.dart';
Expand Down Expand Up @@ -1839,6 +1838,7 @@ class VideoRenderer extends StatelessWidget {
final String videoId;
final bool? autoplay;
final String? youtubeId;
final String? youtubeThumbnail;
final String? heroTag;
final String? caption;
final Function? update;
Expand All @@ -1850,14 +1850,15 @@ class VideoRenderer extends StatelessWidget {
Key? key,
this.autoplay,
this.youtubeId,
this.youtubeThumbnail,
this.heroTag,
this.caption,
this.update,
this.player,
this.articleChampionship,
}) : super(key: key);

Future<Map<String, dynamic>> getYouTubeVideoLinks(String videoId) async {
/* Future<Map<String, dynamic>> getYouTubeVideoLinks(String videoId) async {
String playerQuality =
"${Hive.box('settings').get('playerQuality', defaultValue: 360) as int}p";
String pipedApiUrl = Hive.box('settings')
Expand Down Expand Up @@ -1898,6 +1899,7 @@ class VideoRenderer extends StatelessWidget {
urls['videos'].insert(0, defaultUrl);
return urls;
}
*/

@override
Widget build(BuildContext context) {
Expand All @@ -1907,76 +1909,118 @@ class VideoRenderer extends StatelessWidget {
: width > 1000
? 500
: 400;
return FutureBuilder<Map<String, dynamic>>(
future: (youtubeId ?? '') != ''
? getYouTubeVideoLinks(youtubeId!)
: BrightCove().getVideoLinks(
return (youtubeId ?? '') != ''
? Stack(
children: [
CachedNetworkImage(
imageUrl: youtubeThumbnail!,
placeholder: (context, url) => SizedBox(
height: MediaQuery.of(context).size.width / (16 / 9),
child: const LoadingIndicatorUtil(
replaceImage: true,
fullBorderRadius: false,
borderRadius: false,
),
),
errorWidget: (context, url, error) => ImageRequestErrorUtil(
height: MediaQuery.of(context).size.width / (16 / 9),
),
fadeOutDuration: const Duration(milliseconds: 100),
fadeInDuration: const Duration(seconds: 1),
colorBlendMode: BlendMode.darken,
color: Colors.black.withOpacity(0.5),
),
Center(
child: ElevatedButton.icon(
onPressed: () async => await launchUrl(
Uri.parse('https://youtube.com/watch?v=$youtubeId!'),
mode: LaunchMode.externalApplication,
),
label: Padding(
padding: EdgeInsets.only(top: 15, right: 10, bottom: 15),
child: Text(AppLocalizations.of(context)!.watchOnYouTube),
),
icon: Padding(
padding: EdgeInsets.only(top: 15, left: 10, bottom: 15),
child: Icon(
Icons.play_arrow_outlined,
size: 28,
),
),
),
)
],
)
: FutureBuilder<Map<String, dynamic>>(
future: BrightCove().getVideoLinks(
videoId,
player: player,
articleChampionship: articleChampionship,
),
builder: (context, snapshot) => snapshot.hasError
? RequestErrorWidget(
snapshot.error.toString(),
)
: snapshot.hasData
? Column(
children: [
kIsWeb
? SizedBox(
height: width / (16 / 9),
child: InAppWebView(
initialUrlRequest: URLRequest(
url: WebUri(
snapshot.data!['videos'][0],
builder: (context, snapshot) => snapshot.hasError
? RequestErrorWidget(
snapshot.error.toString(),
)
: snapshot.hasData
? Column(
children: [
kIsWeb
? SizedBox(
height: width / (16 / 9),
child: InAppWebView(
initialUrlRequest: URLRequest(
url: WebUri(
snapshot.data!['videos'][0],
),
),
initialSettings: InAppWebViewSettings(
preferredContentMode:
UserPreferredContentMode.DESKTOP,
transparentBackground: true,
iframeAllowFullscreen: true,
mediaPlaybackRequiresUserGesture:
!(autoplay ?? false),
),
),
)
: BetterPlayerVideoPlayer(
snapshot.data!,
videoId,
autoplay == null ? false : autoplay!,
heroTag ?? '',
Theme.of(context).colorScheme.surface,
(youtubeId ?? '') != '',
update: update,
),
if (caption != null)
Padding(
padding: const EdgeInsets.only(
top: 7,
left: 10,
right: 10,
),
initialSettings: InAppWebViewSettings(
preferredContentMode:
UserPreferredContentMode.DESKTOP,
transparentBackground: true,
iframeAllowFullscreen: true,
mediaPlaybackRequiresUserGesture:
!(autoplay ?? false),
child: Text(
caption!,
textAlign: TextAlign.center,
style: TextStyle(
color: Theme.of(context)
.textTheme
.labelSmall!
.color,
),
),
),
)
: BetterPlayerVideoPlayer(
snapshot.data!,
videoId,
autoplay == null ? false : autoplay!,
heroTag ?? '',
Theme.of(context).colorScheme.surface,
(youtubeId ?? '') != '',
update: update,
),
if (caption != null)
Padding(
padding: const EdgeInsets.only(
top: 7,
left: 10,
right: 10,
),
child: Text(
caption!,
textAlign: TextAlign.center,
style: TextStyle(
color:
Theme.of(context).textTheme.labelSmall!.color,
),
],
)
: SizedBox(
height: MediaQuery.of(context).size.width / (16 / 9),
child: const LoadingIndicatorUtil(
replaceImage: true,
fullBorderRadius: false,
borderRadius: false,
),
),
],
)
: SizedBox(
height: MediaQuery.of(context).size.width / (16 / 9),
child: const LoadingIndicatorUtil(
replaceImage: true,
fullBorderRadius: false,
borderRadius: false,
),
),
);
);
}
}

Expand Down
6 changes: 3 additions & 3 deletions lib/l10n/app_ar.arb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"@filter": {},
"driverAbbreviation": "سائق",
"@driverAbbreviation": {},
"watchOnYoutube": "شاهد أبرز الأحداث على اليوتيوب",
"@watchOnYoutube": {},
"watchHighlightsOnYoutube": "شاهد أبرز الأحداث على اليوتيوب",
"@watchHighlightsOnYoutube": {},
"victories": "انتصارات",
"@victories": {},
"from": "من ",
Expand Down Expand Up @@ -315,4 +315,4 @@
"@fontDescription": {},
"monthAbbreviationFebruary": "فبراير",
"@monthAbbreviationFebruary": {}
}
}
6 changes: 3 additions & 3 deletions lib/l10n/app_bn.arb
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@
"@viewHighlights": {},
"viewMore": "আরো দেখুন",
"@viewMore": {},
"watchOnYoutube": "YouTube এ হাইলাইট দেখুন",
"@watchOnYoutube": {},
"watchHighlightsOnYoutube": "YouTube এ হাইলাইট দেখুন",
"@watchHighlightsOnYoutube": {},
"yes": "হ্যাঁ",
"@yes": {},
"errorOccurredDetails": "অ্যাপটি একটি অজানা ত্রুটির সম্মুখীন হয়েছে ।\nঅনুগ্রহ করে একটু পরে আবার চেষ্টা করুন।",
Expand Down Expand Up @@ -385,4 +385,4 @@
"@refreshChampionshipDataSub": {},
"teamBase": "বেস",
"@teamBase": {}
}
}
Loading

0 comments on commit 30e27b7

Please sign in to comment.