Skip to content
This repository has been archived by the owner on Aug 9, 2020. It is now read-only.

Commit

Permalink
Merge pull request #22 from miguelbcr/master
Browse files Browse the repository at this point in the history
Added interface in order to pre process data before finishing onActivityResult
  • Loading branch information
VictorAlbertos authored Oct 5, 2016
2 parents db268ff + 43cb51c commit 229c125
Show file tree
Hide file tree
Showing 23 changed files with 208 additions and 192 deletions.
45 changes: 37 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion .idea/.name

This file was deleted.

21 changes: 0 additions & 21 deletions .idea/compiler.xml

This file was deleted.

26 changes: 0 additions & 26 deletions .idea/gradle.xml

This file was deleted.

98 changes: 0 additions & 98 deletions .idea/misc.xml

This file was deleted.

10 changes: 0 additions & 10 deletions .idea/modules.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

14 changes: 7 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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") {
Expand Down
7 changes: 7 additions & 0 deletions app/src/androidTest/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
package="${applicationId}.test"
xmlns:tools="http://schemas.android.com/tools">

<uses-sdk tools:overrideLibrary="android.support.test.uiautomator.v18"/>
</manifest>
28 changes: 28 additions & 0 deletions app/src/androidTest/java/app/OnPreResultTest.java
Original file line number Diff line number Diff line change
@@ -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<OnPreResultActivity> 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")));
}

}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<activity android:name="app.multi_start.MultiStartActivity" />
<activity android:name="app.multi_start.FirstActivity"/>
<activity android:name="app.multi_start.SecondActivity"/>
<activity android:name="app.OnPreResultActivity" />
</application>

</manifest>
42 changes: 42 additions & 0 deletions app/src/main/java/app/OnPreResultActivity.java
Original file line number Diff line number Diff line change
@@ -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));
})
);
}

}
3 changes: 3 additions & 0 deletions app/src/main/java/app/StartActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
}
}
22 changes: 22 additions & 0 deletions app/src/main/res/layout/on_pre_result.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<Button
android:id="@+id/start_pre_for_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start activity for result with pre data processing" />

<TextView
android:id="@+id/pre_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<TextView
android:id="@+id/result"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
6 changes: 6 additions & 0 deletions app/src/main/res/layout/start_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/multi_start" />

<Button
android:id="@+id/bt_pre_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pre_result" />
</LinearLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
<string name="using_nested_fragment">Using nested fragment</string>
<string name="intent_sender">Intent sender</string>
<string name="multi_start">Multi start</string>
<string name="pre_result">Pre result processing</string>
</resources>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 229c125

Please sign in to comment.