package com.stanfy.enroscar.sample;

import java.util.List;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.TextView;

import com.stanfy.app.fragments.list.RequestBuilderListFragment;
import com.stanfy.enroscar.sample.model.Tweet;
import com.stanfy.serverapi.request.RequestBuilder;
import com.stanfy.views.LoadableImageView;
import com.stanfy.views.list.ModelListAdapter.ElementRenderer;

/**
 * Fragment that displays tweets of Twitter API.
 */
public class TwitterFragment extends RequestBuilderListFragment<Tweet, List<Tweet>> {

  /** Row view holder. */
  private static class TweetViewHolder {
    LoadableImageView image;
    TextView text;
  }

  /** Post renderer. */
  private static ElementRenderer<Tweet> RENDERER = new ElementRenderer<Tweet>(R.layout.row_tweet) {
    @Override
    public void render(final Adapter adapter, final ViewGroup parent, final Tweet element, final View view, final Object holder, final int position) {
      final TweetViewHolder h = (TweetViewHolder)holder;
      h.text.setText(element.getText());
      h.image.setImageURI(element.getProfileImageUri());
    }
    @Override
    public Object createHolder(final View view) {
      final TweetViewHolder h = new TweetViewHolder();
      h.image = (LoadableImageView)view.findViewById(R.id.tweet_image);
      h.text = (TextView)view.findViewById(R.id.tweet_text);
      return h;
    }
  };

  @Override
  protected ElementRenderer<Tweet> createRenderer() { return RENDERER; }

  @Override
  protected RequestBuilder<List<Tweet>> createRequestBuilder() {
    return new TweetsRequestBuilder(getActivity())
        .setScreenname("twitterapi")
        .asLoadMoreList()
        .setLimit(10)
        .setOffset(1);
  }

  @Override
  public void onActivityCreated(final Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    startLoad();
  }

}

@@ -80,16 +80,106 @@
 Bundle;%0A
+import android.view.Menu;%0Aimport android.view.MenuInflater;%0Aimport android.view.MenuItem;%0A
 import a
@@ -1915,123 +1915,501 @@
 d on
-ActivityCreated(final Bundle savedInstanceState) %7B%0A    super.onActivityCreated(savedInstanceState);%0A    startLoad()
+Create(final Bundle savedInstanceState) %7B%0A    super.onCreate(savedInstanceState);%0A    setHasOptionsMenu(true);%0A  %7D%0A%0A  @Override%0A  public void onActivityCreated(final Bundle savedInstanceState) %7B%0A    super.onActivityCreated(savedInstanceState);%0A    startLoad();%0A  %7D%0A%0A  @Override%0A  public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) %7B%0A    menu.add(%22refresh%22);%0A  %7D%0A%0A  @Override%0A  public boolean onOptionsItemSelected(final MenuItem item) %7B%0A    reload();%0A    return true
 ;%0A  

change library version