Skip to content

Commit

Permalink
merged rx2 into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Matias committed Apr 28, 2017
2 parents 746a906 + 20445ff commit 19f5f01
Show file tree
Hide file tree
Showing 121 changed files with 1,611 additions and 1,416 deletions.
25 changes: 14 additions & 11 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ android {
abortOnError false
disable 'InvalidPackage'
}

packagingOptions {
exclude 'META-INF/rxjava.properties'
}
}

dependencies {
Expand All @@ -40,21 +44,20 @@ dependencies {
compile libraries.supportDesign
compile libraries.retrofit
compile libraries.retrofitGsonConverter
compile libraries.retrofitRx
compile libraries.retrofitRx2
compile libraries.picasso
compile libraries.guava
annotationProcessor libraries.immutablesValue // <-- for annotation processor
provided libraries.immutablesValue // <-- for annotation API
provided libraries.immutablesGson // for annotations
compile 'com.nytimes.android:store:2.0.2'
compile'com.nytimes.android:cache:2.0.2'
compile'com.nytimes.android:middleware:2.0.2'
compile 'com.nytimes.android:filesystem:2.0.2'
//compile project(path: ':store')
//compile project(path: ':cache')
//compile project(path: ':middleware')
//compile project(path: ':filesystem')
//compile 'com.nytimes.android:store:2.0.2'
//compile'com.nytimes.android:cache:2.0.2'
//compile'com.nytimes.android:middleware:2.0.2'
//compile 'com.nytimes.android:filesystem:2.0.2'
compile project(path: ':store')
compile project(path: ':cache')
compile project(path: ':middleware')
compile project(path: ':filesystem')
retrolambdaConfig libraries.retrolambda
compile libraries.rxAndroid

compile libraries.rxAndroid2
}
41 changes: 19 additions & 22 deletions app/src/main/java/com/nytimes/android/sample/SampleApp.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
package com.nytimes.android.sample;

import android.app.Application;
import android.util.Log;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.nytimes.android.external.fs.SourcePersisterFactory;
import com.nytimes.android.external.store.base.Fetcher;
import com.nytimes.android.external.store.base.Persister;
import com.nytimes.android.external.store.base.impl.BarCode;
import com.nytimes.android.external.store.base.impl.MemoryPolicy;
import com.nytimes.android.external.store.base.impl.Store;
import com.nytimes.android.external.store.base.impl.StoreBuilder;
import com.nytimes.android.external.store.middleware.GsonParserFactory;
import com.nytimes.android.external.fs2.SourcePersisterFactory;
import com.nytimes.android.external.store2.base.Persister;
import com.nytimes.android.external.store2.base.impl.BarCode;
import com.nytimes.android.external.store2.base.impl.MemoryPolicy;
import com.nytimes.android.external.store2.base.impl.Store;
import com.nytimes.android.external.store2.base.impl.StoreBuilder;
import com.nytimes.android.external.store2.middleware.GsonParserFactory;
import com.nytimes.android.sample.data.model.GsonAdaptersModel;
import com.nytimes.android.sample.data.model.RedditData;
import com.nytimes.android.sample.data.remote.Api;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

import javax.annotation.Nonnull;

import io.reactivex.Single;
import okhttp3.ResponseBody;
import okio.BufferedSource;
import retrofit2.GsonConverterFactory;
import retrofit2.Retrofit;
import retrofit2.RxJavaCallAdapterFactory;
import rx.Observable;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class SampleApp extends Application {

Expand Down Expand Up @@ -63,11 +60,11 @@ private Store<RedditData, BarCode> provideRedditStore() {
return StoreBuilder.<RedditData>barcode()
.fetcher(barCode -> provideRetrofit().fetchSubreddit(barCode.getKey(), "10"))
.memoryPolicy(
MemoryPolicy
.builder()
.setExpireAfter(10)
.setExpireAfterTimeUnit(TimeUnit.SECONDS)
.build()
MemoryPolicy
.builder()
.setExpireAfter(10)
.setExpireAfterTimeUnit(TimeUnit.SECONDS)
.build()
)
.open();
}
Expand All @@ -84,16 +81,16 @@ private Persister<BufferedSource, BarCode> newPersister() throws IOException {
return SourcePersisterFactory.create(getApplicationContext().getCacheDir());
}

private Observable<BufferedSource> fetcher(BarCode barCode) {
private Single<BufferedSource> fetcher(BarCode barCode) {
return provideRetrofit().fetchSubredditForPersister(barCode.getKey(), "10")
.map(responseBody -> responseBody.source());
.map(ResponseBody::source);
}

private Api provideRetrofit() {
return new Retrofit.Builder()
.baseUrl("http://reddit.com/")
.addConverterFactory(GsonConverterFactory.create(provideGson()))
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.validateEagerly(BuildConfig.DEBUG) // Fail early: check Retrofit configuration at creation time in Debug build.
.build()
.create(Api.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import android.support.v7.widget.Toolbar;
import android.widget.Toast;

import com.nytimes.android.external.store.base.impl.BarCode;
import com.nytimes.android.external.store.base.impl.Store;
import com.nytimes.android.external.store2.base.impl.BarCode;
import com.nytimes.android.external.store2.base.impl.Store;
import com.nytimes.android.sample.R;
import com.nytimes.android.sample.SampleApp;
import com.nytimes.android.sample.data.model.Children;
Expand All @@ -18,9 +18,9 @@

import java.util.List;

import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

import static android.widget.Toast.makeText;

Expand Down Expand Up @@ -52,12 +52,13 @@ private void initStore() {
}
}

@SuppressWarnings("CheckReturnValue")
public void loadPosts() {
BarCode awwRequest = new BarCode(RedditData.class.getSimpleName(), "aww");

this.persistedStore
.get(awwRequest)
.flatMap(this::sanitizeData)
.flatMapObservable(this::sanitizeData)
.toList()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
Expand All @@ -74,7 +75,7 @@ private void showPosts(List<Post> posts) {
}

private Observable<Post> sanitizeData(RedditData redditData) {
return Observable.from(redditData.data().children())
return Observable.fromIterable(redditData.data().children())
.map(Children::data);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import android.util.Log;
import android.widget.Toast;

import com.nytimes.android.external.store.base.impl.BarCode;
import com.nytimes.android.external.store.base.impl.Store;
import com.nytimes.android.external.store2.base.impl.BarCode;
import com.nytimes.android.external.store2.base.impl.Store;
import com.nytimes.android.sample.R;
import com.nytimes.android.sample.SampleApp;
import com.nytimes.android.sample.data.model.Children;
Expand All @@ -19,9 +19,12 @@

import java.util.List;

import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Function;
import io.reactivex.schedulers.Schedulers;

import static android.widget.Toast.makeText;

Expand Down Expand Up @@ -51,12 +54,18 @@ private void initStore() {
}
}

@SuppressWarnings("CheckReturnValue")
public void loadPosts() {
BarCode awwRequest = new BarCode(RedditData.class.getSimpleName(), "aww");

this.nonPersistedStore
.get(awwRequest)
.flatMap(this::sanitizeData)
.flatMapObservable(new Function<RedditData, ObservableSource<Post>>() {
@Override
public ObservableSource<Post> apply(@NonNull RedditData redditData) throws Exception {
return sanitizeData(redditData);
}
})
.toList()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
Expand All @@ -74,7 +83,7 @@ private void showPosts(List<Post> posts) {
}

private Observable<Post> sanitizeData(RedditData redditData) {
return Observable.from(redditData.data().children())
return Observable.fromIterable(redditData.data().children())
.map(Children::data);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@

import com.nytimes.android.sample.data.model.RedditData;

import okhttp3.Response;
import io.reactivex.Single;
import okhttp3.ResponseBody;
import retrofit2.http.GET;
import retrofit2.http.Path;
import retrofit2.http.Query;
import rx.Observable;

public interface Api {

@GET("r/{subredditName}/new/.json")
Observable<RedditData> fetchSubreddit(@Path("subredditName") String subredditName,
@Query("limit") String limit);
Single<RedditData> fetchSubreddit(@Path("subredditName") String subredditName,
@Query("limit") String limit);

@GET("r/{subredditName}/new/.json")
Observable<ResponseBody> fetchSubredditForPersister(@Path("subredditName") String subredditName,
@Query("limit") String limit);
Single<ResponseBody> fetchSubredditForPersister(@Path("subredditName") String subredditName,
@Query("limit") String limit);
}
Original file line number Diff line number Diff line change
@@ -1,42 +1,30 @@
package com.nytimes.android.sample;

import com.nytimes.android.external.store.base.impl.Store;
import com.nytimes.android.external.store.base.impl.BarCode;
import com.nytimes.android.external.store.base.impl.StoreBuilder;
import com.nytimes.android.external.store2.base.impl.Store;
import com.nytimes.android.external.store2.base.impl.BarCode;
import com.nytimes.android.external.store2.base.impl.StoreBuilder;

import org.junit.Before;
import org.junit.Test;

import rx.Observable;
import io.reactivex.Single;

import static junit.framework.Assert.assertEquals;

/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class StoreIntegrationTest {

private Store<String, BarCode> testStore;

@Test
public void addition_isCorrect() throws Exception {

}


@Before
public void setUp() throws Exception {
testStore = StoreBuilder.<String>barcode()
.fetcher(barCode -> Observable.just("hello"))
.fetcher(barCode -> Single.just("hello"))
.open();

}

@Test
public void testRepeatedGet() throws Exception {
String first = testStore.get(BarCode.empty()).toBlocking().first();
String first = testStore.get(BarCode.empty()).blockingGet();
assertEquals(first, "hello");

}
Expand Down
6 changes: 2 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,11 @@ allprojects {
}

ext {
// SDK versions

// POM file
GROUP = "com.nytimes.android"
VERSION_NAME = "2.0.5-SNAPSHOT"
VERSION_NAME = "0.0.1-SNAPSHOT"
POM_PACKAGING = "pom"
POM_DESCRIPTION = "Store"
POM_DESCRIPTION = "Store2 is built with RxJava2"

POM_URL = "https://github.com/nytimes/Store/"
POM_SCM_URL = "https://github.com/nytimes/Store/"
Expand Down
8 changes: 6 additions & 2 deletions buildsystem/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ ext.versions = [

// Reactive.
rxJava : '1.2.6',
rxJava2 : '2.0.7',
rxJavaProGuardRules : '1.1.6.0',
rxJavaAsyncUtil : '0.21.0',
rxAndroid : '1.2.1',
rxAndroid2 : '2.0.1',

// Others.
retrofit : '2.0.0-beta3',
retrofit : '2.2.0',
retrolambda : '2.3.0',
dagger : '2.9',
jsr305 : '3.0.1',
Expand Down Expand Up @@ -80,14 +82,16 @@ ext.libraries = [

// Reactive.
rxJava : "io.reactivex:rxjava:$versions.rxJava",
rxJava2 : "io.reactivex.rxjava2:rxjava:$versions.rxJava2",
rxJavaAsyncUtil : "io.reactivex:rxjava-async-util:$versions.rxJavaAsyncUtil",
rxJavaProGuardRules : "com.artemzin.rxjava:proguard-rules:$versions.rxJavaProGuardRules",
rxAndroid : "io.reactivex:rxandroid:$versions.rxAndroid",
rxAndroid2 : "io.reactivex.rxjava2:rxandroid:$versions.rxAndroid2",

// Others.
retrofit : "com.squareup.retrofit2:retrofit:$versions.retrofit",
retrofitGsonConverter : "com.squareup.retrofit2:converter-gson:$versions.retrofit",
retrofitRx : "com.squareup.retrofit2:adapter-rxjava:$versions.retrofit",
retrofitRx2 : "com.squareup.retrofit2:adapter-rxjava2:$versions.retrofit",
retrolambda : "net.orfjackal.retrolambda:retrolambda:$versions.retrolambda",
dagger : "com.google.dagger:dagger:$versions.dagger",
daggerCompiler : "com.google.dagger:dagger-compiler:$versions.dagger",
Expand Down
2 changes: 1 addition & 1 deletion filesystem/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
POM_NAME=com.nytimes.android
POM_ARTIFACT_ID=filesystem
POM_ARTIFACT_ID=filesystem2
POM_PACKAGING=aar
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.nytimes.android.external.fs;
package com.nytimes.android.external.fs2;

import com.nytimes.android.external.store.base.impl.BarCode;
import com.nytimes.android.external.store2.base.impl.BarCode;

import javax.annotation.Nonnull;

Expand Down
Loading

0 comments on commit 19f5f01

Please sign in to comment.