From 08d73bc5ea2ab1bf77bc6ab7aac154b0d541eb1f Mon Sep 17 00:00:00 2001 From: miguelbcr Date: Wed, 5 Oct 2016 10:05:40 +0200 Subject: [PATCH 1/3] Added interface in order to pre process data before finishing onActivityResult --- .gitignore | 45 +++++++-- .idea/.name | 1 - .idea/compiler.xml | 21 ---- .idea/gradle.xml | 26 ----- .idea/misc.xml | 98 ------------------- .idea/modules.xml | 10 -- .idea/vcs.xml | 6 -- app/build.gradle | 14 +-- app/src/androidTest/AndroidManifest.xml | 7 ++ .../androidTest/java/app/OnPreResultTest.java | 29 ++++++ app/src/main/AndroidManifest.xml | 1 + .../main/java/app/OnPreResultActivity.java | 43 ++++++++ app/src/main/java/app/StartActivity.java | 3 + app/src/main/res/layout/on_pre_result.xml | 22 +++++ app/src/main/res/layout/start_activity.xml | 6 ++ app/src/main/res/values/strings.xml | 1 + build.gradle | 2 +- rx_activity_result/build.gradle | 8 +- .../rx_activity_result/HolderActivity.java | 6 ++ .../java/rx_activity_result/OnResult.java | 2 +- .../main/java/rx_activity_result/Request.java | 17 +++- .../rx_activity_result/RxActivityResult.java | 11 ++- 22 files changed, 189 insertions(+), 190 deletions(-) delete mode 100644 .idea/.name delete mode 100644 .idea/compiler.xml delete mode 100644 .idea/gradle.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml create mode 100644 app/src/androidTest/AndroidManifest.xml create mode 100644 app/src/androidTest/java/app/OnPreResultTest.java create mode 100644 app/src/main/java/app/OnPreResultActivity.java create mode 100644 app/src/main/res/layout/on_pre_result.xml 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..987ef9a 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 14 + 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..20d6941 --- /dev/null +++ b/app/src/androidTest/java/app/OnPreResultTest.java @@ -0,0 +1,29 @@ +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 app.multi_start.MultiStartActivity; +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..27cce64 --- /dev/null +++ b/app/src/main/java/app/OnPreResultActivity.java @@ -0,0 +1,43 @@ +package app; + +import android.content.Intent; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.widget.TextView; + +import app.multi_start.FirstActivity; +import app.multi_start.SecondActivity; +import io.victoralbertos.app.R; +import rx_activity_result.OnResult; +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), (OnResult) (resultCode, data) -> + 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 @@ + + + +