Skip to content

Commit

Permalink
[atlas-core]host 实现接口调整
Browse files Browse the repository at this point in the history
  • Loading branch information
zjutyujf committed Nov 27, 2017
1 parent d21a3ef commit 1704706
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,28 @@ public static HostTransactor get(IRemote remoteItem){



private final IRemoteTransactor hostTransactor;
private final IRemote host;
private final Activity embeddedActivity;

private HostTransactor(IRemoteTransactor transactor,Activity activity){
hostTransactor = transactor;
private HostTransactor(IRemote remote,Activity activity){
host = remote;
embeddedActivity = activity;
}

@Override
public Bundle call(String commandName, Bundle args, IResponse callback) {
if(hostTransactor!=null) {
return hostTransactor.call(commandName, args, callback);
if(host!=null) {
return host.call(commandName, args, callback);
}else{
Log.e("HostTransactor","no real transactor");
return null;
}
}

@Override
public <T> T getRemoteInterface(Class<T> interfaceClass) {
if(hostTransactor!=null) {
return hostTransactor.getRemoteInterface(interfaceClass);
public <T> T getRemoteInterface(Class<T> interfaceClass,Bundle args) {
if(host!=null) {
return host.getRemoteInterface(interfaceClass,args);
}else{
Log.e("HostTransactor","no real transactor");
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/

public interface IRemoteContext {
void registerHostTransactor(IRemoteTransactor transactor);
void registerHostTransactor(IRemote transactor);
String getTargetBundle();
IRemote getRemoteTarget();
IRemoteTransactor getHostTransactor();
IRemote getHostTransactor();
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public interface IRemoteTransactor {

Bundle call(String commandName, Bundle args, IResponse callback);

<T> T getRemoteInterface(Class<T> interfaceClass);
<T> T getRemoteInterface(Class<T> interfaceClass,Bundle args);

interface IResponse{
void OnResponse(Bundle bundle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static RemoteFragment createRemoteFragment(Activity activity, String key,
private Fragment targetFragment;
private String targetBundleName;
private Activity remoteActivity;
private IRemoteTransactor hostTransactor;
private IRemote hostTransactor;
private Field mCalled ;


Expand All @@ -72,12 +72,12 @@ public IRemote getRemoteTarget() {
}

@Override
public IRemoteTransactor getHostTransactor() {
public IRemote getHostTransactor() {
return hostTransactor;
}

@Override
public void registerHostTransactor(IRemoteTransactor transactor) {
public void registerHostTransactor(IRemote transactor) {
hostTransactor = transactor;
}

Expand All @@ -87,8 +87,8 @@ public Bundle call(String commandName, Bundle args, IResponse callback) {
}

@Override
public <T> T getRemoteInterface(Class<T> interfaceClass) {
return ((IRemote)targetFragment).getRemoteInterface(interfaceClass);
public <T> T getRemoteInterface(Class<T> interfaceClass,Bundle args) {
return ((IRemote)targetFragment).getRemoteInterface(interfaceClass,args);
}

private FragmentHostCallback getFragmentHostCallback(FragmentHostCallback callback){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public static RemoteTransactor crateRemoteTransactor(Activity activity,String ke

private String targetBundleName;
private Activity remoteActivity;
private IRemoteTransactor hostTransactor;
private IRemote hostTransactor;
private IRemote targetTransactor;

@Override
public void registerHostTransactor(IRemoteTransactor transactor) {
public void registerHostTransactor(IRemote transactor) {
hostTransactor = transactor;
}

Expand All @@ -50,7 +50,7 @@ public IRemote getRemoteTarget() {
}

@Override
public IRemoteTransactor getHostTransactor() {
public IRemote getHostTransactor() {
return hostTransactor;
}

Expand All @@ -60,7 +60,7 @@ public Bundle call(String commandName, Bundle args, IResponse callback) {
}

@Override
public <T> T getRemoteInterface(Class<T> interfaceClass) {
return targetTransactor.getRemoteInterface(interfaceClass);
public <T> T getRemoteInterface(Class<T> interfaceClass,Bundle args) {
return targetTransactor.getRemoteInterface(interfaceClass,args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static RemoteView createRemoteView(Activity activity,String remoteViewKey
private IRemote targetView;
private String targetBundleName;
private Activity remoteActivity;
private IRemoteTransactor hostTransactor;
private IRemote hostTransactor;

@Override
public Bundle call(String commandName, Bundle args, IResponse callback) {
Expand All @@ -49,16 +49,16 @@ public Bundle call(String commandName, Bundle args, IResponse callback) {
}

@Override
public <T> T getRemoteInterface(Class<T> interfaceClass) {
public <T> T getRemoteInterface(Class<T> interfaceClass,Bundle args) {
if(!(targetView instanceof IRemote)){
throw new IllegalAccessError("targetView is not an implementation of : RemoteTransactor");
}else {
return ((IRemote)targetView).getRemoteInterface(interfaceClass);
return ((IRemote)targetView).getRemoteInterface(interfaceClass,args);
}
}

@Override
public void registerHostTransactor(IRemoteTransactor transactor) {
public void registerHostTransactor(IRemote transactor) {
hostTransactor = transactor;
}

Expand All @@ -73,7 +73,7 @@ public IRemote getRemoteTarget() {
}

@Override
public IRemoteTransactor getHostTransactor() {
public IRemote getHostTransactor() {
return hostTransactor;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@
import android.taobao.atlas.framework.BundleImpl;
import android.taobao.atlas.framework.Framework;
import android.taobao.atlas.hack.AtlasHacks;
import android.taobao.atlas.hack.Hack;
import android.taobao.atlas.runtime.newcomponent.activity.ActivityBridge;
import android.taobao.atlas.util.FileUtils;
import android.taobao.atlas.util.StringUtils;
Expand All @@ -248,6 +249,7 @@
import android.view.MotionEvent;
import android.content.BroadcastReceiver;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -1065,6 +1067,17 @@ public void callApplicationOnCreate(Application app) {
@Override
public void callActivityOnDestroy(Activity activity) {
mBase.callActivityOnDestroy(activity);
if(activity!=null && activity.getBaseContext() instanceof ContextImplHook){
try {
Hack.HackedMethod scheduleFinalCleanup = AtlasHacks.ContextImpl.method("scheduleFinalCleanup",String.class,String.class);
if(scheduleFinalCleanup.getMethod()!=null){
scheduleFinalCleanup.invoke(((ContextImplHook)activity.getBaseContext()).getBaseContext(),
activity.getClass().getName(),"Activity");
}
} catch (Throwable e) {
e.printStackTrace();
}
}
}

@Override
Expand Down

0 comments on commit 1704706

Please sign in to comment.