Skip to content

Commit 5092725

Browse files
committed
- Bump gradle wrapper version.
- Bump android build tools. - Bump android compile sdk version. - Disable frodo for now.
1 parent f043fc4 commit 5092725

File tree

11 files changed

+191
-119
lines changed

11 files changed

+191
-119
lines changed

app/build.gradle

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
apply plugin: 'com.android.application'
22
apply plugin: 'me.tatarka.retrolambda'
3-
apply plugin: 'com.fernandocejas.frodo'
3+
//apply plugin: 'com.fernandocejas.frodo'
44

55
android {
6-
compileSdkVersion 23
7-
buildToolsVersion "21.1.2"
6+
compileSdkVersion 25
7+
buildToolsVersion "23.0.2"
88

99
defaultConfig {
1010
applicationId "com.fernandocejas.android10.rx.sample"
@@ -45,7 +45,7 @@ android {
4545
}
4646

4747
dependencies {
48-
compile 'com.android.support:recyclerview-v7:23.1.1'
48+
compile 'com.android.support:recyclerview-v7:25.0.1'
4949
compile 'com.jakewharton:butterknife:7.0.1'
5050
compile 'com.squareup.okhttp:okhttp:2.5.0'
5151
compile 'io.reactivex:rxjava:1.0.14'

app/src/main/java/com/fernandocejas/android10/rx/sample/activity/backpressure/ActivityBackpressureSamples.java

+18-7
Original file line numberDiff line numberDiff line change
@@ -93,26 +93,30 @@ private void toggleProgressBar(boolean visible) {
9393
}
9494

9595
@OnClick(R.id.btn_backpressureException) void onBackpressureExceptionClick() {
96-
dataManager.milliseconds(1000)
96+
//dataManager.milliseconds(1000)
97+
// .observeOn(AndroidSchedulers.mainThread())
98+
// .subscribeOn(Schedulers.computation())
99+
// .subscribe(new BackpressureSubscriber<>(this, getString(R.string.btn_text_backpressure_exception)));
100+
dataManager.milliseconds(100)
97101
.observeOn(AndroidSchedulers.mainThread())
98102
.subscribeOn(Schedulers.computation())
99-
.subscribe(new BackpressureSubscriber<>(this, getString(R.string.btn_text_backpressure_exception)));
103+
.subscribe(new BackpressureSubscriber<>(this, getString(R.string.btn_text_backpressure_exception), 15));
100104
}
101105

102106
@OnClick(R.id.btn_backpressureDrop) void onBackpressureDropClick() {
103107
dataManager.milliseconds(1000)
104108
.onBackpressureDrop()
105109
.observeOn(AndroidSchedulers.mainThread())
106110
.subscribeOn(Schedulers.computation())
107-
.subscribe(new BackpressureSubscriber<>(this, getString(R.string.btn_text_backpressure_drop), 1000));
111+
.subscribe(new BackpressureSubscriber<>(this, getString(R.string.btn_text_backpressure_drop)));
108112
}
109113

110114
@OnClick(R.id.btn_backpressureBuffer) void onBackpressureBuffer() {
111115
dataManager.milliseconds(600)
112116
.onBackpressureBuffer(200)
113117
.observeOn(AndroidSchedulers.mainThread())
114118
.subscribeOn(Schedulers.computation())
115-
.subscribe(new BackpressureSubscriber<>(this, getString(R.string.btn_text_backpressure_buffer), 600));
119+
.subscribe(new BackpressureSubscriber<>(this, getString(R.string.btn_text_backpressure_buffer)));
116120
}
117121

118122
@OnClick(R.id.btn_backpressureWindow) void onBackpressureWindow() {
@@ -128,15 +132,15 @@ private void toggleProgressBar(boolean visible) {
128132
.toList()
129133
.observeOn(AndroidSchedulers.mainThread())
130134
.subscribeOn(Schedulers.computation())
131-
.subscribe(new BackpressureSubscriber<>(this, getString(R.string.btn_text_backpressure_toList), 1000));
135+
.subscribe(new BackpressureSubscriber<>(this, getString(R.string.btn_text_backpressure_toList)));
132136
}
133137

134138
@OnClick(R.id.btn_backpressureThrottleLast) void onBackpressureThrottleLast() {
135139
dataManager.milliseconds(10000)
136140
.throttleLast(10, TimeUnit.MILLISECONDS)
137141
.observeOn(AndroidSchedulers.mainThread())
138142
.subscribeOn(Schedulers.computation())
139-
.subscribe(new BackpressureSubscriber<>(this, getString(R.string.btn_text_backpressure_throttleLast), 10000));
143+
.subscribe(new BackpressureSubscriber<>(this, getString(R.string.btn_text_backpressure_throttleLast)));
140144
}
141145

142146
@Override
@@ -145,7 +149,14 @@ public void onOperationStart(String name, long itemsRequested) {
145149
toggleProgressBar(true);
146150
sv_container.fullScroll(ScrollView.FOCUS_DOWN);
147151
tv_sampleDescription.setText(name);
148-
tv_itemsRequested.setText(String.valueOf(itemsRequested));
152+
//This check is because you can pass a magic number to request, request(Long.MAX_VALUE),
153+
//to disable reactive pull backpressure and to ask the Observable to emit items at its own pace.
154+
//https://github.com/ReactiveX/RxJava/wiki/Backpressure
155+
if (itemsRequested != Long.MAX_VALUE) {
156+
tv_itemsRequested.setText(String.valueOf(itemsRequested));
157+
} else {
158+
tv_itemsRequested.setText("Observable emitting at its own pace");
159+
}
149160
}
150161

151162
@Override public void onOperationProgress(long itemsProcessedSoFar) {
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/**
22
* Copyright (C) 2016 android10.org Open Source Project
3-
*
3+
* <p>
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
7+
* <p>
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
* <p>
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -15,80 +15,109 @@
1515
*/
1616
package com.fernandocejas.android10.rx.sample.activity.backpressure;
1717

18-
import com.fernandocejas.frodo.annotation.RxLogSubscriber;
19-
import java.lang.ref.WeakReference;
18+
import rx.Producer;
2019
import rx.Subscriber;
2120
import rx.exceptions.MissingBackpressureException;
2221

23-
@RxLogSubscriber
22+
import java.lang.ref.WeakReference;
23+
24+
//@RxLogSubscriber
2425
class BackpressureSubscriber<T> extends Subscriber<T> {
2526

26-
interface BackPressureResultListener {
27-
void onOperationStart(String name, long itemsRequested);
28-
void onOperationProgress(long itemsProcessedSoFar);
29-
void onOperationResult(long itemsEmitted, OperationResult operation);
30-
}
31-
32-
private final WeakReference<BackPressureResultListener> backPressureListener;
33-
private final String name;
34-
private final long itemsRequested;
35-
private boolean shouldRequestItem;
36-
37-
private long itemsEmitted = 0;
38-
39-
BackpressureSubscriber(BackPressureResultListener listener, String name) {
40-
this(listener, name, Long.MAX_VALUE);
41-
}
42-
43-
BackpressureSubscriber(BackPressureResultListener listener, String name, long requestedItems) {
44-
this.backPressureListener = new WeakReference<>(listener);
45-
this.name = name;
46-
this.itemsRequested = requestedItems;
47-
this.shouldRequestItem = requestedItems != Long.MAX_VALUE;
48-
}
49-
50-
@Override public void onStart() {
51-
requestItems();
52-
sendStartData();
53-
}
54-
55-
@Override public void onNext(T item) {
56-
itemsEmitted++;
57-
sendProgressData(itemsEmitted);
58-
requestItems();
59-
}
60-
61-
@Override public void onCompleted() {
62-
sendResultData(OperationResult.success());
63-
}
64-
65-
@Override public void onError(Throwable throwable) {
66-
if (throwable instanceof MissingBackpressureException) {
67-
sendResultData(OperationResult.failure(throwable));
27+
interface BackPressureResultListener {
28+
void onOperationStart(String name, long itemsRequested);
29+
30+
void onOperationProgress(long itemsProcessedSoFar);
31+
32+
void onOperationResult(long itemsEmitted, OperationResult operation);
33+
}
34+
35+
private final WeakReference<BackPressureResultListener> backPressureListener;
36+
private final String name;
37+
private final long itemsRequested;
38+
private boolean shouldRequestItem;
39+
40+
private long itemsEmitted = 0;
41+
private long itemsRequestedProcessed = 0;
42+
43+
BackpressureSubscriber(BackPressureResultListener listener, String name) {
44+
this(listener, name, Long.MAX_VALUE);
6845
}
69-
}
7046

71-
private void requestItems() {
72-
if (shouldRequestItem) {
73-
request(itemsRequested);
47+
BackpressureSubscriber(BackPressureResultListener listener, String name, long requestedItems) {
48+
this.backPressureListener = new WeakReference<>(listener);
49+
this.name = name;
50+
this.itemsRequested = requestedItems;
51+
this.shouldRequestItem = requestedItems != Long.MAX_VALUE;
7452
}
75-
}
7653

77-
private void sendStartData() {
78-
if (backPressureListener.get() != null) {
79-
backPressureListener.get().onOperationStart(name, itemsRequested);
54+
@Override
55+
public void onStart() {
56+
if (shouldRequestItem) {
57+
//setProducer(new QueuedValueProducer<>(this));
58+
// setProducer(new BackPressureProducer());
59+
request(itemsRequested);
60+
}
61+
sendStartData();
8062
}
81-
}
8263

83-
private void sendProgressData(long itemsProcessedSoFar) {
84-
if (backPressureListener.get() != null) {
85-
backPressureListener.get().onOperationProgress(itemsProcessedSoFar);
64+
@Override
65+
public void onNext(T item) {
66+
itemsEmitted++;
67+
sendProgressData(itemsEmitted);
68+
requestMoreItems();
8669
}
87-
}
8870

89-
private void sendResultData(OperationResult operation) {
90-
if (backPressureListener.get() != null) {
91-
backPressureListener.get().onOperationResult(itemsEmitted, operation);
71+
@Override
72+
public void onCompleted() {
73+
sendResultData(OperationResult.success());
74+
}
75+
76+
@Override
77+
public void onError(Throwable throwable) {
78+
if (throwable instanceof MissingBackpressureException) {
79+
sendResultData(OperationResult.failure(throwable));
80+
}
81+
}
82+
83+
private void requestMoreItems() {
84+
itemsRequestedProcessed++;
85+
if (shouldRequestItem && itemsRequestedProcessed >= itemsRequested) {
86+
request(itemsRequested);
87+
itemsRequestedProcessed = 0;
88+
}
89+
}
90+
91+
private void sendStartData() {
92+
if (backPressureListener.get() != null) {
93+
backPressureListener.get().onOperationStart(name, itemsRequested);
94+
}
95+
}
96+
97+
private void sendProgressData(long itemsProcessedSoFar) {
98+
if (backPressureListener.get() != null) {
99+
backPressureListener.get().onOperationProgress(itemsProcessedSoFar);
100+
}
101+
}
102+
103+
private void sendResultData(OperationResult operation) {
104+
if (backPressureListener.get() != null) {
105+
backPressureListener.get().onOperationResult(itemsEmitted, operation);
106+
}
107+
}
108+
109+
private static class BackPressureProducer<T> implements Producer {
110+
private final Subscriber<T> subscriber;
111+
112+
BackPressureProducer(Subscriber subscriber) {
113+
this.subscriber = subscriber;
114+
}
115+
116+
@Override
117+
public void request(long requested) {
118+
for (int i = 0; i < requested && !subscriber.isUnsubscribed(); i++) {
119+
// subscriber.onNext(T);
120+
}
121+
}
92122
}
93-
}
94123
}

app/src/main/java/com/fernandocejas/android10/rx/sample/data/DataManager.java

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ public Observable<Integer> numbers() {
3838
return Observable.from(numberGenerator.numbers());
3939
}
4040

41+
public Observable<Long> numbers(int upUntil) {
42+
return Observable.from(numberGenerator.numbers(upUntil));
43+
}
44+
4145
public Observable<Long> milliseconds(int upUntil) {
4246
return Observable.interval(0, 1, TimeUnit.MILLISECONDS).take(upUntil);
4347
}

app/src/main/java/com/fernandocejas/android10/rx/sample/data/NumberGenerator.java

+8
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,12 @@ public NumberGenerator() {}
2626
List<Integer> numbers() {
2727
return new ArrayList<>(Arrays.asList(2, 3, 4, 5, 6, 7, 8, 9, 10));
2828
}
29+
30+
List<Long> numbers(int upUntil) {
31+
final ArrayList<Long> numberList = new ArrayList<>(upUntil);
32+
for (long i = 0; i < upUntil; i++) {
33+
numberList.add(i);
34+
}
35+
return numberList;
36+
}
2937
}

build.gradle

+16-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ buildscript {
55
mavenLocal()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:2.1.0'
8+
classpath 'com.android.tools.build:gradle:2.2.2'
99
classpath 'me.tatarka:gradle-retrolambda:3.2.2'
10-
classpath "com.fernandocejas.frodo:frodo-plugin:0.8.1"
10+
// classpath "com.fernandocejas.frodo:frodo-plugin:0.8.1"
1111
}
1212
}
1313

@@ -18,3 +18,17 @@ allprojects {
1818
mavenLocal()
1919
}
2020
}
21+
22+
task deployDebug(type: Exec, dependsOn: 'app:installDebug') {
23+
def rootDir = project.rootDir
24+
def localProperties = new File(rootDir, "local.properties")
25+
if (localProperties.exists()) {
26+
Properties properties = new Properties()
27+
localProperties.withInputStream {
28+
inputStream -> properties.load(inputStream)
29+
}
30+
def sdkDir = properties.getProperty('sdk.dir')
31+
def adb = "$sdkDir/platform-tools/adb"
32+
commandLine "$adb", 'shell', 'am', 'start', '-n', 'com.fernandocejas.android10.rx.sample/com.fernandocejas.android10.rx.sample.activity.MainActivity'
33+
}
34+
}

gradle.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
# Specifies the JVM arguments used for the daemon process.
1111
# The setting is particularly useful for tweaking memory settings.
1212
# Default value: -Xmx10248m -XX:MaxPermSize=256m
13-
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
13+
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
1414

1515
# When configured, Gradle will run in incubating parallel mode.
1616
# This option should only be used with decoupled projects. More details, visit
1717
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18-
# org.gradle.parallel=true
18+
org.gradle.parallel=true

gradle/wrapper/gradle-wrapper.jar

588 Bytes
Binary file not shown.
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Fri May 06 11:27:41 CEST 2016
1+
#Sat Dec 10 22:13:26 CET 2016
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-bin.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-3.2.1-all.zip

0 commit comments

Comments
 (0)