settings: added coordinate format
This commit is contained in:
parent
df8d48cd19
commit
ebffcbb27c
7 changed files with 110 additions and 36 deletions
|
@ -1,7 +1,9 @@
|
|||
import 'package:aves/utils/geo_utils.dart';
|
||||
import 'package:aves/widgets/fullscreen/info/location_section.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
|
||||
import 'source/enums.dart';
|
||||
|
||||
|
@ -25,6 +27,7 @@ class Settings {
|
|||
static const infoMapStyleKey = 'info_map_style';
|
||||
static const infoMapZoomKey = 'info_map_zoom';
|
||||
static const launchPageKey = 'launch_page';
|
||||
static const coordinateFormatKey = 'coordinates_format';
|
||||
|
||||
Future<void> init() async {
|
||||
_prefs = await SharedPreferences.getInstance();
|
||||
|
@ -86,6 +89,10 @@ class Settings {
|
|||
|
||||
set launchPage(LaunchPage newValue) => setAndNotify(launchPageKey, newValue.toString());
|
||||
|
||||
CoordinateFormat get coordinateFormat => getEnumOrDefault(coordinateFormatKey, CoordinateFormat.dms, CoordinateFormat.values);
|
||||
|
||||
set coordinateFormat(CoordinateFormat newValue) => setAndNotify(coordinateFormatKey, newValue.toString());
|
||||
|
||||
// convenience methods
|
||||
|
||||
// ignore: avoid_positional_boolean_parameters
|
||||
|
@ -145,3 +152,29 @@ extension ExtraLaunchPage on LaunchPage {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum CoordinateFormat { dms, decimal }
|
||||
|
||||
extension ExtraCoordinateFormat on CoordinateFormat {
|
||||
String get name {
|
||||
switch (this) {
|
||||
case CoordinateFormat.dms:
|
||||
return 'DMS';
|
||||
case CoordinateFormat.decimal:
|
||||
return 'Decimal degrees';
|
||||
default:
|
||||
return toString();
|
||||
}
|
||||
}
|
||||
|
||||
String format(Tuple2<double, double> latLng) {
|
||||
switch (this) {
|
||||
case CoordinateFormat.dms:
|
||||
return toDMS(latLng).join(', ');
|
||||
case CoordinateFormat.decimal:
|
||||
return [latLng.item1, latLng.item2].map((n) => n.toStringAsFixed(6)).join(', ');
|
||||
default:
|
||||
return toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ import 'package:aves/widgets/common/aves_logo.dart';
|
|||
import 'package:aves/widgets/common/icons.dart';
|
||||
import 'package:aves/widgets/debug_page.dart';
|
||||
import 'package:aves/widgets/filter_grid_page.dart';
|
||||
import 'package:aves/widgets/settings_page.dart';
|
||||
import 'package:aves/widgets/settings/settings_page.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
|
|
@ -2,7 +2,6 @@ import 'package:aves/model/filters/location.dart';
|
|||
import 'package:aves/model/image_entry.dart';
|
||||
import 'package:aves/model/settings.dart';
|
||||
import 'package:aves/model/source/collection_lens.dart';
|
||||
import 'package:aves/utils/geo_utils.dart';
|
||||
import 'package:aves/widgets/common/aves_filter_chip.dart';
|
||||
import 'package:aves/widgets/common/icons.dart';
|
||||
import 'package:aves/widgets/fullscreen/info/info_page.dart';
|
||||
|
@ -108,7 +107,7 @@ class _LocationSectionState extends State<LocationSection> {
|
|||
style: settings.infoMapStyle,
|
||||
),
|
||||
),
|
||||
if (entry.hasGps) InfoRowGroup({'Coordinates': toDMS(entry.latLng).join(', ')}),
|
||||
if (entry.hasGps) InfoRowGroup({'Coordinates': settings.coordinateFormat.format(entry.latLng)}),
|
||||
if (location.isNotEmpty) InfoRowGroup({'Address': location}),
|
||||
if (filters.isNotEmpty)
|
||||
Padding(
|
||||
|
|
|
@ -3,9 +3,9 @@ import 'dart:ui';
|
|||
|
||||
import 'package:aves/model/image_entry.dart';
|
||||
import 'package:aves/model/image_metadata.dart';
|
||||
import 'package:aves/model/settings.dart';
|
||||
import 'package:aves/services/metadata_service.dart';
|
||||
import 'package:aves/utils/constants.dart';
|
||||
import 'package:aves/utils/geo_utils.dart';
|
||||
import 'package:aves/widgets/common/fx/blurred.dart';
|
||||
import 'package:aves/widgets/common/icons.dart';
|
||||
import 'package:aves/widgets/fullscreen/overlay/common.dart';
|
||||
|
@ -212,7 +212,7 @@ class _LocationRow extends AnimatedWidget {
|
|||
if (entry.isLocated) {
|
||||
location = entry.shortAddress;
|
||||
} else if (entry.hasGps) {
|
||||
location = toDMS(entry.latLng).join(', ');
|
||||
location = settings.coordinateFormat.format(entry.latLng);
|
||||
}
|
||||
return Row(
|
||||
children: [
|
||||
|
|
31
lib/widgets/settings/coordinate_format.dart
Normal file
31
lib/widgets/settings/coordinate_format.dart
Normal file
|
@ -0,0 +1,31 @@
|
|||
import 'package:aves/model/settings.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class CoordinateFormatSelector extends StatefulWidget {
|
||||
@override
|
||||
_CoordinateFormatSelectorState createState() => _CoordinateFormatSelectorState();
|
||||
}
|
||||
|
||||
class _CoordinateFormatSelectorState extends State<CoordinateFormatSelector> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return DropdownButton<CoordinateFormat>(
|
||||
items: CoordinateFormat.values
|
||||
.map((selected) => DropdownMenuItem(
|
||||
value: selected,
|
||||
child: Text(
|
||||
selected.name,
|
||||
softWrap: false,
|
||||
overflow: TextOverflow.fade,
|
||||
maxLines: 1,
|
||||
),
|
||||
))
|
||||
.toList(),
|
||||
value: settings.coordinateFormat,
|
||||
onChanged: (selected) {
|
||||
settings.coordinateFormat = selected;
|
||||
setState(() {});
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
31
lib/widgets/settings/launch_page.dart
Normal file
31
lib/widgets/settings/launch_page.dart
Normal file
|
@ -0,0 +1,31 @@
|
|||
import 'package:aves/model/settings.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class LaunchPageSelector extends StatefulWidget {
|
||||
@override
|
||||
_LaunchPageSelectorState createState() => _LaunchPageSelectorState();
|
||||
}
|
||||
|
||||
class _LaunchPageSelectorState extends State<LaunchPageSelector> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return DropdownButton<LaunchPage>(
|
||||
items: LaunchPage.values
|
||||
.map((selected) => DropdownMenuItem(
|
||||
value: selected,
|
||||
child: Text(
|
||||
selected.name,
|
||||
softWrap: false,
|
||||
overflow: TextOverflow.fade,
|
||||
maxLines: 1,
|
||||
),
|
||||
))
|
||||
.toList(),
|
||||
value: settings.launchPage,
|
||||
onChanged: (selected) {
|
||||
settings.launchPage = selected;
|
||||
setState(() {});
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:aves/model/settings.dart';
|
||||
import 'package:aves/utils/constants.dart';
|
||||
import 'package:aves/widgets/common/data_providers/media_query_data_provider.dart';
|
||||
import 'package:aves/widgets/settings/coordinate_format.dart';
|
||||
import 'package:aves/widgets/settings/launch_page.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class SettingsPage extends StatelessWidget {
|
||||
|
@ -21,11 +22,19 @@ class SettingsPage extends StatelessWidget {
|
|||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text('Launch Page:'),
|
||||
Text('Launch page:'),
|
||||
SizedBox(width: 8),
|
||||
Flexible(child: LaunchPageSelector()),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text('Coordinate format:'),
|
||||
SizedBox(width: 8),
|
||||
Flexible(child: CoordinateFormatSelector()),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
@ -34,32 +43,3 @@ class SettingsPage extends StatelessWidget {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
class LaunchPageSelector extends StatefulWidget {
|
||||
@override
|
||||
_LaunchPageSelectorState createState() => _LaunchPageSelectorState();
|
||||
}
|
||||
|
||||
class _LaunchPageSelectorState extends State<LaunchPageSelector> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return DropdownButton<LaunchPage>(
|
||||
items: LaunchPage.values
|
||||
.map((selected) => DropdownMenuItem(
|
||||
value: selected,
|
||||
child: Text(
|
||||
selected.name,
|
||||
softWrap: false,
|
||||
overflow: TextOverflow.fade,
|
||||
maxLines: 1,
|
||||
),
|
||||
))
|
||||
.toList(),
|
||||
value: settings.launchPage,
|
||||
onChanged: (selected) {
|
||||
settings.launchPage = selected;
|
||||
setState(() {});
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue