Skip to content

Commit 198c975

Browse files
author
Victor
committed
Added stillLoading = false to onCompleted RxPager
1 parent 4f58b28 commit 198c975

6 files changed

Lines changed: 31 additions & 7 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Add OkAdapter dependency to project level build.gradle.
66

77
```gradle
88
dependencies {
9-
compile 'com.github.FuckBoilerplate:OkAdapters:0.0.9'
9+
compile 'com.github.FuckBoilerplate:OkAdapters:0.1.0'
1010
}
1111
```
1212

app/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ dependencies {
2727
compile "com.jakewharton:butterknife:7.0.1"
2828
compile 'io.reactivex:rxjava:1.1.5'
2929
compile 'io.reactivex:rxandroid:1.2.0'
30+
compile 'com.trello:rxlifecycle:0.6.1'
31+
compile 'com.trello:rxlifecycle-components:0.6.1'
3032

3133
compile project(':ok_adapters')
3234
}

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030

3131
<activity android:name="app.stack_view.StackViewActivity"
3232
android:theme="@style/AppTheme.NoActionBar"/>
33+
34+
<activity android:name="app.recycler_view.DummyActivity"
35+
android:theme="@style/AppTheme.NoActionBar"/>
3336
</application>
3437

3538
</manifest>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package app.recycler_view;
2+
3+
import android.app.Activity;
4+
5+
/**
6+
* Created by victor on 16/05/16.
7+
*/
8+
public class DummyActivity extends Activity {
9+
}

app/src/main/java/app/recycler_view/RecyclerViewPagerActivity.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package app.recycler_view;
22

3+
import android.content.Intent;
34
import android.os.Bundle;
4-
import android.support.v7.app.AppCompatActivity;
55
import android.support.v7.widget.GridLayoutManager;
66
import android.support.v7.widget.RecyclerView;
77
import android.view.View;
88
import android.view.ViewGroup;
99
import android.widget.Toast;
1010

11+
import com.trello.rxlifecycle.RxLifecycle;
12+
import com.trello.rxlifecycle.components.support.RxAppCompatActivity;
13+
1114
import java.util.ArrayList;
1215
import java.util.List;
1316
import java.util.concurrent.TimeUnit;
@@ -22,7 +25,7 @@
2225
import rx.Observable;
2326
import rx.android.schedulers.AndroidSchedulers;
2427

25-
public class RecyclerViewPagerActivity extends AppCompatActivity {
28+
public class RecyclerViewPagerActivity extends RxAppCompatActivity {
2629
@Bind(R.id.rv_items) RecyclerView rv_items;
2730
private boolean isReversed;
2831

@@ -43,13 +46,15 @@ private void setUpRecyclerView(boolean reverseLayout) {
4346

4447
adapter.setOnItemClickListener(new OkRecyclerViewAdapter.Listener<Item, ItemViewGroup>() {
4548
@Override public void onClickItem(Item item, ItemViewGroup itemViewGroup, int position) {
49+
startActivity(new Intent(RecyclerViewPagerActivity.this, DummyActivity.class));
4650
Toast.makeText(RecyclerViewPagerActivity.this, item.toString() + " " + " Pos: " + position, Toast.LENGTH_SHORT).show();
4751
}
4852
});
4953

5054
adapter.setRxPager(R.layout.loading_pager, new RxPager.LoaderPager<Item>() {
5155
@Override public Observable<List<Item>> onNextPage(Item lastItem) {
52-
return getItems(lastItem);
56+
return getItems(lastItem)
57+
.compose(RxLifecycle.<List<Item>>bindActivity(lifecycle()));
5358
}
5459
});
5560

@@ -94,12 +99,12 @@ private Observable<List<Item>> getItems(Item lastItem) {
9499
if (index > 100) {
95100
List<Item> empty = new ArrayList();
96101
return Observable.just(empty)
97-
.delay(2, TimeUnit.SECONDS)
102+
.delay(3, TimeUnit.SECONDS)
98103
.observeOn(AndroidSchedulers.mainThread());
99104
}
100105

101106
return Observable.just(items)
102-
.delay(2, TimeUnit.SECONDS)
107+
.delay(3, TimeUnit.SECONDS)
103108
.observeOn(AndroidSchedulers.mainThread());
104109
}
105110

ok_adapters/src/main/java/library/recycler_view/RxPager.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.List;
2525

2626
import rx.Observable;
27+
import rx.functions.Action0;
2728
import rx.functions.Action1;
2829
import rx.functions.Func1;
2930

@@ -63,7 +64,11 @@ void reset(Observable<List<T>> oItems) {
6364

6465
private void showItems(Observable<List<T>> oItems, final boolean reset) {
6566
stillLoading = true;
66-
oItems.subscribe(new Action1<List<T>>() {
67+
oItems.doOnCompleted(new Action0() {
68+
@Override public void call() {
69+
stillLoading = false;
70+
}
71+
}).subscribe(new Action1<List<T>>() {
6772
@Override public void call(final List<T> items) {
6873
new Handler().post(new Runnable() {
6974
@Override public void run() {

0 commit comments

Comments
 (0)