Extracting parsing of operating system for Desktop/Web into dedicated method

This commit is contained in:
Maxime NATUREL 2022-10-10 11:41:35 +02:00
parent 11f816868b
commit 4e70fcd339

View file

@ -75,17 +75,12 @@ class ParseDeviceUserAgentUseCase @Inject constructor() {
private fun parseDesktopUserAgent(userAgent: String): DeviceExtendedInfo {
val browserInfo = parseBrowserInfoFromDesktopUserAgent(userAgent)
val operatingSystem = parseOperatingSystemFromDesktopUserAgent(userAgent)
val deviceOperatingSystemSegments = userAgent.substringAfter("(").substringBefore(")").split("; ")
val deviceOperatingSystem = if (deviceOperatingSystemSegments.getOrNull(1)?.startsWith("Android").orFalse()) {
deviceOperatingSystemSegments.getOrNull(1)
} else {
deviceOperatingSystemSegments.getOrNull(0)
}
return DeviceExtendedInfo(
deviceType = DeviceType.DESKTOP,
deviceModel = null,
deviceOperatingSystem = deviceOperatingSystem,
deviceOperatingSystem = operatingSystem,
clientName = browserInfo.name,
clientVersion = browserInfo.version,
)
@ -131,6 +126,15 @@ class ParseDeviceUserAgentUseCase @Inject constructor() {
}
}
private fun parseOperatingSystemFromDesktopUserAgent(userAgent: String): String? {
val deviceOperatingSystemSegments = userAgent.substringAfter("(").substringBefore(")").split("; ")
return if (deviceOperatingSystemSegments.getOrNull(1)?.startsWith("Android").orFalse()) {
deviceOperatingSystemSegments.getOrNull(1)
} else {
deviceOperatingSystemSegments.getOrNull(0)
}
}
private fun parseWebUserAgent(userAgent: String): DeviceExtendedInfo {
return parseDesktopUserAgent(userAgent).copy(
deviceType = DeviceType.WEB