cleaned up sloppy ai code
This commit is contained in:
@@ -40,36 +40,21 @@ class _MapsBookmarksState extends State<MapsBookmarks>
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
// Check for shared content when app resumes
|
||||
if (state == AppLifecycleState.resumed) {
|
||||
_checkForSharedContent();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _checkForSharedContent() async {
|
||||
final sharedText = await _shareIntentService.getSharedText();
|
||||
final sharedText = await _shareIntentService.getSharedMapsLink();
|
||||
|
||||
if (sharedText != null && mounted) {
|
||||
// Validate it's a Google Maps link
|
||||
if (_shareIntentService.isGoogleMapsLink(sharedText)) {
|
||||
final metadata = _shareIntentService.extractMetadata(sharedText);
|
||||
_handleSharedMapsLink(metadata);
|
||||
}
|
||||
if (sharedText.isNotEmpty && mounted) {
|
||||
_handleSharedMapsLink(sharedText);
|
||||
}
|
||||
}
|
||||
|
||||
void _handleSharedMapsLink(MapsLinkMetadata metadata) {
|
||||
// Navigate to the appropriate page or show a dialog
|
||||
// You can customize this based on your app's flow
|
||||
|
||||
// Option 1: Navigate to collections page with data
|
||||
_navigatorKey.currentState?.pushNamed(
|
||||
CollectionsPage.routeName,
|
||||
arguments: metadata,
|
||||
);
|
||||
|
||||
// Option 2: Show a dialog to select collection and save
|
||||
// This would be implemented based on your UI requirements
|
||||
void _handleSharedMapsLink(String sharedText) {
|
||||
//TODO: implement
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
26
lib/model/maps_link_metadata.dart
Normal file
26
lib/model/maps_link_metadata.dart
Normal file
@@ -0,0 +1,26 @@
|
||||
class MapsLinkMetadata {
|
||||
final String url;
|
||||
final String placeName;
|
||||
final String latitude;
|
||||
final String longitude;
|
||||
final String address;
|
||||
final String description;
|
||||
|
||||
const MapsLinkMetadata({
|
||||
required this.url,
|
||||
this.placeName = '',
|
||||
this.latitude = '',
|
||||
this.longitude = '',
|
||||
this.address = '',
|
||||
this.description = '',
|
||||
});
|
||||
|
||||
String get coordinates {
|
||||
if (hasCoordinates) {
|
||||
return '$latitude, $longitude';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
bool get hasCoordinates => latitude.isNotEmpty && longitude.isNotEmpty;
|
||||
}
|
||||
@@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import '../model/collection.dart';
|
||||
import '../service/bookmarks_provider.dart';
|
||||
import '../service/share_intent_service.dart';
|
||||
import '../service/storage.dart';
|
||||
import '../widgets/create_bookmark_collection_dialog.dart';
|
||||
import 'bookmarks_page.dart';
|
||||
@@ -59,14 +58,5 @@ class _CollectionsPageState extends State<CollectionsPage> {
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
// Check if we received shared data
|
||||
final metadata =
|
||||
ModalRoute.of(context)?.settings.arguments as MapsLinkMetadata?;
|
||||
if (metadata != null) {
|
||||
// Handle the shared link
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// _showSaveBookmarkDialog(metadata);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class ShareIntentService {
|
||||
static const _platform = MethodChannel('app.channel.shared.data');
|
||||
static ShareIntentService? _instance;
|
||||
|
||||
// Singleton pattern
|
||||
factory ShareIntentService() {
|
||||
_instance ??= ShareIntentService._internal();
|
||||
return _instance!;
|
||||
@@ -12,105 +8,18 @@ class ShareIntentService {
|
||||
|
||||
ShareIntentService._internal();
|
||||
|
||||
/// Retrieves shared text from the platform channel
|
||||
/// Returns null if no shared text is available
|
||||
Future<String?> getSharedText() async {
|
||||
try {
|
||||
static ShareIntentService? _instance;
|
||||
static const _platform = MethodChannel('app.channel.shared.data');
|
||||
|
||||
Future<String> getSharedMapsLink() async {
|
||||
final String? sharedText = await _platform.invokeMethod('getSharedText');
|
||||
return sharedText;
|
||||
} on PlatformException catch (e) {
|
||||
// Log error in production app
|
||||
print('Failed to get shared text: ${e.message}');
|
||||
return null;
|
||||
}
|
||||
if (sharedText != null && _isGoogleMapsLink(sharedText)) return sharedText;
|
||||
return '';
|
||||
}
|
||||
|
||||
/// Checks if the text is a Google Maps link
|
||||
bool isGoogleMapsLink(String text) {
|
||||
bool _isGoogleMapsLink(String text) {
|
||||
return text.contains('maps.google.com') ||
|
||||
text.contains('maps.app.goo.gl') ||
|
||||
text.contains('goo.gl/maps');
|
||||
}
|
||||
|
||||
/// Extracts metadata from a Google Maps link
|
||||
MapsLinkMetadata extractMetadata(String mapsLink) {
|
||||
String? placeName;
|
||||
String? latitude;
|
||||
String? longitude;
|
||||
String? address;
|
||||
|
||||
// Extract place name from URL
|
||||
final placeMatch = RegExp(r'/place/([^/]+)').firstMatch(mapsLink);
|
||||
if (placeMatch != null) {
|
||||
placeName = Uri.decodeComponent(
|
||||
placeMatch.group(1)!,
|
||||
).replaceAll('+', ' ');
|
||||
}
|
||||
|
||||
// Extract coordinates
|
||||
final coordMatch = RegExp(
|
||||
r'@(-?\d+\.\d+),(-?\d+\.\d+)',
|
||||
).firstMatch(mapsLink);
|
||||
if (coordMatch != null) {
|
||||
latitude = coordMatch.group(1);
|
||||
longitude = coordMatch.group(2);
|
||||
}
|
||||
|
||||
// Extract search query/address
|
||||
final searchMatch = RegExp(r'/search/([^/?]+)').firstMatch(mapsLink);
|
||||
if (searchMatch != null) {
|
||||
address = Uri.decodeComponent(searchMatch.group(1)!).replaceAll('+', ' ');
|
||||
// Use address as place name if name not found
|
||||
placeName ??= address;
|
||||
}
|
||||
|
||||
// Extract from data parameter (alternative format)
|
||||
final dataMatch = RegExp(r'[?&]q=([^&]+)').firstMatch(mapsLink);
|
||||
if (dataMatch != null && placeName == null) {
|
||||
final query = Uri.decodeComponent(dataMatch.group(1)!);
|
||||
// Check if it's coordinates
|
||||
final coordPattern = RegExp(r'^(-?\d+\.\d+),(-?\d+\.\d+)$');
|
||||
final coords = coordPattern.firstMatch(query);
|
||||
if (coords != null) {
|
||||
latitude ??= coords.group(1);
|
||||
longitude ??= coords.group(2);
|
||||
} else {
|
||||
placeName = query.replaceAll('+', ' ');
|
||||
}
|
||||
}
|
||||
|
||||
return MapsLinkMetadata(
|
||||
url: mapsLink,
|
||||
placeName: placeName ?? 'Unknown Location',
|
||||
latitude: latitude,
|
||||
longitude: longitude,
|
||||
address: address,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Data class for Google Maps link metadata
|
||||
class MapsLinkMetadata {
|
||||
final String url;
|
||||
final String placeName;
|
||||
final String? latitude;
|
||||
final String? longitude;
|
||||
final String? address;
|
||||
|
||||
const MapsLinkMetadata({
|
||||
required this.url,
|
||||
required this.placeName,
|
||||
this.latitude,
|
||||
this.longitude,
|
||||
this.address,
|
||||
});
|
||||
|
||||
String get coordinates {
|
||||
if (latitude != null && longitude != null) {
|
||||
return '$latitude, $longitude';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
bool get hasCoordinates => latitude != null && longitude != null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user