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( | |
private val db: MusicDatabase | |
) { | |
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
class PlayActivityContainer(val context: Context) { | |
fun provideMusicDatabase(): MusicDatabase { | |
return Room.databaseBuilder( | |
context, MusicDatabase::class.java, "music.db" | |
).build() | |
} | |
fun provideMusicPlayer() = MusicPlayer( | |
provideMusicDatabase() |
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
@Module | |
@InstallIn(SingletonComponent::class) | |
object DataModule { | |
@Provides | |
fun provideMusicDB(@ApplicationContext context: Context): MusicDatabase { | |
return Room.databaseBuilder( | |
context, MusicDatabase::class.java, "music.db" | |
).build() | |
} |
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 PlayActivityContainer(val context: Context) { | |
fun provideMusicDatabase(): MusicDatabase { | |
return Room.databaseBuilder( | |
context, MusicDatabase::class.java, "music.db" | |
).build() | |
} | |
fun provideMusicPlayer() = MusicPlayer( | |
provideMusicDatabase() |
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 PlayActivityContainer { | |
val musicDatabase: MusicDatabase = | |
Room.databaseBuilder( | |
context, MusicDatabase::class.java, "music.db" | |
).build() | |
fun provideMusicPlayer() = MusicPlayer(musicDatabase) | |
} |
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
@Module | |
@InstallIn(SingletonComponent::class) | |
object DataModule { | |
@Singleton | |
@Provides | |
fun provideMusicDB(@ApplicationContext context: Context): MusicDatabase { | |
return Room.databaseBuilder( | |
context, MusicDatabase::class.java, "music.db" | |
).build() |
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
@HiltViewModel | |
class FeedViewModel @Inject constructor( | |
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, |
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
// In the Manifest file: | |
// <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> | |
// <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> | |
class RequestLocationPermissionsSample : ComponentActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContent { |
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 */ | |
class AddEditTaskViewModel( | |
private val tasksRepository: TasksRepository | |
) : ViewModel() { | |
- private val _snackbarText = MutableLiveData<Event<Int>>() | |
- val snackbarText: LiveData<Event<Int>> = _snackbarText |
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 */ | |
// FRAGMENTS CODE CONSUMING THE EVENT WRAPPER SOLUTION | |
- class AddEditTaskFragment : Fragment() { | |
- override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
- ... | |
- viewModel.snackbarText.observe( | |
- lifecycleOwner, |