<commit_before>package com.cuantocuesta.android.activities.templates;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Toast;
import com.cuantocuesta.R;
import com.cuantocuesta.android.adapters.ModelToPictureAdapter;
import com.cuantocuesta.android.applicationModels.Displayable;
import com.octo.android.robospice.persistence.DurationInMillis;
import com.octo.android.robospice.persistence.exception.SpiceException;
import com.octo.android.robospice.request.listener.RequestListener;
import com.octo.android.robospice.request.retrofit.RetrofitSpiceRequest;
import com.octo.android.robospice.spicelist.SpiceListItemView;
import roboguice.util.temp.Ln;

import java.util.List;

public abstract class ListSpiceActivity<TResponse, TService, TModel extends Displayable> extends SpiceActivity {
  protected RetrofitSpiceRequest<TResponse, TService> request;
  protected ListView listingsListView;
  protected View loadingView;

  @Override
  public void onCreateFrame(Bundle savedInstanceState, View view) {
    Ln.getConfig().setLoggingLevel(Log.ERROR);
    listingsListView = (ListView) view.findViewById(R.id.listview_github);
    loadingView = findViewById(R.id.loading_layout);

    request = new RetrofitSpiceRequest<TResponse, TService>(getResponseClass(), getServiceClass()) {
      @Override
      public TResponse loadDataFromNetwork() throws Exception {
        return performQuery(getService());
      }
    };
  }

  @Override
  protected int layoutId() {
    return R.layout.activity_main;
  }

  @Override
  public void onStart() {
    super.onStart();
    loadItems();
  }

  protected abstract Class<TResponse> getResponseClass();
  protected abstract Class<TService> getServiceClass();
  protected abstract TResponse performQuery(TService service);
  protected abstract List<TModel> getResultsFromResponse(TResponse result);
  protected abstract SpiceListItemView<TModel> createView(Context context);

  private ListAdapter getAdapter(List<TModel> items) {
    return new ModelToPictureAdapter<TModel>(ListSpiceActivity.this.getActivity(), getSpiceManagerBinary(), items) {
      @Override
      protected SpiceListItemView<TModel> getView(Context context) {
        return ListSpiceActivity.this.createView(context);
      }

      @Override
      protected String getId(TModel model) {
        return model.getId();
      }

      @Override
      protected String getPictureUrl(TModel model) {
        return model.getThumbnail();
      }
    };
  }

  private void updateListViewContent(List<TModel> items) {
    listingsListView.setAdapter(getAdapter(items));

    loadingView.setVisibility(View.GONE);
    listingsListView.setVisibility(View.VISIBLE);
  }

  private void loadItems() {
    ListSpiceActivity.this.getActivity().setProgressBarIndeterminateVisibility(true);
    getSpiceManager().execute(request, "meli", DurationInMillis.ONE_MINUTE, new ItemsRequestListener());
  }<commit_msg>Recupero el caching de requests<commit_after>package com.cuantocuesta.android.activities.templates;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Toast;
import com.cuantocuesta.R;
import com.cuantocuesta.android.adapters.ModelToPictureAdapter;
import com.cuantocuesta.android.applicationModels.Displayable;
import com.octo.android.robospice.persistence.DurationInMillis;
import com.octo.android.robospice.persistence.exception.SpiceException;
import com.octo.android.robospice.request.listener.RequestListener;
import com.octo.android.robospice.request.retrofit.RetrofitSpiceRequest;
import com.octo.android.robospice.spicelist.SpiceListItemView;
import roboguice.util.temp.Ln;

import java.util.List;

public abstract class ListSpiceActivity<TResponse, TService, TModel extends Displayable> extends SpiceActivity {
  protected RetrofitSpiceRequest<TResponse, TService> request;
  protected ListView listingsListView;
  protected View loadingView;

  @Override
  public void onCreateFrame(Bundle savedInstanceState, View view) {
    Ln.getConfig().setLoggingLevel(Log.ERROR);
    listingsListView = (ListView) view.findViewById(R.id.listview_github);
    loadingView = findViewById(R.id.loading_layout);

    request = new RetrofitSpiceRequest<TResponse, TService>(getResponseClass(), getServiceClass()) {
      @Override
      public TResponse loadDataFromNetwork() throws Exception {
        return performQuery(getService());
      }
    };
  }

  @Override
  protected int layoutId() {
    return R.layout.activity_main;
  }

  @Override
  public void onStart() {
    super.onStart();
    loadItems();
  }

  protected abstract Class<TResponse> getResponseClass();
  protected abstract Class<TService> getServiceClass();
  protected abstract TResponse performQuery(TService service);
  protected abstract List<TModel> getResultsFromResponse(TResponse result);
  protected abstract SpiceListItemView<TModel> createView(Context context);

  private ListAdapter getAdapter(List<TModel> items) {
    return new ModelToPictureAdapter<TModel>(ListSpiceActivity.this.getActivity(), getSpiceManagerBinary(), items) {
      @Override
      protected SpiceListItemView<TModel> getView(Context context) {
        return ListSpiceActivity.this.createView(context);
      }

      @Override
      protected String getId(TModel model) {
        return model.getId();
      }

      @Override
      protected String getPictureUrl(TModel model) {
        return model.getThumbnail();
      }
    };
  }

  private void updateListViewContent(List<TModel> items) {
    listingsListView.setAdapter(getAdapter(items));

    loadingView.setVisibility(View.GONE);
    listingsListView.setVisibility(View.VISIBLE);
  }

  private void loadItems() {
    ListSpiceActivity.this.getActivity().setProgressBarIndeterminateVisibility(true);
    getSpiceManager().execute(request, this.getClass().getName(), DurationInMillis.ONE_MINUTE, new ItemsRequestListener());
  }
{'fraction_non_alphanumeric': 0.09423233143785541, 'fraction_numerical': 0.0, 'mean_word_length': 5.089020771513353, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6651223', 'n_tokens_mistral': 1796, 'n_tokens_neox': 1732, 'n_words': 330}