diff --git a/core/mogo-core-network/src/main/java/com/mogo/eagle/core/network/RequestOptions.java b/core/mogo-core-network/src/main/java/com/mogo/eagle/core/network/RequestOptions.java index 3ebc77c468..c74aa4bb7e 100644 --- a/core/mogo-core-network/src/main/java/com/mogo/eagle/core/network/RequestOptions.java +++ b/core/mogo-core-network/src/main/java/com/mogo/eagle/core/network/RequestOptions.java @@ -2,6 +2,7 @@ package com.mogo.eagle.core.network; import android.content.Context; +import android.view.KeyEvent; import com.mogo.eagle.core.network.utils.Util; @@ -96,7 +97,7 @@ public class RequestOptions { } public Object getCaller() { - return caller; + return caller == null ? null : caller; } public Context getContext() { diff --git a/core/mogo-core-network/src/main/java/com/mogo/eagle/core/network/SubscribeImpl.java b/core/mogo-core-network/src/main/java/com/mogo/eagle/core/network/SubscribeImpl.java index 3c5a354a61..694ce2bec2 100644 --- a/core/mogo-core-network/src/main/java/com/mogo/eagle/core/network/SubscribeImpl.java +++ b/core/mogo-core-network/src/main/java/com/mogo/eagle/core/network/SubscribeImpl.java @@ -28,7 +28,7 @@ public abstract class SubscribeImpl implements Observer { } private void onFinish() { - if (!Util.checkAlive(mRequestOptions.getCaller())) { + if (Util.checkAlive(mRequestOptions.getCaller())) { } } diff --git a/core/mogo-core-network/src/main/java/com/mogo/eagle/core/network/utils/Util.java b/core/mogo-core-network/src/main/java/com/mogo/eagle/core/network/utils/Util.java index 397f5bc20d..aadb0d10db 100644 --- a/core/mogo-core-network/src/main/java/com/mogo/eagle/core/network/utils/Util.java +++ b/core/mogo-core-network/src/main/java/com/mogo/eagle/core/network/utils/Util.java @@ -15,30 +15,37 @@ import com.mogo.eagle.core.network.CallerNotAliveException; public class Util { - public static boolean checkAlive( Object caller ) { - if ( caller instanceof Activity) { - return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 ? !( ( Activity ) caller ).isDestroyed() : !( ( Activity ) caller ).isFinishing(); - } else if ( caller instanceof Fragment) { - return ( ( Fragment ) caller ).isAdded(); - } else if ( caller instanceof androidx.fragment.app.Fragment ) { - return ( ( androidx.fragment.app.Fragment ) caller ).isAdded(); - } else if ( caller instanceof View) { - return true; - } else if ( caller instanceof Dialog) { - return ( ( Dialog ) caller ).getWindow() != null; - } else if ( caller instanceof PopupWindow) { - return ( ( PopupWindow ) caller ).getContentView() != null; + public static boolean checkAlive(Object caller ) { + if ( caller == null){ + return false; + } + if ( caller instanceof Activity) { + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 ? ((Activity) caller).isDestroyed() : ((Activity) caller).isFinishing(); + } else if ( caller instanceof Fragment) { + return !((Fragment) caller).isAdded(); + } else if ( caller instanceof androidx.fragment.app.Fragment ) { + return !((androidx.fragment.app.Fragment) caller).isAdded(); + } else if ( caller instanceof View) { + return false; + } else if ( caller instanceof Dialog) { + return ((Dialog) caller).getWindow() == null; + } else if ( caller instanceof PopupWindow) { + return ((PopupWindow) caller).getContentView() == null; + } else { + return false; } - return caller != null; } public static void assertCallerAlive( Object caller ) throws CallerNotAliveException { - if ( !checkAlive( caller ) ) { + if (checkAlive(caller)) { throw new CallerNotAliveException( "Caller is not alive any more" ); } } public static Context getContext(Object object ) { + if( object == null){ + return null; + } if ( object instanceof Activity ) { return ( Activity ) object; } else if ( object instanceof Fragment ) {