This file contains 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
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) { ... } |
This file contains 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
@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())) | |
} |
This file contains 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 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 | |
} | |
} |
This file contains 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
override fun onAttach(context: Context) { | |
injectMembers() | |
super.onAttach(context) | |
} | |
protected open fun injectMembers() = | |
AndroidSupportInjection.inject(this) |
This file contains 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
override fun onAttach(context: Context) { | |
AndroidSupportInjection.inject(this) | |
super.onAttach(context) | |
} |
This file contains 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
@RunWith(AndroidJUnit4::class) | |
class MyFragmentTest { | |
@Test | |
fun launchFragment() { | |
launchFragmentInContainer<MyFragment>() | |
} | |
} |
This file contains 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
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 } | |
} | |
} |
This file contains 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 (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 |
This file contains 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
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; |
This file contains 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 (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 |