Skip to content

Commit

Permalink
addr:block_number support and few translations
Browse files Browse the repository at this point in the history
  • Loading branch information
Zverik committed May 28, 2023
1 parent 2e35dd7 commit 8c93df9
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ _Unreleased_
* Supporting tagging schema v6, added hundred new presets.
* Some POI like churches and libraries have reduced obsoletion rate (1 year).
* Deleting buildings via lifecycle prefixes is forbidden now.
* Added `block_number` field for japanese addresses.
* `name:signed` is not a language suffix.
* When downloading data for an area, do not delete new notes (but changes
to existing notes would be lost though).
Expand Down
8 changes: 8 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,10 @@
"@addressUnitOptional": {
"description": "Hint for addr:unit that it's optional."
},
"addressBlock": "Block",
"@addressBlock": {
"description": "Label for addr:block_number or addr_block. Keep it short."
},
"addressStreet": "Street",
"@addressStreet": {
"description": "Label for addr:street in the form. Keep it short."
Expand All @@ -1074,6 +1078,10 @@
"@notesAddNote": {
"description": "Tooltip for the button to add a note."
},
"notesComment": "Your comment",
"@notesComment": {
"description": "Label for the note comment field."
},
"notesAnonymous": "Anonymous",
"@notesAnonymous": {
"description": "Name for anonymous note submitters."
Expand Down
30 changes: 27 additions & 3 deletions lib/models/address.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class StreetAddress {
final String? housename;
final String? unit;
final String? street;
final String? block;
final String? blockNumber;
final String? place;
final String? city;

Expand All @@ -16,6 +18,8 @@ class StreetAddress {
this.housename,
this.unit,
this.street,
this.block,
this.blockNumber,
this.place,
this.city,
this.location});
Expand All @@ -28,6 +32,8 @@ class StreetAddress {
housename: tags['addr:housename'],
unit: tags['addr:unit'],
street: tags['addr:street'],
block: tags['addr:block'],
blockNumber: tags['addr:block_number'],
place: tags['addr:place'],
city: (tags['addr:street'] == null && tags['addr:place'] == null)
? tags['addr:city']
Expand All @@ -38,7 +44,11 @@ class StreetAddress {

bool get isEmpty =>
(housenumber == null && housename == null) ||
(street == null && place == null && city == null);
(street == null &&
place == null &&
city == null &&
block == null &&
blockNumber == null);
bool get isNotEmpty => !isEmpty;

setTags(OsmChange element) {
Expand All @@ -48,6 +58,8 @@ class StreetAddress {
else
element['addr:housename'] = housename;
if (unit != null) element['addr:unit'] = unit;
if (block != null) element['addr:block'] = block;
if (blockNumber != null) element['addr:block_number'] = blockNumber;
if (street != null)
element['addr:street'] = street;
else if (place != null)
Expand All @@ -60,6 +72,8 @@ class StreetAddress {
element['addr:housenumber'] = housenumber;
element['addr:housename'] = housename;
element['addr:unit'] = unit;
element['addr:block'] = block;
element['addr:block_number'] = blockNumber;
element['addr:street'] = street;
element['addr:place'] = place;
// TODO: decide something about the city
Expand All @@ -71,6 +85,8 @@ class StreetAddress {
'housenumber',
'housename',
'unit',
'block',
'block_number',
'street',
'place',
'city'
Expand All @@ -84,6 +100,8 @@ class StreetAddress {
return housenumber == other.housenumber &&
housename == other.housename &&
unit == other.unit &&
block == other.block &&
blockNumber == other.blockNumber &&
street == other.street &&
place == other.place &&
city == other.city;
Expand All @@ -92,10 +110,16 @@ class StreetAddress {
@override
int get hashCode =>
(housenumber ?? housename ?? '').hashCode +
(block ?? blockNumber ?? '').hashCode +
(street ?? place ?? city ?? '').hashCode +
unit.hashCode;

@override
String toString() =>
'${housenumber ?? housename}${unit != null ? " u.$unit" : ""}, ${street ?? place ?? city}';
String toString() {
final unitPart = unit != null ? " u.$unit" : "";
final firstPart = '${housenumber ?? housename}$unitPart';
final blockPart = blockNumber ?? block;
final lastPart = street ?? place ?? city;
return [firstPart, blockPart, lastPart].whereType<String>().join(', ');
}
}
2 changes: 1 addition & 1 deletion lib/screens/editor/note.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class _NoteEditorPaneState extends ConsumerState<NoteEditorPane> {
autofocus: true,
initialValue: message,
decoration: InputDecoration(
labelText: 'Your comment',
labelText: loc.notesComment,
),
style: kFieldTextStyle,
onChanged: (value) {
Expand Down
68 changes: 58 additions & 10 deletions lib/widgets/address_form.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:country_coder/country_coder.dart';
import 'package:every_door/constants.dart';
import 'package:every_door/providers/editor_settings.dart';
import 'package:every_door/providers/road_names.dart';
import 'package:every_door/widgets/radio_field.dart';
import 'package:every_door/providers/osm_data.dart';
Expand Down Expand Up @@ -30,14 +32,17 @@ class AddressForm extends ConsumerStatefulWidget {
class _AddressFormState extends ConsumerState<AddressForm> {
late final TextEditingController _houseController;
late final TextEditingController _unitController;
late final TextEditingController _blockController;
late final FocusNode _streetFocus;
List<String> nearestStreets = [];
List<String> nearestBlocks = [];
List<String> nearestPlaces = [];
List<String> nearestCities = [];
String? street;
String? place;
bool isName = false;
bool editingStreet = false;
bool needBlockNumber = false;

@override
void initState() {
Expand All @@ -47,16 +52,24 @@ class _AddressFormState extends ConsumerState<AddressForm> {
_houseController =
TextEditingController(text: address.housenumber ?? address.housename);
_unitController = TextEditingController(text: address.unit);
_blockController =
TextEditingController(text: address.blockNumber ?? address.block);
_streetFocus = FocusNode();
street = address.street;
place = address.place ?? address.city;
needBlockNumber = CountryCoder.instance.isIn(
lat: widget.location.latitude,
lon: widget.location.longitude,
inside: 'Q17', // Japan
);
updateStreets();
}

@override
dispose() {
_houseController.dispose();
_unitController.dispose();
_blockController.dispose();
_streetFocus.dispose();
super.dispose();
}
Expand All @@ -74,6 +87,8 @@ class _AddressFormState extends ConsumerState<AddressForm> {
await ref.read(roadNameProvider).getNamesAround(widget.location);
final addrs = await provider.getAddressesAround(widget.location, limit: 30);
setState(() {
nearestBlocks = _filterDuplicates(
addrs.map((e) => needBlockNumber ? e.blockNumber : e.block));
nearestPlaces = _filterDuplicates(addrs.map((e) => e.place));
nearestCities = _filterDuplicates(addrs.map((e) => e.city));
});
Expand All @@ -86,10 +101,13 @@ class _AddressFormState extends ConsumerState<AddressForm> {

notifyOnChange() {
final unit = _unitController.text.trim();
final block = _blockController.text.trim();
final address = StreetAddress(
housenumber: isName ? null : house,
housename: isName ? house : widget.initialAddress?.housename,
unit: unit.isEmpty ? null : unit,
block: needBlockNumber || block.isEmpty ? null : block,
blockNumber: !needBlockNumber || block.isEmpty ? null : block,
street: street,
place: nearestPlaces.isNotEmpty ? place : null,
city: nearestPlaces.isNotEmpty ? null : place,
Expand All @@ -103,6 +121,7 @@ class _AddressFormState extends ConsumerState<AddressForm> {
@override
Widget build(BuildContext context) {
final loc = AppLocalizations.of(context)!;
final numericKeyboardType = ref.watch(editorSettingsProvider).keyboardType;

return Table(
columnWidths: {
Expand All @@ -116,10 +135,11 @@ class _AddressFormState extends ConsumerState<AddressForm> {
padding: const EdgeInsets.only(right: 10.0),
child: Text(loc.addressHouseNumber,
style: kFieldTextStyle.copyWith(
color:
_houseController.text.trim().isEmpty && street != null
? Colors.red
: null)),
color: _houseController.text.trim().isEmpty &&
(street != null ||
_blockController.text.trim().isNotEmpty)
? Colors.red
: null)),
),
Row(
children: [
Expand Down Expand Up @@ -174,16 +194,44 @@ class _AddressFormState extends ConsumerState<AddressForm> {
),
],
),
if (needBlockNumber)
TableRow(
children: [
Padding(
padding: const EdgeInsets.only(right: 10.0),
child: Text(
loc.addressBlock,
style: kFieldTextStyle.copyWith(
color: _houseController.text.trim().isNotEmpty &&
(street == null &&
_blockController.text.trim().isEmpty)
? Colors.red
: null),
),
),
TextFormField(
controller: _blockController,
keyboardType: numericKeyboardType,
style: kFieldTextStyle,
onChanged: (value) {
notifyOnChange();
},
),
],
),
TableRow(
children: [
Padding(
padding: const EdgeInsets.only(right: 10.0),
child: Text(loc.addressStreet,
style: kFieldTextStyle.copyWith(
color: _houseController.text.trim().isNotEmpty &&
street == null
? Colors.red
: null)),
child: Text(
loc.addressStreet,
style: kFieldTextStyle.copyWith(
color: _houseController.text.trim().isNotEmpty &&
(street == null &&
_blockController.text.trim().isEmpty)
? Colors.red
: null),
),
),
if (!editingStreet)
RadioField(
Expand Down

0 comments on commit 8c93df9

Please sign in to comment.