Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bad bounds #194

Merged
merged 4 commits into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 27 additions & 23 deletions packages/app/lib/event/fragments/details/event_details_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,29 +53,7 @@ class _EventDetailsMapState extends State<EventDetailsMap> {
.of(context)
.size
.width * 0.1,
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
height: 100,
child: Lottie.asset(
fit: BoxFit.cover,
'assets/lottie/lottie_journey.json',
repeat: false,
),
),
const SizedBox(height: 16),
Text(
'Aucun trajet lié à cet évènement ou aucun utilisateur ne partage sa position.',
style: Theme
.of(context)
.textTheme
.bodyMedium,
textAlign: TextAlign.center,
),
],
),
child: _buildPlaceholder(),
),
);
}
Expand All @@ -92,6 +70,32 @@ class _EventDetailsMapState extends State<EventDetailsMap> {
);
}

Widget _buildPlaceholder() {
return Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
height: 100,
child: Lottie.asset(
fit: BoxFit.cover,
'assets/lottie/lottie_journey.json',
repeat: false,
),
),
const SizedBox(height: 16),
Text(
'Aucun trajet lié à cet évènement ou aucun utilisateur ne partage sa position.',
style: Theme
.of(context)
.textTheme
.bodyMedium,
textAlign: TextAlign.center,
),
],
);
}

Future<void> _refreshEventDetails(BuildContext context) {
context.read<EventDetailsBloc>().add(
LoadEventDetails(),
Expand Down
1 change: 1 addition & 0 deletions packages/app/lib/event/screens/event_details_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ class _EventDetailsScreenState extends State<EventDetailsScreen>
profileRepository: RepositoryProvider.of<ProfileRepository>(
context,
),
canSeeUserPositions: eventDetails.isParticipating,
),
child: EventDetailsMap(
eventId: eventDetails.event.id,
Expand Down
10 changes: 7 additions & 3 deletions packages/app/lib/event/widgets/map/journey_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ class _JourneyMapState extends State<JourneyMap> {

final bbox = geoJsonRaw == null
? GeoJSON.calculateBbox(userCoordinates)
: GeoJSON.fromJsonString(geoJsonRaw).dynamicBBox();
: GeoJSON.fromJsonString(geoJsonRaw).dynamicBBox(
extraValues: userCoordinates,
);

final bounds = CoordinateBounds(
southwest: Point(
Expand Down Expand Up @@ -336,7 +338,8 @@ class _JourneyMapState extends State<JourneyMap> {
? profilePicture.image
: placeholderProfilePicture) as Uint8List,
iconAnchor: IconAnchor.BOTTOM,
textField: '${user.user.username}\n${(missingPosition.speed * 3.6).round()} km/h',
textField:
'${user.user.username}\n${(missingPosition.speed * 3.6).round()} km/h',
textAnchor: TextAnchor.TOP,
textSize: 12,
textHaloWidth: 2,
Expand Down Expand Up @@ -373,7 +376,8 @@ class _JourneyMapState extends State<JourneyMap> {
? profilePicture.image
: placeholderProfilePicture) as Uint8List;

point.textField = '${user.user.username}\n${(positionToUpdate.speed * 3.6).round()} km/h';
point.textField =
'${user.user.username}\n${(positionToUpdate.speed * 3.6).round()} km/h';
}

await pointManager.update(point);
Expand Down
162 changes: 88 additions & 74 deletions packages/app/lib/journey/screen/import_gpx_tool_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:hollybike/shared/utils/safe_set_state.dart';

import 'package:http/http.dart' as http;
import 'package:path/path.dart' as path;

Expand Down Expand Up @@ -54,94 +53,103 @@ class _ImportGpxToolScreenState extends State<ImportGpxToolScreen> {
},
child: Scaffold(
body: SafeArea(
child: InAppWebView(
initialUrlRequest: URLRequest(
url: Uri.parse(widget.url),
),
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
useOnDownloadStart: true,
useShouldInterceptFetchRequest: true,
child: Builder(builder: (context) {
return InAppWebView(
initialUrlRequest: URLRequest(
url: Uri.parse(widget.url),
),
),
onWebViewCreated: (controller) {
_controller = controller;
},
onLoadStart: (controller, url) {},
onLoadStop: (controller, url) {},
shouldInterceptFetchRequest: (controller, request) async {
final url = request.url.toString();

final isKurvigerFile =
url.startsWith("https://api.kurviger.de/route");
final isOpenrunnerFile =
url.startsWith("https://api.openrunner.com/api/v2/routes/") &&
url.endsWith("/export/gpx-track");

if (isKurvigerFile || isOpenrunnerFile) {
final response = await http.get(
Uri.parse(url),
headers: {
'User-Agent': request.headers?['User-Agent'] ?? '',
'Accept': request.headers?['Accept'] ?? '',
},
);

if (response.body.contains('<gpx') == false) {
return Future.value(request);
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
useOnDownloadStart: true,
useShouldInterceptFetchRequest: true,
),
),
onWebViewCreated: (controller) {
_controller = controller;
},
onLoadStart: (controller, url) {},
onLoadStop: (controller, url) {},
shouldInterceptFetchRequest: (controller, request) async {
final url = request.url.toString();

final isKurvigerFile =
url.startsWith("https://api.kurviger.de/route");
final isOpenrunnerFile = url.startsWith(
"https://api.openrunner.com/api/v2/routes/") &&
url.endsWith("/export/gpx-track");

if (isKurvigerFile || isOpenrunnerFile) {
final response = await http.get(
Uri.parse(url),
headers: {
'User-Agent': request.headers?['User-Agent'] ?? '',
'Accept': request.headers?['Accept'] ?? '',
},
);

if (response.body.contains('<gpx') == false) {
return Future.value(request);
}

if (context.mounted) {
_onGpxDownloaded(
context,
writeTempFile(response.bodyBytes),
);
}

return Future.value(null);
}

widget.onGpxDownloaded(
writeTempFile(response.bodyBytes),
);
return Future.value(request);
},
onDownloadStartRequest: (controller, data) async {
if (widget.url.contains('kurviger')) {
return;
}

return Future.value(null);
}
final requestUrl = data.url.toString();

return Future.value(request);
},
onDownloadStartRequest: (controller, data) async {
if (widget.url.contains('kurviger')) {
return;
}
if (requestUrl.startsWith('data:text')) {
final cleanUrl = requestUrl.replaceAll(
RegExp(r'data:text.*?,'),
'',
);

final requestUrl = data.url.toString();
final decoded = Uri.decodeFull(cleanUrl);

if (requestUrl.startsWith('data:text')) {
final cleanUrl = requestUrl.replaceAll(
RegExp(r'data:text.*?,'),
'',
);
if (decoded.contains('<gpx') == false) {
return;
}

final decoded = Uri.decodeFull(cleanUrl);
_onGpxDownloaded(
context,
writeTempFile(decoded.codeUnits),
);

if (decoded.contains('<gpx') == false) {
return;
}

widget.onGpxDownloaded(
writeTempFile(decoded.codeUnits),
);

return;
}

final uri = Uri.parse(requestUrl.replaceAll('blob:', ''));
final uri = Uri.parse(requestUrl.replaceAll('blob:', ''));

final response = await http.get(uri, headers: {
'User-Agent': data.userAgent ?? '',
'Accept': data.mimeType ?? '',
});
final response = await http.get(uri, headers: {
'User-Agent': data.userAgent ?? '',
'Accept': data.mimeType ?? '',
});

if (response.body.contains('<gpx') == false) {
return;
}
if (response.body.contains('<gpx') == false) {
return;
}

widget.onGpxDownloaded(
writeTempFile(response.bodyBytes),
);
},
),
if (context.mounted) {
_onGpxDownloaded(
context,
writeTempFile(response.bodyBytes),
);
}
},
);
}),
),
),
);
Expand All @@ -163,4 +171,10 @@ class _ImportGpxToolScreenState extends State<ImportGpxToolScreen> {

return file;
}

void _onGpxDownloaded(BuildContext context, File file) async {
await context.router.maybePop();

widget.onGpxDownloaded(file);
}
}
4 changes: 3 additions & 1 deletion packages/app/lib/journey/service/journey_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ class JourneyApi {
}

Future<Journey> getPositions(int journeyId) async {
final response = await client.dio.get('/journeys/$journeyId/positions');
final response = await client.dio.get(
'/journeys/$journeyId/positions'
);

return Journey.fromJson(response.data);
}
Expand Down
9 changes: 5 additions & 4 deletions packages/app/lib/journey/widgets/journey_location.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ class JourneyLocation extends StatelessWidget {
Widget build(BuildContext context) {
final locations = <Widget>[];

final start = JourneyPosition(pos: journey.start, isLarge: sizeFactor > 1);
if (start is! SizedBox) {
if (journey.start != null) {
final start = JourneyPosition(pos: journey.start!, isLarge: sizeFactor > 1);

locations.add(Row(
children: [
Icon(
Expand All @@ -35,8 +36,8 @@ class JourneyLocation extends StatelessWidget {
locations.add(SizedBox(height: 8 * sizeFactor));
}

final end = JourneyPosition(pos: journey.end, isLarge: sizeFactor > 1);
if (start is! SizedBox) {
if (journey.end != null) {
final end = JourneyPosition(pos: journey.end!, isLarge: sizeFactor > 1);
locations.add(Row(
children: [
Icon(
Expand Down
12 changes: 4 additions & 8 deletions packages/app/lib/journey/widgets/journey_position.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import '../../shared/types/position.dart';

class JourneyPosition extends StatelessWidget {
final bool isLarge;
final Position? pos;
final Position pos;

const JourneyPosition({
super.key,
Expand All @@ -14,10 +14,6 @@ class JourneyPosition extends StatelessWidget {

@override
Widget build(BuildContext context) {
if (pos == null) {
return const SizedBox();
}

final textStyle = getTextStyle(context);

final texts = <TextSpan>[];
Expand All @@ -35,9 +31,9 @@ class JourneyPosition extends StatelessWidget {
texts.add(span);
}

final countyName = pos?.countyName;
final cityName = pos?.cityName;
final countryName = pos?.countryName;
final countyName = pos.countyName;
final cityName = pos.cityName;
final countryName = pos.countryName;

if (cityName != null) {
addSpan(TextSpan(
Expand Down
6 changes: 1 addition & 5 deletions packages/app/lib/journey/widgets/journey_tools_modal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,7 @@ class JourneyToolsModal extends StatelessWidget {
context.router.push(
ImportGpxToolRoute(
url: tool.url,
onGpxDownloaded: (file) {
Navigator.of(context).pop();

onGpxDownloaded(file);
},
onGpxDownloaded: onGpxDownloaded,
onClose: () => Navigator.of(context).pop(),
),
);
Expand Down
Loading