diff --git a/app/lib/pages/memories/page.dart b/app/lib/pages/memories/page.dart index 68425a0ba..029c38a6a 100644 --- a/app/lib/pages/memories/page.dart +++ b/app/lib/pages/memories/page.dart @@ -1,10 +1,15 @@ import 'package:flutter/material.dart'; +import 'package:friend_private/backend/preferences.dart'; import 'package:friend_private/backend/schema/memory.dart'; +import 'package:friend_private/pages/capture/location_service.dart'; import 'package:friend_private/pages/memories/widgets/date_list_item.dart'; import 'package:friend_private/pages/memories/widgets/processing_capture.dart'; import 'package:friend_private/providers/home_provider.dart'; import 'package:friend_private/providers/memory_provider.dart'; +import 'package:friend_private/utils/analytics/mixpanel.dart'; +import 'package:friend_private/widgets/dialog.dart'; import 'package:gradient_borders/box_borders/gradient_box_border.dart'; +import 'package:location/location.dart'; import 'package:provider/provider.dart'; import 'package:visibility_detector/visibility_detector.dart'; @@ -32,13 +37,65 @@ class _MemoriesPageState extends State with AutomaticKeepAliveClie if (Provider.of(context, listen: false).memories.isEmpty) { await Provider.of(context, listen: false).getInitialMemories(); } - // if (mounted) { - // Provider.of(context, listen: false).initFilteredMemories(); - // } + if (await LocationService().displayPermissionsDialog()) { + await showDialog( + context: context, + builder: (c) => getDialog( + context, + () => Navigator.of(context).pop(), + () async { + await requestLocationPermission(); + await LocationService().requestBackgroundPermission(); + if (mounted) Navigator.of(context).pop(); + }, + 'Enable Location? 🌍', + 'Allow location access to tag your memories. Set to "Always Allow" in Settings', + singleButton: false, + okButtonText: 'Continue', + ), + ); + } }); super.initState(); } + Future requestLocationPermission() async { + LocationService locationService = LocationService(); + bool serviceEnabled = await locationService.enableService(); + if (!serviceEnabled) { + debugPrint('Location service not enabled'); + if (mounted) { + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text( + 'Location services are disabled. Enable them for a better experience.', + style: TextStyle(color: Colors.white, fontSize: 14), + ), + ), + ); + } + } else { + PermissionStatus permissionGranted = await locationService.requestPermission(); + SharedPreferencesUtil().locationEnabled = permissionGranted == PermissionStatus.granted; + MixpanelManager().setUserProperty('Location Enabled', SharedPreferencesUtil().locationEnabled); + if (permissionGranted == PermissionStatus.denied) { + debugPrint('Location permission not granted'); + } else if (permissionGranted == PermissionStatus.deniedForever) { + debugPrint('Location permission denied forever'); + if (mounted) { + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text( + 'If you change your mind, you can enable location services in your device settings.', + style: TextStyle(color: Colors.white, fontSize: 14), + ), + ), + ); + } + } + } + } + @override Widget build(BuildContext context) { print('building memories page'); diff --git a/app/lib/pages/memories/widgets/capture.dart b/app/lib/pages/memories/widgets/capture.dart index 14c3252f6..8b155c319 100644 --- a/app/lib/pages/memories/widgets/capture.dart +++ b/app/lib/pages/memories/widgets/capture.dart @@ -67,24 +67,6 @@ class LiteCaptureWidgetState extends State if (context.read().connectedDevice != null) { context.read().stopFindDeviceTimer(); } - if (await LocationService().displayPermissionsDialog()) { - await showDialog( - context: context, - builder: (c) => getDialog( - context, - () => Navigator.of(context).pop(), - () async { - await requestLocationPermission(); - await LocationService().requestBackgroundPermission(); - if (mounted) Navigator.of(context).pop(); - }, - 'Enable Location? 🌍', - 'Allow location access to tag your memories. Set to "Always Allow" in Settings', - singleButton: false, - okButtonText: 'Continue', - ), - ); - } if (mounted) { final connectivityProvider = Provider.of(context, listen: false); if (!connectivityProvider.isConnected) { @@ -103,43 +85,6 @@ class LiteCaptureWidgetState extends State super.dispose(); } - Future requestLocationPermission() async { - LocationService locationService = LocationService(); - bool serviceEnabled = await locationService.enableService(); - if (!serviceEnabled) { - debugPrint('Location service not enabled'); - if (mounted) { - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar( - content: Text( - 'Location services are disabled. Enable them for a better experience.', - style: TextStyle(color: Colors.white, fontSize: 14), - ), - ), - ); - } - } else { - PermissionStatus permissionGranted = await locationService.requestPermission(); - SharedPreferencesUtil().locationEnabled = permissionGranted == PermissionStatus.granted; - MixpanelManager().setUserProperty('Location Enabled', SharedPreferencesUtil().locationEnabled); - if (permissionGranted == PermissionStatus.denied) { - debugPrint('Location permission not granted'); - } else if (permissionGranted == PermissionStatus.deniedForever) { - debugPrint('Location permission denied forever'); - if (mounted) { - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar( - content: Text( - 'If you change your mind, you can enable location services in your device settings.', - style: TextStyle(color: Colors.white, fontSize: 14), - ), - ), - ); - } - } - } - } - @override Widget build(BuildContext context) { super.build(context); diff --git a/app/lib/pages/memories/widgets/processing_capture.dart b/app/lib/pages/memories/widgets/processing_capture.dart index 68f5e4aee..064c38413 100644 --- a/app/lib/pages/memories/widgets/processing_capture.dart +++ b/app/lib/pages/memories/widgets/processing_capture.dart @@ -105,11 +105,11 @@ class _MemoryCaptureWidgetState extends State { context, () => Navigator.pop(context), () async { + Navigator.pop(context); provider.updateRecordingState(RecordingState.initialising); context.read().closeWebSocketWithoutReconnect('Recording with phone mic'); await provider.initiateWebsocket(BleAudioCodec.pcm16, 16000); await provider.streamRecording(); - Navigator.pop(context); }, 'Limited Capabilities', 'Recording with your phone microphone has a few limitations, including but not limited to: speaker profiles, background reliability.',