minor fixes
This commit is contained in:
parent
dd2199ef20
commit
6feb1efb13
3 changed files with 69 additions and 41 deletions
|
@ -8,7 +8,7 @@ final Settings settings = Settings._private();
|
|||
typedef SettingsCallback = void Function(String key, dynamic oldValue, dynamic newValue);
|
||||
|
||||
class Settings {
|
||||
static SharedPreferences prefs;
|
||||
static SharedPreferences _prefs;
|
||||
|
||||
final ObserverList<SettingsCallback> _listeners = ObserverList<SettingsCallback>();
|
||||
|
||||
|
@ -21,11 +21,11 @@ class Settings {
|
|||
static const catalogTimeZoneKey = 'catalog_time_zone';
|
||||
|
||||
Future<void> init() async {
|
||||
prefs = await SharedPreferences.getInstance();
|
||||
_prefs = await SharedPreferences.getInstance();
|
||||
}
|
||||
|
||||
Future<void> reset() {
|
||||
return prefs.clear();
|
||||
return _prefs.clear();
|
||||
}
|
||||
|
||||
void addListener(SettingsCallback listener) => _listeners.add(listener);
|
||||
|
@ -48,11 +48,11 @@ class Settings {
|
|||
}
|
||||
}
|
||||
|
||||
double get infoMapZoom => prefs.getDouble(infoMapZoomKey) ?? 12;
|
||||
double get infoMapZoom => _prefs.getDouble(infoMapZoomKey) ?? 12;
|
||||
|
||||
set infoMapZoom(double newValue) => setAndNotify(infoMapZoomKey, newValue);
|
||||
|
||||
String get catalogTimeZone => prefs.getString(catalogTimeZoneKey) ?? '';
|
||||
String get catalogTimeZone => _prefs.getString(catalogTimeZoneKey) ?? '';
|
||||
|
||||
set catalogTimeZone(String newValue) => setAndNotify(catalogTimeZoneKey, newValue);
|
||||
|
||||
|
@ -66,10 +66,10 @@ class Settings {
|
|||
|
||||
// convenience methods
|
||||
|
||||
bool getBoolOrDefault(String key, bool defaultValue) => prefs.getKeys().contains(key) ? prefs.getBool(key) : defaultValue;
|
||||
bool getBoolOrDefault(String key, bool defaultValue) => _prefs.getKeys().contains(key) ? _prefs.getBool(key) : defaultValue;
|
||||
|
||||
T getEnumOrDefault<T>(String key, T defaultValue, Iterable<T> values) {
|
||||
final valueString = prefs.getString(key);
|
||||
final valueString = _prefs.getString(key);
|
||||
for (final element in values) {
|
||||
if (element.toString() == valueString) {
|
||||
return element;
|
||||
|
@ -79,28 +79,28 @@ class Settings {
|
|||
}
|
||||
|
||||
List<T> getEnumListOrDefault<T>(String key, List<T> defaultValue, Iterable<T> values) {
|
||||
return prefs.getStringList(key)?.map((s) => values.firstWhere((el) => el.toString() == s, orElse: () => null))?.where((el) => el != null)?.toList() ?? defaultValue;
|
||||
return _prefs.getStringList(key)?.map((s) => values.firstWhere((el) => el.toString() == s, orElse: () => null))?.where((el) => el != null)?.toList() ?? defaultValue;
|
||||
}
|
||||
|
||||
void setAndNotify(String key, dynamic newValue) {
|
||||
var oldValue = prefs.get(key);
|
||||
var oldValue = _prefs.get(key);
|
||||
if (newValue == null) {
|
||||
prefs.remove(key);
|
||||
_prefs.remove(key);
|
||||
} else if (newValue is String) {
|
||||
oldValue = prefs.getString(key);
|
||||
prefs.setString(key, newValue);
|
||||
oldValue = _prefs.getString(key);
|
||||
_prefs.setString(key, newValue);
|
||||
} else if (newValue is List<String>) {
|
||||
oldValue = prefs.getStringList(key);
|
||||
prefs.setStringList(key, newValue);
|
||||
oldValue = _prefs.getStringList(key);
|
||||
_prefs.setStringList(key, newValue);
|
||||
} else if (newValue is int) {
|
||||
oldValue = prefs.getInt(key);
|
||||
prefs.setInt(key, newValue);
|
||||
oldValue = _prefs.getInt(key);
|
||||
_prefs.setInt(key, newValue);
|
||||
} else if (newValue is double) {
|
||||
oldValue = prefs.getDouble(key);
|
||||
prefs.setDouble(key, newValue);
|
||||
oldValue = _prefs.getDouble(key);
|
||||
_prefs.setDouble(key, newValue);
|
||||
} else if (newValue is bool) {
|
||||
oldValue = prefs.getBool(key);
|
||||
prefs.setBool(key, newValue);
|
||||
oldValue = _prefs.getBool(key);
|
||||
_prefs.setBool(key, newValue);
|
||||
}
|
||||
if (oldValue != newValue) {
|
||||
notifyListeners(key, oldValue, newValue);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:outline_material_icons/outline_material_icons.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
|
||||
enum FullscreenAction { delete, edit, info, open, openMap, print, rename, rotateCCW, rotateCW, setAs, share, toggleFavourite }
|
||||
|
||||
|
@ -22,36 +21,68 @@ class FullscreenActions {
|
|||
FullscreenAction.setAs,
|
||||
FullscreenAction.openMap,
|
||||
];
|
||||
}
|
||||
|
||||
static Tuple2<String, IconData> getTextIcon(FullscreenAction action) {
|
||||
switch (action) {
|
||||
extension ExtraFullscreenAction on FullscreenAction {
|
||||
String getText() {
|
||||
switch (this) {
|
||||
// in app actions
|
||||
case FullscreenAction.toggleFavourite:
|
||||
// different data depending on toggle state
|
||||
return null;
|
||||
case FullscreenAction.delete:
|
||||
return const Tuple2('Delete', OMIcons.delete);
|
||||
return 'Delete';
|
||||
case FullscreenAction.info:
|
||||
return const Tuple2('Info', OMIcons.info);
|
||||
return 'Info';
|
||||
case FullscreenAction.rename:
|
||||
return const Tuple2('Rename', OMIcons.title);
|
||||
return 'Rename';
|
||||
case FullscreenAction.rotateCCW:
|
||||
return const Tuple2('Rotate left', OMIcons.rotateLeft);
|
||||
return 'Rotate left';
|
||||
case FullscreenAction.rotateCW:
|
||||
return const Tuple2('Rotate right', OMIcons.rotateRight);
|
||||
return 'Rotate right';
|
||||
case FullscreenAction.print:
|
||||
return const Tuple2('Print', OMIcons.print);
|
||||
return 'Print';
|
||||
case FullscreenAction.share:
|
||||
return const Tuple2('Share', OMIcons.share);
|
||||
return 'Share';
|
||||
// external app actions
|
||||
case FullscreenAction.edit:
|
||||
return const Tuple2('Edit with…', null);
|
||||
return 'Edit with…';
|
||||
case FullscreenAction.open:
|
||||
return const Tuple2('Open with…', null);
|
||||
return 'Open with…';
|
||||
case FullscreenAction.setAs:
|
||||
return const Tuple2('Set as…', null);
|
||||
return 'Set as…';
|
||||
case FullscreenAction.openMap:
|
||||
return const Tuple2('Show on map…', null);
|
||||
return 'Show on map…';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
IconData getIcon() {
|
||||
switch (this) {
|
||||
// in app actions
|
||||
case FullscreenAction.toggleFavourite:
|
||||
// different data depending on toggle state
|
||||
return null;
|
||||
case FullscreenAction.delete:
|
||||
return OMIcons.delete;
|
||||
case FullscreenAction.info:
|
||||
return OMIcons.info;
|
||||
case FullscreenAction.rename:
|
||||
return OMIcons.title;
|
||||
case FullscreenAction.rotateCCW:
|
||||
return OMIcons.rotateLeft;
|
||||
case FullscreenAction.rotateCW:
|
||||
return OMIcons.rotateRight;
|
||||
case FullscreenAction.print:
|
||||
return OMIcons.print;
|
||||
case FullscreenAction.share:
|
||||
return OMIcons.share;
|
||||
// external app actions
|
||||
case FullscreenAction.edit:
|
||||
case FullscreenAction.open:
|
||||
case FullscreenAction.setAs:
|
||||
case FullscreenAction.openMap:
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -143,11 +143,10 @@ class FullscreenTopOverlay extends StatelessWidget {
|
|||
case FullscreenAction.rotateCCW:
|
||||
case FullscreenAction.rotateCW:
|
||||
case FullscreenAction.print:
|
||||
final textIcon = FullscreenActions.getTextIcon(action);
|
||||
child = IconButton(
|
||||
icon: Icon(textIcon.item2),
|
||||
icon: Icon(action.getIcon()),
|
||||
onPressed: onPressed,
|
||||
tooltip: textIcon.item1,
|
||||
tooltip: action.getText(),
|
||||
);
|
||||
break;
|
||||
case FullscreenAction.openMap:
|
||||
|
@ -189,16 +188,14 @@ class FullscreenTopOverlay extends StatelessWidget {
|
|||
case FullscreenAction.rotateCCW:
|
||||
case FullscreenAction.rotateCW:
|
||||
case FullscreenAction.print:
|
||||
final textIcon = FullscreenActions.getTextIcon(action);
|
||||
child = MenuRow(text: textIcon.item1, icon: textIcon.item2);
|
||||
child = MenuRow(text: action.getText(), icon: action.getIcon());
|
||||
break;
|
||||
// external app actions
|
||||
case FullscreenAction.edit:
|
||||
case FullscreenAction.open:
|
||||
case FullscreenAction.setAs:
|
||||
case FullscreenAction.openMap:
|
||||
final textIcon = FullscreenActions.getTextIcon(action);
|
||||
child = Text(textIcon.item1);
|
||||
child = Text(action.getText());
|
||||
break;
|
||||
}
|
||||
return PopupMenuItem(
|
||||
|
|
Loading…
Reference in a new issue