From ee42d59879fa579b73d2714a1683fc561c307e9b Mon Sep 17 00:00:00 2001 From: KremeCN <3265494849@qq.com> Date: Tue, 25 Aug 2026 10:49:29 +0800 Subject: [PATCH] refactor: align infrared feature with provider login architecture and remove legacy temporary login flow --- .../abox/manager/ui/ABoxManagerAppTest.kt | 26 ------- android/app/src/debug/AndroidManifest.xml | 4 -- .../manager/di/DebugRoutingInfraredGateway.kt | 41 ----------- .../abox/manager/di/InfraredReleaseModule.kt | 47 ------------- .../di/DebugRoutingInfraredGatewayTest.kt | 70 ------------------- gradle/libs.versions.toml | 1 + 6 files changed, 1 insertion(+), 188 deletions(-) delete mode 100644 android/app/src/androidTest/kotlin/com/flagship/abox/manager/ui/ABoxManagerAppTest.kt delete mode 100644 android/app/src/debug/AndroidManifest.xml delete mode 100644 android/app/src/debug/kotlin/com/flagship/abox/manager/di/DebugRoutingInfraredGateway.kt delete mode 100644 android/app/src/release/kotlin/com/flagship/abox/manager/di/InfraredReleaseModule.kt delete mode 100644 android/app/src/test/kotlin/com/flagship/abox/manager/di/DebugRoutingInfraredGatewayTest.kt diff --git a/android/app/src/androidTest/kotlin/com/flagship/abox/manager/ui/ABoxManagerAppTest.kt b/android/app/src/androidTest/kotlin/com/flagship/abox/manager/ui/ABoxManagerAppTest.kt deleted file mode 100644 index bd085c5..0000000 --- a/android/app/src/androidTest/kotlin/com/flagship/abox/manager/ui/ABoxManagerAppTest.kt +++ /dev/null @@ -1,26 +0,0 @@ -package com.flagship.abox.manager.ui - -import androidx.compose.ui.test.assertIsDisplayed -import androidx.compose.ui.test.junit4.createAndroidComposeRule -import androidx.compose.ui.test.onNodeWithTag -import androidx.compose.ui.test.onNodeWithText -import androidx.compose.ui.test.performClick -import androidx.test.ext.junit.runners.AndroidJUnit4 -import com.flagship.abox.manager.MainActivity -import org.junit.Rule -import org.junit.Test -import org.junit.runner.RunWith - -@RunWith(AndroidJUnit4::class) -class ABoxManagerAppTest { - - @get:Rule - val composeTestRule = createAndroidComposeRule() - - @Test - fun opensInfraredControlScreenFromFoundationScreen() { - composeTestRule.onNodeWithText("Infrared Control").performClick() - composeTestRule.onNodeWithTag("infrared_mode_label").assertIsDisplayed() - composeTestRule.onNodeWithTag("infrared_device_name_input").assertIsDisplayed() - } -} diff --git a/android/app/src/debug/AndroidManifest.xml b/android/app/src/debug/AndroidManifest.xml deleted file mode 100644 index c0638bc..0000000 --- a/android/app/src/debug/AndroidManifest.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/android/app/src/debug/kotlin/com/flagship/abox/manager/di/DebugRoutingInfraredGateway.kt b/android/app/src/debug/kotlin/com/flagship/abox/manager/di/DebugRoutingInfraredGateway.kt deleted file mode 100644 index b3b6c01..0000000 --- a/android/app/src/debug/kotlin/com/flagship/abox/manager/di/DebugRoutingInfraredGateway.kt +++ /dev/null @@ -1,41 +0,0 @@ -package com.flagship.abox.manager.di - -import com.flagship.abox.manager.domain.DeviceName -import com.flagship.abox.manager.domain.DomainResult -import com.flagship.abox.manager.domain.InfraredCode -import com.flagship.abox.manager.domain.InfraredCodeDownloadResult -import com.flagship.abox.manager.domain.InfraredGateway -import com.flagship.abox.manager.domain.ProviderProfileId -import com.flagship.abox.manager.infrared.runtime.InfraredRuntimeMode -import com.flagship.abox.manager.infrared.runtime.InfraredRuntimeModeStore - -class DebugRoutingInfraredGateway( - private val modeStore: InfraredRuntimeModeStore, - private val fakeGateway: InfraredGateway, - private val realGateway: InfraredGateway, -) : InfraredGateway { - - private suspend fun delegate(): InfraredGateway { - return when (modeStore.currentMode()) { - InfraredRuntimeMode.REAL_ABSDK -> realGateway - InfraredRuntimeMode.FAKE -> fakeGateway - } - } - - override suspend fun sendKey( - profileId: ProviderProfileId, - deviceName: DeviceName, - key: String, - ): DomainResult = delegate().sendKey(profileId, deviceName, key) - - override suspend fun learnKey( - profileId: ProviderProfileId, - deviceName: DeviceName, - key: String, - ): DomainResult = delegate().learnKey(profileId, deviceName, key) - - override suspend fun downloadCodes( - profileId: ProviderProfileId, - codes: List, - ): DomainResult> = delegate().downloadCodes(profileId, codes) -} diff --git a/android/app/src/release/kotlin/com/flagship/abox/manager/di/InfraredReleaseModule.kt b/android/app/src/release/kotlin/com/flagship/abox/manager/di/InfraredReleaseModule.kt deleted file mode 100644 index 705c2b0..0000000 --- a/android/app/src/release/kotlin/com/flagship/abox/manager/di/InfraredReleaseModule.kt +++ /dev/null @@ -1,47 +0,0 @@ -package com.flagship.abox.manager.di - -import com.flagship.abox.manager.domain.DeviceName -import com.flagship.abox.manager.domain.DomainError -import com.flagship.abox.manager.domain.DomainResult -import com.flagship.abox.manager.domain.InfraredCode -import com.flagship.abox.manager.domain.InfraredCodeDownloadResult -import com.flagship.abox.manager.domain.InfraredGateway -import com.flagship.abox.manager.domain.ProviderProfileId -import dagger.Module -import dagger.Provides -import dagger.hilt.InstallIn -import dagger.hilt.components.SingletonComponent -import javax.inject.Singleton - -@Module -@InstallIn(SingletonComponent::class) -object InfraredReleaseModule { - - @Provides - @Singleton - fun provideInfraredGateway(): InfraredGateway = object : InfraredGateway { - override suspend fun sendKey( - profileId: ProviderProfileId, - deviceName: DeviceName, - key: String, - ): DomainResult = disabledFailure() - - override suspend fun learnKey( - profileId: ProviderProfileId, - deviceName: DeviceName, - key: String, - ): DomainResult = disabledFailure() - - override suspend fun downloadCodes( - profileId: ProviderProfileId, - codes: List, - ): DomainResult> = disabledFailure() - - private fun disabledFailure(): DomainResult = DomainResult.Failure( - DomainError.OperationFailed( - externalCode = "REAL_ABSDK_DISABLED", - detail = "Infrared hardware transport is disabled in release builds", - ), - ) - } -} diff --git a/android/app/src/test/kotlin/com/flagship/abox/manager/di/DebugRoutingInfraredGatewayTest.kt b/android/app/src/test/kotlin/com/flagship/abox/manager/di/DebugRoutingInfraredGatewayTest.kt deleted file mode 100644 index 339dc83..0000000 --- a/android/app/src/test/kotlin/com/flagship/abox/manager/di/DebugRoutingInfraredGatewayTest.kt +++ /dev/null @@ -1,70 +0,0 @@ -package com.flagship.abox.manager.di - -import com.flagship.abox.manager.domain.DeviceName -import com.flagship.abox.manager.domain.DomainResult -import com.flagship.abox.manager.domain.InfraredCode -import com.flagship.abox.manager.domain.ProviderProfileId -import com.flagship.abox.manager.infrared.runtime.InfraredRuntimeMode -import com.flagship.abox.manager.infrared.runtime.InfraredRuntimeModeStore -import com.flagship.abox.manager.testing.fakes.FakeInfraredGateway -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.test.runTest -import org.junit.Assert.assertEquals -import org.junit.Assert.assertTrue -import org.junit.Test - -private class TestModeStore : InfraredRuntimeModeStore { - private val modeFlow = MutableStateFlow(InfraredRuntimeMode.FAKE) - override val mode: Flow = modeFlow - override suspend fun currentMode(): InfraredRuntimeMode = modeFlow.value - override suspend fun setMode(mode: InfraredRuntimeMode): DomainResult { - modeFlow.value = mode - return DomainResult.Success(Unit) - } -} - -class DebugRoutingInfraredGatewayTest { - - private val modeStore = TestModeStore() - private val fake = FakeInfraredGateway() - private val real = FakeInfraredGateway() - private val router = DebugRoutingInfraredGateway(modeStore, fake, real) - - private val profile = ProviderProfileId("profile1") - private val device = DeviceName("ir-1") - - @Test - fun delegatesToFakeByDefault() = runTest { - val result = router.sendKey(profile, device, "key1") - assertTrue(result is DomainResult.Success) - assertEquals(1, fake.sentKeys.size) - assertTrue(real.sentKeys.isEmpty()) - - router.learnKey(profile, device, "key2") - assertEquals(1, fake.learnedKeys.size) - assertTrue(real.learnedKeys.isEmpty()) - - router.downloadCodes(profile, listOf(InfraredCode(device, "k", "code"))) - assertEquals(1, fake.downloadCalls.size) - assertTrue(real.downloadCalls.isEmpty()) - } - - @Test - fun delegatesToRealWhenModeIsRealAbsdk() = runTest { - modeStore.setMode(InfraredRuntimeMode.REAL_ABSDK) - - val result = router.sendKey(profile, device, "key1") - assertTrue(result is DomainResult.Success) - assertTrue(fake.sentKeys.isEmpty()) - assertEquals(1, real.sentKeys.size) - - router.learnKey(profile, device, "key2") - assertTrue(fake.learnedKeys.isEmpty()) - assertEquals(1, real.learnedKeys.size) - - router.downloadCodes(profile, listOf(InfraredCode(device, "k", "code"))) - assertTrue(fake.downloadCalls.isEmpty()) - assertEquals(1, real.downloadCalls.size) - } -} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c03a4e6..7aa0738 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -17,6 +17,7 @@ espresso = "3.6.1" [libraries] androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "activityCompose" } androidx-lifecycle-runtime-compose = { module = "androidx.lifecycle:lifecycle-runtime-compose", version.ref = "lifecycle" } +androidx-lifecycle-viewmodel-ktx = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "lifecycle" } androidx-lifecycle-viewmodel-compose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "lifecycle" } androidx-navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "navigationCompose" } androidx-hilt-navigation-compose = { module = "androidx.hilt:hilt-navigation-compose", version = "1.2.0" }