From f892c953edcb26edb460c52ea110131e7da98fc8 Mon Sep 17 00:00:00 2001 From: PanierAvide Date: Sat, 24 Mar 2018 18:38:37 +0100 Subject: [PATCH 1/7] Quest for bus stop names (see #551) --- .../streetcomplete/quests/QuestModule.java | 2 + .../quests/bus_stop_name/AddBusStopName.java | 50 ++++++++++++++++ .../bus_stop_name/AddBusStopNameForm.java | 60 +++++++++++++++++++ app/src/main/res/values/strings.xml | 1 + 4 files changed, 113 insertions(+) create mode 100644 app/src/main/java/de/westnordost/streetcomplete/quests/bus_stop_name/AddBusStopName.java create mode 100644 app/src/main/java/de/westnordost/streetcomplete/quests/bus_stop_name/AddBusStopNameForm.java diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/QuestModule.java b/app/src/main/java/de/westnordost/streetcomplete/quests/QuestModule.java index e8b718f912..66cee53a32 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/QuestModule.java +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/QuestModule.java @@ -17,6 +17,7 @@ import de.westnordost.streetcomplete.quests.bikeway.AddCycleway; import de.westnordost.streetcomplete.quests.bridge_structure.AddBridgeStructure; import de.westnordost.streetcomplete.quests.building_levels.AddBuildingLevels; +import de.westnordost.streetcomplete.quests.bus_stop_name.AddBusStopName; import de.westnordost.streetcomplete.quests.bus_stop_shelter.AddBusStopShelter; import de.westnordost.streetcomplete.quests.car_wash_type.AddCarWashType; import de.westnordost.streetcomplete.quests.crossing_type.AddCrossingType; @@ -86,6 +87,7 @@ public class QuestModule new AddInternetAccess(o), new AddParkingAccess(o), new AddParkingFee(o), + new AddBusStopName(o), // ↓ 4. definitely shown as errors in QA tools diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/bus_stop_name/AddBusStopName.java b/app/src/main/java/de/westnordost/streetcomplete/quests/bus_stop_name/AddBusStopName.java new file mode 100644 index 0000000000..44cf7ff63e --- /dev/null +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/bus_stop_name/AddBusStopName.java @@ -0,0 +1,50 @@ +package de.westnordost.streetcomplete.quests.bus_stop_name; + +import android.os.Bundle; +import android.support.annotation.NonNull; + +import java.util.Map; + +import javax.inject.Inject; + +import de.westnordost.streetcomplete.R; +import de.westnordost.streetcomplete.data.osm.SimpleOverpassQuestType; +import de.westnordost.streetcomplete.data.osm.changes.StringMapChangesBuilder; +import de.westnordost.streetcomplete.data.osm.download.OverpassMapDataDao; +import de.westnordost.streetcomplete.quests.AbstractQuestAnswerFragment; + +public class AddBusStopName extends SimpleOverpassQuestType +{ + + @Inject public AddBusStopName(OverpassMapDataDao overpassServer) { super(overpassServer); } + + @Override protected String getTagFilters() + { + return " nodes, ways with !name and noname != yes" + + " and ( highway = bus_stop or public_transport = platform )"; + } + + @Override public AbstractQuestAnswerFragment createForm() + { + return new AddBusStopNameForm(); + } + + @Override public void applyAnswerTo(Bundle answer, StringMapChangesBuilder changes) + { + if(answer.getBoolean(AddBusStopNameForm.NO_NAME)) + { + changes.add("noname", "yes"); + return; + } + + String name = answer.getString(AddBusStopNameForm.NAME); + if(name != null) changes.add("name", name); + } + + @Override public String getCommitMessage() { return "Determine bus stop names"; } + @Override public int getIcon() { return R.drawable.ic_quest_label; } + @Override public int getTitle(@NonNull Map tags) + { + return R.string.quest_busStopName_title; + } +} diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/bus_stop_name/AddBusStopNameForm.java b/app/src/main/java/de/westnordost/streetcomplete/quests/bus_stop_name/AddBusStopNameForm.java new file mode 100644 index 0000000000..eb96d6c540 --- /dev/null +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/bus_stop_name/AddBusStopNameForm.java @@ -0,0 +1,60 @@ +package de.westnordost.streetcomplete.quests.bus_stop_name; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.EditText; + +import de.westnordost.streetcomplete.R; +import de.westnordost.streetcomplete.quests.AbstractQuestFormAnswerFragment; +import de.westnordost.streetcomplete.view.dialogs.AlertDialogBuilder; + +public class AddBusStopNameForm extends AbstractQuestFormAnswerFragment +{ + public static final String NO_NAME = "no_name"; + public static final String NAME = "name"; + + private EditText nameInput; + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) + { + View view = super.onCreateView(inflater, container, savedInstanceState); + + View contentView = setContentView(R.layout.quest_placename); + nameInput = contentView.findViewById(R.id.nameInput); + + addOtherAnswer(R.string.quest_name_answer_noName, this::confirmNoName); + + return view; + } + + @Override protected void onClickOk() + { + Bundle data = new Bundle(); + String name = nameInput.getText().toString().trim(); + data.putString(NAME, name); + applyFormAnswer(data); + } + + private void confirmNoName() + { + new AlertDialogBuilder(getActivity()) + .setTitle(R.string.quest_name_answer_noName_confirmation_title) + .setPositiveButton(R.string.quest_name_noName_confirmation_positive, (dialog, which) -> + { + Bundle data = new Bundle(); + data.putBoolean(NO_NAME, true); + applyImmediateAnswer(data); + }) + .setNegativeButton(R.string.quest_generic_confirmation_no, null) + .show(); + } + + @Override public boolean hasChanges() + { + return !nameInput.getText().toString().trim().isEmpty(); + } +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index caf5ef0294..b17bbce5cf 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -197,6 +197,7 @@ To display the map, vector tiles are retrieved from the <a href=\"https://map "Sett" "Wood" "What is the name of this place?" + "What is the name of this bus stop?" "Is there a sidewalk in this street?" "The map is oriented north up." "Only on northern side" From 52b6fb5f7298ed0050909873bc608cce9d4154e6 Mon Sep 17 00:00:00 2001 From: PanierAvide Date: Sat, 24 Mar 2018 23:04:14 +0100 Subject: [PATCH 2/7] Bus stop name: filter out stop_positions --- .../streetcomplete/quests/bus_stop_name/AddBusStopName.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/bus_stop_name/AddBusStopName.java b/app/src/main/java/de/westnordost/streetcomplete/quests/bus_stop_name/AddBusStopName.java index 44cf7ff63e..f7942a1ca8 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/bus_stop_name/AddBusStopName.java +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/bus_stop_name/AddBusStopName.java @@ -21,7 +21,7 @@ public class AddBusStopName extends SimpleOverpassQuestType @Override protected String getTagFilters() { return " nodes, ways with !name and noname != yes" + - " and ( highway = bus_stop or public_transport = platform )"; + " and (public_transport=platform or (highway=bus_stop and public_transport!=stop_position))"; } @Override public AbstractQuestAnswerFragment createForm() @@ -42,7 +42,7 @@ public class AddBusStopName extends SimpleOverpassQuestType } @Override public String getCommitMessage() { return "Determine bus stop names"; } - @Override public int getIcon() { return R.drawable.ic_quest_label; } + @Override public int getIcon() { return R.drawable.ic_quest_bus; } @Override public int getTitle(@NonNull Map tags) { return R.string.quest_busStopName_title; From 45a681e49f76f1066079ab9b15a9f7c73bf880ad Mon Sep 17 00:00:00 2001 From: PanierAvide Date: Sun, 25 Mar 2018 08:17:44 +0200 Subject: [PATCH 3/7] Bus stop name quest: using proper icon --- .../quests/bus_stop_name/AddBusStopName.java | 2 +- .../res/drawable/ic_quest_bus_stop_name.xml | 170 ++++++++++++++++++ 2 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 app/src/main/res/drawable/ic_quest_bus_stop_name.xml diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/bus_stop_name/AddBusStopName.java b/app/src/main/java/de/westnordost/streetcomplete/quests/bus_stop_name/AddBusStopName.java index f7942a1ca8..38eb770935 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/bus_stop_name/AddBusStopName.java +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/bus_stop_name/AddBusStopName.java @@ -42,7 +42,7 @@ public class AddBusStopName extends SimpleOverpassQuestType } @Override public String getCommitMessage() { return "Determine bus stop names"; } - @Override public int getIcon() { return R.drawable.ic_quest_bus; } + @Override public int getIcon() { return R.drawable.ic_quest_bus_stop_name; } @Override public int getTitle(@NonNull Map tags) { return R.string.quest_busStopName_title; diff --git a/app/src/main/res/drawable/ic_quest_bus_stop_name.xml b/app/src/main/res/drawable/ic_quest_bus_stop_name.xml new file mode 100644 index 0000000000..089e65b4aa --- /dev/null +++ b/app/src/main/res/drawable/ic_quest_bus_stop_name.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From b2a06d3443ff84f7f6b32533220799cf01758059 Mon Sep 17 00:00:00 2001 From: PanierAvide Date: Sun, 25 Mar 2018 12:02:12 +0200 Subject: [PATCH 4/7] WIP refactoring bus stop name + street name quests --- .../quests/AddPlaceNameTest.java | 6 +- .../AddRoadNameTest.java | 6 +- .../data/RoadNameSuggestionsDaoTest.java | 2 +- .../streetcomplete/ApplicationComponent.java | 2 +- .../streetcomplete/data/DbModule.java | 2 +- .../streetcomplete/quests/QuestModule.java | 8 +- .../quests/bus_stop_name/AddBusStopName.java | 50 ---- .../bus_stop_name/AddBusStopNameForm.java | 60 ---- .../quests/localized_name/AddBusStopName.java | 88 ++++++ .../localized_name/AddBusStopNameForm.java | 110 ++++++++ .../AddLocalizedNameAdapter.java} | 144 +++++----- .../localized_name/AddLocalizedNameForm.java | 194 +++++++++++++ .../AddRoadName.java | 6 +- .../AddRoadNameForm.java | 140 ++-------- .../AutoCorrectAbbreviationsEditText.java | 2 +- .../LocalizedName.java} | 6 +- .../data/PutRoadNameSuggestionsHandler.java | 2 +- .../data/RoadNameSuggestionsDao.java | 2 +- .../data/RoadNamesTable.java | 2 +- .../data/RoadNamesTablesHelper.java | 2 +- .../quests/place_name/AddPlaceNameForm.java | 18 +- .../streetcomplete/util/KryoSerializer.java | 4 +- .../res/drawable/ic_quest_bus_stop_name.xml | 257 ++++++------------ ...t_roadname.xml => quest_localizedname.xml} | 0 ...me_row.xml => quest_localizedname_row.xml} | 4 +- app/src/main/res/values/strings.xml | 1 + 26 files changed, 605 insertions(+), 513 deletions(-) rename app/src/androidTest/java/de/westnordost/streetcomplete/quests/{road_name => localized_name}/AddRoadNameTest.java (91%) rename app/src/androidTest/java/de/westnordost/streetcomplete/quests/{road_name => localized_name}/data/RoadNameSuggestionsDaoTest.java (96%) delete mode 100644 app/src/main/java/de/westnordost/streetcomplete/quests/bus_stop_name/AddBusStopName.java delete mode 100644 app/src/main/java/de/westnordost/streetcomplete/quests/bus_stop_name/AddBusStopNameForm.java create mode 100644 app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddBusStopName.java create mode 100644 app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddBusStopNameForm.java rename app/src/main/java/de/westnordost/streetcomplete/quests/{road_name/AddRoadNameAdapter.java => localized_name/AddLocalizedNameAdapter.java} (64%) create mode 100644 app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddLocalizedNameForm.java rename app/src/main/java/de/westnordost/streetcomplete/quests/{road_name => localized_name}/AddRoadName.java (96%) rename app/src/main/java/de/westnordost/streetcomplete/quests/{road_name => localized_name}/AddRoadNameForm.java (55%) rename app/src/main/java/de/westnordost/streetcomplete/quests/{road_name => localized_name}/AutoCorrectAbbreviationsEditText.java (98%) rename app/src/main/java/de/westnordost/streetcomplete/quests/{road_name/RoadName.java => localized_name/LocalizedName.java} (59%) rename app/src/main/java/de/westnordost/streetcomplete/quests/{road_name => localized_name}/data/PutRoadNameSuggestionsHandler.java (96%) rename app/src/main/java/de/westnordost/streetcomplete/quests/{road_name => localized_name}/data/RoadNameSuggestionsDao.java (98%) rename app/src/main/java/de/westnordost/streetcomplete/quests/{road_name => localized_name}/data/RoadNamesTable.java (84%) rename app/src/main/java/de/westnordost/streetcomplete/quests/{road_name => localized_name}/data/RoadNamesTablesHelper.java (93%) rename app/src/main/res/layout/{quest_roadname.xml => quest_localizedname.xml} (100%) rename app/src/main/res/layout/{quest_roadname_row.xml => quest_localizedname_row.xml} (95%) diff --git a/app/src/androidTest/java/de/westnordost/streetcomplete/quests/AddPlaceNameTest.java b/app/src/androidTest/java/de/westnordost/streetcomplete/quests/AddPlaceNameTest.java index adaf420eb1..6c422d674f 100644 --- a/app/src/androidTest/java/de/westnordost/streetcomplete/quests/AddPlaceNameTest.java +++ b/app/src/androidTest/java/de/westnordost/streetcomplete/quests/AddPlaceNameTest.java @@ -2,8 +2,8 @@ import de.westnordost.streetcomplete.data.osm.OsmElementQuestType; import de.westnordost.streetcomplete.data.osm.changes.StringMapEntryAdd; +import de.westnordost.streetcomplete.quests.localized_name.AddNameForm; import de.westnordost.streetcomplete.quests.place_name.AddPlaceName; -import de.westnordost.streetcomplete.quests.place_name.AddPlaceNameForm; public class AddPlaceNameTest extends AOsmElementQuestTypeTest { @@ -15,14 +15,14 @@ public class AddPlaceNameTest extends AOsmElementQuestTypeTest public void testNoName() { - bundle.putBoolean(AddPlaceNameForm.NO_NAME, true); + bundle.putBoolean(AddNameForm.NO_NAME, true); verify( new StringMapEntryAdd("noname","yes")); } public void testName() { - bundle.putString(AddPlaceNameForm.NAME, "my name"); + bundle.putString(AddNameForm.NAME, "my name"); verify( new StringMapEntryAdd("name","my name")); } diff --git a/app/src/androidTest/java/de/westnordost/streetcomplete/quests/road_name/AddRoadNameTest.java b/app/src/androidTest/java/de/westnordost/streetcomplete/quests/localized_name/AddRoadNameTest.java similarity index 91% rename from app/src/androidTest/java/de/westnordost/streetcomplete/quests/road_name/AddRoadNameTest.java rename to app/src/androidTest/java/de/westnordost/streetcomplete/quests/localized_name/AddRoadNameTest.java index 660058ea7f..51785085c1 100644 --- a/app/src/androidTest/java/de/westnordost/streetcomplete/quests/road_name/AddRoadNameTest.java +++ b/app/src/androidTest/java/de/westnordost/streetcomplete/quests/localized_name/AddRoadNameTest.java @@ -1,11 +1,11 @@ -package de.westnordost.streetcomplete.quests.road_name; +package de.westnordost.streetcomplete.quests.localized_name; import de.westnordost.streetcomplete.data.osm.OsmElementQuestType; import de.westnordost.streetcomplete.data.osm.changes.StringMapEntryAdd; import de.westnordost.streetcomplete.data.osm.changes.StringMapEntryModify; import de.westnordost.streetcomplete.quests.AOsmElementQuestTypeTest; -import de.westnordost.streetcomplete.quests.road_name.data.PutRoadNameSuggestionsHandler; -import de.westnordost.streetcomplete.quests.road_name.data.RoadNameSuggestionsDao; +import de.westnordost.streetcomplete.quests.localized_name.data.PutRoadNameSuggestionsHandler; +import de.westnordost.streetcomplete.quests.localized_name.data.RoadNameSuggestionsDao; import static org.mockito.Mockito.mock; diff --git a/app/src/androidTest/java/de/westnordost/streetcomplete/quests/road_name/data/RoadNameSuggestionsDaoTest.java b/app/src/androidTest/java/de/westnordost/streetcomplete/quests/localized_name/data/RoadNameSuggestionsDaoTest.java similarity index 96% rename from app/src/androidTest/java/de/westnordost/streetcomplete/quests/road_name/data/RoadNameSuggestionsDaoTest.java rename to app/src/androidTest/java/de/westnordost/streetcomplete/quests/localized_name/data/RoadNameSuggestionsDaoTest.java index 3c1f0d9edc..b88f99b06f 100644 --- a/app/src/androidTest/java/de/westnordost/streetcomplete/quests/road_name/data/RoadNameSuggestionsDaoTest.java +++ b/app/src/androidTest/java/de/westnordost/streetcomplete/quests/localized_name/data/RoadNameSuggestionsDaoTest.java @@ -1,4 +1,4 @@ -package de.westnordost.streetcomplete.quests.road_name.data; +package de.westnordost.streetcomplete.quests.localized_name.data; import java.util.ArrayList; import java.util.HashMap; diff --git a/app/src/main/java/de/westnordost/streetcomplete/ApplicationComponent.java b/app/src/main/java/de/westnordost/streetcomplete/ApplicationComponent.java index aa283b49f4..3aa3be5ac1 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/ApplicationComponent.java +++ b/app/src/main/java/de/westnordost/streetcomplete/ApplicationComponent.java @@ -13,7 +13,7 @@ import de.westnordost.streetcomplete.quests.AbstractQuestAnswerFragment; import de.westnordost.streetcomplete.quests.QuestModule; import de.westnordost.streetcomplete.quests.opening_hours.AddOpeningHoursForm; -import de.westnordost.streetcomplete.quests.road_name.AddRoadNameForm; +import de.westnordost.streetcomplete.quests.localized_name.AddRoadNameForm; import de.westnordost.streetcomplete.quests.note_discussion.NoteDiscussionForm; import de.westnordost.streetcomplete.settings.SettingsActivity; import de.westnordost.streetcomplete.settings.SettingsFragment; diff --git a/app/src/main/java/de/westnordost/streetcomplete/data/DbModule.java b/app/src/main/java/de/westnordost/streetcomplete/data/DbModule.java index 427324192a..05dbe79d08 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/data/DbModule.java +++ b/app/src/main/java/de/westnordost/streetcomplete/data/DbModule.java @@ -18,7 +18,7 @@ import de.westnordost.streetcomplete.data.visiblequests.QuestTypeOrderList; import de.westnordost.streetcomplete.data.visiblequests.VisibleQuestTypeDao; import de.westnordost.streetcomplete.data.statistics.QuestStatisticsDao; -import de.westnordost.streetcomplete.quests.road_name.data.RoadNamesTablesHelper; +import de.westnordost.streetcomplete.quests.localized_name.data.RoadNamesTablesHelper; import de.westnordost.streetcomplete.util.KryoSerializer; import de.westnordost.streetcomplete.util.Serializer; import de.westnordost.osmapi.changesets.ChangesetsDao; diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/QuestModule.java b/app/src/main/java/de/westnordost/streetcomplete/quests/QuestModule.java index 66cee53a32..55f3630415 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/QuestModule.java +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/QuestModule.java @@ -17,7 +17,7 @@ import de.westnordost.streetcomplete.quests.bikeway.AddCycleway; import de.westnordost.streetcomplete.quests.bridge_structure.AddBridgeStructure; import de.westnordost.streetcomplete.quests.building_levels.AddBuildingLevels; -import de.westnordost.streetcomplete.quests.bus_stop_name.AddBusStopName; +import de.westnordost.streetcomplete.quests.localized_name.AddBusStopName; import de.westnordost.streetcomplete.quests.bus_stop_shelter.AddBusStopShelter; import de.westnordost.streetcomplete.quests.car_wash_type.AddCarWashType; import de.westnordost.streetcomplete.quests.crossing_type.AddCrossingType; @@ -33,8 +33,8 @@ import de.westnordost.streetcomplete.quests.recycling.AddRecyclingType; import de.westnordost.streetcomplete.quests.religion.AddReligionToPlaceOfWorship; import de.westnordost.streetcomplete.quests.religion.AddReligionToWaysideShrine; -import de.westnordost.streetcomplete.quests.road_name.data.PutRoadNameSuggestionsHandler; -import de.westnordost.streetcomplete.quests.road_name.data.RoadNameSuggestionsDao; +import de.westnordost.streetcomplete.quests.localized_name.data.PutRoadNameSuggestionsHandler; +import de.westnordost.streetcomplete.quests.localized_name.data.RoadNameSuggestionsDao; import de.westnordost.streetcomplete.quests.tactile_paving.AddTactilePavingBusStop; import de.westnordost.streetcomplete.quests.tactile_paving.AddTactilePavingCrosswalk; import de.westnordost.streetcomplete.quests.toilet_availability.AddToiletAvailability; @@ -42,7 +42,7 @@ import de.westnordost.streetcomplete.quests.housenumber.AddHousenumber; import de.westnordost.streetcomplete.quests.max_speed.AddMaxSpeed; import de.westnordost.streetcomplete.quests.opening_hours.AddOpeningHours; -import de.westnordost.streetcomplete.quests.road_name.AddRoadName; +import de.westnordost.streetcomplete.quests.localized_name.AddRoadName; import de.westnordost.streetcomplete.quests.road_surface.AddRoadSurface; import de.westnordost.streetcomplete.quests.roof_shape.AddRoofShape; import de.westnordost.streetcomplete.quests.sport.AddSport; diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/bus_stop_name/AddBusStopName.java b/app/src/main/java/de/westnordost/streetcomplete/quests/bus_stop_name/AddBusStopName.java deleted file mode 100644 index 38eb770935..0000000000 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/bus_stop_name/AddBusStopName.java +++ /dev/null @@ -1,50 +0,0 @@ -package de.westnordost.streetcomplete.quests.bus_stop_name; - -import android.os.Bundle; -import android.support.annotation.NonNull; - -import java.util.Map; - -import javax.inject.Inject; - -import de.westnordost.streetcomplete.R; -import de.westnordost.streetcomplete.data.osm.SimpleOverpassQuestType; -import de.westnordost.streetcomplete.data.osm.changes.StringMapChangesBuilder; -import de.westnordost.streetcomplete.data.osm.download.OverpassMapDataDao; -import de.westnordost.streetcomplete.quests.AbstractQuestAnswerFragment; - -public class AddBusStopName extends SimpleOverpassQuestType -{ - - @Inject public AddBusStopName(OverpassMapDataDao overpassServer) { super(overpassServer); } - - @Override protected String getTagFilters() - { - return " nodes, ways with !name and noname != yes" + - " and (public_transport=platform or (highway=bus_stop and public_transport!=stop_position))"; - } - - @Override public AbstractQuestAnswerFragment createForm() - { - return new AddBusStopNameForm(); - } - - @Override public void applyAnswerTo(Bundle answer, StringMapChangesBuilder changes) - { - if(answer.getBoolean(AddBusStopNameForm.NO_NAME)) - { - changes.add("noname", "yes"); - return; - } - - String name = answer.getString(AddBusStopNameForm.NAME); - if(name != null) changes.add("name", name); - } - - @Override public String getCommitMessage() { return "Determine bus stop names"; } - @Override public int getIcon() { return R.drawable.ic_quest_bus_stop_name; } - @Override public int getTitle(@NonNull Map tags) - { - return R.string.quest_busStopName_title; - } -} diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/bus_stop_name/AddBusStopNameForm.java b/app/src/main/java/de/westnordost/streetcomplete/quests/bus_stop_name/AddBusStopNameForm.java deleted file mode 100644 index eb96d6c540..0000000000 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/bus_stop_name/AddBusStopNameForm.java +++ /dev/null @@ -1,60 +0,0 @@ -package de.westnordost.streetcomplete.quests.bus_stop_name; - -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.EditText; - -import de.westnordost.streetcomplete.R; -import de.westnordost.streetcomplete.quests.AbstractQuestFormAnswerFragment; -import de.westnordost.streetcomplete.view.dialogs.AlertDialogBuilder; - -public class AddBusStopNameForm extends AbstractQuestFormAnswerFragment -{ - public static final String NO_NAME = "no_name"; - public static final String NAME = "name"; - - private EditText nameInput; - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) - { - View view = super.onCreateView(inflater, container, savedInstanceState); - - View contentView = setContentView(R.layout.quest_placename); - nameInput = contentView.findViewById(R.id.nameInput); - - addOtherAnswer(R.string.quest_name_answer_noName, this::confirmNoName); - - return view; - } - - @Override protected void onClickOk() - { - Bundle data = new Bundle(); - String name = nameInput.getText().toString().trim(); - data.putString(NAME, name); - applyFormAnswer(data); - } - - private void confirmNoName() - { - new AlertDialogBuilder(getActivity()) - .setTitle(R.string.quest_name_answer_noName_confirmation_title) - .setPositiveButton(R.string.quest_name_noName_confirmation_positive, (dialog, which) -> - { - Bundle data = new Bundle(); - data.putBoolean(NO_NAME, true); - applyImmediateAnswer(data); - }) - .setNegativeButton(R.string.quest_generic_confirmation_no, null) - .show(); - } - - @Override public boolean hasChanges() - { - return !nameInput.getText().toString().trim().isEmpty(); - } -} diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddBusStopName.java b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddBusStopName.java new file mode 100644 index 0000000000..94940023a2 --- /dev/null +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddBusStopName.java @@ -0,0 +1,88 @@ +package de.westnordost.streetcomplete.quests.localized_name; + +import android.os.Bundle; +import android.support.annotation.NonNull; + +import java.util.HashMap; +import java.util.Map; + +import javax.inject.Inject; + +import de.westnordost.streetcomplete.R; +import de.westnordost.streetcomplete.data.osm.SimpleOverpassQuestType; +import de.westnordost.streetcomplete.data.osm.changes.StringMapChangesBuilder; +import de.westnordost.streetcomplete.data.osm.download.OverpassMapDataDao; +import de.westnordost.streetcomplete.quests.AbstractQuestAnswerFragment; + +public class AddBusStopName extends SimpleOverpassQuestType +{ + + @Inject public AddBusStopName(OverpassMapDataDao overpassServer) { super(overpassServer); } + + @Override protected String getTagFilters() + { + return "nodes with" + + " ((public_transport=platform and (bus=yes or trolleybus=yes or tram=yes))" + + " or" + + " (highway=bus_stop and public_transport!=stop_position))" + + " and !name and noname != yes"; + } + + @Override public AbstractQuestAnswerFragment createForm() + { + return new AddBusStopNameForm(); + } + + @Override public void applyAnswerTo(Bundle answer, StringMapChangesBuilder changes) + { + if(answer.getBoolean(AddBusStopNameForm.NO_NAME)) + { + changes.add("noname", "yes"); + return; + } + + String[] names = answer.getStringArray(AddRoadNameForm.NAMES); + String[] languages = answer.getStringArray(AddRoadNameForm.LANGUAGE_CODES); + + HashMap stopNameByLanguage = toStopNameByLanguage(names, languages); + for (Map.Entry e : stopNameByLanguage.entrySet()) + { + if(e.getKey().isEmpty()) + { + changes.add("name", e.getValue()); + } + else + { + changes.add("name:" + e.getKey(), e.getValue()); + } + } + } + + private static HashMap toStopNameByLanguage(String[] names, String[] languages) + { + HashMap result = new HashMap<>(); + result.put("", names[0]); + // add languages only if there is more than one name specified. If there is more than one + // name, the "main" name (name specified in top row) is also added with the language. + if(names.length > 1) + { + for (int i = 0; i < names.length; i++) + { + // (the first) element may have no specific language + if(!languages[i].isEmpty()) + { + result.put(languages[i], names[i]); + } + } + } + return result; + } + + @Override public String getCommitMessage() { return "Determine bus/tram stop names"; } + @Override public int getIcon() { return R.drawable.ic_quest_bus_stop_name; } + @Override public int getTitle(@NonNull Map tags) + { + String tram = tags.get("tram"); + return (tram != null && tram.equals("yes")) ? R.string.quest_tramStopName_title : R.string.quest_busStopName_title; + } +} diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddBusStopNameForm.java b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddBusStopNameForm.java new file mode 100644 index 0000000000..1cc50ebda0 --- /dev/null +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddBusStopNameForm.java @@ -0,0 +1,110 @@ +package de.westnordost.streetcomplete.quests.localized_name; + +import android.content.DialogInterface; +import android.os.Bundle; +import android.support.v7.app.AlertDialog; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import de.westnordost.osmapi.map.data.LatLon; +import de.westnordost.streetcomplete.Injector; +import de.westnordost.streetcomplete.R; +import de.westnordost.streetcomplete.data.osm.ElementGeometry; +import de.westnordost.streetcomplete.view.dialogs.AlertDialogBuilder; + +public class AddBusStopNameForm extends AddLocalizedNameForm +{ + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) + { + View view = super.onCreateView(inflater, container, savedInstanceState); + + View contentView = setContentView(R.layout.quest_localizedname); + + addOtherAnswers(); + + initLocalizedNameAdapter(contentView, savedInstanceState); + + return view; + } + + protected void addOtherAnswers() + { + addOtherAnswer(R.string.quest_name_answer_noName, this::confirmNoStreetName); + addOtherAnswer(R.string.quest_streetName_answer_cantType, this::showKeyboardInfo); + } + + @Override + protected void initLocalizedNameAdapter(View contentView, Bundle savedInstanceState) + { + ArrayList data; + if(savedInstanceState != null) + { + data = serializer.toObject(savedInstanceState.getByteArray(LOCALIZED_NAMES_DATA),ArrayList.class); + } + else + { + data = new ArrayList<>(); + } + + Button addLanguageButton = contentView.findViewById(R.id.btn_add); + + adapter = new AddLocalizedNameAdapter( + data, getActivity(), getPossibleStreetsignLanguages(), + abbreviationsByLocale, null, addLanguageButton); + RecyclerView recyclerView = contentView.findViewById(R.id.roadnames); + recyclerView.setLayoutManager( + new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false)); + recyclerView.setAdapter(adapter); + recyclerView.setNestedScrollingEnabled(false); + } + + @Override + protected void applyNameAnswer() + { + Bundle bundle = new Bundle(); + ArrayList data = adapter.getData(); + + String[] names = new String[data.size()]; + String[] languageCodes = new String[data.size()]; + for (int i = 0; i + { + Bundle data = new Bundle(); + data.putBoolean(NO_NAME, true); + applyImmediateAnswer(data); + }) + .setNegativeButton(R.string.quest_generic_confirmation_no, null) + .show(); + } + + @Override public boolean hasChanges() + { + // either the user added a language or typed something for the street name + return adapter.getData().size() > 1 || !adapter.getData().get(0).name.trim().isEmpty(); + } +} diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/road_name/AddRoadNameAdapter.java b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddLocalizedNameAdapter.java similarity index 64% rename from app/src/main/java/de/westnordost/streetcomplete/quests/road_name/AddRoadNameAdapter.java rename to app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddLocalizedNameAdapter.java index 887ce81820..615712ec79 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/road_name/AddRoadNameAdapter.java +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddLocalizedNameAdapter.java @@ -1,4 +1,4 @@ -package de.westnordost.streetcomplete.quests.road_name; +package de.westnordost.streetcomplete.quests.localized_name; import android.content.Context; import android.graphics.Typeface; @@ -26,30 +26,30 @@ import static android.view.Menu.NONE; -public class AddRoadNameAdapter extends RecyclerView.Adapter +public class AddLocalizedNameAdapter extends RecyclerView.Adapter { - private ArrayList data; + private ArrayList data; private final Context context; private final List languages; private final AbbreviationsByLocale abbreviationsByLocale; - private final List> roadNameSuggestions; + private final List> localizedNameSuggestions; private final Button addLanguageButton; - public AddRoadNameAdapter(ArrayList data, Context context, List languages, - AbbreviationsByLocale abbreviationsByLocale, - List> roadNameSuggestions, Button addLanguageButton) + public AddLocalizedNameAdapter(ArrayList data, Context context, List languages, + AbbreviationsByLocale abbreviationsByLocale, + List> localizedNameSuggestions, Button addLanguageButton) { if(data.isEmpty()) { - data.add(new RoadName(languages.get(0), "")); + data.add(new LocalizedName(languages.get(0), "")); } this.data = data; this.context = context; this.languages = languages; this.abbreviationsByLocale = abbreviationsByLocale; - this.roadNameSuggestions = roadNameSuggestions; - putDefaultRoadNameSuggestion(); + this.localizedNameSuggestions = localizedNameSuggestions; + putDefaultLocalizedNameSuggestion(); this.addLanguageButton = addLanguageButton; this.addLanguageButton.setOnClickListener(v -> { showLanguageSelectMenu(v, getNotAddedLanguages(), this::add); @@ -58,48 +58,47 @@ public AddRoadNameAdapter(ArrayList data, Context context, List roadNames : roadNameSuggestions) - { - if(roadNames.containsKey("")) - { - // name=A -> name=A, name:de=A (in Germany) - if(!roadNames.containsKey(defaultLanguage)) - { - String defaultName = roadNames.get(""); - roadNames.put(defaultLanguage, defaultName); + if(localizedNameSuggestions != null) { + for (Map names : localizedNameSuggestions) { + if (names.containsKey("")) { + // name=A -> name=A, name:de=A (in Germany) + if (!names.containsKey(defaultLanguage)) { + String defaultName = names.get(""); + names.put(defaultLanguage, defaultName); + } } } } } - private static ArrayList toRoadNameList(Map nameByLanguageMap) + private static ArrayList toLocalizedNameList(Map nameByLanguageMap) { - ArrayList result = new ArrayList<>(); + ArrayList result = new ArrayList<>(); String defaultName = nameByLanguageMap.get(""); for (Map.Entry entry : nameByLanguageMap.entrySet()) { // put default name first // (i.e. name=A, name:en=B, name:de=A -> name:de goes first and name is not shown) - RoadName roadName = new RoadName(entry.getKey(), entry.getValue()); - if(roadName.name.equals(defaultName)) + LocalizedName localizedName = new LocalizedName(entry.getKey(), entry.getValue()); + if(localizedName.name.equals(defaultName)) { - if(!roadName.languageCode.isEmpty()) result.add(0, roadName); + if(!localizedName.languageCode.isEmpty()) result.add(0, localizedName); } else { - result.add(roadName); + result.add(localizedName); } } // this is for the case: name=A, name:de=B, name:en=C -> name goes first if(!result.get(0).name.equals(defaultName)) { - result.add(0, new RoadName("",defaultName)); + result.add(0, new LocalizedName("",defaultName)); } return result; } @@ -107,7 +106,7 @@ private static ArrayList toRoadNameList(Map nameByLang @Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { LayoutInflater inflater = LayoutInflater.from(parent.getContext()); - return new ViewHolder(inflater.inflate(R.layout.quest_roadname_row, parent, false)); + return new ViewHolder(inflater.inflate(R.layout.quest_localizedname_row, parent, false)); } @Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) @@ -137,7 +136,7 @@ private void remove(int index) private void add(@NonNull String languageCode) { int insertIndex = getItemCount(); - data.add(new RoadName(languageCode, "")); + data.add(new LocalizedName(languageCode, "")); notifyItemInserted(insertIndex); updateAddLanguageButtonVisibility(); @@ -146,14 +145,14 @@ private void add(@NonNull String languageCode) private List getNotAddedLanguages() { List result = new ArrayList<>(languages); - for (RoadName roadName : data) + for (LocalizedName localizedName : data) { - result.remove(roadName.languageCode); + result.remove(localizedName.languageCode); } return result; } - public ArrayList getData() + public ArrayList getData() { return data; } @@ -205,55 +204,54 @@ private String getLanguageMenuItemTitle(String languageCode) } } - private interface OnRoadNameSuggestionSelected + private interface OnLocalizedNameSuggestionSelected { - void onRoadNameSuggestionSelected(Map selection); + void onLocalizedNameSuggestionSelected(Map selection); } private void showNameSuggestionsMenu(View v, - final Map> roadNameSuggestionsMap, - final OnRoadNameSuggestionSelected callback) + final Map> localizedNameSuggestionsMap, + final OnLocalizedNameSuggestionSelected callback) { PopupMenu m = new PopupMenu(context, v); int i = 0; - for (Map.Entry> entry : roadNameSuggestionsMap.entrySet()) + for (Map.Entry> entry : localizedNameSuggestionsMap.entrySet()) { m.getMenu().add(NONE,i++,NONE, entry.getKey()); } m.setOnMenuItemClickListener(item -> { - Map selected = roadNameSuggestionsMap.get(item.getTitle().toString()); - callback.onRoadNameSuggestionSelected(selected); + Map selected = localizedNameSuggestionsMap.get(item.getTitle().toString()); + callback.onLocalizedNameSuggestionSelected(selected); return true; }); m.show(); } - private Map> getRoadNameSuggestionsByLanguageCode(String languageCode) + private Map> getLocalizedNameSuggestionsByLanguageCode(String languageCode) { - final Map> roadNameSuggestionsMap = new HashMap<>(); - for (Map roadNameSuggestion : roadNameSuggestions) - { - String name = roadNameSuggestion.get(languageCode); - if(name == null) continue; - - // "unspecified language" suggestions - if(languageCode.isEmpty()) - { - int defaultNameOccurances = 0; - for(String other : roadNameSuggestion.values()) - { - if (name.equals(other)) defaultNameOccurances++; + final Map> localizedNameSuggestionsMap = new HashMap<>(); + if(localizedNameSuggestions != null) { + for (Map localizedNameSuggestion : localizedNameSuggestions) { + String name = localizedNameSuggestion.get(languageCode); + if (name == null) continue; + + // "unspecified language" suggestions + if (languageCode.isEmpty()) { + int defaultNameOccurances = 0; + for (String other : localizedNameSuggestion.values()) { + if (name.equals(other)) defaultNameOccurances++; + } + // name=A, name:de=A -> do not consider "A" for "unspecified language" suggestion + if (defaultNameOccurances >= 2) continue; + // only for name=A, name:de=B, name:en=C,... } - // name=A, name:de=A -> do not consider "A" for "unspecified language" suggestion - if (defaultNameOccurances >= 2) continue; - // only for name=A, name:de=B, name:en=C,... + localizedNameSuggestionsMap.put(name, localizedNameSuggestion); } - roadNameSuggestionsMap.put(name, roadNameSuggestion); } - return roadNameSuggestionsMap; + return localizedNameSuggestionsMap; } private class ViewHolder extends RecyclerView.ViewHolder @@ -263,7 +261,7 @@ private class ViewHolder extends RecyclerView.ViewHolder private final TextView deleteButton; private final View nameSuggestionsButton; - private RoadName roadName; + private LocalizedName localizedName; public ViewHolder(View itemView) { @@ -279,10 +277,10 @@ public ViewHolder(View itemView) @Override public void afterTextChanged(Editable s) { String name = s.toString(); - roadName.name = name; + localizedName.name = name; if(name.isEmpty()) { - boolean hasSuggestions = !getRoadNameSuggestionsByLanguageCode(roadName.languageCode).isEmpty(); + boolean hasSuggestions = !getLocalizedNameSuggestionsByLanguageCode(localizedName.languageCode).isEmpty(); nameSuggestionsButton.setVisibility(hasSuggestions ? View.VISIBLE : View.GONE); } else @@ -300,18 +298,18 @@ public ViewHolder(View itemView) }); } - public void update(final int index, RoadName rn) + public void update(final int index, LocalizedName rn) { - this.roadName = rn; + this.localizedName = rn; final boolean isFirst = index == 0; deleteButton.setVisibility(isFirst ? View.INVISIBLE : View.VISIBLE); languageButton.setVisibility(languages.size() > 1 ? View.VISIBLE : View.INVISIBLE); - nameInput.setText(roadName.name); + nameInput.setText(localizedName.name); nameInput.requestFocus(); - languageButton.setText(roadName.languageCode); + languageButton.setText(localizedName.languageCode); // first entry is bold (the first entry is supposed to be the "default language", I // hope that comes across to the users like this. Otherwise, a text hint is necessary) @@ -331,7 +329,7 @@ public void update(final int index, RoadName rn) showLanguageSelectMenu(v, notAddedLanguages, languageCode -> { - roadName.languageCode = languageCode; + localizedName.languageCode = languageCode; languageButton.setText(languageCode); updateAddLanguageButtonVisibility(); updateNameSuggestions(); @@ -345,7 +343,7 @@ public void update(final int index, RoadName rn) { @Override protected Abbreviations doInBackground(Void... params) { - return abbreviationsByLocale.get(new Locale(roadName.languageCode)); + return abbreviationsByLocale.get(new Locale(localizedName.languageCode)); } @Override protected void onPostExecute(Abbreviations abbreviations) @@ -357,17 +355,17 @@ public void update(final int index, RoadName rn) private void updateNameSuggestions() { - final Map> roadNameSuggestionsMap = - getRoadNameSuggestionsByLanguageCode(roadName.languageCode); + final Map> localizedNameSuggestionsMap = + getLocalizedNameSuggestionsByLanguageCode(localizedName.languageCode); boolean nameInputNotEmpty = !nameInput.getText().toString().isEmpty(); nameSuggestionsButton.setVisibility( - roadNameSuggestionsMap.isEmpty() || nameInputNotEmpty ? View.GONE : View.VISIBLE); + localizedNameSuggestionsMap.isEmpty() || nameInputNotEmpty ? View.GONE : View.VISIBLE); nameSuggestionsButton.setOnClickListener(v -> { - showNameSuggestionsMenu(v, roadNameSuggestionsMap, selection -> + showNameSuggestionsMenu(v, localizedNameSuggestionsMap, selection -> { - data = toRoadNameList(selection); + data = toLocalizedNameList(selection); notifyDataSetChanged(); updateAddLanguageButtonVisibility(); }); diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddLocalizedNameForm.java b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddLocalizedNameForm.java new file mode 100644 index 0000000000..d852dfd678 --- /dev/null +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddLocalizedNameForm.java @@ -0,0 +1,194 @@ +package de.westnordost.streetcomplete.quests.localized_name; + +import android.content.Intent; +import android.os.Bundle; +import android.provider.Settings; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.text.Html; +import android.text.Spanned; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.Toast; + +import java.util.ArrayList; +import java.util.LinkedHashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Locale; +import java.util.Queue; + +import javax.inject.Inject; + +import de.westnordost.streetcomplete.Injector; +import de.westnordost.streetcomplete.R; +import de.westnordost.streetcomplete.data.meta.Abbreviations; +import de.westnordost.streetcomplete.data.meta.AbbreviationsByLocale; +import de.westnordost.streetcomplete.quests.AbstractQuestFormAnswerFragment; +import de.westnordost.streetcomplete.util.Serializer; +import de.westnordost.streetcomplete.view.dialogs.AlertDialogBuilder; + +public abstract class AddLocalizedNameForm extends AbstractQuestFormAnswerFragment +{ + protected static final String LOCALIZED_NAMES_DATA = "localized_names_data"; + + public static final String + NO_NAME = "no_name", + NAMES = "names", + LANGUAGE_CODES = "language_codes"; + + @Inject AbbreviationsByLocale abbreviationsByLocale; + @Inject Serializer serializer; + + protected AddLocalizedNameAdapter adapter; + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) + { + View view = super.onCreateView(inflater, container, savedInstanceState); + + Injector.instance.getApplicationComponent().inject(this); + + return view; + } + + protected abstract void addOtherAnswers(); + + protected void initLocalizedNameAdapter(View contentView, Bundle savedInstanceState) + { + ArrayList data; + if(savedInstanceState != null) + { + data = serializer.toObject(savedInstanceState.getByteArray(LOCALIZED_NAMES_DATA),ArrayList.class); + } + else + { + data = new ArrayList<>(); + } + + Button addLanguageButton = contentView.findViewById(R.id.btn_add); + + adapter = new AddLocalizedNameAdapter( + data, getActivity(), getPossibleStreetsignLanguages(), + abbreviationsByLocale, null, addLanguageButton); + RecyclerView recyclerView = contentView.findViewById(R.id.roadnames); + recyclerView.setLayoutManager( + new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false)); + recyclerView.setAdapter(adapter); + recyclerView.setNestedScrollingEnabled(false); + } + + protected List getPossibleStreetsignLanguages() + { + List possibleStreetsignLanguages = new ArrayList<>(); + possibleStreetsignLanguages.addAll(getCountryInfo().getOfficialLanguages()); + possibleStreetsignLanguages.addAll(getCountryInfo().getAdditionalStreetsignLanguages()); + // removes duplicates + return new ArrayList<>(new LinkedHashSet<>(possibleStreetsignLanguages)); + } + + @Override public void onSaveInstanceState(Bundle outState) + { + super.onSaveInstanceState(outState); + outState.putByteArray(LOCALIZED_NAMES_DATA, serializer.toBytes(adapter.getData())); + } + + @Override protected void onClickOk() + { + LinkedList possibleAbbreviations = new LinkedList<>(); + for (LocalizedName localizedName : adapter.getData()) + { + String name = localizedName.name; + if(name.trim().isEmpty()) + { + Toast.makeText(getActivity(), R.string.quest_generic_error_a_field_empty, + Toast.LENGTH_LONG).show(); + return; + } + + Abbreviations abbr = abbreviationsByLocale.get(new Locale(localizedName.languageCode)); + boolean containsAbbreviations = abbr != null && abbr.containsAbbreviations(name); + + if (name.contains(".") || containsAbbreviations) + { + possibleAbbreviations.add(name); + } + } + + confirmPossibleAbbreviationsIfAny(possibleAbbreviations, this::applyNameAnswer); + } + + protected void applyNameAnswer() + { + Bundle bundle = new Bundle(); + ArrayList data = adapter.getData(); + + String[] names = new String[data.size()]; + String[] languageCodes = new String[data.size()]; + for (int i = 0; i names, final Runnable onConfirmedAll) + { + if(names.isEmpty()) + { + onConfirmedAll.run(); + } + else + { + /* recursively call self on confirm until the list of not-abbreviations to confirm is + through */ + String name = names.remove(); + confirmPossibleAbbreviation(name, + () -> confirmPossibleAbbreviationsIfAny(names, onConfirmedAll)); + } + } + + protected void confirmPossibleAbbreviation(String name, final Runnable onConfirmed) + { + Spanned title = Html.fromHtml(getResources().getString( + R.string.quest_streetName_nameWithAbbreviations_confirmation_title_name, + ""+ Html.escapeHtml(name)+"")); + + new AlertDialogBuilder(getActivity()) + .setTitle(title) + .setMessage(R.string.quest_streetName_nameWithAbbreviations_confirmation_description) + .setPositiveButton(R.string.quest_streetName_nameWithAbbreviations_confirmation_positive, (dialog, which) -> onConfirmed.run()) + .setNegativeButton(R.string.quest_generic_confirmation_no, null) + .show(); + } + + protected void showKeyboardInfo() + { + new AlertDialogBuilder(getActivity()) + .setTitle(R.string.quest_streetName_cantType_title) + .setMessage(R.string.quest_streetName_cantType_description) + .setPositiveButton(R.string.quest_streetName_cantType_open_settings, + (dialog, which) -> startActivity(new Intent(Settings.ACTION_SETTINGS))) + .setNeutralButton(R.string.quest_streetName_cantType_open_store, (dialog, which) -> + { + Intent intent = new Intent(Intent.ACTION_MAIN); + intent.addCategory(Intent.CATEGORY_APP_MARKET); + startActivity(intent); + }) + .setNegativeButton(android.R.string.cancel, null) + .show(); + } + + @Override public boolean hasChanges() + { + // either the user added a language or typed something for the street name + return adapter.getData().size() > 1 || !adapter.getData().get(0).name.trim().isEmpty(); + } +} diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/road_name/AddRoadName.java b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddRoadName.java similarity index 96% rename from app/src/main/java/de/westnordost/streetcomplete/quests/road_name/AddRoadName.java rename to app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddRoadName.java index 7daa49c7e6..0688286109 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/road_name/AddRoadName.java +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddRoadName.java @@ -1,4 +1,4 @@ -package de.westnordost.streetcomplete.quests.road_name; +package de.westnordost.streetcomplete.quests.localized_name; import android.os.Bundle; import android.support.annotation.NonNull; @@ -24,8 +24,8 @@ import de.westnordost.streetcomplete.data.osm.tql.TagFilterExpression; import de.westnordost.streetcomplete.quests.AbstractQuestAnswerFragment; import de.westnordost.streetcomplete.data.osm.changes.StringMapChangesBuilder; -import de.westnordost.streetcomplete.quests.road_name.data.PutRoadNameSuggestionsHandler; -import de.westnordost.streetcomplete.quests.road_name.data.RoadNameSuggestionsDao; +import de.westnordost.streetcomplete.quests.localized_name.data.PutRoadNameSuggestionsHandler; +import de.westnordost.streetcomplete.quests.localized_name.data.RoadNameSuggestionsDao; public class AddRoadName implements OsmElementQuestType { diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/road_name/AddRoadNameForm.java b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddRoadNameForm.java similarity index 55% rename from app/src/main/java/de/westnordost/streetcomplete/quests/road_name/AddRoadNameForm.java rename to app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddRoadNameForm.java index 0f1eb4486e..e65ac4eeea 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/road_name/AddRoadNameForm.java +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddRoadNameForm.java @@ -1,61 +1,40 @@ -package de.westnordost.streetcomplete.quests.road_name; +package de.westnordost.streetcomplete.quests.localized_name; import android.content.DialogInterface; -import android.content.Intent; import android.os.Bundle; -import android.provider.Settings; import android.support.v7.app.AlertDialog; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; -import android.text.Html; -import android.text.Spanned; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; -import android.widget.Toast; import java.util.ArrayList; import java.util.Arrays; -import java.util.LinkedHashSet; -import java.util.LinkedList; import java.util.List; -import java.util.Locale; import java.util.Map; -import java.util.Queue; import javax.inject.Inject; import de.westnordost.osmapi.map.data.LatLon; import de.westnordost.streetcomplete.Injector; import de.westnordost.streetcomplete.R; -import de.westnordost.streetcomplete.data.meta.Abbreviations; -import de.westnordost.streetcomplete.data.meta.AbbreviationsByLocale; import de.westnordost.streetcomplete.data.osm.ElementGeometry; -import de.westnordost.streetcomplete.quests.AbstractQuestFormAnswerFragment; -import de.westnordost.streetcomplete.quests.road_name.data.RoadNameSuggestionsDao; -import de.westnordost.streetcomplete.util.Serializer; +import de.westnordost.streetcomplete.quests.localized_name.data.RoadNameSuggestionsDao; import de.westnordost.streetcomplete.view.dialogs.AlertDialogBuilder; -public class AddRoadNameForm extends AbstractQuestFormAnswerFragment +public class AddRoadNameForm extends AddLocalizedNameForm { - private static final String ROAD_NAMES_DATA = "road_names_data"; public static final String - NO_NAME = "no_name", NO_PROPER_ROAD = "no_proper_road", - NAMES = "names", - LANGUAGE_CODES = "language_codes", WAY_ID = "way_id", WAY_GEOMETRY = "way_geometry"; public static final int IS_SERVICE = 1, IS_LINK = 2, IS_TRACK = 3; - @Inject AbbreviationsByLocale abbreviationsByLocale; @Inject RoadNameSuggestionsDao roadNameSuggestionsDao; - @Inject Serializer serializer; - - private AddRoadNameAdapter adapter; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, @@ -65,27 +44,28 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Injector.instance.getApplicationComponent().inject(this); - View contentView = setContentView(R.layout.quest_roadname); + View contentView = setContentView(R.layout.quest_localizedname); addOtherAnswers(); - initRoadNameAdapter(contentView, savedInstanceState); + initLocalizedNameAdapter(contentView, savedInstanceState); return view; } - private void addOtherAnswers() + protected void addOtherAnswers() { addOtherAnswer(R.string.quest_name_answer_noName, this::selectNoStreetNameReason); addOtherAnswer(R.string.quest_streetName_answer_cantType, this::showKeyboardInfo); } - private void initRoadNameAdapter(View contentView, Bundle savedInstanceState) + @Override + protected void initLocalizedNameAdapter(View contentView, Bundle savedInstanceState) { - ArrayList data; + ArrayList data; if(savedInstanceState != null) { - data = serializer.toObject(savedInstanceState.getByteArray(ROAD_NAMES_DATA),ArrayList.class); + data = serializer.toObject(savedInstanceState.getByteArray(LOCALIZED_NAMES_DATA),ArrayList.class); } else { @@ -94,12 +74,12 @@ private void initRoadNameAdapter(View contentView, Bundle savedInstanceState) Button addLanguageButton = contentView.findViewById(R.id.btn_add); - adapter = new AddRoadNameAdapter( - data, getActivity(), getPossibleStreetsignLanguages(), - abbreviationsByLocale, getRoadnameSuggestions(), addLanguageButton); + adapter = new AddLocalizedNameAdapter( + data, getActivity(), getPossibleStreetsignLanguages(), + abbreviationsByLocale, getRoadnameSuggestions(), addLanguageButton); RecyclerView recyclerView = contentView.findViewById(R.id.roadnames); recyclerView.setLayoutManager( - new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false)); + new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false)); recyclerView.setAdapter(adapter); recyclerView.setNestedScrollingEnabled(false); } @@ -117,50 +97,11 @@ private List> getRoadnameSuggestions() return roadNameSuggestionsDao.getNames(onlyFirstAndLast, AddRoadName.MAX_DIST_FOR_ROAD_NAME_SUGGESTION); } - private List getPossibleStreetsignLanguages() - { - List possibleStreetsignLanguages = new ArrayList<>(); - possibleStreetsignLanguages.addAll(getCountryInfo().getOfficialLanguages()); - possibleStreetsignLanguages.addAll(getCountryInfo().getAdditionalStreetsignLanguages()); - // removes duplicates - return new ArrayList<>(new LinkedHashSet<>(possibleStreetsignLanguages)); - } - - @Override public void onSaveInstanceState(Bundle outState) - { - super.onSaveInstanceState(outState); - outState.putByteArray(ROAD_NAMES_DATA, serializer.toBytes(adapter.getData())); - } - - @Override protected void onClickOk() - { - LinkedList possibleAbbreviations = new LinkedList<>(); - for (RoadName roadName : adapter.getData()) - { - String name = roadName.name; - if(name.trim().isEmpty()) - { - Toast.makeText(getActivity(), R.string.quest_generic_error_a_field_empty, - Toast.LENGTH_LONG).show(); - return; - } - - Abbreviations abbr = abbreviationsByLocale.get(new Locale(roadName.languageCode)); - boolean containsAbbreviations = abbr != null && abbr.containsAbbreviations(name); - - if (name.contains(".") || containsAbbreviations) - { - possibleAbbreviations.add(name); - } - } - - confirmPossibleAbbreviationsIfAny(possibleAbbreviations, this::applyNameAnswer); - } - - private void applyNameAnswer() + @Override + protected void applyNameAnswer() { Bundle bundle = new Bundle(); - ArrayList data = adapter.getData(); + ArrayList data = adapter.getData(); String[] names = new String[data.size()]; String[] languageCodes = new String[data.size()]; @@ -177,53 +118,6 @@ private void applyNameAnswer() applyFormAnswer(bundle); } - private void confirmPossibleAbbreviationsIfAny(final Queue names, final Runnable onConfirmedAll) - { - if(names.isEmpty()) - { - onConfirmedAll.run(); - } - else - { - /* recursively call self on confirm until the list of not-abbreviations to confirm is - through */ - String name = names.remove(); - confirmPossibleAbbreviation(name, - () -> confirmPossibleAbbreviationsIfAny(names, onConfirmedAll)); - } - } - - private void confirmPossibleAbbreviation(String name, final Runnable onConfirmed) - { - Spanned title = Html.fromHtml(getResources().getString( - R.string.quest_streetName_nameWithAbbreviations_confirmation_title_name, - ""+ Html.escapeHtml(name)+"")); - - new AlertDialogBuilder(getActivity()) - .setTitle(title) - .setMessage(R.string.quest_streetName_nameWithAbbreviations_confirmation_description) - .setPositiveButton(R.string.quest_streetName_nameWithAbbreviations_confirmation_positive, (dialog, which) -> onConfirmed.run()) - .setNegativeButton(R.string.quest_generic_confirmation_no, null) - .show(); - } - - private void showKeyboardInfo() - { - new AlertDialogBuilder(getActivity()) - .setTitle(R.string.quest_streetName_cantType_title) - .setMessage(R.string.quest_streetName_cantType_description) - .setPositiveButton(R.string.quest_streetName_cantType_open_settings, - (dialog, which) -> startActivity(new Intent(Settings.ACTION_SETTINGS))) - .setNeutralButton(R.string.quest_streetName_cantType_open_store, (dialog, which) -> - { - Intent intent = new Intent(Intent.ACTION_MAIN); - intent.addCategory(Intent.CATEGORY_APP_MARKET); - startActivity(intent); - }) - .setNegativeButton(android.R.string.cancel, null) - .show(); - } - private void selectNoStreetNameReason() { final String diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/road_name/AutoCorrectAbbreviationsEditText.java b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AutoCorrectAbbreviationsEditText.java similarity index 98% rename from app/src/main/java/de/westnordost/streetcomplete/quests/road_name/AutoCorrectAbbreviationsEditText.java rename to app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AutoCorrectAbbreviationsEditText.java index 10c6e09ca2..6c4d1ec565 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/road_name/AutoCorrectAbbreviationsEditText.java +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AutoCorrectAbbreviationsEditText.java @@ -1,4 +1,4 @@ -package de.westnordost.streetcomplete.quests.road_name; +package de.westnordost.streetcomplete.quests.localized_name; import android.content.Context; import android.text.Editable; diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/road_name/RoadName.java b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/LocalizedName.java similarity index 59% rename from app/src/main/java/de/westnordost/streetcomplete/quests/road_name/RoadName.java rename to app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/LocalizedName.java index a4645b508f..51ad48f01f 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/road_name/RoadName.java +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/LocalizedName.java @@ -1,14 +1,14 @@ -package de.westnordost.streetcomplete.quests.road_name; +package de.westnordost.streetcomplete.quests.localized_name; import android.support.annotation.NonNull; /** Carries the data language code + name in that language */ -public class RoadName +public class LocalizedName { @NonNull public String languageCode; @NonNull public String name; - public RoadName(@NonNull String languageCode, @NonNull String name) + public LocalizedName(@NonNull String languageCode, @NonNull String name) { this.languageCode = languageCode; this.name = name; diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/road_name/data/PutRoadNameSuggestionsHandler.java b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/data/PutRoadNameSuggestionsHandler.java similarity index 96% rename from app/src/main/java/de/westnordost/streetcomplete/quests/road_name/data/PutRoadNameSuggestionsHandler.java rename to app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/data/PutRoadNameSuggestionsHandler.java index 1c4cf363aa..a9a493a99d 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/road_name/data/PutRoadNameSuggestionsHandler.java +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/data/PutRoadNameSuggestionsHandler.java @@ -1,4 +1,4 @@ -package de.westnordost.streetcomplete.quests.road_name.data; +package de.westnordost.streetcomplete.quests.localized_name.data; import android.support.annotation.NonNull; import android.support.annotation.Nullable; diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/road_name/data/RoadNameSuggestionsDao.java b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/data/RoadNameSuggestionsDao.java similarity index 98% rename from app/src/main/java/de/westnordost/streetcomplete/quests/road_name/data/RoadNameSuggestionsDao.java rename to app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/data/RoadNameSuggestionsDao.java index 7f1c1e8b99..f61c17f74e 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/road_name/data/RoadNameSuggestionsDao.java +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/data/RoadNameSuggestionsDao.java @@ -1,4 +1,4 @@ -package de.westnordost.streetcomplete.quests.road_name.data; +package de.westnordost.streetcomplete.quests.localized_name.data; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/road_name/data/RoadNamesTable.java b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/data/RoadNamesTable.java similarity index 84% rename from app/src/main/java/de/westnordost/streetcomplete/quests/road_name/data/RoadNamesTable.java rename to app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/data/RoadNamesTable.java index e2a6e81801..85022b763d 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/road_name/data/RoadNamesTable.java +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/data/RoadNamesTable.java @@ -1,4 +1,4 @@ -package de.westnordost.streetcomplete.quests.road_name.data; +package de.westnordost.streetcomplete.quests.localized_name.data; public class RoadNamesTable { diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/road_name/data/RoadNamesTablesHelper.java b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/data/RoadNamesTablesHelper.java similarity index 93% rename from app/src/main/java/de/westnordost/streetcomplete/quests/road_name/data/RoadNamesTablesHelper.java rename to app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/data/RoadNamesTablesHelper.java index bbbfc59e5b..b3cd77a337 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/road_name/data/RoadNamesTablesHelper.java +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/data/RoadNamesTablesHelper.java @@ -1,4 +1,4 @@ -package de.westnordost.streetcomplete.quests.road_name.data; +package de.westnordost.streetcomplete.quests.localized_name.data; import android.database.sqlite.SQLiteDatabase; diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/place_name/AddPlaceNameForm.java b/app/src/main/java/de/westnordost/streetcomplete/quests/place_name/AddPlaceNameForm.java index e0b79c28fe..f45eb47981 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/place_name/AddPlaceNameForm.java +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/place_name/AddPlaceNameForm.java @@ -42,15 +42,15 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, private void confirmNoName() { new AlertDialogBuilder(getActivity()) - .setTitle(R.string.quest_name_answer_noName_confirmation_title) - .setPositiveButton(R.string.quest_name_noName_confirmation_positive, (dialog, which) -> - { - Bundle data = new Bundle(); - data.putBoolean(NO_NAME, true); - applyImmediateAnswer(data); - }) - .setNegativeButton(R.string.quest_generic_confirmation_no, null) - .show(); + .setTitle(R.string.quest_name_answer_noName_confirmation_title) + .setPositiveButton(R.string.quest_name_noName_confirmation_positive, (dialog, which) -> + { + Bundle data = new Bundle(); + data.putBoolean(NO_NAME, true); + applyImmediateAnswer(data); + }) + .setNegativeButton(R.string.quest_generic_confirmation_no, null) + .show(); } @Override public boolean hasChanges() diff --git a/app/src/main/java/de/westnordost/streetcomplete/util/KryoSerializer.java b/app/src/main/java/de/westnordost/streetcomplete/util/KryoSerializer.java index aaf1442fe9..d79a84d35f 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/util/KryoSerializer.java +++ b/app/src/main/java/de/westnordost/streetcomplete/util/KryoSerializer.java @@ -26,7 +26,7 @@ import de.westnordost.streetcomplete.quests.opening_hours.OpeningWeekdays; import de.westnordost.streetcomplete.quests.opening_hours.TimeRange; import de.westnordost.streetcomplete.quests.opening_hours.Weekdays; -import de.westnordost.streetcomplete.quests.road_name.RoadName; +import de.westnordost.streetcomplete.quests.localized_name.LocalizedName; @Singleton public class KryoSerializer implements Serializer @@ -55,7 +55,7 @@ public class KryoSerializer implements Serializer boolean[].class, OpeningMonths.class, OpeningWeekdays.class, - RoadName.class + LocalizedName.class }; diff --git a/app/src/main/res/drawable/ic_quest_bus_stop_name.xml b/app/src/main/res/drawable/ic_quest_bus_stop_name.xml index 089e65b4aa..5fa3e7b69b 100644 --- a/app/src/main/res/drawable/ic_quest_bus_stop_name.xml +++ b/app/src/main/res/drawable/ic_quest_bus_stop_name.xml @@ -1,170 +1,87 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/quest_roadname.xml b/app/src/main/res/layout/quest_localizedname.xml similarity index 100% rename from app/src/main/res/layout/quest_roadname.xml rename to app/src/main/res/layout/quest_localizedname.xml diff --git a/app/src/main/res/layout/quest_roadname_row.xml b/app/src/main/res/layout/quest_localizedname_row.xml similarity index 95% rename from app/src/main/res/layout/quest_roadname_row.xml rename to app/src/main/res/layout/quest_localizedname_row.xml index 5ca13f2a2e..e98bc7047c 100644 --- a/app/src/main/res/layout/quest_roadname_row.xml +++ b/app/src/main/res/layout/quest_localizedname_row.xml @@ -28,7 +28,7 @@ android:paddingEnd="14dp" > - - \ No newline at end of file + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b17bbce5cf..888cebaa4b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -198,6 +198,7 @@ To display the map, vector tiles are retrieved from the <a href=\"https://map "Wood" "What is the name of this place?" "What is the name of this bus stop?" + "What is the name of this tram stop?" "Is there a sidewalk in this street?" "The map is oriented north up." "Only on northern side" From 053807f88acb56872d3e4575b30e4554cf1e5eb4 Mon Sep 17 00:00:00 2001 From: PanierAvide Date: Wed, 28 Mar 2018 18:41:27 +0200 Subject: [PATCH 5/7] Missing bus stop name : fixed quest --- .../localized_name/AddBusStopNameForm.java | 19 +++++------ .../AddLocalizedNameAdapter.java | 2 +- .../localized_name/AddLocalizedNameForm.java | 33 +------------------ .../quests/localized_name/AddRoadName.java | 2 +- .../localized_name/AddRoadNameForm.java | 31 +++++++++++++++++ 5 files changed, 42 insertions(+), 45 deletions(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddBusStopNameForm.java b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddBusStopNameForm.java index 1cc50ebda0..7f93ceeb9b 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddBusStopNameForm.java +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddBusStopNameForm.java @@ -1,8 +1,6 @@ package de.westnordost.streetcomplete.quests.localized_name; -import android.content.DialogInterface; import android.os.Bundle; -import android.support.v7.app.AlertDialog; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; @@ -11,14 +9,8 @@ import android.widget.Button; import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import de.westnordost.osmapi.map.data.LatLon; -import de.westnordost.streetcomplete.Injector; import de.westnordost.streetcomplete.R; -import de.westnordost.streetcomplete.data.osm.ElementGeometry; import de.westnordost.streetcomplete.view.dialogs.AlertDialogBuilder; public class AddBusStopNameForm extends AddLocalizedNameForm @@ -38,9 +30,14 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, return view; } + @Override + protected void onClickOk() { + this.applyNameAnswer(); + } + protected void addOtherAnswers() { - addOtherAnswer(R.string.quest_name_answer_noName, this::confirmNoStreetName); + addOtherAnswer(R.string.quest_name_answer_noName, this::confirmNoName); addOtherAnswer(R.string.quest_streetName_answer_cantType, this::showKeyboardInfo); } @@ -61,7 +58,7 @@ protected void initLocalizedNameAdapter(View contentView, Bundle savedInstanceSt adapter = new AddLocalizedNameAdapter( data, getActivity(), getPossibleStreetsignLanguages(), - abbreviationsByLocale, null, addLanguageButton); + null, null, addLanguageButton); RecyclerView recyclerView = contentView.findViewById(R.id.roadnames); recyclerView.setLayoutManager( new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false)); @@ -88,7 +85,7 @@ protected void applyNameAnswer() applyFormAnswer(bundle); } - private void confirmNoStreetName() + private void confirmNoName() { new AlertDialogBuilder(getActivity()) .setTitle(R.string.quest_name_answer_noName_confirmation_title) diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddLocalizedNameAdapter.java b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddLocalizedNameAdapter.java index 615712ec79..06da2d0746 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddLocalizedNameAdapter.java +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddLocalizedNameAdapter.java @@ -343,7 +343,7 @@ public void update(final int index, LocalizedName rn) { @Override protected Abbreviations doInBackground(Void... params) { - return abbreviationsByLocale.get(new Locale(localizedName.languageCode)); + return abbreviationsByLocale != null ? abbreviationsByLocale.get(new Locale(localizedName.languageCode)) : null; } @Override protected void onPostExecute(Abbreviations abbreviations) diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddLocalizedNameForm.java b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddLocalizedNameForm.java index d852dfd678..549ae69b4f 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddLocalizedNameForm.java +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddLocalizedNameForm.java @@ -11,21 +11,16 @@ import android.view.View; import android.view.ViewGroup; import android.widget.Button; -import android.widget.Toast; import java.util.ArrayList; import java.util.LinkedHashSet; -import java.util.LinkedList; import java.util.List; -import java.util.Locale; import java.util.Queue; import javax.inject.Inject; import de.westnordost.streetcomplete.Injector; import de.westnordost.streetcomplete.R; -import de.westnordost.streetcomplete.data.meta.Abbreviations; -import de.westnordost.streetcomplete.data.meta.AbbreviationsByLocale; import de.westnordost.streetcomplete.quests.AbstractQuestFormAnswerFragment; import de.westnordost.streetcomplete.util.Serializer; import de.westnordost.streetcomplete.view.dialogs.AlertDialogBuilder; @@ -39,7 +34,6 @@ public abstract class AddLocalizedNameForm extends AbstractQuestFormAnswerFragme NAMES = "names", LANGUAGE_CODES = "language_codes"; - @Inject AbbreviationsByLocale abbreviationsByLocale; @Inject Serializer serializer; protected AddLocalizedNameAdapter adapter; @@ -73,7 +67,7 @@ protected void initLocalizedNameAdapter(View contentView, Bundle savedInstanceSt adapter = new AddLocalizedNameAdapter( data, getActivity(), getPossibleStreetsignLanguages(), - abbreviationsByLocale, null, addLanguageButton); + null, null, addLanguageButton); RecyclerView recyclerView = contentView.findViewById(R.id.roadnames); recyclerView.setLayoutManager( new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false)); @@ -96,31 +90,6 @@ protected List getPossibleStreetsignLanguages() outState.putByteArray(LOCALIZED_NAMES_DATA, serializer.toBytes(adapter.getData())); } - @Override protected void onClickOk() - { - LinkedList possibleAbbreviations = new LinkedList<>(); - for (LocalizedName localizedName : adapter.getData()) - { - String name = localizedName.name; - if(name.trim().isEmpty()) - { - Toast.makeText(getActivity(), R.string.quest_generic_error_a_field_empty, - Toast.LENGTH_LONG).show(); - return; - } - - Abbreviations abbr = abbreviationsByLocale.get(new Locale(localizedName.languageCode)); - boolean containsAbbreviations = abbr != null && abbr.containsAbbreviations(name); - - if (name.contains(".") || containsAbbreviations) - { - possibleAbbreviations.add(name); - } - } - - confirmPossibleAbbreviationsIfAny(possibleAbbreviations, this::applyNameAnswer); - } - protected void applyNameAnswer() { Bundle bundle = new Bundle(); diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddRoadName.java b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddRoadName.java index 0688286109..1db396b7a1 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddRoadName.java +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddRoadName.java @@ -17,13 +17,13 @@ import de.westnordost.streetcomplete.data.osm.Countries; import de.westnordost.streetcomplete.data.osm.ElementGeometry; import de.westnordost.streetcomplete.data.osm.OsmElementQuestType; +import de.westnordost.streetcomplete.data.osm.changes.StringMapChangesBuilder; import de.westnordost.streetcomplete.data.osm.download.MapDataWithGeometryHandler; import de.westnordost.streetcomplete.data.osm.download.OverpassMapDataDao; import de.westnordost.streetcomplete.data.osm.tql.FiltersParser; import de.westnordost.streetcomplete.data.osm.tql.OverpassQLUtil; import de.westnordost.streetcomplete.data.osm.tql.TagFilterExpression; import de.westnordost.streetcomplete.quests.AbstractQuestAnswerFragment; -import de.westnordost.streetcomplete.data.osm.changes.StringMapChangesBuilder; import de.westnordost.streetcomplete.quests.localized_name.data.PutRoadNameSuggestionsHandler; import de.westnordost.streetcomplete.quests.localized_name.data.RoadNameSuggestionsDao; diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddRoadNameForm.java b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddRoadNameForm.java index e65ac4eeea..8ca632b948 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddRoadNameForm.java +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddRoadNameForm.java @@ -9,10 +9,13 @@ import android.view.View; import android.view.ViewGroup; import android.widget.Button; +import android.widget.Toast; import java.util.ArrayList; import java.util.Arrays; +import java.util.LinkedList; import java.util.List; +import java.util.Locale; import java.util.Map; import javax.inject.Inject; @@ -20,6 +23,8 @@ import de.westnordost.osmapi.map.data.LatLon; import de.westnordost.streetcomplete.Injector; import de.westnordost.streetcomplete.R; +import de.westnordost.streetcomplete.data.meta.Abbreviations; +import de.westnordost.streetcomplete.data.meta.AbbreviationsByLocale; import de.westnordost.streetcomplete.data.osm.ElementGeometry; import de.westnordost.streetcomplete.quests.localized_name.data.RoadNameSuggestionsDao; import de.westnordost.streetcomplete.view.dialogs.AlertDialogBuilder; @@ -34,6 +39,7 @@ public class AddRoadNameForm extends AddLocalizedNameForm public static final int IS_SERVICE = 1, IS_LINK = 2, IS_TRACK = 3; + @Inject AbbreviationsByLocale abbreviationsByLocale; @Inject RoadNameSuggestionsDao roadNameSuggestionsDao; @Override @@ -97,6 +103,31 @@ private List> getRoadnameSuggestions() return roadNameSuggestionsDao.getNames(onlyFirstAndLast, AddRoadName.MAX_DIST_FOR_ROAD_NAME_SUGGESTION); } + @Override protected void onClickOk() + { + LinkedList possibleAbbreviations = new LinkedList<>(); + for (LocalizedName localizedName : adapter.getData()) + { + String name = localizedName.name; + if(name.trim().isEmpty()) + { + Toast.makeText(getActivity(), R.string.quest_generic_error_a_field_empty, + Toast.LENGTH_LONG).show(); + return; + } + + Abbreviations abbr = abbreviationsByLocale.get(new Locale(localizedName.languageCode)); + boolean containsAbbreviations = abbr != null && abbr.containsAbbreviations(name); + + if (name.contains(".") || containsAbbreviations) + { + possibleAbbreviations.add(name); + } + } + + confirmPossibleAbbreviationsIfAny(possibleAbbreviations, this::applyNameAnswer); + } + @Override protected void applyNameAnswer() { From f55c0833f045770c1488a9deae723345e579e27b Mon Sep 17 00:00:00 2001 From: PanierAvide Date: Thu, 29 Mar 2018 08:26:17 +0200 Subject: [PATCH 6/7] Localized name quests : more merging of common methods --- .../quests/localized_name/AddBusStopName.java | 26 +-------- .../localized_name/AddBusStopNameForm.java | 58 +------------------ .../AddLocalizedNameAdapter.java | 5 +- .../localized_name/AddLocalizedNameForm.java | 43 ++++++++++++-- .../quests/localized_name/AddRoadName.java | 22 +------ .../localized_name/AddRoadNameForm.java | 44 ++------------ 6 files changed, 50 insertions(+), 148 deletions(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddBusStopName.java b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddBusStopName.java index 94940023a2..7e9a220285 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddBusStopName.java +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddBusStopName.java @@ -41,10 +41,10 @@ public class AddBusStopName extends SimpleOverpassQuestType return; } - String[] names = answer.getStringArray(AddRoadNameForm.NAMES); - String[] languages = answer.getStringArray(AddRoadNameForm.LANGUAGE_CODES); + String[] names = answer.getStringArray(AddLocalizedNameForm.NAMES); + String[] languages = answer.getStringArray(AddLocalizedNameForm.LANGUAGE_CODES); - HashMap stopNameByLanguage = toStopNameByLanguage(names, languages); + HashMap stopNameByLanguage = AddLocalizedNameForm.toNameByLanguage(names, languages); for (Map.Entry e : stopNameByLanguage.entrySet()) { if(e.getKey().isEmpty()) @@ -58,26 +58,6 @@ public class AddBusStopName extends SimpleOverpassQuestType } } - private static HashMap toStopNameByLanguage(String[] names, String[] languages) - { - HashMap result = new HashMap<>(); - result.put("", names[0]); - // add languages only if there is more than one name specified. If there is more than one - // name, the "main" name (name specified in top row) is also added with the language. - if(names.length > 1) - { - for (int i = 0; i < names.length; i++) - { - // (the first) element may have no specific language - if(!languages[i].isEmpty()) - { - result.put(languages[i], names[i]); - } - } - } - return result; - } - @Override public String getCommitMessage() { return "Determine bus/tram stop names"; } @Override public int getIcon() { return R.drawable.ic_quest_bus_stop_name; } @Override public int getTitle(@NonNull Map tags) diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddBusStopNameForm.java b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddBusStopNameForm.java index 7f93ceeb9b..4c1ec43510 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddBusStopNameForm.java +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddBusStopNameForm.java @@ -23,7 +23,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, View contentView = setContentView(R.layout.quest_localizedname); - addOtherAnswers(); + addOtherAnswers(this::confirmNoName); initLocalizedNameAdapter(contentView, savedInstanceState); @@ -35,56 +35,6 @@ protected void onClickOk() { this.applyNameAnswer(); } - protected void addOtherAnswers() - { - addOtherAnswer(R.string.quest_name_answer_noName, this::confirmNoName); - addOtherAnswer(R.string.quest_streetName_answer_cantType, this::showKeyboardInfo); - } - - @Override - protected void initLocalizedNameAdapter(View contentView, Bundle savedInstanceState) - { - ArrayList data; - if(savedInstanceState != null) - { - data = serializer.toObject(savedInstanceState.getByteArray(LOCALIZED_NAMES_DATA),ArrayList.class); - } - else - { - data = new ArrayList<>(); - } - - Button addLanguageButton = contentView.findViewById(R.id.btn_add); - - adapter = new AddLocalizedNameAdapter( - data, getActivity(), getPossibleStreetsignLanguages(), - null, null, addLanguageButton); - RecyclerView recyclerView = contentView.findViewById(R.id.roadnames); - recyclerView.setLayoutManager( - new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false)); - recyclerView.setAdapter(adapter); - recyclerView.setNestedScrollingEnabled(false); - } - - @Override - protected void applyNameAnswer() - { - Bundle bundle = new Bundle(); - ArrayList data = adapter.getData(); - - String[] names = new String[data.size()]; - String[] languageCodes = new String[data.size()]; - for (int i = 0; i 1 || !adapter.getData().get(0).name.trim().isEmpty(); - } } diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddLocalizedNameAdapter.java b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddLocalizedNameAdapter.java index 06da2d0746..fbe9ad6ba8 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddLocalizedNameAdapter.java +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddLocalizedNameAdapter.java @@ -4,6 +4,7 @@ import android.graphics.Typeface; import android.os.AsyncTask; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.v7.widget.PopupMenu; import android.support.v7.widget.RecyclerView; import android.text.Editable; @@ -37,8 +38,8 @@ public class AddLocalizedNameAdapter extends RecyclerView.Adapter private final Button addLanguageButton; public AddLocalizedNameAdapter(ArrayList data, Context context, List languages, - AbbreviationsByLocale abbreviationsByLocale, - List> localizedNameSuggestions, Button addLanguageButton) + @Nullable AbbreviationsByLocale abbreviationsByLocale, + @Nullable List> localizedNameSuggestions, Button addLanguageButton) { if(data.isEmpty()) { diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddLocalizedNameForm.java b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddLocalizedNameForm.java index 549ae69b4f..b9efef6adb 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddLocalizedNameForm.java +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddLocalizedNameForm.java @@ -13,6 +13,7 @@ import android.widget.Button; import java.util.ArrayList; +import java.util.HashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Queue; @@ -49,7 +50,10 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, return view; } - protected abstract void addOtherAnswers(); + protected void addOtherAnswers(Runnable noNameAction) { + addOtherAnswer(R.string.quest_name_answer_noName, noNameAction); + addOtherAnswer(R.string.quest_streetName_answer_cantType, this::showKeyboardInfo); + } protected void initLocalizedNameAdapter(View contentView, Bundle savedInstanceState) { @@ -65,9 +69,7 @@ protected void initLocalizedNameAdapter(View contentView, Bundle savedInstanceSt Button addLanguageButton = contentView.findViewById(R.id.btn_add); - adapter = new AddLocalizedNameAdapter( - data, getActivity(), getPossibleStreetsignLanguages(), - null, null, addLanguageButton); + adapter = setupNameAdapter(data, addLanguageButton); RecyclerView recyclerView = contentView.findViewById(R.id.roadnames); recyclerView.setLayoutManager( new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false)); @@ -75,6 +77,12 @@ data, getActivity(), getPossibleStreetsignLanguages(), recyclerView.setNestedScrollingEnabled(false); } + protected AddLocalizedNameAdapter setupNameAdapter(ArrayList data, Button addLanguageButton) { + return new AddLocalizedNameAdapter( + data, getActivity(), getPossibleStreetsignLanguages(), + null, null, addLanguageButton); + } + protected List getPossibleStreetsignLanguages() { List possibleStreetsignLanguages = new ArrayList<>(); @@ -92,6 +100,10 @@ protected List getPossibleStreetsignLanguages() protected void applyNameAnswer() { + applyFormAnswer(prepareAnswerBundle()); + } + + protected Bundle prepareAnswerBundle() { Bundle bundle = new Bundle(); ArrayList data = adapter.getData(); @@ -105,7 +117,8 @@ protected void applyNameAnswer() bundle.putStringArray(NAMES, names); bundle.putStringArray(LANGUAGE_CODES, languageCodes); - applyFormAnswer(bundle); + + return bundle; } protected void confirmPossibleAbbreviationsIfAny(final Queue names, final Runnable onConfirmedAll) @@ -155,6 +168,26 @@ protected void showKeyboardInfo() .show(); } + protected static HashMap toNameByLanguage(String[] names, String[] languages) + { + HashMap result = new HashMap<>(); + result.put("", names[0]); + // add languages only if there is more than one name specified. If there is more than one + // name, the "main" name (name specified in top row) is also added with the language. + if(names.length > 1) + { + for (int i = 0; i < names.length; i++) + { + // (the first) element may have no specific language + if(!languages[i].isEmpty()) + { + result.put(languages[i], names[i]); + } + } + } + return result; + } + @Override public boolean hasChanges() { // either the user added a language or typed something for the street name diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddRoadName.java b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddRoadName.java index 1db396b7a1..0ecb6c0fdd 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddRoadName.java +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddRoadName.java @@ -111,7 +111,7 @@ else if(noProperRoad == AddRoadNameForm.IS_LINK) String[] names = answer.getStringArray(AddRoadNameForm.NAMES); String[] languages = answer.getStringArray(AddRoadNameForm.LANGUAGE_CODES); - HashMap roadNameByLanguage = toRoadNameByLanguage(names, languages); + HashMap roadNameByLanguage = AddLocalizedNameForm.toNameByLanguage(names, languages); for (Map.Entry e : roadNameByLanguage.entrySet()) { if(e.getKey().isEmpty()) @@ -136,26 +136,6 @@ else if(noProperRoad == AddRoadNameForm.IS_LINK) } } - private static HashMap toRoadNameByLanguage(String[] names, String[] languages) - { - HashMap result = new HashMap<>(); - result.put("", names[0]); - // add languages only if there is more than one name specified. If there is more than one - // name, the "main" name (name specified in top row) is also added with the language. - if(names.length > 1) - { - for (int i = 0; i < names.length; i++) - { - // (the first) element may have no specific language - if(!languages[i].isEmpty()) - { - result.put(languages[i], names[i]); - } - } - } - return result; - } - @Nullable @Override public Boolean isApplicableTo(Element element) { return ROADS_WITHOUT_NAMES_TFE.matches(element); diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddRoadNameForm.java b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddRoadNameForm.java index 8ca632b948..073343be7a 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddRoadNameForm.java +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddRoadNameForm.java @@ -52,42 +52,18 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, View contentView = setContentView(R.layout.quest_localizedname); - addOtherAnswers(); + addOtherAnswers(this::selectNoStreetNameReason); initLocalizedNameAdapter(contentView, savedInstanceState); return view; } - protected void addOtherAnswers() - { - addOtherAnswer(R.string.quest_name_answer_noName, this::selectNoStreetNameReason); - addOtherAnswer(R.string.quest_streetName_answer_cantType, this::showKeyboardInfo); - } - @Override - protected void initLocalizedNameAdapter(View contentView, Bundle savedInstanceState) - { - ArrayList data; - if(savedInstanceState != null) - { - data = serializer.toObject(savedInstanceState.getByteArray(LOCALIZED_NAMES_DATA),ArrayList.class); - } - else - { - data = new ArrayList<>(); - } - - Button addLanguageButton = contentView.findViewById(R.id.btn_add); - - adapter = new AddLocalizedNameAdapter( + protected AddLocalizedNameAdapter setupNameAdapter(ArrayList data, Button addLanguageButton) { + return new AddLocalizedNameAdapter( data, getActivity(), getPossibleStreetsignLanguages(), abbreviationsByLocale, getRoadnameSuggestions(), addLanguageButton); - RecyclerView recyclerView = contentView.findViewById(R.id.roadnames); - recyclerView.setLayoutManager( - new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false)); - recyclerView.setAdapter(adapter); - recyclerView.setNestedScrollingEnabled(false); } private List> getRoadnameSuggestions() @@ -131,19 +107,7 @@ private List> getRoadnameSuggestions() @Override protected void applyNameAnswer() { - Bundle bundle = new Bundle(); - ArrayList data = adapter.getData(); - - String[] names = new String[data.size()]; - String[] languageCodes = new String[data.size()]; - for (int i = 0; i Date: Fri, 30 Mar 2018 10:49:33 +0200 Subject: [PATCH 7/7] Localized name quest: refactoring of some methods --- .../quests/localized_name/AddBusStopName.java | 7 ++----- .../quests/localized_name/AddBusStopNameForm.java | 7 ++++++- .../localized_name/AddLocalizedNameForm.java | 14 ++++++-------- .../quests/localized_name/AddRoadName.java | 7 ++----- .../quests/localized_name/AddRoadNameForm.java | 7 ++++++- 5 files changed, 22 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddBusStopName.java b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddBusStopName.java index 7e9a220285..2d67edede1 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddBusStopName.java +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddBusStopName.java @@ -35,16 +35,13 @@ public class AddBusStopName extends SimpleOverpassQuestType @Override public void applyAnswerTo(Bundle answer, StringMapChangesBuilder changes) { - if(answer.getBoolean(AddBusStopNameForm.NO_NAME)) + if(answer.getBoolean(AddLocalizedNameForm.NO_NAME)) { changes.add("noname", "yes"); return; } - String[] names = answer.getStringArray(AddLocalizedNameForm.NAMES); - String[] languages = answer.getStringArray(AddLocalizedNameForm.LANGUAGE_CODES); - - HashMap stopNameByLanguage = AddLocalizedNameForm.toNameByLanguage(names, languages); + HashMap stopNameByLanguage = AddLocalizedNameForm.toNameByLanguage(answer); for (Map.Entry e : stopNameByLanguage.entrySet()) { if(e.getKey().isEmpty()) diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddBusStopNameForm.java b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddBusStopNameForm.java index 4c1ec43510..ea60b2eb54 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddBusStopNameForm.java +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddBusStopNameForm.java @@ -23,13 +23,18 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, View contentView = setContentView(R.layout.quest_localizedname); - addOtherAnswers(this::confirmNoName); + addOtherAnswers(); initLocalizedNameAdapter(contentView, savedInstanceState); return view; } + private void addOtherAnswers() { + addOtherAnswer(R.string.quest_name_answer_noName, this::confirmNoName); + addOtherAnswer(R.string.quest_streetName_answer_cantType, this::showKeyboardInfo); + } + @Override protected void onClickOk() { this.applyNameAnswer(); diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddLocalizedNameForm.java b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddLocalizedNameForm.java index b9efef6adb..eb5d19b394 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddLocalizedNameForm.java +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddLocalizedNameForm.java @@ -30,8 +30,8 @@ public abstract class AddLocalizedNameForm extends AbstractQuestFormAnswerFragme { protected static final String LOCALIZED_NAMES_DATA = "localized_names_data"; - public static final String - NO_NAME = "no_name", + public static final String NO_NAME = "no_name"; + private static final String NAMES = "names", LANGUAGE_CODES = "language_codes"; @@ -50,11 +50,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, return view; } - protected void addOtherAnswers(Runnable noNameAction) { - addOtherAnswer(R.string.quest_name_answer_noName, noNameAction); - addOtherAnswer(R.string.quest_streetName_answer_cantType, this::showKeyboardInfo); - } - protected void initLocalizedNameAdapter(View contentView, Bundle savedInstanceState) { ArrayList data; @@ -168,8 +163,11 @@ protected void showKeyboardInfo() .show(); } - protected static HashMap toNameByLanguage(String[] names, String[] languages) + protected static HashMap toNameByLanguage(Bundle answer) { + String[] names = answer.getStringArray(NAMES); + String[] languages = answer.getStringArray(LANGUAGE_CODES); + HashMap result = new HashMap<>(); result.put("", names[0]); // add languages only if there is more than one name specified. If there is more than one diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddRoadName.java b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddRoadName.java index 0ecb6c0fdd..0c06851550 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddRoadName.java +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddRoadName.java @@ -84,7 +84,7 @@ public AbstractQuestAnswerFragment createForm() public void applyAnswerTo(Bundle answer, StringMapChangesBuilder changes) { - if(answer.getBoolean(AddRoadNameForm.NO_NAME)) + if(answer.getBoolean(AddLocalizedNameForm.NO_NAME)) { changes.add("noname", "yes"); return; @@ -108,10 +108,7 @@ else if(noProperRoad == AddRoadNameForm.IS_LINK) return; } - String[] names = answer.getStringArray(AddRoadNameForm.NAMES); - String[] languages = answer.getStringArray(AddRoadNameForm.LANGUAGE_CODES); - - HashMap roadNameByLanguage = AddLocalizedNameForm.toNameByLanguage(names, languages); + HashMap roadNameByLanguage = AddLocalizedNameForm.toNameByLanguage(answer); for (Map.Entry e : roadNameByLanguage.entrySet()) { if(e.getKey().isEmpty()) diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddRoadNameForm.java b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddRoadNameForm.java index 073343be7a..54edbd8f14 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddRoadNameForm.java +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/localized_name/AddRoadNameForm.java @@ -52,13 +52,18 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, View contentView = setContentView(R.layout.quest_localizedname); - addOtherAnswers(this::selectNoStreetNameReason); + addOtherAnswers(); initLocalizedNameAdapter(contentView, savedInstanceState); return view; } + private void addOtherAnswers() { + addOtherAnswer(R.string.quest_name_answer_noName, this::selectNoStreetNameReason); + addOtherAnswer(R.string.quest_streetName_answer_cantType, this::showKeyboardInfo); + } + @Override protected AddLocalizedNameAdapter setupNameAdapter(ArrayList data, Button addLanguageButton) { return new AddLocalizedNameAdapter(