Skip to content

Commit eddcbed

Browse files
committed
Reduce complexity of factory
Change-Id: I823555e51436bd72fb0a6118aa0a36df71517ff2
1 parent 1ea8834 commit eddcbed

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

firestore/src/main/java/com/firebase/ui/firestore/paging/FirestoreDataSource.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,14 @@ public class FirestoreDataSource extends PageKeyedDataSource<PageKey, DocumentSn
2929
public static class Factory extends DataSource.Factory<PageKey, DocumentSnapshot> {
3030

3131
private final Query mQuery;
32-
private final MutableLiveData<FirestoreDataSource> mDataSource = new MutableLiveData<>();
3332

3433
public Factory(Query query) {
3534
mQuery = query;
3635
}
3736

3837
@Override
3938
public DataSource<PageKey, DocumentSnapshot> create() {
40-
FirestoreDataSource source = new FirestoreDataSource(mQuery);
41-
mDataSource.postValue(source);
42-
return source;
43-
}
44-
45-
public LiveData<FirestoreDataSource> getDataSource() {
46-
return mDataSource;
39+
return new FirestoreDataSource(mQuery);
4740
}
4841
}
4942

firestore/src/main/java/com/firebase/ui/firestore/paging/PagingData.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.arch.lifecycle.Transformations;
66
import android.arch.paging.LivePagedListBuilder;
77
import android.arch.paging.PagedList;
8+
import android.support.annotation.NonNull;
89
import android.support.annotation.RestrictTo;
910

1011
import com.google.firebase.firestore.DocumentSnapshot;
@@ -18,16 +19,17 @@ public class PagingData {
1819
private final LiveData<PagedList<DocumentSnapshot>> mSnapshots;
1920
private final LiveData<LoadingState> mLoadingState;
2021

21-
public PagingData(FirestoreDataSource.Factory factory,
22-
PagedList.Config config) {
22+
public PagingData(@NonNull FirestoreDataSource.Factory factory,
23+
@NonNull PagedList.Config config) {
2324

2425
mSnapshots = new LivePagedListBuilder<>(factory, config).build();
2526

26-
mLoadingState = Transformations.switchMap(factory.getDataSource(),
27-
new Function<FirestoreDataSource, LiveData<LoadingState>>() {
27+
mLoadingState = Transformations.switchMap(mSnapshots,
28+
new Function<PagedList<DocumentSnapshot>, LiveData<LoadingState>>() {
2829
@Override
29-
public LiveData<LoadingState> apply(FirestoreDataSource input) {
30-
return input.getLoadingState();
30+
public LiveData<LoadingState> apply(PagedList<DocumentSnapshot> input) {
31+
FirestoreDataSource dataSource = (FirestoreDataSource) input.getDataSource();
32+
return dataSource.getLoadingState();
3133
}
3234
});
3335
}

0 commit comments

Comments
 (0)