Skip to content

Instantly share code, notes, and snippets.

View krzdabrowski's full-sized avatar

Krzysztof Dąbrowski krzdabrowski

View GitHub Profile
class RocketsListContentTest {
@get:Rule
val composeTestRule = createComposeRule()
private val testRockets = generateTestRocketsFromPresentation()
@Before
fun setUp() {
composeTestRule.setContent {
class RocketsViewModelTest {
@JvmField
@RegisterExtension
val mainDispatcherExtension = MainDispatcherExtension()
@RelaxedMockK
private lateinit var getRocketsUseCase: GetRocketsUseCase
(...)
@Composable
fun AndroidStarterTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
content: @Composable () -> Unit
) {
val colorScheme = pickColorScheme(darkTheme)
(...)
MaterialTheme(
@Composable
inline fun <reified T> Flow<T>.collectWithLifecycle(
key: Any = Unit,
lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current,
minActiveState: Lifecycle.State = Lifecycle.State.STARTED,
noinline action: suspend (T) -> Unit
) {
val lifecycleAwareFlow = remember(this, lifecycleOwner) {
flowWithLifecycle(
lifecycle = lifecycleOwner.lifecycle,
@Composable
private fun HandleEvents(events: Flow<RocketsEvent>) {
val uriHandler = LocalUriHandler.current
events.collectWithLifecycle {
when (it) {
is OpenWebBrowserWithDetails -> {
uriHandler.openUri(it.uri)
}
}
class EventDelegateImpl<EVENT> : EventDelegate<EVENT> {
private val eventChannel = Channel<EVENT>(Channel.BUFFERED)
override fun getEvents(): Flow<EVENT> = eventChannel.receiveAsFlow()
override suspend fun setEvent(event: EVENT) {
eventChannel.send(event)
}
}
@Singleton
class NavigationManager @Inject constructor(
@MainImmediateScope private val externalMainImmediateScope: CoroutineScope
) {
private val navigationCommandChannel = Channel<NavigationCommand>(Channel.BUFFERED)
val navigationEvent = navigationCommandChannel.receiveAsFlow()
fun navigate(command: NavigationCommand) {
externalMainImmediateScope.launch {
navigationCommandChannel.send(command)
interface NavigationManager {
val navigationEvent: Flow<NavigationCommand>
fun navigate(command: NavigationCommand)
}
sealed class NavigationDestination(
val route: String
) {
data object Rockets : NavigationDestination("rocketsDestination")
data object Back : NavigationDestination("navigationBack")
}
interface NavigationCommand {
val destination: String
val configuration: NavOptions
get() = NavOptions.Builder().build()
}