Search in sources :

Example 1 with SourceEvenementList

use of ca.etsmtl.applets.etsmobile.model.applets_events.SourceEvenementList in project ETSMobile-Android2 by ApplETS.

the class EventsFragment method onResume.

@Override
public void onResume() {
    super.onResume();
    expandableListAdapter.clearEvents();
    progressBar.setVisibility(View.VISIBLE);
    countSourcesLoaded = 0;
    nbSources = 0;
    progressBar.setProgress(0);
    AppletsApiSourcesRequest requestSources = new AppletsApiSourcesRequest(getActivity());
    String cacheKey = requestSources.createCacheKey();
    spiceManager.execute(requestSources, cacheKey, DurationInMillis.ONE_MINUTE * 10, new RequestListener<SourceEvenementList>() {

        @Override
        public void onRequestFailure(SpiceException spiceException) {
            spiceException.printStackTrace();
            Toast.makeText(getActivity(), getString(R.string.SupportKit_errorCouldNotConnect), Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onRequestSuccess(SourceEvenementList sourceEvenements) {
            progressBar.setMax(sourceEvenements.size());
            EventsFragment.this.nbSources = sourceEvenements.size();
            for (SourceEvenement source : sourceEvenements) {
                AppletsApiEvenementsRequest requestEvents = new AppletsApiEvenementsRequest(getActivity(), source);
                String cacheKey = requestEvents.createCacheKey();
                spiceManager.execute(requestEvents, cacheKey, DurationInMillis.ONE_MINUTE * 10, EventsFragment.this);
            }
        }
    });
}
Also used : SourceEvenementList(ca.etsmtl.applets.etsmobile.model.applets_events.SourceEvenementList) SourceEvenement(ca.etsmtl.applets.etsmobile.model.applets_events.SourceEvenement) SpiceException(com.octo.android.robospice.persistence.exception.SpiceException) AppletsApiSourcesRequest(ca.etsmtl.applets.etsmobile.http.AppletsApiSourcesRequest) AppletsApiEvenementsRequest(ca.etsmtl.applets.etsmobile.http.AppletsApiEvenementsRequest)

Example 2 with SourceEvenementList

use of ca.etsmtl.applets.etsmobile.model.applets_events.SourceEvenementList in project ETSMobile-Android2 by ApplETS.

the class AppletsApiSourcesRequest method loadDataFromNetwork.

@Override
public SourceEvenementList loadDataFromNetwork() throws Exception {
    String sourceAddress = context.getString(R.string.applets_api_events_sources);
    OkHttpClient client = new OkHttpClient();
    Request request = new Request.Builder().url(sourceAddress).get().build();
    Response response = client.newCall(request).execute();
    String result = response.body().string();
    SourceEvenementList sources = new Gson().fromJson(result, SourceEvenementList.class);
    return sources;
}
Also used : Response(com.squareup.okhttp.Response) SourceEvenementList(ca.etsmtl.applets.etsmobile.model.applets_events.SourceEvenementList) OkHttpClient(com.squareup.okhttp.OkHttpClient) SpringAndroidSpiceRequest(com.octo.android.robospice.request.springandroid.SpringAndroidSpiceRequest) Request(com.squareup.okhttp.Request) Gson(com.google.gson.Gson)

Aggregations

SourceEvenementList (ca.etsmtl.applets.etsmobile.model.applets_events.SourceEvenementList)2 AppletsApiEvenementsRequest (ca.etsmtl.applets.etsmobile.http.AppletsApiEvenementsRequest)1 AppletsApiSourcesRequest (ca.etsmtl.applets.etsmobile.http.AppletsApiSourcesRequest)1 SourceEvenement (ca.etsmtl.applets.etsmobile.model.applets_events.SourceEvenement)1 Gson (com.google.gson.Gson)1 SpiceException (com.octo.android.robospice.persistence.exception.SpiceException)1 SpringAndroidSpiceRequest (com.octo.android.robospice.request.springandroid.SpringAndroidSpiceRequest)1 OkHttpClient (com.squareup.okhttp.OkHttpClient)1 Request (com.squareup.okhttp.Request)1 Response (com.squareup.okhttp.Response)1