• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 com.android.photopicker.features.categorygrid.data
18 
19 import android.os.CancellationSignal
20 import androidx.paging.PagingSource
21 import com.android.photopicker.data.model.Group
22 import com.android.photopicker.data.model.GroupPageKey
23 import com.android.photopicker.data.model.Media
24 import com.android.photopicker.data.model.MediaPageKey
25 
26 /**
27  * Powers UI with data for the category feature which includes the category grid, media sets grid,
28  * and media set content grid. This class owns the responsibility to:
29  * - fetch categories, albums, media sets and media on demand
30  * - cache data if required
31  * - keep track of data updates in the data source
32  * - detect and refresh stale data
33  */
34 interface CategoryDataService {
35     companion object {
36         const val TAG: String = "PhotopickerSearchCategoryService"
37     }
38 
39     /**
40      * Creates a paging source that can load categories and albums.
41      *
42      * @param category the parent [Category]. If the parent category is null then the method returns
43      *   root categories.
44      * @param cancellationSignal An optional [CancellationSignal] that can be marked as cancelled
45      *   when the query results are no longer required.
46      * @return The [PagingSource] that fetches a page using [GroupPageKey]. A page in the paging
47      *   source contains a [List] of [Group.Category] items.
48      */
getCategoriesnull49     fun getCategories(
50         parentCategory: Group.Category? = null,
51         cancellationSignal: CancellationSignal? = null,
52     ): PagingSource<GroupPageKey, Group>
53 
54     /**
55      * Creates a paging source that can load media sets. Leaf categories contain [MediaSet]-s. A
56      * [MediaSet] can only contain media items.
57      *
58      * @param category the parent [Category].
59      * @param cancellationSignal An optional [CancellationSignal] that can be marked as cancelled
60      *   when the query results are no longer required.
61      * @return The [PagingSource] that fetches a page using [GroupPageKey]. A page in the paging
62      *   source contains a [List] of [Group.MediaSet] items.
63      */
64     fun getMediaSets(
65         category: Group.Category,
66         cancellationSignal: CancellationSignal? = null,
67     ): PagingSource<GroupPageKey, Group.MediaSet>
68 
69     /**
70      * Creates a paging source that can load media items of a media set.
71      *
72      * @param mediaSet the parent [MediaSet].
73      * @param cancellationSignal An optional [CancellationSignal] that can be marked as cancelled
74      *   when the query results are no longer required.
75      * @return The [PagingSource] that fetches a page using [MediaPageKey]. A page in the paging
76      *   source contains a [List] of [Media] items.
77      */
78     fun getMediaSetContents(
79         mediaSet: Group.MediaSet,
80         cancellationSignal: CancellationSignal? = null,
81     ): PagingSource<MediaPageKey, Media>
82 }
83