-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e59392f
commit 53b478a
Showing
4 changed files
with
20 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 14 additions & 13 deletions
27
...ts/archive/impl/src/main/java/com/flipperdevices/archive/impl/viewmodel/SpeedViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,23 @@ | ||
package com.flipperdevices.archive.impl.viewmodel | ||
|
||
import com.flipperdevices.bridge.service.api.provider.FlipperServiceProvider | ||
import com.flipperdevices.bridge.connection.feature.provider.api.FFeatureProvider | ||
import com.flipperdevices.bridge.connection.feature.provider.api.FFeatureStatus | ||
import com.flipperdevices.bridge.connection.feature.provider.api.get | ||
import com.flipperdevices.bridge.connection.feature.serialspeed.api.FSpeedFeatureApi | ||
import com.flipperdevices.core.ui.lifecycle.DecomposeViewModel | ||
import kotlinx.coroutines.flow.SharingStarted | ||
import kotlinx.coroutines.flow.collect | ||
import kotlinx.coroutines.flow.flow | ||
import kotlinx.coroutines.flow.onEach | ||
import kotlinx.coroutines.flow.shareIn | ||
import kotlinx.coroutines.flow.flatMapLatest | ||
import kotlinx.coroutines.flow.flowOf | ||
import kotlinx.coroutines.flow.map | ||
import kotlinx.coroutines.flow.stateIn | ||
import javax.inject.Inject | ||
|
||
class SpeedViewModel @Inject constructor( | ||
private val serviceProvider: FlipperServiceProvider, | ||
fFeatureProvider: FFeatureProvider, | ||
) : DecomposeViewModel() { | ||
val speedFlow = flow { | ||
serviceProvider.getServiceApi() | ||
.requestApi | ||
.getSpeed() | ||
.onEach { emit(it) } | ||
.collect() | ||
}.shareIn(viewModelScope, SharingStarted.Eagerly, 1) | ||
val speedFlow = fFeatureProvider | ||
.get<FSpeedFeatureApi>() | ||
.map { status -> status as? FFeatureStatus.Supported<FSpeedFeatureApi> } | ||
.flatMapLatest { status -> status?.featureApi?.getSpeed() ?: flowOf(null) } | ||
.stateIn(viewModelScope, SharingStarted.Eagerly, null) | ||
} |