From bf4576d1556fe20336d405abbe88f9d7187f6175 Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Fri, 30 Sep 2022 13:21:44 +0300 Subject: [PATCH] Code review fixes. --- .../devices/v2/ParseDeviceUserAgentUseCase.kt | 25 ++++++++++++++++--- .../v2/ParseDeviceUserAgentUseCaseTest.kt | 22 ++++++++-------- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/ParseDeviceUserAgentUseCase.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/ParseDeviceUserAgentUseCase.kt index eb70addbb9..82c6edcbdf 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/ParseDeviceUserAgentUseCase.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/ParseDeviceUserAgentUseCase.kt @@ -48,7 +48,13 @@ class ParseDeviceUserAgentUseCase @Inject constructor() { deviceModel = deviceInfoSegments.getOrNull(0) deviceOperatingSystem = deviceInfoSegments.getOrNull(1) } - return DeviceExtendedInfo(DeviceType.MOBILE, deviceModel, deviceOperatingSystem, appName, appVersion) + return DeviceExtendedInfo( + deviceType = DeviceType.MOBILE, + deviceModel = deviceModel, + deviceOperatingSystem = deviceOperatingSystem, + clientName = appName, + clientVersion = appVersion + ) } private fun parseIosUserAgent(userAgent: String): DeviceExtendedInfo { @@ -57,7 +63,13 @@ class ParseDeviceUserAgentUseCase @Inject constructor() { val deviceInfoSegments = userAgent.substringAfter("(").substringBeforeLast(")").split("; ") val deviceModel = deviceInfoSegments.getOrNull(0) val deviceOperatingSystem = deviceInfoSegments.getOrNull(1) - return DeviceExtendedInfo(DeviceType.MOBILE, deviceModel, deviceOperatingSystem, appName, appVersion) + return DeviceExtendedInfo( + deviceType = DeviceType.MOBILE, + deviceModel = deviceModel, + deviceOperatingSystem = deviceOperatingSystem, + clientName = appName, + clientVersion = appVersion + ) } private fun parseDesktopUserAgent(userAgent: String): DeviceExtendedInfo { @@ -86,7 +98,14 @@ class ParseDeviceUserAgentUseCase @Inject constructor() { } else { deviceOperatingSystemSegments.getOrNull(0) } - return DeviceExtendedInfo(DeviceType.DESKTOP, browserName, deviceOperatingSystem, null, null) + return DeviceExtendedInfo( + deviceType = DeviceType.DESKTOP, + deviceModel = null, + deviceOperatingSystem = deviceOperatingSystem, + clientName = null, + clientVersion = null, + browser = browserName + ) } private fun parseWebUserAgent(userAgent: String): DeviceExtendedInfo { diff --git a/vector/src/test/java/im/vector/app/features/settings/devices/v2/ParseDeviceUserAgentUseCaseTest.kt b/vector/src/test/java/im/vector/app/features/settings/devices/v2/ParseDeviceUserAgentUseCaseTest.kt index 0cb0019a2a..11f319f472 100644 --- a/vector/src/test/java/im/vector/app/features/settings/devices/v2/ParseDeviceUserAgentUseCaseTest.kt +++ b/vector/src/test/java/im/vector/app/features/settings/devices/v2/ParseDeviceUserAgentUseCaseTest.kt @@ -61,8 +61,8 @@ private val A_USER_AGENT_LIST_FOR_DESKTOP = listOf( "Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) ElementNightly/2022091301 Chrome/104.0.5112.102 Electron/20.1.1 Safari/537.36", ) private val AN_EXPECTED_RESULT_LIST_FOR_DESKTOP = listOf( - DeviceExtendedInfo(DeviceType.DESKTOP, "Electron", "Macintosh", null, null), - DeviceExtendedInfo(DeviceType.DESKTOP, "Electron", "Windows NT 10.0", null, null), + DeviceExtendedInfo(DeviceType.DESKTOP, null, "Macintosh", null, null, "Electron"), + DeviceExtendedInfo(DeviceType.DESKTOP, null, "Windows NT 10.0", null, null, "Electron"), ) private val A_USER_AGENT_LIST_FOR_WEB = listOf( @@ -77,15 +77,15 @@ private val A_USER_AGENT_LIST_FOR_WEB = listOf( "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246", ) private val AN_EXPECTED_RESULT_LIST_FOR_WEB = listOf( - DeviceExtendedInfo(DeviceType.WEB, "Chrome", "Macintosh", null, null), - DeviceExtendedInfo(DeviceType.WEB, "Chrome", "Windows NT 10.0", null, null), - DeviceExtendedInfo(DeviceType.WEB, "Firefox", "Macintosh", null, null), - DeviceExtendedInfo(DeviceType.WEB, "Safari", "Macintosh", null, null), - DeviceExtendedInfo(DeviceType.WEB, "Chrome", "Android 9", null, null), - DeviceExtendedInfo(DeviceType.WEB, "Safari", "iPad", null, null), - DeviceExtendedInfo(DeviceType.WEB, "Safari", "iPhone", null, null), - DeviceExtendedInfo(DeviceType.WEB, "Firefox", "Windows NT 6.0", null, null), - DeviceExtendedInfo(DeviceType.WEB, "Edge", "Windows NT 10.0", null, null), + DeviceExtendedInfo(DeviceType.WEB, null, "Macintosh", null, null, "Chrome"), + DeviceExtendedInfo(DeviceType.WEB, null, "Windows NT 10.0", null, null, "Chrome"), + DeviceExtendedInfo(DeviceType.WEB, null, "Macintosh", null, null, "Firefox"), + DeviceExtendedInfo(DeviceType.WEB, null, "Macintosh", null, null, "Safari"), + DeviceExtendedInfo(DeviceType.WEB, null, "Android 9", null, null, "Chrome"), + DeviceExtendedInfo(DeviceType.WEB, null, "iPad", null, null, "Safari"), + DeviceExtendedInfo(DeviceType.WEB, null, "iPhone", null, null, "Safari"), + DeviceExtendedInfo(DeviceType.WEB, null, "Windows NT 6.0", null, null, "Firefox"), + DeviceExtendedInfo(DeviceType.WEB, null, "Windows NT 10.0", null, null, "Edge"), ) private val AN_UNKNOWN_USER_AGENT_LIST = listOf(