1 /*
2  * Copyright 2021 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 internal class MutableLoadStateCollection {
22     var refresh: LoadState = NotLoading.Incomplete
23     var prepend: LoadState = NotLoading.Incomplete
24     var append: LoadState = NotLoading.Incomplete
25 
snapshotnull26     fun snapshot() =
27         LoadStates(
28             refresh = refresh,
29             prepend = prepend,
30             append = append,
31         )
32 
33     fun get(loadType: LoadType) =
34         when (loadType) {
35             LoadType.REFRESH -> refresh
36             LoadType.APPEND -> append
37             LoadType.PREPEND -> prepend
38         }
39 
setnull40     fun set(type: LoadType, state: LoadState) =
41         when (type) {
42             LoadType.REFRESH -> refresh = state
43             LoadType.APPEND -> append = state
44             LoadType.PREPEND -> prepend = state
45         }
46 
setnull47     fun set(states: LoadStates) {
48         refresh = states.refresh
49         append = states.append
50         prepend = states.prepend
51     }
52 }
53