I know there's some similar existing questions on this matter but none have worked so far and the amount of solutions via different versions of dependecies has gotten me confused.
Firstly, here are my dependencies. Would be appreciated if solutions are answered regarding the versions.
dependencies {
implementation 'androidx.appcompat:appcompat:1.5.0'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.google.code.gson:gson:2.9.1'
implementation "com.squareup.retrofit2:adapter-rxjava2:2.3.0"
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
Here is my working mode
public interface QuoteService {
@GET("https://www.alphavantage.co/query?function=GLOBAL_QUOTE")
Call<Quote> getQuote (@Query("symbol") String company, @Query("apikey") String api_key);
Here is my main activity:
for (String s: companylist) {
Call<Quote> call = service.getQuote(s, API.API_KEY);
call.enqueue(new Callback<Quote>() {
@Override
public void onResponse(Call<Quote> call, Response<Quote> response) {
if (response.isSuccessful()) {
data = response.body();
items.add(data.getApp());
}
}
});
}
I know Rxjava is needed to handle multiple requests, How to make multiple request and wait until data is come from all the requests in retrofit 2.0 - android.
Code from link:
Observable.zip(
requests,
new Function<Object[], Object>() {
@Override
public Object apply(Object[] objects) throws Exception {
// Objects[] is an array of combined results of completed requests
// do something with those results and emit new event
return new Object();
}
})
// After all requests had been performed the next observer will receive the Object, returned from Function
.subscribe(
// Will be triggered if all requests will end successfully (4xx and 5xx also are successful requests too)
new Consumer<Object>() {
@Override
public void accept(Object o) throws Exception {
//Do something on successful completion of all requests
}
},
// Will be triggered if any error during requests will happen
new Consumer<Throwable>() {
@Override
public void accept(Throwable e) throws Exception {
//Do something on error completion of requests
}
}
);
But upon making the observable list I keep coming up with "cannot resolve method" at subscribe and new Consumer object. Some research explained that i may be using another version of rxjava.
At the end I just want to return data from the multiple api calls into a list which i will use to insert into an adapter. Was hoping to set my adapter with the list during the subscribe method.