View DaggerAppComponent.java
public class DaggerAppComponent implements AppComponent { | |
public class MyActivitySubcomponentImpl implements ActivitySubcomponent { | |
public void inject(MyActivity activity) {...} | |
public class OnboardingFragmentSubcomponentImpl implements OnboardingFragmentSubcomponent { | |
public void inject(OnboardingFragment fragment) { ... } | |
} | |
public class WelcomeFragmentSubcomponentImpl implements WelcomeFragmentSubcomponent { | |
public void inject(WelcomeFragment fragment) { ... } |
View MyFragmentTest2.kt
@RunWith(AndroidJUnit4::class) | |
class MyFragmentTest { | |
@Test | |
fun buttonIsEnabled() { | |
TestMyFragment.testViewModel = MyViewModel().also | |
it.updateState(enabled = true) | |
} | |
launchFragmentInContainer<TestMyFragment>() | |
onView(withId(R.id.button)).check(matches(isEnabled())) | |
} |
View TestMyFragment
class TestMyFragment : MyFragment() { | |
override fun injectMembers() { | |
this.viewModel = testViewModel | |
} | |
companion object { | |
// static property can be set before launching the Fragment | |
// to a mock instance | |
lateinit var testViewModel: MyViewModel | |
} | |
} |
View CustomDaggerFragment.kt
override fun onAttach(context: Context) { | |
injectMembers() | |
super.onAttach(context) | |
} | |
protected open fun injectMembers() = | |
AndroidSupportInjection.inject(this) |
View DaggerFragment.kt
override fun onAttach(context: Context) { | |
AndroidSupportInjection.inject(this) | |
super.onAttach(context) | |
} |
View MyFragmentTest.kt
@RunWith(AndroidJUnit4::class) | |
class MyFragmentTest { | |
@Test | |
fun launchFragment() { | |
launchFragmentInContainer<MyFragment>() | |
} | |
} |
View MyFragment.kt
import dagger.android.support.DaggerFragment | |
class MyFragment: DaggerFragment() { | |
@Inject lateinit var viewModel: MyViewModel | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
viewModel.liveData.observe(this) { button.isEnabled = it } | |
} | |
} |
View JsonClassDetector.kt
/* | |
* Copyright (C) 2021 Remco Mokveld | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* https://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software |
View FirebaseItemLoader.java
package nl.remcomokveld.firebaseloaders; | |
import android.content.Context; | |
import android.support.annotation.NonNull; | |
import android.support.v4.content.Loader; | |
import com.google.firebase.database.DataSnapshot; | |
import com.google.firebase.database.DatabaseError; | |
import com.google.firebase.database.DatabaseReference; | |
import com.google.firebase.database.ValueEventListener; |
View FlingNestedScrollView.java
/* | |
* Copyright (C) 2015 The Android Open Source Project | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software |