Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ See my blog post for the full story: [http://randomdotnext.com/retrofit-rxjava/]
Let's take care of the depency injection for retrofit and RxJava/RxAndroid:
```java
dependencies {
compile 'io.reactivex:rxjava:1.0.+'
compile 'io.reactivex:rxandroid:0.23.+'
compile 'com.squareup.retrofit:retrofit:1.9.+'
compile 'io.reactivex:rxandroid:1.1.0'
compile 'io.reactivex:rxjava:1.1.0'
compile 'com.squareup.retrofit2:retrofit:2.0.2'
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.2'
compile 'com.squareup.retrofit2:converter-gson:2.0.0'
}
```

Expand All @@ -39,12 +41,12 @@ public interface GithubService {
Hang on! GithubService needs a RestAdapter implementation. In the spirit of good programming practice, I created a generic factory class to do the implementation:
```java
static <T> T createRetrofitService(final Class<T> clazz, final String endPoint) {
final RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint(endPoint)
.build();
T service = restAdapter.create(clazz);

return service;
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(endPoint)
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.build();
return retrofit.create(clazz);
}
```

Expand Down
15 changes: 10 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.1'
classpath 'com.android.tools.build:gradle:2.3.2'
}
}
apply plugin: 'com.android.application'
Expand All @@ -14,7 +14,7 @@ repositories {

android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
buildToolsVersion '25.0.0'

defaultConfig {
applicationId "com.example.githubdemo.app"
Expand All @@ -41,7 +41,12 @@ dependencies {
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.android.support:cardview-v7:21.0.+'
compile 'com.android.support:recyclerview-v7:21.0.+'
compile 'io.reactivex:rxjava:1.0.+'
compile 'io.reactivex:rxandroid:0.23.+'
compile 'com.squareup.retrofit:retrofit:1.9.+'
compile 'io.reactivex:rxandroid:1.1.0'
compile 'io.reactivex:rxjava:1.1.0'
compile 'com.squareup.retrofit2:retrofit:2.0.2'
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.2'
compile 'com.squareup.retrofit2:converter-gson:2.0.0'



}
4 changes: 2 additions & 2 deletions app/src/main/java/app/service/GithubService.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package app.service;

import app.model.Github;
import retrofit.http.GET;
import retrofit.http.Path;
import retrofit2.http.GET;
import retrofit2.http.Path;
import rx.Observable;

public interface GithubService {
Expand Down
16 changes: 11 additions & 5 deletions app/src/main/java/app/service/ServiceFactory.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package app.service;

import retrofit.RestAdapter;

import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class ServiceFactory {

Expand All @@ -11,11 +14,14 @@ public class ServiceFactory {
* @return retrofit service with defined endpoint
*/
public static <T> T createRetrofitService(final Class<T> clazz, final String endPoint) {
final RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint(endPoint)

Retrofit retrofit = new Retrofit.Builder()
.baseUrl(endPoint)
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.build();
T service = restAdapter.create(clazz);

return service;
return retrofit.create(clazz);

}
}
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:1.1.1'
classpath 'com.android.tools.build:gradle:2.3.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down