package flowless;

import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;

/**
 * Created by Zhuinden on 2016.05.26..
 */
public class ActivityUtils {
    public static final String ACTIVITY_SERVICE_TAG = "flowless.ACTIVITY";

    public static Activity getActivity(Context context) {
        if(context instanceof Activity) {
            return (Activity) context;
        } else if(context instanceof ContextWrapper) {
            if(context instanceof FlowContextWrapper || context instanceof InternalContextWrapper) {
                return InternalContextWrapper.getActivity(context);
            } else {
                Context baseContext = ((ContextWrapper) context).getBaseContext();
                if(baseContext instanceof Activity) {
                    return (Activity) baseContext;
                }
            }
        }
        throw new IllegalStateException("No activity could be found in [" + context + "]");
    }
}

@@ -193,84 +193,8 @@
 s %7B%0A
-    public static final String ACTIVITY_SERVICE_TAG = %22flowless.ACTIVITY%22;%0A%0A
     
@@ -249,32 +249,33 @@
 xt) %7B%0A        if
+ 
 (context instanc
@@ -346,16 +346,17 @@
  else if
+ 
 (context
@@ -401,35 +401,17 @@
     
-if(c
+C
 ontext 
-instanceof FlowC
+c
 onte
@@ -424,18 +424,17 @@
 per 
-%7C%7C
+=
  context
  ins
@@ -425,24 +425,59 @@
 er = context
+;%0A            while (contextWrapper
  instanceof 
@@ -476,24 +476,16 @@
 tanceof 
-Internal
 ContextW
@@ -494,98 +494,64 @@
 pper
-) %7B%0A                return InternalContextWrapper.getActivity(context);%0A            %7D else
+ && ((ContextWrapper) context).getBaseContext() != null)
  %7B%0A 
@@ -569,27 +569,22 @@
     
-C
+c
 ontext
- baseContext
+Wrapper
  = (
@@ -599,32 +599,39 @@
 Wrapper) context
+Wrapper
 ).getBaseContext
@@ -656,20 +656,24 @@
   if
-(baseContext
+ (contextWrapper
  ins
@@ -734,19 +734,22 @@
 ty) 
-baseC
+c
 ontext
+Wrapper
 ;%0A  

fix activity utils with multiple context wrappers