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
@Module | |
public abstract class BaseFragmentModule { | |
public static final String FRAGMENT = "BaseFragmentModule.fragment"; | |
static final String CHILD_FRAGMENT_MANAGER = "BaseFragmentModule.childFragmentManager"; | |
@Provides | |
@Named(CHILD_FRAGMENT_MANAGER) | |
@PerFragment |
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
@Module | |
public abstract class BaseChildFragmentModule { | |
public static final String CHILD_FRAGMENT = "BaseChildFragmentModule.childFragment"; | |
} |
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
@Singleton | |
public final class SingletonUtil { | |
@Inject | |
SingletonUtil() { | |
} | |
public String doSomething() { | |
return "SingletonUtil: " + hashCode(); | |
} |
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
@PerActivity | |
public final class PerActivityUtil { | |
private final Activity activity; | |
@Inject | |
PerActivityUtil(Activity activity) { | |
this.activity = activity; | |
} |
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
@PerFragment | |
public final class PerFragmentUtil { | |
private final Fragment fragment; | |
@Inject | |
PerFragmentUtil(@Named(BaseFragmentModule.FRAGMENT) Fragment fragment) { | |
this.fragment = 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
@PerChildFragment | |
public final class PerChildFragmentUtil { | |
private final Fragment childFragment; | |
@Inject | |
PerChildFragmentUtil(@Named(BaseChildFragmentModule.CHILD_FRAGMENT) Fragment childFragment) { | |
this.childFragment = childFragment; | |
} |
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 final class MainFragment extends BaseFragment implements View.OnClickListener { | |
@Inject | |
MainFragmentListener listener; | |
@Override | |
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, | |
Bundle savedInstanceState) { | |
return inflater.inflate(R.layout.main_fragment, container, false); | |
} |
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
interface MainFragmentListener { | |
void onExample1Clicked(); | |
void onExample2Clicked(); | |
void onExample3Clicked(); | |
} |
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
@Module(includes = BaseFragmentModule.class) | |
abstract class MainFragmentModule { | |
@Binds | |
@Named(BaseFragmentModule.FRAGMENT) | |
@PerFragment | |
abstract Fragment fragment(MainFragment mainFragment); | |
} |
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
// TODO (ContributesAndroidInjector) remove this in favor of @ContributesAndroidInjector | |
@PerFragment | |
@Subcomponent(modules = MainFragmentModule.class) | |
public interface MainFragmentSubcomponent extends AndroidInjector<MainFragment> { | |
@Subcomponent.Builder | |
abstract class Builder extends AndroidInjector.Builder<MainFragment> { | |
} | |
} |