31
31
import fr .free .nrw .commons .utils .ViewUtil ;
32
32
import io .reactivex .Observable ;
33
33
import io .reactivex .android .schedulers .AndroidSchedulers ;
34
+ import io .reactivex .disposables .CompositeDisposable ;
34
35
import io .reactivex .schedulers .Schedulers ;
35
36
import timber .log .Timber ;
36
37
@@ -51,6 +52,7 @@ public class CategoryImagesListFragment extends DaggerFragment {
51
52
@ BindView (R .id .loadingImagesProgressBar ) ProgressBar progressBar ;
52
53
@ BindView (R .id .categoryImagesList ) GridView gridView ;
53
54
@ BindView (R .id .parentLayout ) RelativeLayout parentLayout ;
55
+ private CompositeDisposable compositeDisposable = new CompositeDisposable ();
54
56
private boolean hasMoreImages = true ;
55
57
private boolean isLoading = true ;
56
58
private String categoryName = null ;
@@ -74,6 +76,12 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
74
76
initViews ();
75
77
}
76
78
79
+ @ Override
80
+ public void onDestroy () {
81
+ super .onDestroy ();
82
+ compositeDisposable .clear ();
83
+ }
84
+
77
85
/**
78
86
* Initializes the UI elements for the fragment
79
87
* Setup the grid view to and scroll listener for it
@@ -109,11 +117,11 @@ private void initList() {
109
117
110
118
isLoading = true ;
111
119
progressBar .setVisibility (VISIBLE );
112
- Observable .fromCallable (() -> controller .getCategoryImages (categoryName ))
120
+ compositeDisposable . add ( Observable .fromCallable (() -> controller .getCategoryImages (categoryName ))
113
121
.subscribeOn (Schedulers .io ())
114
122
.observeOn (AndroidSchedulers .mainThread ())
115
123
.timeout (TIMEOUT_SECONDS , TimeUnit .SECONDS )
116
- .subscribe (this ::handleSuccess , this ::handleError );
124
+ .subscribe (this ::handleSuccess , this ::handleError )) ;
117
125
}
118
126
119
127
/**
@@ -215,11 +223,11 @@ private void fetchMoreImages() {
215
223
}
216
224
217
225
progressBar .setVisibility (VISIBLE );
218
- Observable .fromCallable (() -> controller .getCategoryImages (categoryName ))
226
+ compositeDisposable . add ( Observable .fromCallable (() -> controller .getCategoryImages (categoryName ))
219
227
.subscribeOn (Schedulers .io ())
220
228
.observeOn (AndroidSchedulers .mainThread ())
221
229
.timeout (TIMEOUT_SECONDS , TimeUnit .SECONDS )
222
- .subscribe (this ::handleSuccess , this ::handleError );
230
+ .subscribe (this ::handleSuccess , this ::handleError )) ;
223
231
}
224
232
225
233
/**
0 commit comments