mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-17 04:20:00 +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 {
|
private fun parseDesktopUserAgent(userAgent: String): DeviceExtendedInfo {
|
||||||
val browserInfo = parseBrowserInfoFromDesktopUserAgent(userAgent)
|
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(
|
return DeviceExtendedInfo(
|
||||||
deviceType = DeviceType.DESKTOP,
|
deviceType = DeviceType.DESKTOP,
|
||||||
deviceModel = null,
|
deviceModel = null,
|
||||||
deviceOperatingSystem = deviceOperatingSystem,
|
deviceOperatingSystem = operatingSystem,
|
||||||
clientName = browserInfo.name,
|
clientName = browserInfo.name,
|
||||||
clientVersion = browserInfo.version,
|
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 {
|
private fun parseWebUserAgent(userAgent: String): DeviceExtendedInfo {
|
||||||
return parseDesktopUserAgent(userAgent).copy(
|
return parseDesktopUserAgent(userAgent).copy(
|
||||||
deviceType = DeviceType.WEB
|
deviceType = DeviceType.WEB
|
||||||
|
|
Loading…
Add table
Reference in a new issue