Skip to content

Commit

Permalink
Added two languages, added draggable choose to draw modes, made draw …
Browse files Browse the repository at this point in the history
…selector prettier
  • Loading branch information
Zverik committed Apr 14, 2024
1 parent 9d5c244 commit 76a1efd
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 56 deletions.
6 changes: 3 additions & 3 deletions lib/helpers/draw_style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ const kTypeStyles = <String, DrawingStyle>{
"path": DrawingStyle(color: Colors.red, dashed: true),
"cycleway": DrawingStyle(color: Colors.purpleAccent),
"cycleway_shared": DrawingStyle(color: Colors.purpleAccent, dashed: true),
"wall": DrawingStyle(color: Colors.yellow),
"fence": DrawingStyle(color: Colors.yellow, dashed: true),
"power": DrawingStyle(color: Colors.orangeAccent),
"wall": DrawingStyle(color: Colors.yellow, thin: true),
"fence": DrawingStyle(color: Colors.yellow, dashed: true, thin: true),
"power": DrawingStyle(color: Colors.orangeAccent, thin: true),
"stream": DrawingStyle(color: Colors.lightBlue),
"drain": DrawingStyle(color: Colors.lightBlue, dashed: true),
};
Expand Down
4 changes: 4 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,10 @@
"@notesCloseMessage": {
"description": "Confirmation message when pressed a close note button."
},
"notesDelete": "Delete",
"@notesDelete": {
"description": "Button title for deleting a new note."
},
"notesCancelMessage": "Cancel your OSM note?",
"@notesCancelMessage": {
"description": "Message when cancelling an OSM note that has non-empty content."
Expand Down
1 change: 1 addition & 0 deletions lib/models/note.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class BaseNote {
}

class MapNote extends BaseNote {
static const kMaxLength = 40;
static const dbType = 1;
final String? author;
String message;
Expand Down
45 changes: 28 additions & 17 deletions lib/screens/editor/note.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ class _NoteEditorPaneState extends ConsumerState<NoteEditorPane> {
}
return note;
} else {
if (message.isEmpty) return null; // Not deleting MapNotes by clearing a message.
if (message.isEmpty)
return null; // Not deleting MapNotes by clearing a message.
final note = widget.note as MapNote;
note.message = message;
return note;
Expand Down Expand Up @@ -227,7 +228,12 @@ class _NoteEditorPaneState extends ConsumerState<NoteEditorPane> {
),
style: kFieldTextStyle,
onChanged: (value) {
message = value.trim();
setState(() {
message = value.trim();
if (!isOsmNote && message.length > MapNote.kMaxLength) {
isOsmNote = true;
}
});
},
),
if (!isOsmNote)
Expand Down Expand Up @@ -266,31 +272,36 @@ class _NoteEditorPaneState extends ConsumerState<NoteEditorPane> {
SwitchListTile(
value: isOsmNote,
title: Text('Publish to OSM'),
onChanged: (value) {
setState(() {
isOsmNote = !isOsmNote;
});
},
onChanged: message.length > MapNote.kMaxLength
? null
: (value) {
setState(() {
isOsmNote = !isOsmNote;
});
},
),
Row(
children: [
if (widget.note != null)
TextButton(
child: Text(
loc.notesClose.toUpperCase(),
widget.note!.isNew
? loc.notesDelete.toUpperCase()
: loc.notesClose.toUpperCase(),
style: TextStyle(
color: Theme.of(context).colorScheme.error),
),
onPressed: () async {
final answer = await showOkCancelAlertDialog(
context: context,
title: loc.notesCloseMessage,
okLabel: loc.notesClose,
isDestructiveAction: true,
);
if (answer == OkCancelResult.ok) {
deleteAndClose();
if (widget.note is OsmNote && !widget.note!.isNew) {
final answer = await showOkCancelAlertDialog(
context: context,
title: loc.notesCloseMessage,
okLabel: loc.notesClose,
isDestructiveAction: true,
);
if (answer != OkCancelResult.ok) return;
}
deleteAndClose();
},
),
Expanded(child: Container()),
Expand All @@ -299,7 +310,7 @@ class _NoteEditorPaneState extends ConsumerState<NoteEditorPane> {
MaterialLocalizations.of(context).cancelButtonLabel),
onPressed: () async {
final navigator = Navigator.of(context);
if (message.trim().isNotEmpty) {
if (isChanged) {
final answer = await showOkCancelAlertDialog(
context: context,
title: MaterialLocalizations.of(context)
Expand Down
19 changes: 13 additions & 6 deletions lib/screens/modes/notes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,14 @@ class _NotesPaneState extends ConsumerState<NotesPane> {
onTap: !locked
? null
: (position, ll) {
final markers =
findMarkerUnderTap(ll).whereType<OsmNote>();
if (markers.isNotEmpty)
_openNoteEditor(markers.first);
final markers = findMarkerUnderTap(ll);
for (final note in markers) {
if (note is OsmNote ||
(note is MapNote && note.isNew)) {
_openNoteEditor(note);
break;
}
}
},
),
children: [
Expand Down Expand Up @@ -210,7 +214,7 @@ class _NotesPaneState extends ConsumerState<NotesPane> {
point: mapNote.location,
rotate: true,
alignment: Alignment.topRight,
width: 150,
width: 300,
child: Padding(
padding: const EdgeInsets.all(4.0),
child: Row(
Expand Down Expand Up @@ -337,7 +341,10 @@ class _NotesPaneState extends ConsumerState<NotesPane> {
bool found = false;
final closestNotes = findMarkerUnderTap(location);
for (final note in closestNotes) {
if (note is OsmNote) {
if (note is OsmNote ||
(note is MapNote &&
note.isNew &&
currentTool != kToolEraser)) {
_openNoteEditor(note);
found = true;
break;
Expand Down
2 changes: 2 additions & 0 deletions lib/screens/settings/language.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class LanguagePage extends ConsumerWidget {
Locale('en', 'GB'): 'English (Great Britain)',
Locale('eo'): 'Esperanto',
Locale('es'): 'Español',
Locale('et'): 'Eesti keel',
Locale('eu'): 'Euskara',
Locale('fa'): 'فارسی',
Locale('fi'): 'Suomi',
Expand All @@ -31,6 +32,7 @@ class LanguagePage extends ConsumerWidget {
Locale('mr'): 'मराठी',
Locale('nb'): 'Bokmål',
Locale('nl'): 'Nederlands',
Locale('or'): 'ଓଡ଼ିଆ',
Locale('pa'): 'ਪੰਜਾਬੀ',
Locale('pa', 'PK'): 'پنجابی',
Locale('pl'): 'Polski',
Expand Down
119 changes: 89 additions & 30 deletions lib/widgets/style_chooser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class StyleChooserButton extends ConsumerStatefulWidget {

class _StyleChooserButtonState extends ConsumerState<StyleChooserButton> {
bool isOpen = false;
bool isDragging = false;

selectTool(String tool) {
widget.onChange(tool);
Expand Down Expand Up @@ -85,9 +86,21 @@ class _StyleChooserButtonState extends ConsumerState<StyleChooserButton> {
// crossAxisCount: 2,
children: [
for (final tool in kDrawingTools)
GestureDetector(
child: StylePill(style: tool),
onTap: () {
DragTarget(
builder: (BuildContext context,
List<Object?> candidateData,
List<dynamic> rejectedData) {
return GestureDetector(
child: StylePill(
style: tool,
focused: candidateData.isNotEmpty,
),
onTap: () {
selectTool(tool);
},
);
},
onAccept: (data) {
selectTool(tool);
},
),
Expand All @@ -100,7 +113,7 @@ class _StyleChooserButtonState extends ConsumerState<StyleChooserButton> {
leftHand ? TextDirection.rtl : TextDirection.ltr,
mainAxisSize: MainAxisSize.min,
children: [
if (widget.onLock != null)
if (widget.onLock != null && !isDragging)
RoundButton(
icon: Icons.lock_open,
foreground: Colors.grey,
Expand All @@ -109,22 +122,48 @@ class _StyleChooserButtonState extends ConsumerState<StyleChooserButton> {
if (widget.onLock != null) widget.onLock!();
},
),
SizedBox(width: widget.onLock == null ? 100 : 20),
RoundButton(
icon:
kStyleIcons[kToolScribble] ?? kUnknownStyleIcon,
foreground: Colors.black,
background: Colors.white,
onPressed: () {
SizedBox(
width: widget.onLock == null || isDragging
? 100
: 20),
DragTarget(
builder: (BuildContext context,
List<Object?> candidateData,
List<dynamic> rejectedData) {
return RoundButton(
icon: kStyleIcons[kToolScribble] ??
kUnknownStyleIcon,
foreground: Colors.black,
background: candidateData.isEmpty
? Colors.white
: Colors.yellowAccent,
onPressed: () {
selectTool(kToolScribble);
},
);
},
onAccept: (data) {
selectTool(kToolScribble);
},
),
SizedBox(width: 20),
RoundButton(
icon: kStyleIcons[kToolEraser] ?? kUnknownStyleIcon,
foreground: Colors.red,
background: Colors.white,
onPressed: () {
DragTarget(
builder: (BuildContext context,
List<Object?> candidateData,
List<dynamic> rejectedData) {
return RoundButton(
icon: kStyleIcons[kToolEraser] ??
kUnknownStyleIcon,
foreground: Colors.red,
background: candidateData.isEmpty
? Colors.white
: Colors.yellowAccent,
onPressed: () {
selectTool(kToolEraser);
},
);
},
onAccept: (data) {
selectTool(kToolEraser);
},
),
Expand All @@ -138,14 +177,30 @@ class _StyleChooserButtonState extends ConsumerState<StyleChooserButton> {
),
child: isOpen
? Container()
: RoundButton(
icon: kStyleIcons[widget.style] ?? kUnknownStyleIcon,
tooltip: loc.drawChangeTool,
onPressed: () {
: Draggable(
feedback: Container(),
data: 1,
onDraggableCanceled: (v, o) {
setState(() {
isOpen = false;
});
},
onDragStarted: () {
setState(() {
isOpen = true;
isDragging = true;
});
},
child: RoundButton(
icon: kStyleIcons[widget.style] ?? kUnknownStyleIcon,
tooltip: loc.drawChangeTool,
onPressed: () {
setState(() {
isOpen = true;
isDragging = false;
});
},
),
),
),
),
Expand All @@ -155,8 +210,9 @@ class _StyleChooserButtonState extends ConsumerState<StyleChooserButton> {

class StylePill extends StatelessWidget {
final String style;
final bool focused;

const StylePill({super.key, required this.style});
const StylePill({super.key, required this.style, this.focused = false});

String getLocalizedStyle(AppLocalizations loc) {
switch (style) {
Expand Down Expand Up @@ -192,29 +248,32 @@ class StylePill extends StatelessWidget {
@override
Widget build(BuildContext context) {
final loc = AppLocalizations.of(context)!;
final drStyle = kTypeStyles[style] ?? kUnknownStyle;

// TODO: make it round
return Container(
padding: EdgeInsets.symmetric(vertical: 15.0, horizontal: 5.0),
padding: EdgeInsets.symmetric(vertical: 15.0, horizontal: 10.0),
decoration: BoxDecoration(
color: Colors.white70,
borderRadius: BorderRadius.circular(5.0),
border: Border.fromBorderSide(BorderSide(color: Colors.black)),
color: focused ? Colors.yellowAccent : Colors.white70,
borderRadius: BorderRadius.circular(25.0),
),
child: Row(
children: [
Container(
padding: EdgeInsets.all(5.0),
decoration: BoxDecoration(
color: Colors.white,
color: drStyle.color,
borderRadius: BorderRadius.circular(45.0),
border: Border.fromBorderSide(BorderSide(color: Colors.black)),
),
child: Icon(kStyleIcons[style] ?? kUnknownStyleIcon),
child: Icon(
kStyleIcons[style] ?? kUnknownStyleIcon,
color: drStyle.casing,
),
),
SizedBox(width: 5.0),
SizedBox(width: 8.0),
Text(
getLocalizedStyle(loc),
style: TextStyle(fontSize: kFieldFontSize),
overflow: TextOverflow.clip, // does not work :(
),
],
),
Expand Down

0 comments on commit 76a1efd

Please sign in to comment.