1 /*
2  * Copyright 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package androidx.paging
18 
19 import androidx.paging.LoadState.NotLoading
20 
21 /**
22  * Test-only local-only LoadStates builder which defaults each state to [NotLoading], with
23  * [LoadState.endOfPaginationReached] = `false`
24  */
localLoadStatesOfnull25 fun localLoadStatesOf(
26     refreshLocal: LoadState = NotLoading(endOfPaginationReached = false),
27     prependLocal: LoadState = NotLoading(endOfPaginationReached = false),
28     appendLocal: LoadState = NotLoading(endOfPaginationReached = false)
29 ) =
30     CombinedLoadStates(
31         refresh = refreshLocal,
32         prepend = prependLocal,
33         append = appendLocal,
34         source =
35             LoadStates(
36                 refresh = refreshLocal,
37                 prepend = prependLocal,
38                 append = appendLocal,
39             ),
40     )
41 
42 /**
43  * Test-only remote LoadStates builder which defaults each state to [NotLoading], with
44  * [LoadState.endOfPaginationReached] = `false`
45  */
46 fun remoteLoadStatesOf(
47     refresh: LoadState = NotLoading(endOfPaginationReached = false),
48     prepend: LoadState = NotLoading(endOfPaginationReached = false),
49     append: LoadState = NotLoading(endOfPaginationReached = false),
50     refreshLocal: LoadState = NotLoading(endOfPaginationReached = false),
51     prependLocal: LoadState = NotLoading(endOfPaginationReached = false),
52     appendLocal: LoadState = NotLoading(endOfPaginationReached = false),
53     refreshRemote: LoadState = NotLoading(endOfPaginationReached = false),
54     prependRemote: LoadState = NotLoading(endOfPaginationReached = false),
55     appendRemote: LoadState = NotLoading(endOfPaginationReached = false)
56 ) =
57     CombinedLoadStates(
58         refresh = refresh,
59         prepend = prepend,
60         append = append,
61         source =
62             LoadStates(
63                 refresh = refreshLocal,
64                 prepend = prependLocal,
65                 append = appendLocal,
66             ),
67         mediator =
68             LoadStates(
69                 refresh = refreshRemote,
70                 prepend = prependRemote,
71                 append = appendRemote,
72             ),
73     )
74 
75 /**
76  * Test-only LoadStates builder which defaults each state to [NotLoading], with
77  * [LoadState.endOfPaginationReached] = `false`
78  */
79 fun loadStates(
80     refresh: LoadState = NotLoading(endOfPaginationReached = false),
81     prepend: LoadState = NotLoading(endOfPaginationReached = false),
82     append: LoadState = NotLoading(endOfPaginationReached = false),
83 ) =
84     LoadStates(
85         refresh = refresh,
86         prepend = prepend,
87         append = append,
88     )
89