package com.thefuntasty.infinity.sample;

import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.thefuntasty.infinity.InfinityAdapter;
import com.thefuntasty.infinity.InfinityEventListener;
import com.thefuntasty.infinity.InfinityFiller;

import java.util.List;

import rx.functions.Action1;

public class SampleActivity extends AppCompatActivity {

	RecyclerView recyclerView;
	SwipeRefreshLayout refresh;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_sample);

		recyclerView = (RecyclerView) findViewById(R.id.recycler);
		refresh = (SwipeRefreshLayout) findViewById(R.id.refresh);

		final InfinityAdapter<User, ?> adapter = new SampleUserAdapter();
		refresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
			@Override public void onRefresh() {
				adapter.restart(true);
			}
		});
		recyclerView.setLayoutManager(new LinearLayoutManager(this));
		recyclerView.setAdapter(adapter);

		adapter.setLimit(10);
		adapter.setFiller(new InfinityFiller<User>() {
			@Override public void onLoad(final int limit, final int offset, final InfinityFiller.Callback<User> callback) {
				DataManager.get().getDataObservable(limit, offset)
						.subscribe(new Action1<List<User>>() {
							@Override public void call(List<User> users) {
								callback.onData(users);
							}
						}, new Action1<Throwable>() {
							@Override public void call(Throwable throwable) {
								callback.onError(throwable);
							}
						});
			}
		});
		adapter.setEventListener(new InfinityEventListener() {
			@Override public void onFirstLoaded(boolean pullToRefresh) {
				super.onFirstLoaded(pullToRefresh);
			}

			@Override public void onFirstUnavailable(Throwable error, boolean pullToRefresh) {
				super.onFirstUnavailable(error, pullToRefresh);
			}

			@Override public void onFirstEmpty(boolean pullToRefresh) {
				super.onFirstEmpty(pullToRefresh);
			}

			@Override public void onNextLoaded() {
				super.onNextLoaded();
			}

			@Override public void onNextUnavailable(Throwable error) {
				super.onNextUnavailable(error);
			}

			@Override public void onFinished() {
				super.onFinished();
			}

			@Override public void onPreLoadFirst(boolean pullToRefresh) {
				super.onPreLoadFirst(pullToRefresh);
			}

			@Override public void onPreLoadNext() {
				super.onPreLoadNext();
			}
		});
		adapter.start();
	}
}

@@ -1852,41 +1852,35 @@
 %09%09%09%09
-super.onFirstLoaded(pullToRefresh
+refresh.setRefreshing(false
 );%0A%09
@@ -1978,53 +1978,35 @@
 %09%09%09%09
-super.onFirstUnavailable(error, pullToRefresh
+refresh.setRefreshing(false
 );%0A%09
@@ -2081,40 +2081,35 @@
 %09%09%09%09
-super.onFirstEmpty(pullToRefresh
+refresh.setRefreshing(false
 );%0A%09
@@ -2158,38 +2158,9 @@
 () %7B
-%0A%09%09%09%09super.onNextLoaded();%0A%09%09%09
+ 
 %7D%0A%0A%09
@@ -2223,48 +2223,9 @@
 r) %7B
-%0A%09%09%09%09super.onNextUnavailable(error);%0A%09%09%09
+ 
 %7D%0A%0A%09
@@ -2266,36 +2266,9 @@
 () %7B
-%0A%09%09%09%09super.onFinished();%0A%09%09%09
+ 
 %7D%0A%0A%09
@@ -2334,53 +2334,9 @@
 h) %7B
-%0A%09%09%09%09super.onPreLoadFirst(pullToRefresh);%0A%09%09%09
+ 
 %7D%0A%0A%09
@@ -2380,39 +2380,9 @@
 () %7B
-%0A%09%09%09%09super.onPreLoadNext();%0A%09%09%09
+ 
 %7D%0A%09%09

fix pull to refresh in sample app