generated from nimblehq/git-template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#102] Integrate implementation for no connection dialog
- Loading branch information
1 parent
e0e0e42
commit fd3afad
Showing
8 changed files
with
92 additions
and
38 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
app/src/main/java/co/nimblehq/compose/crypto/extension/FlowExt.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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package co.nimblehq.compose.crypto.extension | ||
|
||
import android.annotation.SuppressLint | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import kotlinx.coroutines.flow.* | ||
import kotlin.coroutines.CoroutineContext | ||
import kotlin.coroutines.EmptyCoroutineContext | ||
|
||
@SuppressLint("ComposableNaming") | ||
@Composable | ||
fun <T> Flow<T>.collectAsEffect( | ||
context: CoroutineContext = EmptyCoroutineContext, | ||
block: suspend (T) -> Unit, | ||
) { | ||
LaunchedEffect(key1 = Unit) { | ||
onEach(block).flowOn(context).launchIn(this) | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
app/src/main/java/co/nimblehq/compose/crypto/ui/screens/MainViewModel.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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package co.nimblehq.compose.crypto.ui.screens | ||
|
||
import androidx.lifecycle.viewModelScope | ||
import co.nimblehq.compose.crypto.domain.usecase.GetConnectionStatusUseCase | ||
import co.nimblehq.compose.crypto.ui.base.* | ||
import co.nimblehq.compose.crypto.util.DispatchersProvider | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.flow.* | ||
import javax.inject.Inject | ||
|
||
interface Input : BaseInput | ||
|
||
interface Output : BaseOutput { | ||
val isNetworkConnected: SharedFlow<Boolean?> | ||
} | ||
|
||
@HiltViewModel | ||
class MainViewModel @Inject constructor( | ||
getConnectionStatusUseCase: GetConnectionStatusUseCase, | ||
dispatchersProvider: DispatchersProvider, | ||
) : BaseViewModel(dispatchersProvider), Input, Output { | ||
private val _isNetworkConnected = MutableSharedFlow<Boolean?>() | ||
override val isNetworkConnected: SharedFlow<Boolean?> | ||
get() = _isNetworkConnected | ||
|
||
override val input: BaseInput = this | ||
override val output: BaseOutput = this | ||
|
||
init { | ||
getConnectionStatusUseCase() | ||
.catch { | ||
_error.emit(it) | ||
} | ||
.onEach { | ||
_isNetworkConnected.emit(it) | ||
} | ||
.flowOn(dispatchersProvider.io) | ||
.launchIn(viewModelScope) | ||
} | ||
} |
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
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