From 1066fb59cff81bf51fe80312f1ff96ec93ac7a04 Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Wed, 14 Jun 2017 13:46:53 +0200 Subject: [PATCH] ask about detailing surface=paved/unpaved fixes #279 --- .../streetcomplete/quests/QuestModule.java | 4 + .../quests/road_surface/AddRoadSurface.java | 17 +-- .../road_surface/AddRoadSurfaceForm.java | 114 ++++-------------- .../road_surface/DetailPavedRoadSurface.java | 52 ++++++++ .../DetailPavedRoadSurfaceForm.java | 17 +++ .../DetailUnpavedRoadSurface.java | 53 ++++++++ .../DetailUnpavedRoadSurfaceForm.java | 19 +++ .../road_surface/RoadSurfaceConfig.java | 13 ++ .../quests/road_surface/RoadSurfaceForm.java | 75 ++++++++++++ 9 files changed, 260 insertions(+), 104 deletions(-) create mode 100644 app/src/main/java/de/westnordost/streetcomplete/quests/road_surface/DetailPavedRoadSurface.java create mode 100644 app/src/main/java/de/westnordost/streetcomplete/quests/road_surface/DetailPavedRoadSurfaceForm.java create mode 100644 app/src/main/java/de/westnordost/streetcomplete/quests/road_surface/DetailUnpavedRoadSurface.java create mode 100644 app/src/main/java/de/westnordost/streetcomplete/quests/road_surface/DetailUnpavedRoadSurfaceForm.java create mode 100644 app/src/main/java/de/westnordost/streetcomplete/quests/road_surface/RoadSurfaceConfig.java create mode 100644 app/src/main/java/de/westnordost/streetcomplete/quests/road_surface/RoadSurfaceForm.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 6b8bb87b9a4..7aa053ac17f 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/QuestModule.java +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/QuestModule.java @@ -13,6 +13,8 @@ import de.westnordost.streetcomplete.quests.bike_parking_cover.AddBikeParkingCover; import de.westnordost.streetcomplete.quests.building_levels.AddBuildingLevels; import de.westnordost.streetcomplete.quests.bus_stop_shelter.AddBusStopShelter; +import de.westnordost.streetcomplete.quests.road_surface.DetailPavedRoadSurface; +import de.westnordost.streetcomplete.quests.road_surface.DetailUnpavedRoadSurface; import de.westnordost.streetcomplete.quests.tactile_paving.AddTactilePavingBusStop; import de.westnordost.streetcomplete.quests.tactile_paving.AddTactilePavingCrosswalk; import de.westnordost.streetcomplete.quests.toilets_fee.AddToiletsFee; @@ -35,6 +37,8 @@ public class QuestModule new AddRoofShape(o), // new AddPlaceName(), doesn't make sense as long as the app cannot tell the generic name of elements new AddRoadSurface(o), + new DetailPavedRoadSurface(o), + new DetailUnpavedRoadSurface(o), new AddBusStopShelter(o), new AddToiletsFee(o), new AddHousenumber(o), diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/road_surface/AddRoadSurface.java b/app/src/main/java/de/westnordost/streetcomplete/quests/road_surface/AddRoadSurface.java index c0637f3445b..efe3d0a70e4 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/road_surface/AddRoadSurface.java +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/road_surface/AddRoadSurface.java @@ -11,18 +11,7 @@ import de.westnordost.streetcomplete.data.osm.download.OverpassMapDataDao; import de.westnordost.streetcomplete.quests.AbstractQuestAnswerFragment; -public class AddRoadSurface extends SimpleOverpassQuestType -{ - // well, all roads have surfaces, what I mean is that not all ways with highway key are - // "something with a surface" - private static final String[] ROADS_WITH_SURFACES = { - // "trunk","trunk_link","motorway","motorway_link", // too much, motorways are almost by definition asphalt (or concrete) - "primary", "primary_link", "secondary", "secondary_link", "tertiary", "tertiary_link", - "unclassified", "residential", "bicycle_road", "living_street", "pedestrian", - "track", "road", - /*"service", */ // this is too much, and the information value is very low - }; - +public class AddRoadSurface extends SimpleOverpassQuestType { @Inject public AddRoadSurface(OverpassMapDataDao overpassServer) { super(overpassServer); @@ -31,8 +20,8 @@ public class AddRoadSurface extends SimpleOverpassQuestType @Override protected String getTagFilters() { - return " ways with ( highway ~ " + TextUtils.join("|",ROADS_WITH_SURFACES) + " and" + - " !surface)"; + return " ways with ( highway ~ " + TextUtils.join("|", RoadSurfaceConfig.ROADS_WITH_SURFACES) + " and" + + " !surface)"; } @Override diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/road_surface/AddRoadSurfaceForm.java b/app/src/main/java/de/westnordost/streetcomplete/quests/road_surface/AddRoadSurfaceForm.java index 9796684a296..e084d26d15b 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/road_surface/AddRoadSurfaceForm.java +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/road_surface/AddRoadSurfaceForm.java @@ -1,97 +1,31 @@ package de.westnordost.streetcomplete.quests.road_surface; -import android.os.Bundle; -import android.support.v7.widget.RecyclerView; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -import java.util.Arrays; - import de.westnordost.streetcomplete.R; -import de.westnordost.streetcomplete.quests.AbstractQuestFormAnswerFragment; -import de.westnordost.streetcomplete.view.GroupedImageSelectAdapter; - -public class AddRoadSurfaceForm extends AbstractQuestFormAnswerFragment -{ - public static final String SURFACE = "surface"; - - private final Surface[] SURFACES = new Surface[] { - new Surface("paved", R.drawable.panorama_surface_paved, R.string.quest_surface_value_paved, new Surface[]{ - new Surface("asphalt", R.drawable.surface_asphalt, R.string.quest_surface_value_asphalt), - new Surface("concrete", R.drawable.surface_concrete, R.string.quest_surface_value_concrete), - new Surface("sett", R.drawable.surface_sett, R.string.quest_surface_value_sett), - new Surface("paving_stones", R.drawable.surface_paving_stones, R.string.quest_surface_value_paving_stones), - new Surface("cobblestone", R.drawable.surface_cobblestone, R.string.quest_surface_value_cobblestone), - new Surface("wood", R.drawable.surface_wood, R.string.quest_surface_value_wood), - }), - new Surface("unpaved", R.drawable.panorama_surface_unpaved, R.string.quest_surface_value_unpaved, new Surface[]{ - new Surface("compacted", R.drawable.surface_compacted, R.string.quest_surface_value_compacted), - new Surface("gravel", R.drawable.surface_gravel, R.string.quest_surface_value_gravel), - new Surface("fine_gravel", R.drawable.surface_fine_gravel, R.string.quest_surface_value_fine_gravel), - new Surface("pebblestone", R.drawable.surface_pebblestone, R.string.quest_surface_value_pebblestone), - new Surface("grass_paver", R.drawable.surface_grass_paver, R.string.quest_surface_value_grass_paver), - }), - new Surface("ground", R.drawable.panorama_surface_ground, R.string.quest_surface_value_ground, new Surface[]{ - new Surface("dirt", R.drawable.surface_dirt, R.string.quest_surface_value_dirt), - new Surface("grass", R.drawable.surface_grass, R.string.quest_surface_value_grass), - new Surface("sand", R.drawable.surface_sand, R.string.quest_surface_value_sand), - }), - }; - - private GroupedImageSelectAdapter imageSelector; - - @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) - { - View view = super.onCreateView(inflater, container, savedInstanceState); - - setTitle(R.string.quest_streetSurface_title); - - View contentView = setContentView(R.layout.quest_street_surface); - - RecyclerView surfaceSelect = (RecyclerView) contentView.findViewById(R.id.surfaceSelect); - imageSelector = new GroupedImageSelectAdapter(Arrays.asList(SURFACES)); - surfaceSelect.setAdapter(imageSelector); - surfaceSelect.setNestedScrollingEnabled(false); - - return view; - } - @Override protected void onClickOk() +public class AddRoadSurfaceForm extends RoadSurfaceForm { + RoadSurfaceForm.Surface[] GetSurfaceMenuStructure() { - Bundle answer = new Bundle(); - if(getSelectedSurface() != null) - { - answer.putString(SURFACE, getSelectedSurface().value); - } - applyFormAnswer(answer); - } - - @Override public boolean hasChanges() - { - return getSelectedSurface() != null; - } - - private Surface getSelectedSurface() - { - return (Surface) imageSelector.getSelectedItem(); - } - - private static class Surface extends GroupedImageSelectAdapter.Item - { - public final String value; - - public Surface(String value, int drawableId, int titleId) - { - super(drawableId, titleId); - this.value = value; - } - - public Surface(String value, int drawableId, int titleId, GroupedImageSelectAdapter.Item[] items) - { - super(drawableId, titleId, items); - this.value = value; - } + return new RoadSurfaceForm.Surface[]{ + new RoadSurfaceForm.Surface("paved", R.drawable.panorama_surface_paved, R.string.quest_surface_value_paved, new RoadSurfaceForm.Surface[]{ + new RoadSurfaceForm.Surface("asphalt", R.drawable.surface_asphalt, R.string.quest_surface_value_asphalt), + new RoadSurfaceForm.Surface("concrete", R.drawable.surface_concrete, R.string.quest_surface_value_concrete), + new RoadSurfaceForm.Surface("sett", R.drawable.surface_sett, R.string.quest_surface_value_sett), + new RoadSurfaceForm.Surface("paving_stones", R.drawable.surface_paving_stones, R.string.quest_surface_value_paving_stones), + new RoadSurfaceForm.Surface("cobblestone", R.drawable.surface_cobblestone, R.string.quest_surface_value_cobblestone), + new RoadSurfaceForm.Surface("wood", R.drawable.surface_wood, R.string.quest_surface_value_wood), + }), + new RoadSurfaceForm.Surface("unpaved", R.drawable.panorama_surface_unpaved, R.string.quest_surface_value_unpaved, new RoadSurfaceForm.Surface[]{ + new RoadSurfaceForm.Surface("compacted", R.drawable.surface_compacted, R.string.quest_surface_value_compacted), + new RoadSurfaceForm.Surface("gravel", R.drawable.surface_gravel, R.string.quest_surface_value_gravel), + new RoadSurfaceForm.Surface("fine_gravel", R.drawable.surface_fine_gravel, R.string.quest_surface_value_fine_gravel), + new RoadSurfaceForm.Surface("pebblestone", R.drawable.surface_pebblestone, R.string.quest_surface_value_pebblestone), + new RoadSurfaceForm.Surface("grass_paver", R.drawable.surface_grass_paver, R.string.quest_surface_value_grass_paver), + }), + new RoadSurfaceForm.Surface("ground", R.drawable.panorama_surface_ground, R.string.quest_surface_value_ground, new RoadSurfaceForm.Surface[]{ + new RoadSurfaceForm.Surface("dirt", R.drawable.surface_dirt, R.string.quest_surface_value_dirt), + new RoadSurfaceForm.Surface("grass", R.drawable.surface_grass, R.string.quest_surface_value_grass), + new RoadSurfaceForm.Surface("sand", R.drawable.surface_sand, R.string.quest_surface_value_sand), + }), + }; } } diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/road_surface/DetailPavedRoadSurface.java b/app/src/main/java/de/westnordost/streetcomplete/quests/road_surface/DetailPavedRoadSurface.java new file mode 100644 index 00000000000..0d9e03f707e --- /dev/null +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/road_surface/DetailPavedRoadSurface.java @@ -0,0 +1,52 @@ +package de.westnordost.streetcomplete.quests.road_surface; + +import android.os.Bundle; +import android.text.TextUtils; + +import javax.inject.Inject; + +import de.westnordost.streetcomplete.data.QuestImportance; +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 DetailPavedRoadSurface extends SimpleOverpassQuestType { + @Inject public DetailPavedRoadSurface(OverpassMapDataDao overpassServer) + { + super(overpassServer); + } + + @Override + protected String getTagFilters() + { + return " ways with ( highway ~ " + TextUtils.join("|", RoadSurfaceConfig.ROADS_WITH_SURFACES) + " and" + + " surface=paved)"; + } + + @Override + public int importance() + { + return QuestImportance.MINOR; + } + + public AbstractQuestAnswerFragment createForm() + { + return new DetailPavedRoadSurfaceForm(); + } + + public void applyAnswerTo(Bundle answer, StringMapChangesBuilder changes) + { + changes.modify("surface", answer.getString(DetailPavedRoadSurfaceForm.SURFACE)); + } + + @Override public String getCommitMessage() + { + return "Detail road surfaces"; + } + + @Override public String getIconName() + { + return "street_surface"; + } +} diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/road_surface/DetailPavedRoadSurfaceForm.java b/app/src/main/java/de/westnordost/streetcomplete/quests/road_surface/DetailPavedRoadSurfaceForm.java new file mode 100644 index 00000000000..8f9ea0e90ee --- /dev/null +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/road_surface/DetailPavedRoadSurfaceForm.java @@ -0,0 +1,17 @@ +package de.westnordost.streetcomplete.quests.road_surface; + +import de.westnordost.streetcomplete.R; + +public class DetailPavedRoadSurfaceForm extends RoadSurfaceForm { + RoadSurfaceForm.Surface[] GetSurfaceMenuStructure() + { + return new RoadSurfaceForm.Surface[]{ + new RoadSurfaceForm.Surface("asphalt", R.drawable.surface_asphalt, R.string.quest_surface_value_asphalt), + new RoadSurfaceForm.Surface("concrete", R.drawable.surface_concrete, R.string.quest_surface_value_concrete), + new RoadSurfaceForm.Surface("sett", R.drawable.surface_sett, R.string.quest_surface_value_sett), + new RoadSurfaceForm.Surface("paving_stones", R.drawable.surface_paving_stones, R.string.quest_surface_value_paving_stones), + new RoadSurfaceForm.Surface("cobblestone", R.drawable.surface_cobblestone, R.string.quest_surface_value_cobblestone), + new RoadSurfaceForm.Surface("wood", R.drawable.surface_wood, R.string.quest_surface_value_wood), + }; + } +} diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/road_surface/DetailUnpavedRoadSurface.java b/app/src/main/java/de/westnordost/streetcomplete/quests/road_surface/DetailUnpavedRoadSurface.java new file mode 100644 index 00000000000..3b4f139ebbf --- /dev/null +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/road_surface/DetailUnpavedRoadSurface.java @@ -0,0 +1,53 @@ +package de.westnordost.streetcomplete.quests.road_surface; + +import android.os.Bundle; +import android.text.TextUtils; + +import javax.inject.Inject; + +import de.westnordost.streetcomplete.data.QuestImportance; +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 DetailUnpavedRoadSurface extends SimpleOverpassQuestType { + @Inject public DetailUnpavedRoadSurface(OverpassMapDataDao overpassServer) + { + super(overpassServer); + } + + @Override + protected String getTagFilters() + { + return " ways with ( highway ~ " + TextUtils.join("|", RoadSurfaceConfig.ROADS_WITH_SURFACES) + " and" + + " surface=unpaved)"; + } + + @Override + public int importance() + { + return QuestImportance.MINOR; + } + + public AbstractQuestAnswerFragment createForm() + { + return new DetailUnpavedRoadSurfaceForm(); + } + + public void applyAnswerTo(Bundle answer, StringMapChangesBuilder changes) + { + changes.modify("surface", answer.getString(DetailUnpavedRoadSurfaceForm.SURFACE)); + } + + @Override + public String getCommitMessage() + { + return "Detail road surfaces"; + } + + @Override + public String getIconName() { + return "street_surface"; + } +} diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/road_surface/DetailUnpavedRoadSurfaceForm.java b/app/src/main/java/de/westnordost/streetcomplete/quests/road_surface/DetailUnpavedRoadSurfaceForm.java new file mode 100644 index 00000000000..c2281d665b5 --- /dev/null +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/road_surface/DetailUnpavedRoadSurfaceForm.java @@ -0,0 +1,19 @@ +package de.westnordost.streetcomplete.quests.road_surface; + +import de.westnordost.streetcomplete.R; + +public class DetailUnpavedRoadSurfaceForm extends RoadSurfaceForm { + Surface[] GetSurfaceMenuStructure() + { + return new Surface[]{ + new RoadSurfaceForm.Surface("compacted", R.drawable.surface_compacted, R.string.quest_surface_value_compacted), + new RoadSurfaceForm.Surface("gravel", R.drawable.surface_gravel, R.string.quest_surface_value_gravel), + new RoadSurfaceForm.Surface("fine_gravel", R.drawable.surface_fine_gravel, R.string.quest_surface_value_fine_gravel), + new RoadSurfaceForm.Surface("pebblestone", R.drawable.surface_pebblestone, R.string.quest_surface_value_pebblestone), + new RoadSurfaceForm.Surface("grass_paver", R.drawable.surface_grass_paver, R.string.quest_surface_value_grass_paver), + new RoadSurfaceForm.Surface("dirt", R.drawable.surface_dirt, R.string.quest_surface_value_dirt), + new RoadSurfaceForm.Surface("grass", R.drawable.surface_grass, R.string.quest_surface_value_grass), + new RoadSurfaceForm.Surface("sand", R.drawable.surface_sand, R.string.quest_surface_value_sand), + }; + } +} diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/road_surface/RoadSurfaceConfig.java b/app/src/main/java/de/westnordost/streetcomplete/quests/road_surface/RoadSurfaceConfig.java new file mode 100644 index 00000000000..c7c55809625 --- /dev/null +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/road_surface/RoadSurfaceConfig.java @@ -0,0 +1,13 @@ +package de.westnordost.streetcomplete.quests.road_surface; + +public class RoadSurfaceConfig { + // well, all roads have surfaces, what I mean is that not all ways with highway key are + // "something with a surface" + static final String[] ROADS_WITH_SURFACES = { + // "trunk","trunk_link","motorway","motorway_link", // too much, motorways are almost by definition asphalt (or concrete) + "primary", "primary_link", "secondary", "secondary_link", "tertiary", "tertiary_link", + "unclassified", "residential", "bicycle_road", "living_street", "pedestrian", + "track", "road", + /*"service", */ // this is too much, and the information value is very low + }; +} diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/road_surface/RoadSurfaceForm.java b/app/src/main/java/de/westnordost/streetcomplete/quests/road_surface/RoadSurfaceForm.java new file mode 100644 index 00000000000..c53ab01e949 --- /dev/null +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/road_surface/RoadSurfaceForm.java @@ -0,0 +1,75 @@ +package de.westnordost.streetcomplete.quests.road_surface; + +import android.os.Bundle; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import java.util.Arrays; + +import de.westnordost.streetcomplete.R; +import de.westnordost.streetcomplete.quests.AbstractQuestFormAnswerFragment; +import de.westnordost.streetcomplete.view.GroupedImageSelectAdapter; + +public abstract class RoadSurfaceForm extends AbstractQuestFormAnswerFragment { + public static final String SURFACE = "surface"; + private GroupedImageSelectAdapter imageSelector; + + abstract Surface[] GetSurfaceMenuStructure(); + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) + { + View view = super.onCreateView(inflater, container, savedInstanceState); + + setTitle(R.string.quest_streetSurface_title); + + View contentView = setContentView(R.layout.quest_street_surface); + + RecyclerView surfaceSelect = (RecyclerView) contentView.findViewById(R.id.surfaceSelect); + imageSelector = new GroupedImageSelectAdapter(Arrays.asList(GetSurfaceMenuStructure())); + surfaceSelect.setAdapter(imageSelector); + surfaceSelect.setNestedScrollingEnabled(false); + + return view; + } + + @Override + protected void onClickOk() + { + Bundle answer = new Bundle(); + if (getSelectedSurface() != null) { + answer.putString(SURFACE, getSelectedSurface().value); + } + applyFormAnswer(answer); + } + + @Override + public boolean hasChanges() + { + return getSelectedSurface() != null; + } + + private Surface getSelectedSurface() + { + return (Surface) imageSelector.getSelectedItem(); + } + + protected static class Surface extends GroupedImageSelectAdapter.Item { + public final String value; + + public Surface(String value, int drawableId, int titleId) + { + super(drawableId, titleId); + this.value = value; + } + + public Surface(String value, int drawableId, int titleId, GroupedImageSelectAdapter.Item[] items) + { + super(drawableId, titleId, items); + this.value = value; + } + } +}