diff --git a/.gitignore b/.gitignore
index c6cbe56..31f119b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,8 +1,37 @@
-*.iml
-.gradle
-/local.properties
-/.idea/workspace.xml
-/.idea/libraries
-.DS_Store
-/build
-/captures
+# Built application files
+*.apk
+*.ap_
+
+# Files for the Dalvik VM
+*.dex
+
+# Java class files
+*.class
+
+# Generated files
+bin/
+gen/
+
+# Gradle files
+.gradle/
+**/build/
+
+# Local configuration file (sdk path, etc)
+local.properties
+
+# Proguard folder generated by Eclipse
+proguard/
+
+# Log Files
+*.log
+
+# Android Studio
+.navigation/
+.idea/
+**/*.iml
+
+# Android Studio captures folder
+captures/
+
+# .DS_Store files
+**/.DS_Store
diff --git a/.idea/.name b/.idea/.name
deleted file mode 100644
index f43a55b..0000000
--- a/.idea/.name
+++ /dev/null
@@ -1 +0,0 @@
-RxActivityResult
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
deleted file mode 100644
index 1f2af51..0000000
--- a/.idea/compiler.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
deleted file mode 100644
index 195dcc3..0000000
--- a/.idea/gradle.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
deleted file mode 100644
index 6438839..0000000
--- a/.idea/misc.xml
+++ /dev/null
@@ -1,98 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Android Lint
-
-
- General
-
-
- Maven
-
-
-
-
- Android
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 1.8
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
deleted file mode 100644
index 0d080c4..0000000
--- a/.idea/modules.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
deleted file mode 100644
index 830a534..0000000
--- a/.idea/vcs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index df6e524..07f5628 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -13,13 +13,13 @@ buildscript {
}
android {
- compileSdkVersion 23
- buildToolsVersion "23.0.3"
+ compileSdkVersion 24
+ buildToolsVersion "24.0.1"
defaultConfig {
applicationId "io.victoralbertos.app"
- minSdkVersion 18
- targetSdkVersion 23
+ minSdkVersion 16
+ targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@@ -43,9 +43,9 @@ dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(":rx_activity_result")
- compile 'com.android.support:appcompat-v7:23.4.0'
- compile 'com.android.support:design:23.4.0'
- compile 'io.reactivex:rxjava:1.1.0'
+ compile 'com.android.support:appcompat-v7:24.2.1'
+ compile 'com.android.support:design:24.2.1'
+ compile 'io.reactivex:rxjava:1.1.10'
testCompile 'junit:junit:4.12'
androidTestCompile ("com.android.support.test:runner:0.4.1") {
diff --git a/app/src/androidTest/AndroidManifest.xml b/app/src/androidTest/AndroidManifest.xml
new file mode 100644
index 0000000..1202373
--- /dev/null
+++ b/app/src/androidTest/AndroidManifest.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
diff --git a/app/src/androidTest/java/app/OnPreResultTest.java b/app/src/androidTest/java/app/OnPreResultTest.java
new file mode 100644
index 0000000..3677dec
--- /dev/null
+++ b/app/src/androidTest/java/app/OnPreResultTest.java
@@ -0,0 +1,28 @@
+package app;
+
+import android.support.test.rule.ActivityTestRule;
+import android.support.test.runner.AndroidJUnit4;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import io.victoralbertos.app.R;
+
+import static android.support.test.espresso.Espresso.onView;
+import static android.support.test.espresso.action.ViewActions.click;
+import static android.support.test.espresso.assertion.ViewAssertions.matches;
+import static android.support.test.espresso.matcher.ViewMatchers.withId;
+import static android.support.test.espresso.matcher.ViewMatchers.withText;
+
+@RunWith(AndroidJUnit4.class)
+public class OnPreResultTest {
+ @Rule public ActivityTestRule activityRule = new ActivityTestRule<>(OnPreResultActivity.class);
+
+ @Test public void CheckHasBothResults() {
+ onView(withId(R.id.start_pre_for_result)).perform(click());
+ onView(withId(R.id.pre_result)).check(matches(withText("Do whatever you want with the data, but not with the UI")));
+ onView(withId(R.id.result)).check(matches(withText("Well done first")));
+ }
+
+}
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 65455e0..3434065 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -36,6 +36,7 @@
+
\ No newline at end of file
diff --git a/app/src/main/java/app/OnPreResultActivity.java b/app/src/main/java/app/OnPreResultActivity.java
new file mode 100644
index 0000000..367c88e
--- /dev/null
+++ b/app/src/main/java/app/OnPreResultActivity.java
@@ -0,0 +1,42 @@
+package app;
+
+import android.content.Intent;
+import android.os.Bundle;
+import android.support.v7.app.AppCompatActivity;
+import android.view.View;
+import android.widget.TextView;
+
+import app.multi_start.FirstActivity;
+import io.victoralbertos.app.R;
+import rx.Observable;
+import rx_activity_result.RxActivityResult;
+
+public class OnPreResultActivity extends AppCompatActivity {
+ public static final String EXTRA_PRE = "EXTRA_PRE";
+ private TextView preResult;
+ private TextView result;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.on_pre_result);
+
+ View startPreForResult = findViewById(R.id.start_pre_for_result);
+ preResult = (TextView) findViewById(R.id.pre_result);
+ result = (TextView) findViewById(R.id.result);
+
+ startPreForResult.setOnClickListener(v ->
+ RxActivityResult.on(this)
+ .startIntent(new Intent(this, FirstActivity.class), (resultCode, data) ->
+ Observable.just(data.getData())
+ .map(uri -> data.putExtra(EXTRA_PRE, "Do whatever you want with the data, but not with the UI")))
+ .subscribe(result -> {
+ result.targetUI()
+ .preResult.setText(result.data().getStringExtra(EXTRA_PRE));
+ result.targetUI()
+ .result.setText(result.data().getStringExtra(FirstActivity.EXTRA));
+ })
+ );
+ }
+
+}
diff --git a/app/src/main/java/app/StartActivity.java b/app/src/main/java/app/StartActivity.java
index d5df736..a421383 100644
--- a/app/src/main/java/app/StartActivity.java
+++ b/app/src/main/java/app/StartActivity.java
@@ -29,5 +29,8 @@ public class StartActivity extends AppCompatActivity {
startActivity(new Intent(StartActivity.this, MultiStartActivity.class));
});
+ findViewById(R.id.bt_pre_result).setOnClickListener(view -> {
+ startActivity(new Intent(StartActivity.this, OnPreResultActivity.class));
+ });
}
}
diff --git a/app/src/main/res/layout/on_pre_result.xml b/app/src/main/res/layout/on_pre_result.xml
new file mode 100644
index 0000000..be5102c
--- /dev/null
+++ b/app/src/main/res/layout/on_pre_result.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/start_activity.xml b/app/src/main/res/layout/start_activity.xml
index 127e76f..85eee85 100644
--- a/app/src/main/res/layout/start_activity.xml
+++ b/app/src/main/res/layout/start_activity.xml
@@ -27,4 +27,10 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/multi_start" />
+
+
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 4d42049..5c2fbf9 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -8,4 +8,5 @@
Using nested fragment
Intent sender
Multi start
+ Pre result processing
diff --git a/build.gradle b/build.gradle
index 73350f3..422743d 100644
--- a/build.gradle
+++ b/build.gradle
@@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
- classpath 'com.android.tools.build:gradle:2.1.3'
+ classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
diff --git a/rx_activity_result/build.gradle b/rx_activity_result/build.gradle
index c1c730b..aebdc8b 100644
--- a/rx_activity_result/build.gradle
+++ b/rx_activity_result/build.gradle
@@ -4,7 +4,7 @@ group='com.github.VictorAlbertos'
android {
compileSdkVersion 24
- buildToolsVersion "24.0.0"
+ buildToolsVersion "24.0.1"
defaultConfig {
minSdkVersion 16
@@ -22,8 +22,8 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
- compile 'com.android.support:appcompat-v7:24.1.1'
- compile 'io.reactivex:rxjava:1.1.8'
+ compile 'com.android.support:appcompat-v7:24.2.1'
+ compile 'io.reactivex:rxjava:1.1.10'
testCompile 'junit:junit:4.12'
}
diff --git a/rx_activity_result/src/main/java/rx_activity_result/HolderActivity.java b/rx_activity_result/src/main/java/rx_activity_result/HolderActivity.java
index 568219d..7b59178 100644
--- a/rx_activity_result/src/main/java/rx_activity_result/HolderActivity.java
+++ b/rx_activity_result/src/main/java/rx_activity_result/HolderActivity.java
@@ -21,8 +21,13 @@
import android.content.IntentSender;
import android.os.Bundle;
+import rx.functions.Action0;
+import rx.functions.Action1;
+import rx.schedulers.Schedulers;
+
public class HolderActivity extends Activity {
private static Request request;
+ private OnPreResult onPreResult;
private OnResult onResult;
private int resultCode;
private Intent data;
@@ -35,6 +40,7 @@ public class HolderActivity extends Activity {
return;
}
+ onPreResult = request.onPreResult();
onResult = request.onResult();
if (savedInstanceState != null) return;
@@ -76,7 +82,18 @@ private void startIntentSenderWithOptions(RequestIntentSender requestIntentSende
this.resultCode = resultCode;
this.data = data;
- finish();
+ if (this.onPreResult != null) {
+ this.onPreResult.response(resultCode, data)
+ .doOnCompleted(new Action0() {
+ @Override
+ public void call() {
+ finish();
+ }
+ })
+ .subscribe();
+ } else {
+ finish();
+ }
}
@Override protected void onDestroy() {
diff --git a/rx_activity_result/src/main/java/rx_activity_result/OnPreResult.java b/rx_activity_result/src/main/java/rx_activity_result/OnPreResult.java
new file mode 100644
index 0000000..3b165c7
--- /dev/null
+++ b/rx_activity_result/src/main/java/rx_activity_result/OnPreResult.java
@@ -0,0 +1,10 @@
+package rx_activity_result;
+
+import android.content.Intent;
+import android.support.annotation.Nullable;
+
+import rx.Observable;
+
+public interface OnPreResult {
+ Observable response(int resultCode, @Nullable Intent data);
+}
diff --git a/rx_activity_result/src/main/java/rx_activity_result/OnResult.java b/rx_activity_result/src/main/java/rx_activity_result/OnResult.java
index 6e889a7..3560dfd 100644
--- a/rx_activity_result/src/main/java/rx_activity_result/OnResult.java
+++ b/rx_activity_result/src/main/java/rx_activity_result/OnResult.java
@@ -3,8 +3,6 @@
import android.content.Intent;
import android.support.annotation.Nullable;
-import java.io.Serializable;
-
-interface OnResult extends Serializable {
+interface OnResult {
void response(int resultCode, @Nullable Intent data);
}
diff --git a/rx_activity_result/src/main/java/rx_activity_result/Request.java b/rx_activity_result/src/main/java/rx_activity_result/Request.java
index f0a8b28..213b500 100644
--- a/rx_activity_result/src/main/java/rx_activity_result/Request.java
+++ b/rx_activity_result/src/main/java/rx_activity_result/Request.java
@@ -20,21 +20,30 @@
class Request {
private final Intent intent;
+ private OnPreResult onPreResult;
private OnResult onResult;
- public Request(Intent intent) {
+ Request(Intent intent) {
this.intent = intent;
}
- public void setOnResult(OnResult onResult) {
+ void setOnPreResult(OnPreResult onPreResult) {
+ this.onPreResult = onPreResult;
+ }
+
+ OnPreResult onPreResult() {
+ return onPreResult;
+ }
+
+ void setOnResult(OnResult onResult) {
this.onResult = onResult;
}
- public OnResult onResult() {
+ OnResult onResult() {
return onResult;
}
- public Intent intent() {
+ Intent intent() {
return intent;
}
}
diff --git a/rx_activity_result/src/main/java/rx_activity_result/RxActivityResult.java b/rx_activity_result/src/main/java/rx_activity_result/RxActivityResult.java
index 03d4bd3..62a1d43 100644
--- a/rx_activity_result/src/main/java/rx_activity_result/RxActivityResult.java
+++ b/rx_activity_result/src/main/java/rx_activity_result/RxActivityResult.java
@@ -65,17 +65,22 @@ public Observable> startIntentSender(IntentSender intentSender, @Nulla
public Observable> startIntentSender(IntentSender intentSender, @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) {
RequestIntentSender requestIntentSender = new RequestIntentSender(intentSender, fillInIntent, flagsMask, flagsValues, extraFlags, options);
- return startHolderActivity(requestIntentSender);
+ return startHolderActivity(requestIntentSender, null);
}
public Observable> startIntent(final Intent intent) {
- return startHolderActivity(new Request(intent));
+ return startIntent(intent, null);
}
- private Observable> startHolderActivity(Request request) {
+ public Observable> startIntent(final Intent intent, OnPreResult onPreResult) {
+ return startHolderActivity(new Request(intent), onPreResult);
+ }
+
+ private Observable> startHolderActivity(Request request, OnPreResult onPreResult) {
OnResult onResult = uiTargetActivity ? onResultActivity() : onResultFragment();
request.setOnResult(onResult);
+ request.setOnPreResult(onPreResult);
HolderActivity.setRequest(request);