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
@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
@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
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
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 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 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) { |
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() | |
} |