I'm trying to use Retrofit2 with RxJava2, here is Api:
public class App extends Application {
final String SERVER_ENDPOINT = "https://api.vk.com";
private Retrofit mRetrofit;
private static ImageService mImageService;
HttpLoggingInterceptor httpLoggingInterceptor;
@Override
public void onCreate() {
super.onCreate();
httpLoggingInterceptor = new HttpLoggingInterceptor();
httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient okHttpClient = createClient();
mRetrofit = new Retrofit.Builder()
.baseUrl(SERVER_ENDPOINT)
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build();
mImageService = mRetrofit.create(ImageService.class);
}
private OkHttpClient createClient() {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.addInterceptor(httpLoggingInterceptor);
return builder.build();
}
public static ImageService getImageService() {
return mImageService;
}
}
That is service interface:
public interface ImageService {
@GET("/method/photos.get")
Observable<GetPhotoResponse> getImages(
@Query("owner_id") int owner_id,
@Query("album_id") String album_id,
@Query("count") int count,
@Query("v") String version);
}
When I'm calling method getImages(), no OkHttp logging appears in logcat. And pictures dont downloading to the imageviews
There is gradle.build:
//RxJava2
compile "io.reactivex.rxjava2:rxjava:2.1.0"
//Retrofit2
compile 'com.squareup.retrofit2:retrofit:2.2.0'
compile 'com.squareup.retrofit2:adapter-rxjava2:2.2.0'
compile 'com.squareup.retrofit2:converter-gson:2.2.0'
//Okhttp
compile 'com.squareup.okhttp3:okhttp:3.6.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.6.0'
//Glide
compile 'com.github.bumptech.glide:glide:3.7.0'
//Gson
compile 'com.google.code.gson:gson:2.7'
//RecyclerView
compile 'com.android.support:recyclerview-v7:25.3.0'
What's wrong with it?? Need help!
The code, where I call method in Interactor:
public Observable<GetPhotoResponse> downloadImages() {
Log.d("tag", "downloadImages: ");
return downloadImagesFromVK()
.doOnNext(getPhotoResponse -> {
Log.d("tag", "downloadImages: YESSS");
})
.doOnComplete(() -> {
Log.d("tag", "downloadImages: COMPLETE");
})
.doOnError(throwable -> {
Log.d("tag", "downloadImages: ERROR");
});
}
public Observable<GetPhotoResponse> downloadImagesFromVK() {
return imageService.getImages(
VkConstants.OWNER_ID,
VkConstants.ALBUM_ID,
VkConstants.COUNT,
VkConstants.VK_API_VERSION);
}
Presenter:
public void startDownloadImages() {
mMainView.showProgressBar();
mInteractor.downloadImages()
.doOnNext(getPhotoResponse -> {
mMainView.setImagesToView(mInteractor
.getUrlsListMaxSize(getPhotoResponse));
})
.doOnError(throwable -> mMainView.showConnectionProblemError());
}