[3.4.0] add null if in util
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -28,7 +28,7 @@ public abstract class SubscribeImpl<T extends BaseData> implements Observer<T> {
|
||||
}
|
||||
|
||||
private void onFinish() {
|
||||
if (!Util.checkAlive(mRequestOptions.getCaller())) {
|
||||
if (Util.checkAlive(mRequestOptions.getCaller())) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 ) {
|
||||
|
||||
Reference in New Issue
Block a user