Skip to content

Instantly share code, notes, and snippets.

Avatar

Bhavesh Sharma bhavesh3005sharma

View GitHub Profile
@bhavesh3005sharma
bhavesh3005sharma / PowerplayDaggerModule.kt
Last active Aug 24, 2022
Script demonstrate how we can inject the dependencies into the classes not supported by Hilt directly.
View PowerplayDaggerModule.kt
@Module
@InstallIn(SingletonComponent::class)
object PowerplayDaggerModule {
@EntryPoint
@InstallIn(SingletonComponent::class)
interface SampleAdapterEntryPointEntryPoint {
val sampleClass : SampleClass
}
View SampleFragment.kt
@AndroidEntryPoint
class SampleFragment : Fragment() {
@Inject lateinit var sampleWorker : SampleWorkerInterface
....
....
private fun sendData(input : String, onComplete: ((String?) -> Unit)?) {
sampleWorker.sendData(input) { responseString ->
View SampleFragment.kt
@AndroidEntryPoint
class SampleFragment : Fragment() {
// No need to extract it here
// private val expId by lazy { intent?.getStringExtra("EXPERIMENT_ID") }
val viewModel: SampleViewModel by activityViewModels()
.....
.....
@bhavesh3005sharma
bhavesh3005sharma / SampleActivity.kt
Last active Aug 24, 2022
Script demonstrating the use of @AssistedInject & @AssistedFactory in case parameterized viewmodel
View SampleActivity.kt
@AndroidEntryPoint
class SampleActivity : AppCompatActivity() {
@Inject lateinit var factory: SampleViewModelFactory
val viewModel: SampleViewModel by viewModels {
SampleViewModel.provideFactory(
factory,
"data"
)