diff --git a/CHANGELOG.md b/CHANGELOG.md index 513cb017f3..34881d6e15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ Attention: don't forget to add the flag for F-Droid before release - [FIX] Fix flaky test - [FIX] Infinite dispatch after screen close on remote-control screens - [FIX] Bad bottom sheet animation on infrared setup screen +- [FIX] Share infrared remote after rename - [CI] Fix merge-queue files diff - [CI] Add https://github.com/LionZXY/detekt-decompose-rule - [CI] Enabling detekt module for android and kmp modules diff --git a/components/infrared/impl/src/main/kotlin/com/flipperdevices/infrared/impl/api/InfraredViewDecomposeComponentImpl.kt b/components/infrared/impl/src/main/kotlin/com/flipperdevices/infrared/impl/api/InfraredViewDecomposeComponentImpl.kt index f2426d43ef..7f4091a6a3 100644 --- a/components/infrared/impl/src/main/kotlin/com/flipperdevices/infrared/impl/api/InfraredViewDecomposeComponentImpl.kt +++ b/components/infrared/impl/src/main/kotlin/com/flipperdevices/infrared/impl/api/InfraredViewDecomposeComponentImpl.kt @@ -56,7 +56,7 @@ class InfraredViewDecomposeComponentImpl @AssistedInject constructor( } shareBottomUiApi.ComposableShareBottomSheet( - viewModel.keyPath, + provideFlipperKeyPath = viewModel::getKeyPath, onSheetStateVisible = { isShown, onClose -> val isBackPressHandled by isBackPressHandledFlow.collectAsState() backCallback.isEnabled = isShown diff --git a/components/infrared/impl/src/main/kotlin/com/flipperdevices/infrared/impl/viewmodel/InfraredViewModel.kt b/components/infrared/impl/src/main/kotlin/com/flipperdevices/infrared/impl/viewmodel/InfraredViewModel.kt index 9d9f2268ec..506c1f7f2c 100644 --- a/components/infrared/impl/src/main/kotlin/com/flipperdevices/infrared/impl/viewmodel/InfraredViewModel.kt +++ b/components/infrared/impl/src/main/kotlin/com/flipperdevices/infrared/impl/viewmodel/InfraredViewModel.kt @@ -10,6 +10,7 @@ import com.flipperdevices.core.ui.lifecycle.DecomposeViewModel import com.flipperdevices.infrared.api.InfraredConnectionApi import com.flipperdevices.infrared.api.InfraredConnectionApi.InfraredEmulateState import com.flipperdevices.keyscreen.api.KeyStateHelperApi +import com.flipperdevices.keyscreen.model.KeyScreenState import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject @@ -19,16 +20,23 @@ import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach class InfraredViewModel @AssistedInject constructor( - @Assisted val keyPath: FlipperKeyPath, // For get value to bottom sheet + @Assisted private val paramKeyPath: FlipperKeyPath, // For get value to bottom sheet keyStateHelperApi: KeyStateHelperApi.Builder, serviceProvider: FlipperServiceProvider, private val infraredConnectionApi: InfraredConnectionApi ) : DecomposeViewModel(), FlipperBleServiceConsumer, LogTagProvider { override val TAG: String = "InfraredViewModel" - private val keyStateHelper = keyStateHelperApi.build(keyPath, viewModelScope) + private val keyStateHelper = keyStateHelperApi.build(paramKeyPath, viewModelScope) fun getState() = keyStateHelper.getKeyScreenState() + fun getKeyPath(): FlipperKeyPath { + return (keyStateHelper.getKeyScreenState().value as? KeyScreenState.Ready) + ?.flipperKey + ?.getKeyPath() + ?: paramKeyPath + } + private val emulateStateFlow = MutableStateFlow(null) fun getEmulateState() = emulateStateFlow.asStateFlow() diff --git a/components/keyscreen/impl/src/main/java/com/flipperdevices/keyscreen/impl/api/KeyScreenViewDecomposeComponentImpl.kt b/components/keyscreen/impl/src/main/java/com/flipperdevices/keyscreen/impl/api/KeyScreenViewDecomposeComponentImpl.kt index f48178ce98..3f0e7c5307 100644 --- a/components/keyscreen/impl/src/main/java/com/flipperdevices/keyscreen/impl/api/KeyScreenViewDecomposeComponentImpl.kt +++ b/components/keyscreen/impl/src/main/java/com/flipperdevices/keyscreen/impl/api/KeyScreenViewDecomposeComponentImpl.kt @@ -59,7 +59,7 @@ class KeyScreenViewDecomposeComponentImpl @AssistedInject constructor( keyScreenViewModelFactory(keyPath) } shareBottomApi.ComposableShareBottomSheet( - flipperKeyPath = viewModel.keyPath, + provideFlipperKeyPath = viewModel::getKeyPath, onSheetStateVisible = { isShown, onClose -> val isBackPressHandled by isBackPressHandledFlow.collectAsState() backCallback.isEnabled = isShown diff --git a/components/keyscreen/impl/src/main/java/com/flipperdevices/keyscreen/impl/viewmodel/KeyScreenViewModel.kt b/components/keyscreen/impl/src/main/java/com/flipperdevices/keyscreen/impl/viewmodel/KeyScreenViewModel.kt index 036eb9cdf0..638d189343 100644 --- a/components/keyscreen/impl/src/main/java/com/flipperdevices/keyscreen/impl/viewmodel/KeyScreenViewModel.kt +++ b/components/keyscreen/impl/src/main/java/com/flipperdevices/keyscreen/impl/viewmodel/KeyScreenViewModel.kt @@ -14,13 +14,20 @@ import kotlinx.coroutines.flow.StateFlow @Suppress("LongParameterList") class KeyScreenViewModel @AssistedInject constructor( - @Assisted val keyPath: FlipperKeyPath, // For get value to bottom sheet + @Assisted val paramKeyPath: FlipperKeyPath, // For get value to bottom sheet keyStateHelperApi: KeyStateHelperApi.Builder, private val metricApi: MetricApi ) : DecomposeViewModel(), LogTagProvider { override val TAG = "KeyScreenViewModel" - private val keyStateHelper = keyStateHelperApi.build(keyPath, viewModelScope) + private val keyStateHelper = keyStateHelperApi.build(paramKeyPath, viewModelScope) + + fun getKeyPath(): FlipperKeyPath { + return (keyStateHelper.getKeyScreenState().value as? KeyScreenState.Ready) + ?.flipperKey + ?.getKeyPath() + ?: paramKeyPath + } fun getKeyScreenState(): StateFlow = keyStateHelper.getKeyScreenState() diff --git a/components/remote-controls/grid/saved/impl/src/main/kotlin/com/flipperdevices/remotecontrols/impl/grid/local/presentation/decompose/internal/LocalGridScreenDecomposeComponentImpl.kt b/components/remote-controls/grid/saved/impl/src/main/kotlin/com/flipperdevices/remotecontrols/impl/grid/local/presentation/decompose/internal/LocalGridScreenDecomposeComponentImpl.kt index f45b3d1d32..bd1769545e 100644 --- a/components/remote-controls/grid/saved/impl/src/main/kotlin/com/flipperdevices/remotecontrols/impl/grid/local/presentation/decompose/internal/LocalGridScreenDecomposeComponentImpl.kt +++ b/components/remote-controls/grid/saved/impl/src/main/kotlin/com/flipperdevices/remotecontrols/impl/grid/local/presentation/decompose/internal/LocalGridScreenDecomposeComponentImpl.kt @@ -49,7 +49,7 @@ class LocalGridScreenDecomposeComponentImpl @AssistedInject constructor( @Composable override fun Render() { shareBottomUiApi.ComposableShareBottomSheet( - keyPath, + provideFlipperKeyPath = { keyPath }, onSheetStateVisible = { isShown, onClose -> val isBackPressHandled by isBackPressHandledFlow.collectAsState() backCallback.isEnabled = isShown diff --git a/components/share/api/src/main/java/com/flipperdevices/share/api/ShareBottomUIApi.kt b/components/share/api/src/main/java/com/flipperdevices/share/api/ShareBottomUIApi.kt index 6864f2f580..d41de5fdba 100644 --- a/components/share/api/src/main/java/com/flipperdevices/share/api/ShareBottomUIApi.kt +++ b/components/share/api/src/main/java/com/flipperdevices/share/api/ShareBottomUIApi.kt @@ -7,7 +7,7 @@ import com.flipperdevices.bridge.dao.api.model.FlipperKeyPath interface ShareBottomUIApi { @Composable fun ComposableShareBottomSheet( - flipperKeyPath: FlipperKeyPath, + provideFlipperKeyPath: () -> FlipperKeyPath, componentContext: ComponentContext, onSheetStateVisible: @Composable (isVisible: Boolean, onClose: () -> Unit) -> Unit, screenContent: @Composable (() -> Unit) -> Unit, diff --git a/components/share/uploader/src/main/kotlin/com/flipperdevices/uploader/api/ShareBottomUIImpl.kt b/components/share/uploader/src/main/kotlin/com/flipperdevices/uploader/api/ShareBottomUIImpl.kt index 96cd7e4cb7..0540a1fcb8 100644 --- a/components/share/uploader/src/main/kotlin/com/flipperdevices/uploader/api/ShareBottomUIImpl.kt +++ b/components/share/uploader/src/main/kotlin/com/flipperdevices/uploader/api/ShareBottomUIImpl.kt @@ -37,13 +37,13 @@ class ShareBottomUIImpl @Inject constructor( @Composable @Suppress("NonSkippableComposable") override fun ComposableShareBottomSheet( - flipperKeyPath: FlipperKeyPath, + provideFlipperKeyPath: () -> FlipperKeyPath, componentContext: ComponentContext, onSheetStateVisible: @Composable (isVisible: Boolean, onClose: () -> Unit) -> Unit, screenContent: @Composable (() -> Unit) -> Unit, ) { - val viewModel = componentContext.viewModelWithFactory(flipperKeyPath) { - uploaderViewModelFactory(flipperKeyPath) + val viewModel = componentContext.viewModelWithFactory(provideFlipperKeyPath.invoke()) { + uploaderViewModelFactory(provideFlipperKeyPath) } val scrimColor = if (MaterialTheme.colors.isLight) { diff --git a/components/share/uploader/src/main/kotlin/com/flipperdevices/uploader/viewmodel/UploaderViewModel.kt b/components/share/uploader/src/main/kotlin/com/flipperdevices/uploader/viewmodel/UploaderViewModel.kt index 5d4d0d2cbe..80121edd0c 100644 --- a/components/share/uploader/src/main/kotlin/com/flipperdevices/uploader/viewmodel/UploaderViewModel.kt +++ b/components/share/uploader/src/main/kotlin/com/flipperdevices/uploader/viewmodel/UploaderViewModel.kt @@ -36,13 +36,13 @@ class UploaderViewModel @AssistedInject constructor( private val cryptoStorageApi: CryptoStorageApi, private val simpleKeyApi: SimpleKeyApi, private val metricApi: MetricApi, - @Assisted private val flipperKeyPath: FlipperKeyPath + @Assisted private val provideFlipperKeyPath: () -> FlipperKeyPath ) : DecomposeViewModel(), LogTagProvider { override val TAG: String = "UploaderViewModel" private val _state = MutableStateFlow(ShareState.Initial) fun getState() = _state.asStateFlow() - fun getFlipperKeyName() = flipperKeyPath.path.nameWithExtension + fun getFlipperKeyName() = provideFlipperKeyPath.invoke().path.nameWithExtension fun invalidate() { viewModelScope.launch { @@ -52,7 +52,7 @@ class UploaderViewModel @AssistedInject constructor( } private suspend fun parseFlipperKeyPath() { - simpleKeyApi.getKeyAsFlow(flipperKeyPath).collectLatest { flipperKey -> + simpleKeyApi.getKeyAsFlow(provideFlipperKeyPath.invoke()).collectLatest { flipperKey -> if (flipperKey == null) { _state.emit(ShareState.Error(ShareError.OTHER)) return@collectLatest @@ -88,7 +88,7 @@ class UploaderViewModel @AssistedInject constructor( ) _state.emit(ShareState.Completed) }.onFailure { exception -> - error(exception) { "Error on share $flipperKeyPath by file" } + error(exception) { "Error on share ${provideFlipperKeyPath.invoke()} by file" } _state.emit(ShareState.Error(ShareError.OTHER)) } } @@ -157,7 +157,7 @@ class UploaderViewModel @AssistedInject constructor( @AssistedFactory fun interface Factory { operator fun invoke( - flipperKeyPath: FlipperKeyPath + provideFlipperKeyPath: () -> FlipperKeyPath ): UploaderViewModel } }