Skip to content

Commit

Permalink
Wikimedia Commons field hack, and releasing 3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Zverik committed Jun 3, 2023
1 parent 86ad43e commit dbb8ec7
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 3.1

_Unreleased_
_Released on 2023-06-03_

* Updated Maxar and Mapbox imagery keys.
* Supporting tagging schema v6, added hundred new presets.
Expand All @@ -16,6 +16,7 @@ _Unreleased_
* Update all secondary tags when changing a type for an amenity.
* Fixed error when after uploading new amenities and editing them, duplicates
might have appeared.
* Pasting a `wikimedia_commons` value strips it of wiki formatting.
* Fixed long press on the sharing icon at the raw tags panel.
* Snack bar when removing a change does not time out for some reason.
Forcibly closing it when leaving the changes list.
Expand Down
2 changes: 1 addition & 1 deletion lib/constants.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart' show Colors, TextStyle;

const kAppTitle = 'Every Door';
const kAppVersion = '3.1-beta1'; // Also used for presets.db versioning
const kAppVersion = '3.1'; // Also used for presets.db versioning

const kDefaultLocation = <double>[59.42, 24.71];
const kDatabaseName = 'every_door.db';
Expand Down
90 changes: 90 additions & 0 deletions lib/fields/wiki_commons.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import 'package:every_door/constants.dart';
import 'package:every_door/models/amenity.dart';
import 'package:flutter/material.dart';
import 'package:every_door/models/field.dart';

class WikiCommonsPresetField extends PresetField {
const WikiCommonsPresetField({
String? key,
String? label,
IconData? icon,
String? placeholder,
FieldPrerequisite? prerequisite,
}) : super(
key: key ?? 'wikimedia_commons',
label: label ?? 'Wikimedia Commons',
icon: icon,
placeholder: placeholder,
prerequisite: prerequisite);

@override
Widget buildWidget(OsmChange element) => WikiCommonsInputField(this, element);
}

class WikiCommonsInputField extends StatefulWidget {
final WikiCommonsPresetField field;
final OsmChange element;

const WikiCommonsInputField(this.field, this.element);

@override
State createState() => _WikiCommonsInputFieldState();
}

class _WikiCommonsInputFieldState extends State<WikiCommonsInputField> {
late final TextEditingController _controller;

@override
void initState() {
super.initState();
_controller =
TextEditingController(text: widget.element[widget.field.key] ?? '');
}

@override
void dispose() {
_controller.dispose();
super.dispose();
}

final kReMarkup = RegExp(r'^\s*\[\[([^|\]]+)(?:\|.*)?\]\]\s*$');
final kReURL = RegExp(r'^.*(https://commons\S+(?:File|Category)\S+\.[a-z]+)\s*$');

String _removeWikiMarkup(String value) {
final match = kReMarkup.matchAsPrefix(value);
if (match != null) return match.group(1)!;
final urlMatch = kReURL.firstMatch(value);
if (urlMatch != null) return urlMatch.group(1)!;
return value;
}

@override
Widget build(BuildContext context) {
final value = widget.element[widget.field.key] ?? '';
if (value != _controller.text.trim()) {
// Hopefully that's not the time when we type a letter in the field.
// TODO: only update when page is back from inactive?
_controller.text = value;
}

return Padding(
padding: EdgeInsets.only(right: 10.0),
child: TextField(
controller: _controller,
keyboardType: TextInputType.url,
decoration: InputDecoration(
hintText: widget.field.placeholder,
labelText: widget.field.icon != null ? widget.field.label : null,
),
style: kFieldTextStyle,
maxLength: value.length > 200 ? 255 : null,
onChanged: (value) {
// On every keypress, since the focus can change at any minute.
setState(() {
widget.element[widget.field.key] = _removeWikiMarkup(value.trim());
});
},
),
);
}
}
2 changes: 1 addition & 1 deletion lib/helpers/nsi_features.dart

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions lib/models/field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:every_door/fields/radio.dart';
import 'package:every_door/fields/text.dart';
import 'package:every_door/fields/website.dart';
import 'package:every_door/fields/wheelchair.dart';
import 'package:every_door/fields/wiki_commons.dart';
import 'package:flutter/material.dart';
import 'package:every_door/models/amenity.dart';

Expand Down Expand Up @@ -134,6 +135,12 @@ PresetField fieldFromJson(Map<String, dynamic> data,
return WheelchairPresetField(label: label);
case 'level':
return FloorPresetField(label: label);
case 'wikimedia_commons':
return WikiCommonsPresetField(
label: label,
placeholder: placeholder,
prerequisite: prerequisite,
);
}

if (key.contains('opening_hours')) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: Next generation OpenStreetMap amenity mapper
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

# Also update version in constants.dart!
version: 3.0.99+33
version: 3.1.0+34

environment:
sdk: ">=2.18.0 <3.0.0"
Expand Down

0 comments on commit dbb8ec7

Please sign in to comment.