This file contains hidden or 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
class LocationActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
lifecycleScope.launch { | |
someLocationProvider.locations | |
.flowWithLifecycle(lifecycle, STARTED) | |
.collect { | |
// New location! Update the map | |
} |
This file contains hidden or 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
/* Copyright 2022 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 */ | |
inline fun <T> Flow<T>.launchAndCollectIn( | |
owner: LifecycleOwner, | |
minActiveState: Lifecycle.State = Lifecycle.State.STARTED, | |
crossinline action: suspend CoroutineScope.(T) -> Unit | |
) = owner.lifecycleScope.launch { | |
owner.repeatOnLifecycle(minActiveState) { | |
collect { | |
action(it) |
This file contains hidden or 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
class LocationActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
someLocationProvider.locations.launchAndCollectIn(this, STARTED) { | |
// New location! Update the map | |
} | |
} | |
} |
This file contains hidden or 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
// NOTE: This code uses Compose 1.0.0-beta09 | |
import androidx.compose.foundation.Canvas | |
import androidx.compose.foundation.layout.BoxWithConstraints | |
import androidx.compose.foundation.layout.padding | |
import androidx.compose.foundation.layout.size | |
import androidx.compose.material.MaterialTheme | |
import androidx.compose.material.Text | |
import androidx.compose.runtime.Composable | |
import androidx.compose.runtime.getValue |
This file contains hidden or 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
class FeedViewModel( | |
private val loadCurrentMomentUseCase: LoadCurrentMomentUseCase, | |
loadAnnouncementsUseCase: LoadAnnouncementsUseCase, | |
private val loadStarredAndReservedSessionsUseCase: LoadStarredAndReservedSessionsUseCase, | |
getTimeZoneUseCase: GetTimeZoneUseCase, | |
getConferenceStateUseCase: GetConferenceStateUseCase, | |
private val timeProvider: TimeProvider, | |
private val analyticsHelper: AnalyticsHelper, | |
private val signInViewModelDelegate: SignInViewModelDelegate, | |
themedActivityDelegate: ThemedActivityDelegate, |
This file contains hidden or 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
@HiltAndroidApp | |
class MusicApp : Application() | |
@AndroidEntryPoint | |
class PlayActivity : AppCompatActivity() { /* ... */ } |
This file contains hidden or 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
@AndroidEntryPoint | |
class PlayActivity : AppCompatActivity() { | |
@Inject lateinit var player: MusicPlayer | |
override fun onCreate(savedInstanceState: Bundle) { | |
super.onCreate(bundle) | |
player.play("YHLQMDLG") | |
} | |
} |
This file contains hidden or 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
class MusicPlayer @Inject constructor() { | |
fun play(id: String) { ... } | |
} |
This file contains hidden or 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
// PlayActivity annotated with @AndroidEntryPoint | |
class PlayActivityContainer { | |
// MusicPlayer annotated with @Inject | |
fun provideMusicPlayer() = MusicPlayer() | |
} |
This file contains hidden or 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
class PlayActivity : AppCompatActivity() { | |
private lateinit var player: MusicPlayer | |
// Created by Hilt when annotating the activity with @AndroidEntryPoint | |
private lateinit var container: PlayActivityContainer | |
override fun onCreate(savedInstanceState: Bundle) { |