diff --git a/lib/Screens/custom_home_feed_settings.dart b/lib/Screens/custom_home_feed_settings.dart index 7058881..3b9aad0 100644 --- a/lib/Screens/custom_home_feed_settings.dart +++ b/lib/Screens/custom_home_feed_settings.dart @@ -17,6 +17,7 @@ * Copyright (c) 2022-2024, BrightDV */ +import 'package:boxbox/helpers/constants.dart'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:hive_flutter/hive_flutter.dart'; @@ -34,7 +35,7 @@ class _CustomeHomeFeedSettingsScreenState extends State { @override Widget build(BuildContext context) { - const String officialFeed = "https://api.formula1.com"; + final String officialFeed = Constants().F1_API_URL; List savedFeedUrl = Hive.box('settings') .get('homeFeed', defaultValue: [officialFeed, "api"]) as List; List customFeeds = diff --git a/lib/Screens/racehub.dart b/lib/Screens/racehub.dart index e25e0f0..26f88bd 100644 --- a/lib/Screens/racehub.dart +++ b/lib/Screens/racehub.dart @@ -21,6 +21,7 @@ import 'package:boxbox/Screens/circuit.dart'; import 'package:boxbox/api/event_tracker.dart'; import 'package:boxbox/api/race_components.dart'; import 'package:boxbox/helpers/buttons.dart'; +import 'package:boxbox/helpers/constants.dart'; import 'package:boxbox/helpers/hover.dart'; import 'package:boxbox/helpers/loading_indicator_util.dart'; import 'package:boxbox/helpers/request_error.dart'; @@ -518,7 +519,7 @@ class PdfViewer extends StatelessWidget { @override Widget build(BuildContext context) { - const String defaultServer = "https://api.formula1.com"; + final String defaultServer = Constants().F1_API_URL; String server = Hive.box('settings') .get('server', defaultValue: defaultServer) as String; return Scaffold( diff --git a/lib/Screens/server_settings.dart b/lib/Screens/server_settings.dart index f0f72b0..8e75fd4 100644 --- a/lib/Screens/server_settings.dart +++ b/lib/Screens/server_settings.dart @@ -17,6 +17,7 @@ * Copyright (c) 2022-2024, BrightDV */ +import 'package:boxbox/helpers/constants.dart'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:hive_flutter/hive_flutter.dart'; @@ -32,7 +33,7 @@ class ServerSettingsScreen extends StatefulWidget { class _ServerSettingsScreenState extends State { @override Widget build(BuildContext context) { - const String officialServer = "https://api.formula1.com"; + final String officialServer = Constants().F1_API_URL; List customServers = Hive.box('settings').get('customServers', defaultValue: []) as List; String savedServer = Hive.box('settings') diff --git a/lib/api/brightcove.dart b/lib/api/brightcove.dart index ae1408a..952c629 100644 --- a/lib/api/brightcove.dart +++ b/lib/api/brightcove.dart @@ -19,6 +19,7 @@ import 'dart:convert'; +import 'package:boxbox/helpers/constants.dart'; import 'package:boxbox/helpers/download.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter_cache_manager/file.dart'; @@ -43,13 +44,15 @@ class BrightCove { String championship = Hive.box('settings') .get('championship', defaultValue: 'Formula 1') as String; late Map responseAsJson; + final String f1BrightCovePlayerId = Constants().F1_BRIGHTCOVE_PLAYER_ID; + final String fEBrightCovePlayerId = Constants().FE_BRIGHTCOVE_PLAYER_ID; if (kIsWeb) { late Uri uri; if (articleChampionship != null) { uri = Uri.parse( articleChampionship == 'Formula 1' - ? 'https://edge.api.brightcove.com/playback/v1/accounts/6057949432001/videos/$videoId' - : 'https://edge.api.brightcove.com/playback/v1/accounts/6275361344001/videos/$videoId', + ? 'https://edge.api.brightcove.com/playback/v1/accounts/$f1BrightCovePlayerId/videos/$videoId' + : 'https://edge.api.brightcove.com/playback/v1/accounts/$fEBrightCovePlayerId/videos/$videoId', ); } else if (player != null) { uri = Uri.parse( @@ -58,8 +61,8 @@ class BrightCove { } else { uri = Uri.parse( championship == 'Formula 1' - ? 'https://edge.api.brightcove.com/playback/v1/accounts/6057949432001/videos/$videoId' - : 'https://edge.api.brightcove.com/playback/v1/accounts/6275361344001/videos/$videoId', + ? 'https://edge.api.brightcove.com/playback/v1/accounts/$f1BrightCovePlayerId/videos/$videoId' + : 'https://edge.api.brightcove.com/playback/v1/accounts/$fEBrightCovePlayerId/videos/$videoId', ); } Response res = await get( @@ -67,11 +70,11 @@ class BrightCove { headers: { 'Accept': articleChampionship != null ? articleChampionship == 'Formula 1' - ? ' application/json;pk=BCpkADawqM1hQVBuXkSlsl6hUsBZQMmrLbIfOjJQ3_n8zmPOhlNSwZhQBF6d5xggxm0t052lQjYyhqZR3FW2eP03YGOER9ihJkUnIhRZGBxuLhnL-QiFpvcDWIh_LvwN5j8zkjTtGKarhsdV' - : ' application/json;pk=BCpkADawqM0CZElkVwfs62q-JTOc4CeZSNJRfxT923qzbMSqp6qn5VEgWV1iao1cEf2sXX9ce8achTuOfYKUvfchSis_rB5Sxz_ih70GYLYdf8bZgHi3Yq1VK_6v3mj29rxxcJjF3OX6Ri32' + ? Constants().F1_BRIGHTCOVE_PLAYER_KEY + : Constants().FE_BRIGHTCOVE_PLAYER_KEY : championship == 'Formula 1' - ? ' application/json;pk=BCpkADawqM1hQVBuXkSlsl6hUsBZQMmrLbIfOjJQ3_n8zmPOhlNSwZhQBF6d5xggxm0t052lQjYyhqZR3FW2eP03YGOER9ihJkUnIhRZGBxuLhnL-QiFpvcDWIh_LvwN5j8zkjTtGKarhsdV' - : ' application/json;pk=BCpkADawqM0CZElkVwfs62q-JTOc4CeZSNJRfxT923qzbMSqp6qn5VEgWV1iao1cEf2sXX9ce8achTuOfYKUvfchSis_rB5Sxz_ih70GYLYdf8bZgHi3Yq1VK_6v3mj29rxxcJjF3OX6Ri32', + ? Constants().F1_BRIGHTCOVE_PLAYER_KEY + : Constants().FE_BRIGHTCOVE_PLAYER_KEY }, ); responseAsJson = jsonDecode(res.body); @@ -80,26 +83,26 @@ class BrightCove { if (articleChampionship != null) { url = articleChampionship == 'Formula 1' - ? 'https://edge.api.brightcove.com/playback/v1/accounts/6057949432001/videos/$videoId' - : 'https://edge.api.brightcove.com/playback/v1/accounts/6275361344001/videos/$videoId'; + ? 'https://edge.api.brightcove.com/playback/v1/accounts/$f1BrightCovePlayerId/videos/$videoId' + : 'https://edge.api.brightcove.com/playback/v1/accounts/$fEBrightCovePlayerId/videos/$videoId'; } else if (player != null) { url = 'https://edge.api.brightcove.com/playback/v1/accounts/$player/videos/$videoId'; } else { url = championship == 'Formula 1' - ? 'https://edge.api.brightcove.com/playback/v1/accounts/6057949432001/videos/$videoId' - : 'https://edge.api.brightcove.com/playback/v1/accounts/6275361344001/videos/$videoId'; + ? 'https://edge.api.brightcove.com/playback/v1/accounts/$f1BrightCovePlayerId/videos/$videoId' + : 'https://edge.api.brightcove.com/playback/v1/accounts/$fEBrightCovePlayerId/videos/$videoId'; } final Future fileStream = videoCache.getSingleFile( url, headers: { 'Accept': articleChampionship != null ? articleChampionship == 'Formula 1' - ? ' application/json;pk=BCpkADawqM1hQVBuXkSlsl6hUsBZQMmrLbIfOjJQ3_n8zmPOhlNSwZhQBF6d5xggxm0t052lQjYyhqZR3FW2eP03YGOER9ihJkUnIhRZGBxuLhnL-QiFpvcDWIh_LvwN5j8zkjTtGKarhsdV' - : ' application/json;pk=BCpkADawqM0CZElkVwfs62q-JTOc4CeZSNJRfxT923qzbMSqp6qn5VEgWV1iao1cEf2sXX9ce8achTuOfYKUvfchSis_rB5Sxz_ih70GYLYdf8bZgHi3Yq1VK_6v3mj29rxxcJjF3OX6Ri32' + ? Constants().F1_BRIGHTCOVE_PLAYER_KEY + : Constants().FE_BRIGHTCOVE_PLAYER_KEY : championship == 'Formula 1' - ? ' application/json;pk=BCpkADawqM1hQVBuXkSlsl6hUsBZQMmrLbIfOjJQ3_n8zmPOhlNSwZhQBF6d5xggxm0t052lQjYyhqZR3FW2eP03YGOER9ihJkUnIhRZGBxuLhnL-QiFpvcDWIh_LvwN5j8zkjTtGKarhsdV' - : ' application/json;pk=BCpkADawqM0CZElkVwfs62q-JTOc4CeZSNJRfxT923qzbMSqp6qn5VEgWV1iao1cEf2sXX9ce8achTuOfYKUvfchSis_rB5Sxz_ih70GYLYdf8bZgHi3Yq1VK_6v3mj29rxxcJjF3OX6Ri32', + ? Constants().F1_BRIGHTCOVE_PLAYER_KEY + : Constants().FE_BRIGHTCOVE_PLAYER_KEY }, ); final response = await fileStream; diff --git a/lib/api/ergast.dart b/lib/api/ergast.dart index 4d225f2..3e30494 100644 --- a/lib/api/ergast.dart +++ b/lib/api/ergast.dart @@ -23,11 +23,13 @@ import 'dart:convert'; import 'package:boxbox/api/driver_components.dart'; import 'package:boxbox/api/race_components.dart'; import 'package:boxbox/api/team_components.dart'; +import 'package:boxbox/helpers/constants.dart'; import 'package:boxbox/helpers/convert_ergast_and_formula_one.dart'; import 'package:hive_flutter/hive_flutter.dart'; import 'package:http/http.dart' as http; class _ErgastApiCalls { + final String defaultEndpoint = Constants().ERGAST_API_URL; List formatRaceStandings(Map raceStandings) { List formatedRaceStandings = []; List jsonResponse = @@ -94,7 +96,7 @@ class _ErgastApiCalls { return formatRaceStandings(results); } else { var url = Uri.parse( - 'https://ergast.com/api/f1/${DateTime.now().year}/$round/results.json', + '$defaultEndpoint/f1/${DateTime.now().year}/$round/results.json', ); var response = await http.get(url); Map responseAsJson = jsonDecode(response.body); @@ -112,7 +114,7 @@ class _ErgastApiCalls { FutureOr> getSprintStandings(String round) async { var url = Uri.parse( - 'https://ergast.com/api/f1/${DateTime.now().year}/$round/sprint.json'); + '$defaultEndpoint/f1/${DateTime.now().year}/$round/sprint.json'); var response = await http.get(url); Map responseAsJson = jsonDecode(response.body); List formatedRaceStandings = []; @@ -173,7 +175,7 @@ class _ErgastApiCalls { String round) async { List driversResults = []; var url = Uri.parse( - 'https://ergast.com/api/f1/${DateTime.now().year}/$round/qualifying.json', + '$defaultEndpoint/f1/${DateTime.now().year}/$round/qualifying.json', ); var response = await http.get(url); Map responseAsJson = jsonDecode(response.body); @@ -247,7 +249,7 @@ class _ErgastApiCalls { return formatLastStandings(driversStandings); } else { var url = Uri.parse( - 'https://ergast.com/api/f1/current/driverStandings.json', + '$defaultEndpoint/f1/current/driverStandings.json', ); var response = await http.get(url); Map responseAsJson = jsonDecode(response.body); @@ -261,7 +263,7 @@ class _ErgastApiCalls { Future> getDriverList(String year) async { var url = Uri.parse( - 'https://ergast.com/api/f1/$year/drivers.json', + '$defaultEndpoint/f1/$year/drivers.json', ); var response = await http.get(url); Map responseAsJson = jsonDecode(response.body); @@ -377,7 +379,7 @@ class _ErgastApiCalls { Future> getDriverResults(String driverId) async { var url = Uri.parse( - 'https://ergast.com/api/f1/${DateTime.now().year}/drivers/$driverId/results.json', + '$defaultEndpoint/f1/${DateTime.now().year}/drivers/$driverId/results.json', ); var response = await http.get(url); Map responseAsJson = jsonDecode(response.body); @@ -416,7 +418,7 @@ class _ErgastApiCalls { Future>> getTeamResults(String team) async { var url = Uri.parse( - 'https://ergast.com/api/f1/${DateTime.now().year}/constructors/$team/results.json', + '$defaultEndpoint/f1/${DateTime.now().year}/constructors/$team/results.json', ); var response = await http.get(url); Map responseAsJson = jsonDecode(response.body); @@ -499,8 +501,9 @@ class _ErgastApiCalls { scheduleLastSavedFormat == 'ergast') { return formatLastSchedule(schedule, toCome); } else { - var url = - Uri.parse('https://ergast.com/api/f1/${DateTime.now().year}.json'); + var url = Uri.parse( + '$defaultEndpoint/f1/${DateTime.now().year}.json', + ); var response = await http.get(url); Map responseAsJson = jsonDecode(response.body); List races = formatLastSchedule(responseAsJson, toCome); @@ -513,7 +516,7 @@ class _ErgastApiCalls { Future getRaceDetails(String round) async { var url = Uri.parse( - 'https://ergast.com/api/f1/${DateTime.now().year}/$round.json', + '$defaultEndpoint/f1/${DateTime.now().year}/$round.json', ); var response = await http.get(url); Map responseAsJson = @@ -596,7 +599,7 @@ class _ErgastApiCalls { return formatLastTeamsStandings(teamsStandings); } else { var url = Uri.parse( - 'https://ergast.com/api/f1/current/constructorStandings.json', + '$defaultEndpoint/f1/current/constructorStandings.json', ); var response = await http.get(url); Map responseAsJson = jsonDecode(response.body); diff --git a/lib/api/event_tracker.dart b/lib/api/event_tracker.dart index 4f5901f..2c1fbee 100644 --- a/lib/api/event_tracker.dart +++ b/lib/api/event_tracker.dart @@ -22,6 +22,7 @@ import 'dart:convert'; import 'package:boxbox/api/formulae.dart'; import 'package:boxbox/api/race_components.dart'; +import 'package:boxbox/helpers/constants.dart'; import 'package:hive_flutter/hive_flutter.dart'; import 'package:http/http.dart'; import 'package:intl/intl.dart'; @@ -71,9 +72,9 @@ class Session { } class EventTracker { - final String defaultEndpoint = "https://api.formula1.com"; - final String apikey = "qPgPPRJyGCIPxFT3el4MF7thXHyJCzAP"; - final String feEndpoint = 'https://api.formula-e.pulselive.com'; + final String defaultEndpoint = Constants().F1_API_URL; + final String apikey = Constants().F1_API_KEY; + final String feEndpoint = Constants().FE_API_URL; bool isEventRunning(DateTime meetingStartDate, DateTime meetingEndDate) { DateTime now = DateTime.now(); diff --git a/lib/api/formula1.dart b/lib/api/formula1.dart index fc2d5c0..8fa7f98 100644 --- a/lib/api/formula1.dart +++ b/lib/api/formula1.dart @@ -24,14 +24,15 @@ import 'dart:ui'; import 'package:boxbox/api/driver_components.dart'; import 'package:boxbox/api/race_components.dart'; import 'package:boxbox/api/team_components.dart'; +import 'package:boxbox/helpers/constants.dart'; import 'package:boxbox/helpers/convert_ergast_and_formula_one.dart'; import 'package:hive_flutter/hive_flutter.dart'; import 'package:http/http.dart' as http; import 'package:intl/intl.dart'; class Formula1 { - final String defaultEndpoint = "https://api.formula1.com"; - final String apikey = "qPgPPRJyGCIPxFT3el4MF7thXHyJCzAP"; + final String defaultEndpoint = Constants().F1_API_URL; + final String apikey = Constants().F1_API_KEY; List formatResponse(Map responseAsJson) { bool useDataSaverMode = Hive.box('settings') diff --git a/lib/api/formulae.dart b/lib/api/formulae.dart index 8659d82..6930059 100644 --- a/lib/api/formulae.dart +++ b/lib/api/formulae.dart @@ -25,13 +25,14 @@ import 'package:boxbox/api/formula1.dart'; import 'package:boxbox/api/race_components.dart'; import 'package:boxbox/api/team_components.dart'; import 'package:boxbox/api/videos.dart'; +import 'package:boxbox/helpers/constants.dart'; import 'package:flutter/material.dart'; import 'package:hive_flutter/hive_flutter.dart'; import 'package:http/http.dart' as http; class FormulaE { - final String defaultEndpoint = "https://api.formula-e.pulselive.com"; - final String defaultF1Endpoint = "https://api.formula1.com"; + final String defaultEndpoint = Constants().FE_API_URL; + final String defaultF1Endpoint = Constants().F1_API_URL; late final String championshipId = Hive.box('settings').get( 'feChampionshipId', defaultValue: '84467676-4d5d-4c97-ae07-0b7520bb95ea', diff --git a/lib/api/videos.dart b/lib/api/videos.dart index 44e3af6..58c4b6a 100644 --- a/lib/api/videos.dart +++ b/lib/api/videos.dart @@ -20,12 +20,13 @@ import 'dart:async'; import 'dart:convert'; +import 'package:boxbox/helpers/constants.dart'; import 'package:hive_flutter/hive_flutter.dart'; import 'package:http/http.dart' as http; class F1VideosFetcher { - final String defaultEndpoint = "https://api.formula1.com"; - final String apikey = "qPgPPRJyGCIPxFT3el4MF7thXHyJCzAP"; + final String defaultEndpoint = Constants().F1_API_URL; + final String apikey = Constants().F1_API_KEY; List