From 6d315e3b9f828b3b1e4069fd59d8614787d4767a Mon Sep 17 00:00:00 2001 From: Tobias Zwick Date: Thu, 18 Nov 2021 01:48:25 +0100 Subject: [PATCH] revert addition of possibility to only display certain quests during night/day (fixes #3248) --- app/build.gradle.kts | 3 -- .../data/quest/DayNightCycle.kt | 3 -- .../streetcomplete/data/quest/QuestType.kt | 3 -- .../data/quest/VisibleQuestsSource.kt | 6 ++-- .../data/visiblequests/DayNightQuestFilter.kt | 32 ----------------- .../streetcomplete/quests/QuestModule.kt | 8 +++-- .../quests/bus_stop_lit/AddBusStopLit.kt | 2 -- .../quests/way_lit/AddWayLit.kt | 2 -- .../questselection/QuestSelectionAdapter.kt | 9 +---- .../streetcomplete/util/Daylight.kt | 34 ------------------- app/src/main/res/values/strings.xml | 1 - .../data/quest/VisibleQuestsSourceTest.kt | 16 +-------- 12 files changed, 9 insertions(+), 110 deletions(-) delete mode 100644 app/src/main/java/de/westnordost/streetcomplete/data/quest/DayNightCycle.kt delete mode 100644 app/src/main/java/de/westnordost/streetcomplete/data/visiblequests/DayNightQuestFilter.kt delete mode 100644 app/src/main/java/de/westnordost/streetcomplete/util/Daylight.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index e702cc83a3..c6d9d2c3dd 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -178,9 +178,6 @@ dependencies { // opening hours parser implementation("ch.poole:OpeningHoursParser:0.25.0") - - // sunset-sunrise parser for lit quests - implementation("com.luckycatlabs:SunriseSunsetCalculator:1.2") } /** Localizations that should be pulled from POEditor etc. */ diff --git a/app/src/main/java/de/westnordost/streetcomplete/data/quest/DayNightCycle.kt b/app/src/main/java/de/westnordost/streetcomplete/data/quest/DayNightCycle.kt deleted file mode 100644 index 1e3b34fa3f..0000000000 --- a/app/src/main/java/de/westnordost/streetcomplete/data/quest/DayNightCycle.kt +++ /dev/null @@ -1,3 +0,0 @@ -package de.westnordost.streetcomplete.data.quest - -enum class DayNightCycle { DAY_AND_NIGHT, ONLY_DAY, ONLY_NIGHT } diff --git a/app/src/main/java/de/westnordost/streetcomplete/data/quest/QuestType.kt b/app/src/main/java/de/westnordost/streetcomplete/data/quest/QuestType.kt index 3bb2037dda..676328204d 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/data/quest/QuestType.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/data/quest/QuestType.kt @@ -21,9 +21,6 @@ interface QuestType { /** The quest type can clean it's metadata that is older than the given timestamp here, if any */ fun deleteMetadataOlderThan(timestamp: Long) {} - /** if the quest should only be shown during day-light or night-time hours */ - val dayNightVisibility: DayNightCycle get() = DayNightCycle.DAY_AND_NIGHT - /** towards which achievements the quest should count */ val questTypeAchievements: List } diff --git a/app/src/main/java/de/westnordost/streetcomplete/data/quest/VisibleQuestsSource.kt b/app/src/main/java/de/westnordost/streetcomplete/data/quest/VisibleQuestsSource.kt index bda6e3f468..de7f602c26 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/data/quest/VisibleQuestsSource.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/data/quest/VisibleQuestsSource.kt @@ -5,7 +5,6 @@ import de.westnordost.streetcomplete.data.osm.osmquests.OsmQuest import de.westnordost.streetcomplete.data.osm.osmquests.OsmQuestSource import de.westnordost.streetcomplete.data.osmnotes.notequests.OsmNoteQuest import de.westnordost.streetcomplete.data.osmnotes.notequests.OsmNoteQuestSource -import de.westnordost.streetcomplete.data.visiblequests.DayNightQuestFilter import de.westnordost.streetcomplete.data.visiblequests.TeamModeQuestFilter import de.westnordost.streetcomplete.data.visiblequests.VisibleQuestTypeSource import java.util.concurrent.CopyOnWriteArrayList @@ -18,8 +17,7 @@ import javax.inject.Singleton private val osmQuestSource: OsmQuestSource, private val osmNoteQuestSource: OsmNoteQuestSource, private val visibleQuestTypeSource: VisibleQuestTypeSource, - private val teamModeQuestFilter: TeamModeQuestFilter, - private val dayNightQuestFilter: DayNightQuestFilter, + private val teamModeQuestFilter: TeamModeQuestFilter ) { interface Listener { /** Called when given quests in the given group have been added/removed */ @@ -89,7 +87,7 @@ import javax.inject.Singleton } private fun isVisible(quest: Quest): Boolean = - visibleQuestTypeSource.isVisible(quest.type) && teamModeQuestFilter.isVisible(quest) && dayNightQuestFilter.isVisible(quest) + visibleQuestTypeSource.isVisible(quest.type) && teamModeQuestFilter.isVisible(quest) fun addListener(listener: Listener) { listeners.add(listener) diff --git a/app/src/main/java/de/westnordost/streetcomplete/data/visiblequests/DayNightQuestFilter.kt b/app/src/main/java/de/westnordost/streetcomplete/data/visiblequests/DayNightQuestFilter.kt deleted file mode 100644 index b1f13be9ac..0000000000 --- a/app/src/main/java/de/westnordost/streetcomplete/data/visiblequests/DayNightQuestFilter.kt +++ /dev/null @@ -1,32 +0,0 @@ -package de.westnordost.streetcomplete.data.visiblequests - -import de.westnordost.streetcomplete.data.osm.mapdata.LatLon -import de.westnordost.streetcomplete.data.quest.DayNightCycle.* -import de.westnordost.streetcomplete.data.quest.Quest -import de.westnordost.streetcomplete.util.DaylightTimes -import de.westnordost.streetcomplete.util.getDaylightTimes -import de.westnordost.streetcomplete.util.isDaylight -import javax.inject.Inject -import javax.inject.Singleton -import kotlin.math.round - -@Singleton class DayNightQuestFilter @Inject internal constructor() { - /* This is a singleton because it owns an in-memory cache, no need to duplicate that */ - - private val cache: MutableMap = mutableMapOf() - - private fun isDaylightAt(pos: LatLon): Boolean { - // using low precision lat lons (~ city level) because the sun and the earth is big - val lowPrecisionLatLon = LatLon(round(pos.latitude*10)/10, round(pos.longitude*10)/10) - val daylightTimes = cache.getOrPut(lowPrecisionLatLon) { getDaylightTimes(pos) } - return isDaylight(daylightTimes) - } - - fun isVisible(quest: Quest): Boolean { - return when (quest.type.dayNightVisibility) { - DAY_AND_NIGHT -> true - ONLY_DAY -> isDaylightAt(quest.position) - ONLY_NIGHT -> !isDaylightAt(quest.position) - } - } -} diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/QuestModule.kt b/app/src/main/java/de/westnordost/streetcomplete/quests/QuestModule.kt index f5a05b611a..6a9c395c36 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/QuestModule.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/QuestModule.kt @@ -164,13 +164,13 @@ import javax.inject.Singleton /* ↓ 1. solvable from a distance or while passing by ----------------------------------- */ // bus stop quests - AddBusStopLit(), AddBusStopShelter(), // used by at least OsmAnd AddBenchStatusOnBusStop(), // can be seen from across the street AddBinStatusOnBusStop(), // can be seen from across the street AddTactilePavingBusStop(), // requires you to be very close to it AddBusStopName(), // requires text input AddBusStopRef(), // requires text input + AddBusStopLit(), // at least during day requires to stand in it to see if there is a light in the shelter AddRailwayCrossingBarrier(), // useful for routing @@ -186,7 +186,7 @@ import javax.inject.Singleton // sport pitches AddSport(), AddPitchSurface(), - AddPitchLit(), // Not affected by new DayNight cycle because the lights are usually only on during games + AddPitchLit(), // parking AddParkingType(), @@ -347,7 +347,6 @@ import javax.inject.Singleton /* ↓ 5.quests that are very numerous ---------------------------------------------------- */ // roads - AddWayLit(), // used by OsmAnd if "Street lighting" is enabled. (Configure map, Map rendering, Details) AddSidewalk(), // for any pedestrian routers, needs minimal thinking AddRoadSurface(), // used by BRouter, OsmAnd, OSRM, graphhopper, HOT map style... - sometimes requires way to be split AddTracktype(), // widely used in map rendering - OSM Carto, OsmAnd... @@ -370,5 +369,8 @@ import javax.inject.Singleton AddRoofShape(countryInfos), AddStepCount(), // can only be gathered when walking along this way, also needs the most effort and least useful + + /* at the very last because it can be difficult to ascertain during day. used by OsmAnd if "Street lighting" is enabled. (Configure map, Map rendering, Details) */ + AddWayLit(), )) } diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/bus_stop_lit/AddBusStopLit.kt b/app/src/main/java/de/westnordost/streetcomplete/quests/bus_stop_lit/AddBusStopLit.kt index 097d433495..ffa48e5909 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/bus_stop_lit/AddBusStopLit.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/bus_stop_lit/AddBusStopLit.kt @@ -4,7 +4,6 @@ import de.westnordost.streetcomplete.R import de.westnordost.streetcomplete.data.meta.updateWithCheckDate import de.westnordost.streetcomplete.data.osm.edits.update_tags.StringMapChangesBuilder import de.westnordost.streetcomplete.data.osm.osmquests.OsmFilterQuestType -import de.westnordost.streetcomplete.data.quest.DayNightCycle.ONLY_NIGHT import de.westnordost.streetcomplete.data.user.achievements.QuestTypeAchievement.PEDESTRIAN import de.westnordost.streetcomplete.ktx.arrayOfNotNull import de.westnordost.streetcomplete.ktx.containsAnyKey @@ -31,7 +30,6 @@ class AddBusStopLit : OsmFilterQuestType() { override val commitMessage = "Add whether a bus stop is lit" override val wikiLink = "Key:lit" override val icon = R.drawable.ic_quest_bus_stop_lit - override val dayNightVisibility = ONLY_NIGHT override val questTypeAchievements = listOf(PEDESTRIAN) diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/way_lit/AddWayLit.kt b/app/src/main/java/de/westnordost/streetcomplete/quests/way_lit/AddWayLit.kt index 4805df9251..afcaae2d45 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/way_lit/AddWayLit.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/way_lit/AddWayLit.kt @@ -5,7 +5,6 @@ import de.westnordost.streetcomplete.data.meta.MAXSPEED_TYPE_KEYS import de.westnordost.streetcomplete.data.meta.updateWithCheckDate import de.westnordost.streetcomplete.data.osm.edits.update_tags.StringMapChangesBuilder import de.westnordost.streetcomplete.data.osm.osmquests.OsmFilterQuestType -import de.westnordost.streetcomplete.data.quest.DayNightCycle.ONLY_NIGHT import de.westnordost.streetcomplete.data.user.achievements.QuestTypeAchievement.PEDESTRIAN class AddWayLit : OsmFilterQuestType() { @@ -46,7 +45,6 @@ class AddWayLit : OsmFilterQuestType() { override val wikiLink = "Key:lit" override val icon = R.drawable.ic_quest_lantern override val isSplitWayEnabled = true - override val dayNightVisibility = ONLY_NIGHT override val questTypeAchievements = listOf(PEDESTRIAN) diff --git a/app/src/main/java/de/westnordost/streetcomplete/settings/questselection/QuestSelectionAdapter.kt b/app/src/main/java/de/westnordost/streetcomplete/settings/questselection/QuestSelectionAdapter.kt index fd1328dd32..02b31ad15a 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/settings/questselection/QuestSelectionAdapter.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/settings/questselection/QuestSelectionAdapter.kt @@ -241,11 +241,6 @@ class QuestSelectionAdapter @Inject constructor( lateinit var item: QuestVisibility - private val isEnabledOnlyAtNight: Boolean - get() { - return item.questType.dayNightVisibility == DayNightCycle.ONLY_NIGHT - } - private val isEnabledInCurrentCountry: Boolean get() { (item.questType as? OsmElementQuestType<*>)?.let { questType -> @@ -278,14 +273,12 @@ class QuestSelectionAdapter @Inject constructor( true } - binding.disabledText.isGone = isEnabledInCurrentCountry && !isEnabledOnlyAtNight + binding.disabledText.isGone = isEnabledInCurrentCountry if (!isEnabledInCurrentCountry) { val cc = if (currentCountryCodes.isEmpty()) "Atlantis" else currentCountryCodes[0] binding.disabledText.text = binding.disabledText.resources.getString( R.string.questList_disabled_in_country, Locale("", cc).displayCountry ) - } else if (isEnabledOnlyAtNight) { - binding.disabledText.text = binding.disabledText.resources.getString(R.string.questList_disabled_at_day) } updateSelectionStatus() diff --git a/app/src/main/java/de/westnordost/streetcomplete/util/Daylight.kt b/app/src/main/java/de/westnordost/streetcomplete/util/Daylight.kt deleted file mode 100644 index 54d099a53c..0000000000 --- a/app/src/main/java/de/westnordost/streetcomplete/util/Daylight.kt +++ /dev/null @@ -1,34 +0,0 @@ -package de.westnordost.streetcomplete.util - -import com.luckycatlabs.sunrisesunset.Zenith -import com.luckycatlabs.sunrisesunset.calculator.SolarEventCalculator -import com.luckycatlabs.sunrisesunset.dto.Location -import de.westnordost.streetcomplete.data.osm.mapdata.LatLon -import java.time.LocalTime -import java.util.* - -fun isDaylight(daylightTimes: DaylightTimes): Boolean { - val (sunrise, sunset) = daylightTimes - val now = LocalTime.now() - - // if sunset is after midnight - return if (sunset < sunrise) { - now > sunrise || now < sunset - } else { - now > sunrise && now < sunset - } -} - -data class DaylightTimes(val sunrise: LocalTime, val sunset: LocalTime) - -fun getDaylightTimes(pos: LatLon): DaylightTimes { - val timezone = TimeZone.getDefault().id - val location = Location(pos.latitude, pos.longitude) - val calculator = SolarEventCalculator(location, timezone) - val today = Calendar.getInstance() - - return DaylightTimes( - LocalTime.parse(calculator.computeSunriseTime(Zenith.CIVIL, today)), - LocalTime.parse(calculator.computeSunsetTime(Zenith.CIVIL, today)) - ) -} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2155729370..d6a7ec5903 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -602,7 +602,6 @@ Otherwise, you can download another keyboard in the app store. Popular keyboards Is this way completed? Is this building completed? Never shown in %s - Only shown at night Does this rest area have restroom facilities? What is the speed limit for %s here? Reset both quest enablement and order to the default? diff --git a/app/src/test/java/de/westnordost/streetcomplete/data/quest/VisibleQuestsSourceTest.kt b/app/src/test/java/de/westnordost/streetcomplete/data/quest/VisibleQuestsSourceTest.kt index 827b78d58c..09f709c257 100644 --- a/app/src/test/java/de/westnordost/streetcomplete/data/quest/VisibleQuestsSourceTest.kt +++ b/app/src/test/java/de/westnordost/streetcomplete/data/quest/VisibleQuestsSourceTest.kt @@ -4,7 +4,6 @@ import de.westnordost.streetcomplete.data.osm.osmquests.OsmQuest import de.westnordost.streetcomplete.data.osm.osmquests.OsmQuestSource import de.westnordost.streetcomplete.data.osmnotes.notequests.OsmNoteQuest import de.westnordost.streetcomplete.data.osmnotes.notequests.OsmNoteQuestSource -import de.westnordost.streetcomplete.data.visiblequests.DayNightQuestFilter import de.westnordost.streetcomplete.data.visiblequests.TeamModeQuestFilter import de.westnordost.streetcomplete.data.visiblequests.VisibleQuestTypeSource import de.westnordost.streetcomplete.testutils.* @@ -22,7 +21,6 @@ class VisibleQuestsSourceTest { private lateinit var osmNoteQuestSource: OsmNoteQuestSource private lateinit var visibleQuestTypeSource: VisibleQuestTypeSource private lateinit var teamModeQuestFilter: TeamModeQuestFilter - private lateinit var dayNightQuestFilter: DayNightQuestFilter private lateinit var source: VisibleQuestsSource private lateinit var noteQuestListener: OsmNoteQuestSource.Listener @@ -42,7 +40,6 @@ class VisibleQuestsSourceTest { visibleQuestTypeSource = mock() teamModeQuestFilter = mock() questTypeRegistry = QuestTypeRegistry(questTypes) - dayNightQuestFilter = mock() on(visibleQuestTypeSource.isVisible(any())).thenReturn(true) on(teamModeQuestFilter.isVisible(any())).thenReturn(true) @@ -64,9 +61,7 @@ class VisibleQuestsSourceTest { Unit } - on(dayNightQuestFilter.isVisible(any())).thenReturn(true) - - source = VisibleQuestsSource(questTypeRegistry, osmQuestSource, osmNoteQuestSource, visibleQuestTypeSource, teamModeQuestFilter, dayNightQuestFilter) + source = VisibleQuestsSource(questTypeRegistry, osmQuestSource, osmNoteQuestSource, visibleQuestTypeSource, teamModeQuestFilter) listener = mock() source.addListener(listener) @@ -105,15 +100,6 @@ class VisibleQuestsSourceTest { assertTrue(quests.isEmpty()) } - @Test fun `getAllVisible does not return those that are invisible at day`() { - on(osmQuestSource.getAllVisibleInBBox(bbox, questTypeNames)).thenReturn(listOf(mock())) - on(osmNoteQuestSource.getAllVisibleInBBox(bbox)).thenReturn(listOf(mock())) - on(dayNightQuestFilter.isVisible(any())).thenReturn(false) - - val quests = source.getAllVisible(bbox) - assertTrue(quests.isEmpty()) - } - @Test fun `osm quests added or removed triggers listener`() { val quests = listOf(osmQuest(elementId = 1), osmQuest(elementId = 2)) val deleted = listOf(osmQuestKey(elementId = 3), osmQuestKey(elementId = 4))