Skip to content

Commit

Permalink
Move location permission and minor ux improvement for mic dialog (#822)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdmohsin7 committed Sep 12, 2024
2 parents 8e7c41f + b693a46 commit 8e82e11
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 59 deletions.
63 changes: 60 additions & 3 deletions app/lib/pages/memories/page.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -32,13 +37,65 @@ class _MemoriesPageState extends State<MemoriesPage> with AutomaticKeepAliveClie
if (Provider.of<MemoryProvider>(context, listen: false).memories.isEmpty) {
await Provider.of<MemoryProvider>(context, listen: false).getInitialMemories();
}
// if (mounted) {
// Provider.of<MemoryProvider>(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');
Expand Down
55 changes: 0 additions & 55 deletions app/lib/pages/memories/widgets/capture.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,6 @@ class LiteCaptureWidgetState extends State<LiteCaptureWidget>
if (context.read<DeviceProvider>().connectedDevice != null) {
context.read<OnboardingProvider>().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<ConnectivityProvider>(context, listen: false);
if (!connectivityProvider.isConnected) {
Expand All @@ -103,43 +85,6 @@ class LiteCaptureWidgetState extends State<LiteCaptureWidget>
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);
Expand Down
2 changes: 1 addition & 1 deletion app/lib/pages/memories/widgets/processing_capture.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ class _MemoryCaptureWidgetState extends State<MemoryCaptureWidget> {
context,
() => Navigator.pop(context),
() async {
Navigator.pop(context);
provider.updateRecordingState(RecordingState.initialising);
context.read<WebSocketProvider>().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.',
Expand Down

0 comments on commit 8e82e11

Please sign in to comment.