mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-22 17:35:54 +03:00
Extracting parsing of operating system for Desktop/Web into dedicated method
This commit is contained in:
parent
11f816868b
commit
4e70fcd339
1 changed files with 11 additions and 7 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue