Skip to content

Commit

Permalink
current stand
Browse files Browse the repository at this point in the history
  • Loading branch information
Myzel394 committed Sep 16, 2023
1 parent 9091e7b commit c20f4dc
Show file tree
Hide file tree
Showing 16 changed files with 376 additions and 152 deletions.
5 changes: 3 additions & 2 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@
"androidNotificationChannel_locationAlarms_description": "Receive notifications for location alarms",
"location_manageAlarms_title": "Manage Alarms",
"location_manageAlarms_empty_title": "No Alarms",
"location_manageAlarms_empty_description": "Add alarms to be notified when certain conditions are met (e.g. when this person enters a certain area).",
"location_manageAlarms_empty_description": "Add alarms to be notified when certain conditions are met",
"location_manageAlarms_addNewAlarm_actionLabel": "Add Alarm",
"location_manageAlarms_lastCheck_description": "Last checked at {date}",
"@location_manageAlarms_lastCheck_description": {
Expand All @@ -710,10 +710,11 @@
}
},
"location_addAlarm_geo_title": "Add geo-based alarm",
"location_addAlarm_geo_description": "Define a region and get notified when your friend enters or leaves this region",
"location_addAlarm_geo_name_description": "Please enter a name for this region",
"location_addAlarm_geo_help_tapDescription": "Tap on the map to mark the center of your region",
"location_addAlarm_proximity_title": "Add proximity alarm",
"location_addAlarm_proximity_description": "Proximity alarms are triggered when you are within a certain distance of your friend.",
"location_addAlarm_proximity_description": "Get notified when your friend is within a certain distance of you",
"location_addAlarm_radiusBased_radius_meters": "Radius: {value} meters",
"@location_addAlarm_radiusBased_radius_meters": {
"placeholders": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,21 @@ import 'package:locus/utils/theme.dart';
import '../../widgets/ModalSheet.dart';
import '../../widgets/PlatformListTile.dart';

class RadiusRegionMetaDataSheet extends StatefulWidget {
class GeoAlarmMetaDataSheet extends StatefulWidget {
final LatLng center;
final double radius;

const RadiusRegionMetaDataSheet({
const GeoAlarmMetaDataSheet({
required this.center,
required this.radius,
super.key,
});

@override
State<RadiusRegionMetaDataSheet> createState() =>
_RadiusRegionMetaDataSheetState();
State<GeoAlarmMetaDataSheet> createState() => _GeoAlarmMetaDataSheetState();
}

class _RadiusRegionMetaDataSheetState extends State<RadiusRegionMetaDataSheet> {
class _GeoAlarmMetaDataSheetState extends State<GeoAlarmMetaDataSheet> {
final _nameController = TextEditingController();
final _formKey = GlobalKey<FormState>();
RadiusBasedRegionLocationAlarmType? _type;
Expand Down Expand Up @@ -104,7 +103,7 @@ class _RadiusRegionMetaDataSheetState extends State<RadiusRegionMetaDataSheet> {
if (_formKey.currentState!.validate()) {
Navigator.pop(
context,
RadiusBasedRegionLocationAlarm.create(
GeoLocationAlarm.create(
zoneName: _nameController.text,
center: widget.center,
radius: widget.radius,
Expand Down
82 changes: 82 additions & 0 deletions lib/screens/view_alarm_screen_widgets/GeoLocationAlarmPreview.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
import 'package:locus/constants/spacing.dart';
import 'package:locus/screens/locations_overview_screen_widgets/LocationFetchers.dart';
import 'package:locus/services/location_alarm_service/index.dart';
import 'package:locus/services/view_service.dart';
import 'package:locus/utils/map.dart';
import 'package:locus/widgets/LocusFlutterMap.dart';
import 'package:provider/provider.dart';

class GeoLocationAlarmPreview extends StatelessWidget {
final TaskView view;
final GeoLocationAlarm alarm;
final VoidCallback onDelete;

const GeoLocationAlarmPreview({
super.key,
required this.view,
required this.alarm,
required this.onDelete,
});

@override
Widget build(BuildContext context) {
final locationFetchers = context.watch<LocationFetchers>();
final lastLocation =
locationFetchers.getLocations(view).lastOrNull?.asLatLng();

return Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
PlatformListTile(
title: Text(alarm.zoneName),
leading: alarm.getIcon(context),
trailing: PlatformIconButton(
icon: Icon(context.platformIcons.delete),
onPressed: onDelete,
),
),
ClipRRect(
borderRadius: BorderRadius.circular(LARGE_SPACE),
child: SizedBox(
width: double.infinity,
height: 200,
child: IgnorePointer(
ignoring: true,
child: LocusFlutterMap(
options: MapOptions(
center: alarm.center,
maxZoom: 18,
// create zoom based of radius
zoom: getZoomLevelForRadius(alarm.radius),
),
children: [
CircleLayer(
circles: [
if (lastLocation != null)
CircleMarker(
point: lastLocation,
radius: 5,
color: Colors.blue,
),
CircleMarker(
point: alarm.center,
useRadiusInMeter: true,
color: Colors.red.withOpacity(0.3),
borderStrokeWidth: 5,
borderColor: Colors.red,
radius: alarm.radius,
),
],
),
],
),
),
),
),
],
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:locus/constants/spacing.dart';
import 'package:locus/services/location_alarm_service/ProximityLocationAlarm.dart';
import 'package:locus/utils/theme.dart';

import '../../widgets/ModalSheet.dart';
import '../../widgets/PlatformListTile.dart';

class ProximityAlarmMetaDataSheet extends StatelessWidget {
final double radius;

const ProximityAlarmMetaDataSheet({
required this.radius,
super.key,
});

void _createAlarm(
final BuildContext context,
final ProximityLocationAlarmType type,
) {
final alarm = ProximityLocationAlarm.create(
radius: radius,
type: type,
);

Navigator.pop(
context,
alarm,
);
}

@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context);

return ModalSheet(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
l10n.location_addAlarm_radiusBased_trigger_title,
style: getSubTitleTextStyle(context),
),
const SizedBox(height: MEDIUM_SPACE),
PlatformListTile(
onTap: () {
_createAlarm(context, ProximityLocationAlarmType.whenEnter);
},
leading: const Icon(Icons.arrow_circle_right_rounded),
title: Text(l10n.location_addAlarm_radiusBased_trigger_whenEnter),
),
PlatformListTile(
onTap: () {
_createAlarm(context, ProximityLocationAlarmType.whenLeave);
},
leading: const Icon(Icons.arrow_circle_left_rounded),
title: Text(l10n.location_addAlarm_radiusBased_trigger_whenLeave),
),
],
),
);
}
}
108 changes: 108 additions & 0 deletions lib/screens/view_alarm_screen_widgets/ProximityAlarmPreview.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
import 'package:latlong2/latlong.dart';
import 'package:locus/constants/spacing.dart';
import 'package:locus/screens/locations_overview_screen_widgets/LocationFetchers.dart';
import 'package:locus/services/current_location_service.dart';
import 'package:locus/services/location_alarm_service/ProximityLocationAlarm.dart';
import 'package:locus/services/view_service.dart';
import 'package:locus/utils/location/get-fallback-location.dart';
import 'package:locus/utils/map.dart';
import 'package:locus/widgets/LocusFlutterMap.dart';
import 'package:provider/provider.dart';

class ProximityAlarmPreview extends StatelessWidget {
final TaskView view;
final ProximityLocationAlarm alarm;
final VoidCallback onDelete;

const ProximityAlarmPreview({
required this.view,
required this.alarm,
required this.onDelete,
super.key,
});

@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context);
final locationFetchers = context.watch<LocationFetchers>();
final lastLocation =
locationFetchers.getLocations(view).lastOrNull?.asLatLng();
final currentPosition =
context.watch<CurrentLocationService>().currentPosition;

return Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
PlatformListTile(
title: Text(
alarm.radius > 10000
? l10n.location_addAlarm_radiusBased_radius_kilometers(
double.parse(
(alarm.radius / 1000).toStringAsFixed(1),
),
)
: l10n.location_addAlarm_radiusBased_radius_meters(
alarm.radius.round()),
),
leading: alarm.getIcon(context),
trailing: PlatformIconButton(
icon: Icon(context.platformIcons.delete),
onPressed: onDelete,
),
),
ClipRRect(
borderRadius: BorderRadius.circular(LARGE_SPACE),
child: SizedBox(
width: double.infinity,
height: 200,
child: IgnorePointer(
ignoring: true,
child: LocusFlutterMap(
options: MapOptions(
center: currentPosition == null
? getFallbackLocation(context)
: LatLng(
currentPosition.latitude,
currentPosition.longitude,
),
maxZoom: 18,
// create zoom based of radius
zoom: getZoomLevelForRadius(alarm.radius),
),
children: [
CircleLayer(
circles: [
if (lastLocation != null)
CircleMarker(
point: lastLocation,
radius: 5,
color: Colors.blue,
),
CircleMarker(
point: currentPosition == null
? getFallbackLocation(context)
: LatLng(
currentPosition.latitude,
currentPosition.longitude,
),
useRadiusInMeter: true,
color: Colors.red.withOpacity(0.3),
borderStrokeWidth: 5,
borderColor: Colors.red,
radius: alarm.radius,
),
],
),
],
),
),
),
),
],
);
}
}
Loading

0 comments on commit c20f4dc

Please sign in to comment.