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

Pass onActivityResult event to current Screen #106

Closed
wants to merge 2 commits into from
Closed
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
@@ -1,8 +1,10 @@
package com.wealthfront.magellan;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
Expand All @@ -23,10 +25,10 @@
import static com.wealthfront.magellan.NavigationType.GO;
import static com.wealthfront.magellan.NavigationType.NO_ANIM;
import static com.wealthfront.magellan.NavigationType.SHOW;
import static com.wealthfront.magellan.Views.whenMeasured;
import static com.wealthfront.magellan.Preconditions.checkArgument;
import static com.wealthfront.magellan.Preconditions.checkNotNull;
import static com.wealthfront.magellan.Preconditions.checkState;
import static com.wealthfront.magellan.Views.whenMeasured;

/**
* Class responsible for navigating between screens and maintaining collection of screens in a back stack.
Expand Down Expand Up @@ -154,6 +156,24 @@ public void onResume(Activity activity) {
}
}

/**
* Notifies Navigator that the activity's onActivityResult callback has been hit. Call this method from
* {@code onActivityResult} of the Activity associated with this Navigator.
*
* This method will notify the current screen of the event if the activity parameter is the same as the
* activity provided to this Navigator in {@link #onCreate(Activity, Bundle) onCreate}.
*
* @param requestCode the request code originally supplied to startActivityForResult()
* @param resultCode the result code returned by the child activity through its setResult()
* @param data result data for the caller
*
*/
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
if (sameActivity(activity)) {
currentScreen().onActivityResult(requestCode, resultCode, data);
}
}

/**
* Notifies Navigator that the activity's onPause lifecycle callback has been hit. Call this method from
* {@link Activity#onPause() onPause} of the Activity associated with this Navigator.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.annotation.ColorRes;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.annotation.VisibleForTesting;
import android.util.SparseArray;
Expand Down Expand Up @@ -198,6 +200,11 @@ protected void onRestore(Bundle savedInstanceState) {}
*/
protected void onUpdateMenu(Menu menu) {}

/**
* Called when the Activity receives a result from a startActivityForResult call
*/
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {}

/**
* Called when the Activity is resumed and when the Screen is shown.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,23 @@ public void onPause_differentActivity() {
navigator.onPause(new Activity());
}

@Test
public void onActivityResult() {
navigator.onCreate(activity, null);
reset(root);
navigator.onActivityResult(1138, Activity.RESULT_OK, null);

verify(root).onActivityResult(1138, Activity.RESULT_OK, null);
}

@Test
public void onActivityResult_differentActivity() {
navigator.onCreate(activity, null);
reset(root);
verifyNoMoreInteractions(root);
navigator.onActivityResult(1138, Activity.RESULT_OK, null);
}

@Test
public void lifecycleListener() {
navigator.addLifecycleListener(lifecycleListener);
Expand Down