use of retrofit2.http.GET in project FuryViewer by TheDoctor-95.
the class SeriesTmdbDTOService method getDurationEpisode.
/**
* Devuelve la duraciĆ³n estandar de un episode.
* @param seriesId int | id de la api de TMDB.
* @return double | Duracion estandar de un episode.
*/
public double getDurationEpisode(int seriesId) {
double duration = -1;
CompleteSeriesTmdbDTO series;
getDuration: for (int i = 0; i < 3; i++) {
try {
Call<CompleteSeriesTmdbDTO> callSeries = apiTMDB.getCompleteSeries(seriesId, apikey);
Response<CompleteSeriesTmdbDTO> response = callSeries.execute();
if (response.isSuccessful()) {
series = response.body();
if (series.getEpisodeRunTime() != null) {
duration = series.getEpisodeRunTime().get(0);
}
}
// Salimos del bucle
break getDuration;
} catch (IOException e) {
e.printStackTrace();
try {
Thread.sleep(5000L);
System.out.println("Durmiendo el thread 5 segundos desde SeriesTmdbDTOService#getDurationEpisode");
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
return duration;
}
use of retrofit2.http.GET in project My-MVP by REBOOTERS.
the class RxJavaBaseActivity method withRetrofit2AndGson.
private void withRetrofit2AndGson() {
final OkHttpClient mClient = new OkHttpClient.Builder().readTimeout(10, TimeUnit.SECONDS).connectTimeout(30, TimeUnit.SECONDS).addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)).build();
final Retrofit mRetrofit = new Retrofit.Builder().client(mClient).baseUrl(BASE_URL).addConverterFactory(GsonConverterFactory.create()).addCallAdapterFactory(RxJava2CallAdapterFactory.create()).build();
GankApi mGankApi = mRetrofit.create(GankApi.class);
Observable<GankAndroid> mAndroidObservable = mGankApi.getData("10/1");
mAndroidObservable.subscribeOn(Schedulers.io()).map(new Function<GankAndroid, GankAndroid.ResultsEntity>() {
@Override
public GankAndroid.ResultsEntity apply(GankAndroid gankAndroid) throws Exception {
return gankAndroid.getResults().get(0);
}
}).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<GankAndroid.ResultsEntity>() {
@Override
public void accept(GankAndroid.ResultsEntity resultsEntity) throws Exception {
sb.append(resultsEntity.getCreatedAt()).append("\n").append(resultsEntity.getType()).append("\n").append(resultsEntity.getDesc()).append("\n").append(resultsEntity.getUrl()).append("\n").append(resultsEntity.getWho());
logContent.setText(sb.toString());
}
});
}
use of retrofit2.http.GET in project Gladys-Android-App by LeptitGeek.
the class AllSentencesFragment method setStatus.
public void setStatus(final Long id, final String status) {
getConnection();
if (connection) {
Retrofit retrofit = new Retrofit.Builder().baseUrl(url).addConverterFactory(GsonConverterFactory.create()).client(SelfSigningClientBuilder.getUnsafeOkHttpClient()).build();
RetrofitAPI service = retrofit.create(RetrofitAPI.class);
Call<Void> call = service.setStatus(id, status, pref_token);
call.enqueue(new Callback<Void>() {
@Override
public void onResponse(Call<Void> call, Response<Void> response) {
if (response.code() == 200) {
if (getActivity() != null) {
SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.command_send));
}
BrainSentences brainSentences = (SugarRecord.find(BrainSentences.class, "sentencesid = ?", id.toString())).get(0);
brainSentences.setStatue(status);
SugarRecord.save(brainSentences);
onCreateAdapterView();
} else {
if (getActivity() != null) {
SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.error_code_4));
}
}
}
@Override
public void onFailure(Call<Void> call, Throwable t) {
if (getActivity() != null) {
SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.error_code_5));
}
}
});
}
}
use of retrofit2.http.GET in project Gladys-Android-App by LeptitGeek.
the class AllSentencesFragment method setLabel.
public void setLabel(final Long id, final String label) {
getConnection();
if (connection) {
Retrofit retrofit = new Retrofit.Builder().baseUrl(url).addConverterFactory(GsonConverterFactory.create()).client(SelfSigningClientBuilder.getUnsafeOkHttpClient()).build();
RetrofitAPI service = retrofit.create(RetrofitAPI.class);
Call<BrainSentences> call = service.setLabel(id, label, pref_token);
call.enqueue(new Callback<BrainSentences>() {
@Override
public void onResponse(Call<BrainSentences> call, Response<BrainSentences> response) {
if (response.code() == 200) {
if (getActivity() != null) {
SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.command_send));
}
BrainSentences brainSentences = (SugarRecord.find(BrainSentences.class, "sentencesid = ?", id.toString())).get(0);
brainSentences.setLabel(response.body().getLabel());
brainSentences.setService(response.body().getService());
SugarRecord.save(brainSentences);
onCreateAdapterView();
} else {
if (getActivity() != null) {
SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.error_code_4));
}
}
}
@Override
public void onFailure(Call<BrainSentences> call, Throwable t) {
if (getActivity() != null) {
SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.error_code_5));
}
}
});
}
}
use of retrofit2.http.GET in project Gladys-Android-App by LeptitGeek.
the class ApprovedSentencesFragment method setLabel.
public void setLabel(final Long id, final String label) {
getConnection();
if (connection) {
Retrofit retrofit = new Retrofit.Builder().baseUrl(url).addConverterFactory(GsonConverterFactory.create()).client(SelfSigningClientBuilder.getUnsafeOkHttpClient()).build();
RetrofitAPI service = retrofit.create(RetrofitAPI.class);
Call<BrainSentences> call = service.setLabel(id, label, pref_token);
call.enqueue(new Callback<BrainSentences>() {
@Override
public void onResponse(Call<BrainSentences> call, Response<BrainSentences> response) {
if (response.code() == 200) {
if (getActivity() != null) {
SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.command_send));
}
BrainSentences brainSentences = (SugarRecord.find(BrainSentences.class, "sentencesid = ?", id.toString())).get(0);
brainSentences.setLabel(response.body().getLabel());
brainSentences.setService(response.body().getService());
SugarRecord.save(brainSentences);
onCreateAdapterView();
} else {
if (getActivity() != null) {
SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.error_code_4));
}
}
}
@Override
public void onFailure(Call<BrainSentences> call, Throwable t) {
if (getActivity() != null) {
SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.error_code_5));
}
}
});
}
}
Aggregations