Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fragment下监听onActivityForResult #968

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ public void navigation(Activity mContext, int requestCode, NavigationCallback ca
ARouter.getInstance().navigation(mContext, this, requestCode, callback);
}

public void navigation(android.support.v4.app.Fragment fragment, int requestCode) {
ARouter.getInstance().navigation(fragment, this, requestCode, null);
}


/**
* Green channel, it will skip all of interceptors.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.alibaba.android.arouter.exception.InitException;
import com.alibaba.android.arouter.facade.Postcard;
import com.alibaba.android.arouter.facade.callback.NavigationCallback;
import com.alibaba.android.arouter.facade.model.RouteMeta;
import com.alibaba.android.arouter.facade.template.ILogger;
import com.alibaba.android.arouter.facade.template.IRouteGroup;
import com.alibaba.android.arouter.utils.Consts;
Expand Down Expand Up @@ -186,6 +185,10 @@ public Object navigation(Context mContext, Postcard postcard, int requestCode, N
return _ARouter.getInstance().navigation(mContext, postcard, requestCode, callback);
}

public Object navigation(android.support.v4.app.Fragment fragment, Postcard postcard, int requestCode, NavigationCallback callback) {
return _ARouter.getInstance().navigation(fragment, fragment.getActivity(), postcard, requestCode, callback);
}

/**
* Add route group dynamic.
* @param group route group.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,19 @@ protected <T> T navigation(Class<? extends T> service) {
}
}

/**
* Use router navigation.
*
* @param context Activity or null.
* @param postcard Route metas
* @param requestCode RequestCode
* @param callback cb
*/
protected Object navigation(final Context context, final Postcard postcard, final int requestCode, final NavigationCallback callback) {
protected Object navigation(Context context, final Postcard postcard, final int requestCode, final NavigationCallback callback) {
return navigation(null, context, postcard, requestCode, callback);
}

/**
* Use router navigation.
*
* @param context Activity or null.
* @param postcard Route metas
* @param requestCode RequestCode
* @param callback cb
*/
protected Object navigation(final android.support.v4.app.Fragment fragment, final Context context, final Postcard postcard, final int requestCode, final NavigationCallback callback) {
PretreatmentService pretreatmentService = ARouter.getInstance().navigation(PretreatmentService.class);
if (null != pretreatmentService && !pretreatmentService.onPretreatment(context, postcard)) {
// Pretreatment failed, navigation canceled.
Expand Down Expand Up @@ -334,7 +338,7 @@ public void run() {
*/
@Override
public void onContinue(Postcard postcard) {
_navigation(postcard, requestCode, callback);
_navigation(fragment, postcard, requestCode, callback);
}

/**
Expand All @@ -352,13 +356,13 @@ public void onInterrupt(Throwable exception) {
}
});
} else {
return _navigation(postcard, requestCode, callback);
return _navigation(fragment, postcard, requestCode, callback);
}

return null;
}

private Object _navigation(final Postcard postcard, final int requestCode, final NavigationCallback callback) {
private Object _navigation(final android.support.v4.app.Fragment fragment, final Postcard postcard, final int requestCode, final NavigationCallback callback) {
final Context currentContext = postcard.getContext();

switch (postcard.getType()) {
Expand Down Expand Up @@ -388,7 +392,7 @@ private Object _navigation(final Postcard postcard, final int requestCode, final
runInMainThread(new Runnable() {
@Override
public void run() {
startActivity(requestCode, currentContext, intent, postcard, callback);
startActivity(fragment, requestCode, currentContext, intent, postcard, callback);
}
});

Expand Down Expand Up @@ -438,9 +442,11 @@ private void runInMainThread(Runnable runnable) {
*
* @see ActivityCompat
*/
private void startActivity(int requestCode, Context currentContext, Intent intent, Postcard postcard, NavigationCallback callback) {
private void startActivity(android.support.v4.app.Fragment fragment, int requestCode, Context currentContext, Intent intent, Postcard postcard, NavigationCallback callback) {
if (requestCode >= 0) { // Need start for result
if (currentContext instanceof Activity) {
if (fragment != null) {
fragment.startActivityForResult(intent, requestCode);
} if (currentContext instanceof Activity) {
ActivityCompat.startActivityForResult((Activity) currentContext, intent, requestCode, postcard.getOptionsBundle());
} else {
logger.warning(Consts.TAG, "Must use [navigation(activity, ...)] to support [startActivityForResult]");
Expand Down