From 16b31b66916b7d204d983e464dbc3c3a765c4c8e Mon Sep 17 00:00:00 2001 From: Mohammed Mohsin <59914433+mdmohsin7@users.noreply.github.com> Date: Thu, 12 Sep 2024 11:52:09 +0530 Subject: [PATCH 1/2] move location dialog to other place --- app/lib/pages/memories/page.dart | 63 ++++++++++++++++++++- app/lib/pages/memories/widgets/capture.dart | 55 ------------------ 2 files changed, 60 insertions(+), 58 deletions(-) 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); From b693a467db6341ec250d4becd5e4d3da0a304cc7 Mon Sep 17 00:00:00 2001 From: Mohammed Mohsin <59914433+mdmohsin7@users.noreply.github.com> Date: Thu, 12 Sep 2024 11:52:29 +0530 Subject: [PATCH 2/2] pop the mic dialog --- app/lib/pages/memories/widgets/processing_capture.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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.',