Use Set for opening hours instead of list
This commit is contained in:
parent
30f11565cf
commit
c9241320af
@ -26,7 +26,10 @@ data class OpeningHours(
|
|||||||
sealed interface OpeningSchedule {
|
sealed interface OpeningSchedule {
|
||||||
data object TwentyFourSeven : OpeningSchedule
|
data object TwentyFourSeven : OpeningSchedule
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Hours(@Serializable val openingHours: List<OpeningHours>) : OpeningSchedule
|
data class Hours(@Serializable val openingHours: Set<OpeningHours>) : OpeningSchedule {
|
||||||
|
@Deprecated("Use the constructor with Set<OpeningHours> instead.")
|
||||||
|
constructor(openingHours: List<OpeningHours>) : this(openingHours.toSet())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -44,7 +44,7 @@ object OpeningScheduleSerializer : KSerializer<OpeningSchedule> {
|
|||||||
)
|
)
|
||||||
} catch (e: SerializationException) {
|
} catch (e: SerializationException) {
|
||||||
Log.e("MM20", "Failed to deserialize OpeningSchedule.Hours", e)
|
Log.e("MM20", "Failed to deserialize OpeningSchedule.Hours", e)
|
||||||
return OpeningSchedule.Hours(openingHours = emptyList())
|
return OpeningSchedule.Hours(openingHours = emptySet())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,9 @@
|
|||||||
package de.mm20.launcher2.locations.providers.openstreetmaps
|
package de.mm20.launcher2.locations.providers.openstreetmaps
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import de.mm20.launcher2.ktx.flatMapNotNull
|
|
||||||
import de.mm20.launcher2.ktx.ifNullOrEmpty
|
import de.mm20.launcher2.ktx.ifNullOrEmpty
|
||||||
import de.mm20.launcher2.ktx.into
|
import de.mm20.launcher2.ktx.into
|
||||||
import de.mm20.launcher2.ktx.map
|
import de.mm20.launcher2.ktx.map
|
||||||
import de.mm20.launcher2.ktx.toMultiMap
|
|
||||||
import de.mm20.launcher2.locations.OsmLocationSerializer
|
import de.mm20.launcher2.locations.OsmLocationSerializer
|
||||||
import de.mm20.launcher2.openstreetmaps.R
|
import de.mm20.launcher2.openstreetmaps.R
|
||||||
import de.mm20.launcher2.search.Location
|
import de.mm20.launcher2.search.Location
|
||||||
@ -332,10 +330,10 @@ private fun Map<String, String>.categorize(context: Context): Pair<String?, Loca
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal fun parseOpeningSchedule(
|
internal fun parseOpeningSchedule(
|
||||||
it: String?,
|
openingHours: String?,
|
||||||
localTime: LocalDateTime = LocalDateTime.now()
|
localTime: LocalDateTime = LocalDateTime.now()
|
||||||
): OpeningSchedule? {
|
): OpeningSchedule? {
|
||||||
val parsed = it?.toOpeningHoursOrNull(lenient = true) ?: return null
|
val parsed = openingHours?.toOpeningHoursOrNull(lenient = true) ?: return null
|
||||||
|
|
||||||
if (parsed.rules.singleOrNull()?.selector is TwentyFourSeven) {
|
if (parsed.rules.singleOrNull()?.selector is TwentyFourSeven) {
|
||||||
return OpeningSchedule.TwentyFourSeven
|
return OpeningSchedule.TwentyFourSeven
|
||||||
@ -386,7 +384,7 @@ internal fun parseOpeningSchedule(
|
|||||||
.singleOrNull()
|
.singleOrNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
val hours = mutableListOf<OpeningHours>()
|
val hours = mutableSetOf<OpeningHours>()
|
||||||
|
|
||||||
for (range in applicableRules) {
|
for (range in applicableRules) {
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user