package com.github.aleksandermielczarek.napkin;

import android.content.Context;
import android.support.v4.app.Fragment;

/**
 * Created by Aleksander Mielczarek on 14.05.2016.
 */
public class Napkin {

    private Napkin() {

    }

    public static <T> T provideComponent(Object object) {
        ComponentProvider<T> componentProvider = (ComponentProvider<T>) object;
        return componentProvider.provideComponent();
    }

    public static <T> T provideAppComponent(Context context) {
        Context application = context.getApplicationContext();
        return provideComponent(application);
    }

    public static <T> T provideAppComponent(Fragment fragment) {
        Context application = fragment.getContext().getApplicationContext();
        return provideComponent(application);
    }

    public static <T> T provideActivityComponent(Fragment fragment) {
        Context activity = fragment.getActivity();
        return provideComponent(activity);
    }

}

@@ -113,16 +113,42 @@
 ragment;
+%0Aimport android.view.View;
 %0A%0A/**%0A *
@@ -246,32 +246,67 @@
 kin() %7B%0A%0A    %7D%0A%0A
+    @SuppressWarnings(%22unchecked%22)%0A
     public stati
@@ -747,27 +747,23 @@
 Context 
-application
+context
  = fragm
@@ -778,31 +778,161 @@
 ontext()
-.getApplication
+;%0A        return provideAppComponent(context);%0A    %7D%0A%0A    public static %3CT%3E T provideAppComponent(View view) %7B%0A        Context context = view.get
 Context(
@@ -948,32 +948,35 @@
   return provide
+App
 Component(applic
@@ -965,35 +965,31 @@
 ppComponent(
-application
+context
 );%0A    %7D%0A%0A  
@@ -1157,10 +1157,167 @@
 %0A    %7D%0A%0A
+    public static %3CT%3E T provideActivityComponent(View view) %7B%0A        Context activity = view.getContext();%0A        return provideComponent(activity);%0A    %7D%0A
 %7D%0A

Allow to retrieve component from View