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#DEFAULT} 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#DEFAULT} 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} and 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,17 @@ 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 paginate.
110
+ *
111
+ * @param query the Firestore query. This query should only contain where() and
112
+ * orderBy() clauses. Any limit() or pagination clauses will cause errors.
113
+ * @param source the data source to use for query data.
114
+ * @param config paging configuration, passed directly to the support paging library.
115
+ * @param parser the {@link SnapshotParser} to parse {@link DocumentSnapshot} into model
116
+ * objects.
117
+ * @return this, for chaining.
118
+ */
86
119
@ NonNull
87
120
public Builder <T > setQuery (@ NonNull Query query ,
88
121
@ NonNull Source source ,
@@ -96,18 +129,36 @@ public Builder<T> setQuery(@NonNull Query query,
96
129
return this ;
97
130
}
98
131
132
+ /**
133
+ * Sets an optional custom {@link DiffUtil.ItemCallback} to compare
134
+ * {@link DocumentSnapshot} objects.
135
+ *
136
+ * The default implementation is {@link DefaultSnapshotDiffCallback}.
137
+ *
138
+ * @return this, for chaining.
139
+ */
99
140
@ NonNull
100
141
public Builder <T > setDiffCallback (@ NonNull DiffUtil .ItemCallback <DocumentSnapshot > diffCallback ) {
101
142
mDiffCallback = diffCallback ;
102
143
return this ;
103
144
}
104
145
146
+ /**
147
+ * Sets an optional {@link LifecycleOwner} to control the lifecycle of the adapter. Otherwise,
148
+ * you must manually call {@link FirestorePagingAdapter#startListening()}
149
+ * and {@link FirestorePagingAdapter#stopListening()}.
150
+ *
151
+ * @return this, for chaining.
152
+ */
105
153
@ NonNull
106
154
public Builder <T > setLifecycleOwner (@ NonNull LifecycleOwner owner ) {
107
155
mOwner = owner ;
108
156
return this ;
109
157
}
110
158
159
+ /**
160
+ * Build the {@link FirestorePagingOptions} object.
161
+ */
111
162
@ NonNull
112
163
public FirestorePagingOptions <T > build () {
113
164
if (mData == null || mParser == null ) {
0 commit comments