diff --git a/chat-android/build.gradle.kts b/chat-android/build.gradle.kts index b5b35dc0..fba33949 100644 --- a/chat-android/build.gradle.kts +++ b/chat-android/build.gradle.kts @@ -33,7 +33,6 @@ android { } compileOptions { - isCoreLibraryDesugaringEnabled = true sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 } @@ -53,7 +52,6 @@ dependencies { api(libs.ably.android) implementation(libs.gson) implementation(libs.coroutine.core) - coreLibraryDesugaring(libs.desugar.jdk.libs) testImplementation(libs.junit) testImplementation(libs.mockk) @@ -68,6 +66,10 @@ tasks.withType().configureEach { testLogging { exceptionFormat = TestExceptionFormat.FULL } + // Skip tests for the "release" build type so we don't run tests twice + if (name.lowercase().contains("release")) { + enabled = false + } } tasks.withType().configureEach { diff --git a/chat-android/src/main/java/com/ably/chat/Logger.kt b/chat-android/src/main/java/com/ably/chat/Logger.kt index 573cf5a3..af897aab 100644 --- a/chat-android/src/main/java/com/ably/chat/Logger.kt +++ b/chat-android/src/main/java/com/ably/chat/Logger.kt @@ -1,7 +1,9 @@ package com.ably.chat import android.util.Log -import java.time.LocalDateTime +import java.text.SimpleDateFormat +import java.util.Date +import java.util.Locale fun interface LogHandler { fun log(message: String, level: LogLevel, throwable: Throwable?, context: LogContext) @@ -90,13 +92,14 @@ internal class AndroidLogger( } override fun log(message: String, level: LogLevel, throwable: Throwable?, newTag: String?, newStaticContext: Map) { - if (level.logLevelValue <= minimalVisibleLogLevel.logLevelValue) return + if (level.logLevelValue < minimalVisibleLogLevel.logLevelValue) return val finalContext = context.mergeWith(newTag, newStaticContext) val tag = finalContext.tag val completeContext = finalContext.staticContext + finalContext.dynamicContext.mapValues { it.value() } val contextString = ", context: $completeContext" - val formattedMessage = "[${LocalDateTime.now()}] $tag ${level.name} ably-chat: ${message}$contextString" + val currentTime = SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S", Locale.US).format(Date()) + val formattedMessage = "$currentTime [$tag] (${level.name.uppercase()}) ably-chat: ${message}$contextString" when (level) { // We use Logcat's info level for Trace and Debug LogLevel.Trace -> Log.i(tag, formattedMessage, throwable) @@ -124,7 +127,7 @@ internal class CustomLogger( } override fun log(message: String, level: LogLevel, throwable: Throwable?, newTag: String?, newStaticContext: Map) { - if (level.logLevelValue <= minimalVisibleLogLevel.logLevelValue) return + if (level.logLevelValue < minimalVisibleLogLevel.logLevelValue) return val finalContext = context.mergeWith(newTag, newStaticContext) logHandler.log( message = message, diff --git a/chat-android/src/main/java/com/ably/chat/RoomOptions.kt b/chat-android/src/main/java/com/ably/chat/RoomOptions.kt index dee12831..03f20304 100644 --- a/chat-android/src/main/java/com/ably/chat/RoomOptions.kt +++ b/chat-android/src/main/java/com/ably/chat/RoomOptions.kt @@ -39,8 +39,8 @@ data class RoomOptions( val default = RoomOptions( typing = TypingOptions(), presence = PresenceOptions(), - reactions = RoomReactionsOptions, - occupancy = OccupancyOptions, + reactions = RoomReactionsOptions(), + occupancy = OccupancyOptions(), ) } } @@ -80,13 +80,25 @@ data class TypingOptions( /** * Represents the reactions options for a chat room. + * + * Note: This class is currently empty but allows for future extensions + * while maintaining backward compatibility. */ -object RoomReactionsOptions +class RoomReactionsOptions { + override fun equals(other: Any?) = other is RoomReactionsOptions + override fun hashCode() = javaClass.hashCode() +} /** * Represents the occupancy options for a chat room. + * + * Note: This class is currently empty but allows for future extensions + * while maintaining backward compatibility. */ -object OccupancyOptions +class OccupancyOptions { + override fun equals(other: Any?) = other is OccupancyOptions + override fun hashCode() = javaClass.hashCode() +} /** * Throws AblyException for invalid room configuration. diff --git a/chat-android/src/test/java/com/ably/chat/RoomOptionTest.kt b/chat-android/src/test/java/com/ably/chat/RoomOptionTest.kt new file mode 100644 index 00000000..a5cf14aa --- /dev/null +++ b/chat-android/src/test/java/com/ably/chat/RoomOptionTest.kt @@ -0,0 +1,30 @@ +package com.ably.chat + +import org.junit.Assert.assertEquals +import org.junit.Test + +class RoomOptionTest { + + @Test + fun `default occupancy options should be equal`() { + assertEquals(OccupancyOptions(), OccupancyOptions()) + } + + @Test + fun `default room reaction options should be equal`() { + assertEquals(RoomReactionsOptions(), RoomReactionsOptions()) + } + + @Test + fun `default room options should be equal`() { + assertEquals( + RoomOptions.default, + RoomOptions( + typing = TypingOptions(), + presence = PresenceOptions(), + reactions = RoomReactionsOptions(), + occupancy = OccupancyOptions(), + ), + ) + } +} diff --git a/chat-android/src/test/java/com/ably/chat/SandboxTest.kt b/chat-android/src/test/java/com/ably/chat/SandboxTest.kt index 373b65df..f8580601 100644 --- a/chat-android/src/test/java/com/ably/chat/SandboxTest.kt +++ b/chat-android/src/test/java/com/ably/chat/SandboxTest.kt @@ -56,7 +56,7 @@ class SandboxTest { fun `should return occupancy for the client`() = runTest { val chatClient = sandbox.createSandboxChatClient("client1") val roomId = UUID.randomUUID().toString() - val roomOptions = RoomOptions(occupancy = OccupancyOptions) + val roomOptions = RoomOptions(occupancy = OccupancyOptions()) val chatClientRoom = chatClient.rooms.get(roomId, roomOptions) @@ -91,7 +91,7 @@ class SandboxTest { fun `should observe room reactions`() = runTest { val chatClient = sandbox.createSandboxChatClient() val roomId = UUID.randomUUID().toString() - val roomOptions = RoomOptions(reactions = RoomReactionsOptions) + val roomOptions = RoomOptions(reactions = RoomReactionsOptions()) val room = chatClient.rooms.get(roomId, roomOptions) room.attach() diff --git a/example/README.md b/example/README.md index 1efe8b46..5c74fdc5 100644 --- a/example/README.md +++ b/example/README.md @@ -9,6 +9,14 @@ Ensure you have the following installed: - Java 17 or higher - Android SDK with API Level 34 or higher +Add your Ably key to the `local.properties` file: + +```properties +sdk.dir=/path/to/android/sdk + +ABLY_KEY=xxxx:yyyyyy +``` + ## Steps to Run the App 1. Open in Android Studio diff --git a/example/build.gradle.kts b/example/build.gradle.kts index bc3a226f..2307a660 100644 --- a/example/build.gradle.kts +++ b/example/build.gradle.kts @@ -37,7 +37,6 @@ android { } } compileOptions { - isCoreLibraryDesugaringEnabled = true sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 } @@ -68,7 +67,6 @@ dependencies { implementation(libs.androidx.ui.graphics) implementation(libs.androidx.ui.tooling.preview) implementation(libs.androidx.material3) - coreLibraryDesugaring(libs.desugar.jdk.libs) testImplementation(libs.junit) androidTestImplementation(libs.androidx.junit) androidTestImplementation(libs.androidx.espresso.core) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 8a37af32..ca52090b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,11 +3,9 @@ [versions] ably = "1.2.46" -desugar-jdk-libs = "2.1.2" junit = "4.13.2" agp = "8.5.2" detekt = "1.23.6" -konfetti-compose = "2.0.4" kotlin = "2.0.10" androidx-test = "1.6.1" androidx-junit = "1.2.1" @@ -23,7 +21,6 @@ build-config = "5.5.1" ktor = "3.0.1" [libraries] -desugar-jdk-libs = { module = "com.android.tools:desugar_jdk_libs", version.ref = "desugar-jdk-libs" } junit = { group = "junit", name = "junit", version.ref = "junit" } detekt-formatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detekt" } ably-android = { module = "io.ably:ably-android", version.ref = "ably" }