dagger.android.support.HasSupportFragmentInjector Java Examples

The following examples show how to use dagger.android.support.HasSupportFragmentInjector. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AppInjector.java    From mvvm-template with GNU General Public License v3.0 6 votes vote down vote up
private static void handleActivity(Activity activity) {
    if (activity instanceof HasSupportFragmentInjector || activity instanceof Injectable) {
        AndroidInjection.inject(activity);
    }
    if (activity instanceof FragmentActivity) {
        ((FragmentActivity) activity).getSupportFragmentManager()
                .registerFragmentLifecycleCallbacks(
                        new FragmentManager.FragmentLifecycleCallbacks() {
                            @Override
                            public void onFragmentCreated(FragmentManager fm, Fragment f,
                                                          Bundle savedInstanceState) {
                                if (f instanceof Injectable) {
                                    AndroidSupportInjection.inject(f);
                                }
                            }
                        }, true);
    }
}
 
Example #2
Source File: TestAppInjector.java    From mvvm-template with GNU General Public License v3.0 6 votes vote down vote up
private static void handleActivity(Activity activity) {
    if (activity instanceof HasSupportFragmentInjector || activity instanceof Injectable) {
        AndroidInjection.inject(activity);
    }
    if (activity instanceof FragmentActivity) {
        ((FragmentActivity) activity).getSupportFragmentManager()
                .registerFragmentLifecycleCallbacks(
                        new FragmentManager.FragmentLifecycleCallbacks() {
                            @Override
                            public void onFragmentCreated(FragmentManager fm, Fragment f,
                                                          Bundle savedInstanceState) {
                                if (f instanceof Injectable) {
                                    AndroidSupportInjection.inject(f);
                                }
                            }
                        }, true);
    }
}
 
Example #3
Source File: AppInjector.java    From tv-samples with Apache License 2.0 5 votes vote down vote up
/**
 * The strategy for automated dependency injection is:
 *
 *   If this activity has implemented HasSupportFragmentInjector interfacea which means it has
 *   to return the DispatchInjector through overriding public AndroidInjector<Fragment>
 *   fragmentInjector() method to return the @Inject DispatchInjector. Then this activity must
 *   be processed with the AndroidInjection by calling the AndroidInjection.inject method.
 *
 *   If the activity is extended from the FragmentActivity, then we will set up the dependency
 *   injection for all the fragments by instrumenting the AndroidInjection.inject method at
 *   the beginning of fragment's creation. Since the fragment takes the main responsibility on
 *   UI rendering.
 *
 * @param activity activity to be processed.
 */
private static void handleActivity(Activity activity) {

    // TODO: an injectable for activity separately
    if (activity instanceof HasSupportFragmentInjector) {

        // When the activity has implemented the HasSupportFragmentInjector interface, android
        // injector will inject into it, so the activity can be injected with the dispatch
        // injector specific for fragment. Then this dispatch injector will be returned through
        // the override method and contribute to android injector factory for fragment
        AndroidInjection.inject(activity);
    }
    if (activity instanceof FragmentActivity) {
        ((FragmentActivity) activity).getSupportFragmentManager()
                .registerFragmentLifecycleCallbacks(
                        new FragmentManager.FragmentLifecycleCallbacks() {
                            @Override
                            public void onFragmentCreated(FragmentManager fm, Fragment f,
                                    Bundle savedInstanceState) {
                                if (f instanceof Injectable) {

                                    // The injector only contains the provision method for the
                                    // field in the fragment.
                                    // But for activity, there will be a module providing the
                                    // binding method which will be bound to the fragment's
                                    // subcomponent's builder (Android injector builder) and
                                    // then be cast to AndroidInjector.Factory
                                    AndroidSupportInjection.inject(f);
                                }
                            }
                        }, true);
    }
}
 
Example #4
Source File: AppInjector.java    From leanback-showcase with Apache License 2.0 5 votes vote down vote up
/**
 * The strategy for automated dependency injection is:
 *
 *   If this activity has implemented HasSupportFragmentInjector interfacea which means it has
 *   to return the DispatchInjector through overriding public AndroidInjector<Fragment>
 *   fragmentInjector() method to return the @Inject DispatchInjector. Then this activity must
 *   be processed with the AndroidInjection by calling the AndroidInjection.inject method.
 *
 *   If the activity is extended from the FragmentActivity, then we will set up the dependency
 *   injection for all the fragments by instrumenting the AndroidInjection.inject method at
 *   the beginning of fragment's creation. Since the fragment takes the main responsibility on
 *   UI rendering.
 *
 * @param activity activity to be processed.
 */
private static void handleActivity(Activity activity) {

    // TODO: an injectable for activity separately
    if (activity instanceof HasSupportFragmentInjector) {

        // When the activity has implemented the HasSupportFragmentInjector interface, android
        // injector will inject into it, so the activity can be injected with the dispatch
        // injector specific for fragment. Then this dispatch injector will be returned through
        // the override method and contribute to android injector factory for fragment
        AndroidInjection.inject(activity);
    }
    if (activity instanceof FragmentActivity) {
        ((FragmentActivity) activity).getSupportFragmentManager()
                .registerFragmentLifecycleCallbacks(
                        new FragmentManager.FragmentLifecycleCallbacks() {
                            @Override
                            public void onFragmentCreated(FragmentManager fm, Fragment f,
                                    Bundle savedInstanceState) {
                                if (f instanceof Injectable) {

                                    // The injector only contains the provision method for the
                                    // field in the fragment.
                                    // But for activity, there will be a module providing the
                                    // binding method which will be bound to the fragment's
                                    // subcomponent's builder (Android injector builder) and
                                    // then be cast to AndroidInjector.Factory
                                    AndroidSupportInjection.inject(f);
                                }
                            }
                        }, true);
    }
}