Skip to content

Commit a36585a

Browse files
author
Randy Webster
committed
Update to RxJava 2.0.0 release.
Skip onNext for null values in Callbacks. Add example project.
1 parent ee4e533 commit a36585a

17 files changed

Lines changed: 351 additions & 8 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# RxLoader
22
[![License](http://img.shields.io/badge/License-Apache%202.0-blue.svg?style=flat-square)](http://www.apache.org/licenses/LICENSE-2.0)
33
[![API](https://img.shields.io/badge/API-16%2B-blue.svg?style=flat-square)](https://developer.android.com/about/versions/android-4.1.html)
4-
[![Download](https://img.shields.io/badge/JCenter-2.0.0--RC2-brightgreen.svg?style=flat-square)](https://bintray.com/l4digital/maven/RxLoader/_latestVersion)
4+
[![Download](https://img.shields.io/badge/JCenter-2.0.0-brightgreen.svg?style=flat-square)](https://bintray.com/l4digital/maven/RxLoader/_latestVersion)
55

66
An Android Loader that wraps an RxJava Observable.
77

@@ -14,7 +14,7 @@ RxLoader caches the data emitted by your Observable across orientation changes b
1414
#### Gradle:
1515
~~~groovy
1616
dependencies {
17-
compile 'com.l4digital.rxloader:rxloader:2.0.0-RC2'
17+
compile 'com.l4digital.rxloader:rxloader:2.0.0'
1818
}
1919
~~~
2020

@@ -23,7 +23,7 @@ dependencies {
2323
<dependency>
2424
<groupId>com.l4digital.rxloader</groupId>
2525
<artifactId>rxloader</artifactId>
26-
<version>2.0.0-RC2</version>
26+
<version>2.0.0</version>
2727
</dependency>
2828
~~~
2929

example/build.gradle

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2016 L4 Digital LLC. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
apply plugin: 'com.android.application'
18+
19+
ext {
20+
supportLibVersion = '24.2.1'
21+
}
22+
23+
android {
24+
compileSdkVersion 24
25+
buildToolsVersion "24.0.2"
26+
27+
defaultConfig {
28+
applicationId "com.l4digital.rxloader.example"
29+
30+
minSdkVersion 16
31+
targetSdkVersion 24
32+
33+
versionCode 1
34+
versionName "1.0"
35+
36+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
37+
38+
}
39+
40+
buildTypes {
41+
release {
42+
minifyEnabled true
43+
shrinkResources true
44+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
45+
}
46+
}
47+
}
48+
49+
dependencies {
50+
compile project(':rxloader')
51+
compile "com.android.support:appcompat-v7:${supportLibVersion}"
52+
}

example/proguard-rules.pro

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Users/randy/Development/Android/sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright 2016 L4 Digital LLC. All rights reserved.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<manifest
19+
xmlns:android="http://schemas.android.com/apk/res/android"
20+
package="com.l4digital.rxloader.example">
21+
22+
<application
23+
android:allowBackup="false"
24+
android:icon="@mipmap/ic_launcher"
25+
android:label="@string/app_name"
26+
android:theme="@style/AppTheme">
27+
28+
<activity
29+
android:name=".ExampleActivity"
30+
android:configChanges="keyboardHidden|orientation|screenSize">
31+
<intent-filter>
32+
<action android:name="android.intent.action.MAIN" />
33+
<category android:name="android.intent.category.LAUNCHER" />
34+
</intent-filter>
35+
</activity>
36+
37+
</application>
38+
39+
</manifest>
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
* Copyright 2016 L4 Digital LLC. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.l4digital.rxloader.example;
18+
19+
import android.os.Bundle;
20+
import android.support.v7.app.AppCompatActivity;
21+
import android.view.View;
22+
import android.widget.TextView;
23+
24+
import com.l4digital.rxloader.RxLoader;
25+
import com.l4digital.rxloader.RxLoaderCallbacks;
26+
27+
import java.util.concurrent.TimeUnit;
28+
29+
import io.reactivex.Observable;
30+
import io.reactivex.Observer;
31+
import io.reactivex.disposables.Disposable;
32+
import io.reactivex.functions.Function;
33+
import io.reactivex.functions.Predicate;
34+
35+
public class ExampleActivity extends AppCompatActivity implements Observer<String> {
36+
37+
private static final String[] sVersionNames = new String[]{
38+
"Cupcake", "Donut", "Eclair", "Froyo", "Gingerbread", "Honeycomb", "Ice Cream Sandwich",
39+
"Jelly Bean", "KitKat", "Lollipop", "Marshmallow", "Nougat"
40+
};
41+
42+
private Disposable mDisposable;
43+
private TextView mExampleText;
44+
45+
@Override
46+
protected void onCreate(Bundle savedInstanceState) {
47+
super.onCreate(savedInstanceState);
48+
setContentView(R.layout.activity_example);
49+
50+
mExampleText = (TextView) findViewById(R.id.example_text);
51+
52+
RxLoader<String> loader = new RxLoader<>(this, getObservable());
53+
RxLoaderCallbacks<String> callbacks = new RxLoaderCallbacks<>(loader);
54+
55+
callbacks.getObservable().subscribe(this);
56+
57+
getLoaderManager().initLoader(1, Bundle.EMPTY, callbacks);
58+
}
59+
60+
@Override
61+
protected void onDestroy() {
62+
unsubscribe();
63+
super.onDestroy();
64+
}
65+
66+
@Override
67+
public void onSubscribe(Disposable disposable) {
68+
unsubscribe();
69+
mDisposable = disposable;
70+
}
71+
72+
@Override
73+
public void onNext(String value) {
74+
mExampleText.append(value + "\n");
75+
}
76+
77+
@Override
78+
public void onError(Throwable e) {
79+
mExampleText.setText(e.getMessage());
80+
}
81+
82+
@Override
83+
public void onComplete() {
84+
findViewById(R.id.progress).setVisibility(View.GONE);
85+
}
86+
87+
private Observable<String> getObservable() {
88+
return Observable.interval(500, TimeUnit.MILLISECONDS)
89+
.takeWhile(new Predicate<Long>() {
90+
91+
@Override
92+
public boolean test(Long tick) throws Exception {
93+
return tick < sVersionNames.length;
94+
}
95+
})
96+
.map(new Function<Long, String>() {
97+
98+
@Override
99+
public String apply(Long tick) throws Exception {
100+
return sVersionNames[tick.intValue()];
101+
}
102+
});
103+
}
104+
105+
private void unsubscribe() {
106+
if (mDisposable != null && !mDisposable.isDisposed()) {
107+
mDisposable.dispose();
108+
mDisposable = null;
109+
}
110+
}
111+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright 2016 L4 Digital LLC. All rights reserved.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<FrameLayout
19+
xmlns:android="http://schemas.android.com/apk/res/android"
20+
xmlns:tools="http://schemas.android.com/tools"
21+
android:id="@+id/activity_example"
22+
android:layout_width="match_parent"
23+
android:layout_height="match_parent"
24+
tools:context=".ExampleActivity">
25+
26+
<android.support.v7.widget.AppCompatTextView
27+
android:id="@+id/example_text"
28+
android:layout_width="match_parent"
29+
android:layout_height="wrap_content"
30+
android:padding="8dp"
31+
android:textSize="18sp"
32+
android:textStyle="bold"
33+
tools:text="John Doe" />
34+
35+
<ProgressBar
36+
android:id="@+id/progress"
37+
android:layout_width="wrap_content"
38+
android:layout_height="wrap_content"
39+
android:layout_gravity="center" />
40+
41+
</FrameLayout>
3.18 KB
Loading
1.99 KB
Loading
4.51 KB
Loading
7.24 KB
Loading

0 commit comments

Comments
 (0)