16
16
17
17
/**
18
18
* Options to configure an {@link FirestorePagingAdapter}.
19
+ *
20
+ * Use {@link Builder} to create a new instance.
19
21
*/
20
22
public final class FirestorePagingOptions <T > {
21
23
@@ -54,27 +56,47 @@ public LifecycleOwner getOwner() {
54
56
return mOwner ;
55
57
}
56
58
59
+ /**
60
+ * Builder for {@link FirestorePagingOptions}.
61
+ */
57
62
public static final class Builder <T > {
58
63
59
64
private LiveData <PagedList <DocumentSnapshot >> mData ;
60
65
private SnapshotParser <T > mParser ;
61
66
private LifecycleOwner mOwner ;
62
67
private DiffUtil .ItemCallback <DocumentSnapshot > mDiffCallback ;
63
68
69
+ /**
70
+ * Sets the query using {@link Source#SERVER} and a {@link ClassSnapshotParser} based
71
+ * on the given Class.
72
+ *
73
+ * See {@link #setQuery(Query, Source, PagedList.Config, SnapshotParser)}.
74
+ */
64
75
@ NonNull
65
76
public Builder <T > setQuery (@ NonNull Query query ,
66
77
@ NonNull PagedList .Config config ,
67
78
@ NonNull Class <T > modelClass ) {
68
79
return setQuery (query , Source .DEFAULT , config , modelClass );
69
80
}
70
81
82
+ /**
83
+ * Sets the query using {@link Source#SERVER} and a custom {@link SnapshotParser}.
84
+ *
85
+ * See {@link #setQuery(Query, Source, PagedList.Config, SnapshotParser)}.
86
+ */
71
87
@ NonNull
72
88
public Builder <T > setQuery (@ NonNull Query query ,
73
89
@ NonNull PagedList .Config config ,
74
90
@ NonNull SnapshotParser <T > parser ) {
75
91
return setQuery (query , Source .DEFAULT , config , parser );
76
92
}
77
93
94
+ /**
95
+ * Sets the query using a custom {@link Source} amd a {@link ClassSnapshotParser} based
96
+ * on the given class.
97
+ *
98
+ * See {@link #setQuery(Query, Source, PagedList.Config, SnapshotParser)}.
99
+ */
78
100
@ NonNull
79
101
public Builder <T > setQuery (@ NonNull Query query ,
80
102
@ NonNull Source source ,
@@ -83,6 +105,16 @@ public Builder<T> setQuery(@NonNull Query query,
83
105
return setQuery (query , source , config , new ClassSnapshotParser <>(modelClass ));
84
106
}
85
107
108
+ /**
109
+ * Sets the Firestore query to page.
110
+ * @param query the Firestore query. This query should only contain where() and
111
+ * orderBy() clauses. Any limit() pr pagination clauses will cause errors.
112
+ * @param source the data source to use for query data.
113
+ * @param config paging configuration, passed directly to the support paging library.
114
+ * @param parser the {@link SnapshotParser} to parse {@link DocumentSnapshot} into model
115
+ * objects.
116
+ * @return this, for chaining.
117
+ */
86
118
@ NonNull
87
119
public Builder <T > setQuery (@ NonNull Query query ,
88
120
@ NonNull Source source ,
@@ -96,18 +128,34 @@ public Builder<T> setQuery(@NonNull Query query,
96
128
return this ;
97
129
}
98
130
131
+ /**
132
+ * Sets an optional custom {@link DiffUtil.ItemCallback} to compare
133
+ * {@link DocumentSnapshot} objects.
134
+ *
135
+ * The default implementation is {@link DefaultSnapshotDiffCallback}.
136
+ * @return this, for chaining.
137
+ */
99
138
@ NonNull
100
139
public Builder <T > setDiffCallback (@ NonNull DiffUtil .ItemCallback <DocumentSnapshot > diffCallback ) {
101
140
mDiffCallback = diffCallback ;
102
141
return this ;
103
142
}
104
143
144
+ /**
145
+ * Sets an optional {@link LifecycleOwner} to control the lifecycle of the view. Otherwise,
146
+ * developer must manually call {@link FirestorePagingAdapter#startListening()}
147
+ * and {@link FirestorePagingAdapter#stopListening()}.
148
+ * @return this, for chaining.
149
+ */
105
150
@ NonNull
106
151
public Builder <T > setLifecycleOwner (@ NonNull LifecycleOwner owner ) {
107
152
mOwner = owner ;
108
153
return this ;
109
154
}
110
155
156
+ /**
157
+ * Build the {@link FirestorePagingOptions} object.
158
+ */
111
159
@ NonNull
112
160
public FirestorePagingOptions <T > build () {
113
161
if (mData == null || mParser == null ) {
0 commit comments