[3.4.0] add null if in util

This commit is contained in:
zhongchao
2023-07-26 14:24:05 +08:00
parent 328245f3af
commit 5bd7c8a7ab
3 changed files with 25 additions and 17 deletions

View File

@@ -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() {

View File

@@ -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())) {
}
}

View File

@@ -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 ) {