From 5e703a4d63b415e3d533fdf5f0951cd991be1f6d Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Sat, 27 Jan 2018 08:30:07 +0100 Subject: [PATCH] new quest: wayside shrine, fixes #799 --- .../streetcomplete/data/meta/CountryInfo.java | 7 ++ .../streetcomplete/quests/QuestModule.java | 2 + .../religion/AddReligionToWaysideShrine.java | 50 +++++++++++ .../AddReligionToWaysideShrineForm.java | 84 +++++++++++++++++++ app/src/main/res/values/strings.xml | 1 + .../popularReligionsForWaysideShrines.yml | 10 +++ 6 files changed, 154 insertions(+) create mode 100644 app/src/main/java/de/westnordost/streetcomplete/quests/religion/AddReligionToWaysideShrine.java create mode 100644 app/src/main/java/de/westnordost/streetcomplete/quests/religion/AddReligionToWaysideShrineForm.java create mode 100644 res/country_metadata/popularReligionsForWaysideShrines.yml diff --git a/app/src/main/java/de/westnordost/streetcomplete/data/meta/CountryInfo.java b/app/src/main/java/de/westnordost/streetcomplete/data/meta/CountryInfo.java index 219dab5be7e..82bbcafc834 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/data/meta/CountryInfo.java +++ b/app/src/main/java/de/westnordost/streetcomplete/data/meta/CountryInfo.java @@ -17,6 +17,7 @@ public class CountryInfo implements Serializable, Cloneable List speedUnit; List popularSports; List popularReligions; + List popularReligionsForWaysideShrines; String firstDayOfWorkweek; Integer regularShoppingDays; String additionalValidHousenumberRegex; @@ -50,6 +51,12 @@ public List getPopularReligions() return Collections.unmodifiableList(popularReligions); } + public List getPopularReligionsForWaysideShrines() + { + if(popularReligionsForWaysideShrines == null) return new ArrayList<>(1); + return Collections.unmodifiableList(popularReligionsForWaysideShrines); + } + public String getFirstDayOfWorkweek() { return firstDayOfWorkweek; 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 c6903f1c5a8..97406ef7de7 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/QuestModule.java +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/QuestModule.java @@ -26,6 +26,7 @@ import de.westnordost.streetcomplete.quests.orchard_produce.AddOrchardProduce; 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.tactile_paving.AddTactilePavingBusStop; @@ -92,6 +93,7 @@ public class QuestModule new AddWheelchairAccessBusiness(o), new AddToiletAvailability(o), new AddWheelChairAccessToilets(o), + new AddReligionToWaysideShrine(o), // ↓ 8. defined in the wiki, but not really used by anyone yet. Just collected for // the sake of mapping it in case it makes sense later diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/religion/AddReligionToWaysideShrine.java b/app/src/main/java/de/westnordost/streetcomplete/quests/religion/AddReligionToWaysideShrine.java new file mode 100644 index 00000000000..3afc1182191 --- /dev/null +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/religion/AddReligionToWaysideShrine.java @@ -0,0 +1,50 @@ +package de.westnordost.streetcomplete.quests.religion; + +import android.os.Bundle; +import android.text.TextUtils; + +import java.util.ArrayList; +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 AddReligionToWaysideShrine extends SimpleOverpassQuestType +{ + @Inject public AddReligionToWaysideShrine(OverpassMapDataDao overpassServer) { super(overpassServer); } + + @Override + protected String getTagFilters() + { + return "nodes, ways, relations with historic=wayside_shrine and" + + " !religion and" + + " (access !~ private|no)"; // exclude ones without access to general public + } + + public AbstractQuestAnswerFragment createForm() + { + return new AddReligionToWaysideShrineForm(); + } + + public void applyAnswerTo(Bundle answer, StringMapChangesBuilder changes) + { + ArrayList values = answer.getStringArrayList(AddReligionToWaysideShrineForm.OSM_VALUES); + if(values != null && !values.isEmpty()) + { + String religionValueStr = values.get(0); + changes.add("religion", religionValueStr); + } + } + + @Override public String getCommitMessage() { return "Add religion for historic=wayside_shrine"; } + @Override public int getIcon() { return R.drawable.ic_quest_religion; } + @Override public int getTitle(Map tags) + { + return R.string.quest_religion_for_wayside_shrine_title; + } +} diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/religion/AddReligionToWaysideShrineForm.java b/app/src/main/java/de/westnordost/streetcomplete/quests/religion/AddReligionToWaysideShrineForm.java new file mode 100644 index 00000000000..d0cfe7777e3 --- /dev/null +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/religion/AddReligionToWaysideShrineForm.java @@ -0,0 +1,84 @@ +package de.westnordost.streetcomplete.quests.religion; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import de.westnordost.streetcomplete.R; +import de.westnordost.streetcomplete.quests.ImageListQuestAnswerFragment; +import de.westnordost.streetcomplete.quests.PriorityList; +import de.westnordost.streetcomplete.view.Item; + +public class AddReligionToWaysideShrineForm extends ImageListQuestAnswerFragment +{ + private static final int INITIALLY_DISPLAYED_ITEMS = 8; + + private static final Item[] ALL_RELIGION_VALUES = new Item[]{ + // worldwide usage, values covering vast majority of used tags + new Item("christian", R.drawable.ic_religion_christian, R.string.quest_religion_christian), + new Item("shinto", R.drawable.ic_religion_shinto, R.string.quest_religion_shinto), + new Item("buddhist", R.drawable.ic_religion_buddhist, R.string.quest_religion_buddhist), + new Item("bahai", R.drawable.ic_religion_bahai, R.string.quest_religion_bahai), + new Item("caodaism", R.drawable.ic_religion_caodaist, R.string.quest_religion_caodaist), + new Item("confucian", R.drawable.ic_religion_confucian, R.string.quest_religion_confucian), + new Item("hindu", R.drawable.ic_religion_hindu, R.string.quest_religion_hindu), + new Item("jain", R.drawable.ic_religion_jain, R.string.quest_religion_jain), + new Item("jewish", R.drawable.ic_religion_jewish, R.string.quest_religion_jewish), + new Item("muslim", R.drawable.ic_religion_muslim, R.string.quest_religion_muslim), + new Item("sikh", R.drawable.ic_religion_sikh, R.string.quest_religion_sikh), + new Item("taoist", R.drawable.ic_religion_taoist, R.string.quest_religion_taoist), + }; + + private Item[] actualReligionsValues; + + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) + { + View view = super.onCreateView(inflater, container, savedInstanceState); + actualReligionsValues = createItems(); + imageSelector.setCellLayout(R.layout.cell_icon_select_with_label_below); + + addOtherAnswer(R.string.quest_religion_for_place_of_worship_answer_multi, this::applyMultiAnswer); + + return view; + } + + private Item[] createItems() + { + List religionsList = new ArrayList<>(Arrays.asList(ALL_RELIGION_VALUES)); + List popularReligionsNames = getCountryInfo().getPopularReligionsForWaysideShrines(); + + religionsList = PriorityList.BuildList(religionsList, popularReligionsNames); + + return religionsList.toArray(new Item[religionsList.size()]); + } + + @Override protected int getMaxSelectableItems() + { + return 1; + } + + @Override protected int getMaxNumberOfInitiallyShownItems() + { + return INITIALLY_DISPLAYED_ITEMS; + } + + @Override protected Item[] getItems() + { + return actualReligionsValues; + } + + private void applyMultiAnswer() + { + Bundle answer = new Bundle(); + ArrayList strings = new ArrayList<>(1); + strings.add("multifaith"); + answer.putStringArrayList(OSM_VALUES, strings); + applyImmediateAnswer(answer); + } +} \ 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 33485b18729..6ca2eb6ccda 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -470,4 +470,5 @@ Otherwise, you can download another keyboard in the app store. Popular keyboards Bahá\'í Faith Caodaism Confucianism + What religion is represented at this shrine? diff --git a/res/country_metadata/popularReligionsForWaysideShrines.yml b/res/country_metadata/popularReligionsForWaysideShrines.yml new file mode 100644 index 00000000000..70b353ee47d --- /dev/null +++ b/res/country_metadata/popularReligionsForWaysideShrines.yml @@ -0,0 +1,10 @@ +# religions that should be shown first before the order defined in the form. +# no total order required. Just mention the religions that should show within the first few entries +default: [] +CN: [buddhist] +JP: [shinto, buddhist] +LK: [christian, buddhist] +MM: [buddhist] +MN: [buddhist] +TH: [buddhist] +TW: [taoist]