blob: b86e6dfe51d6d7e491f4269424c069669d0ca364 [file] [log] [blame]
Jon Miranda16ea1b12017-12-12 14:52:48 -08001/*
2 * Copyright (C) 2017 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 */
16package com.android.wallpaper.model;
17
Sunny Goyal8600a3f2018-08-15 12:48:01 -070018import androidx.annotation.Nullable;
Jon Miranda16ea1b12017-12-12 14:52:48 -080019
20/**
21 * Fetches and provides wallpaper categories to any registered {@link CategoryReceiver}s.
22 */
23public interface CategoryProvider {
24
25 /**
26 * Fetches the categories asynchronously; once ready, provides results to the given
27 * {@link CategoryReceiver}.
28 *
29 * @param receiver The receiver of categories.
30 * @param forceRefresh Whether to force the CategoryProvider to refresh the categories
31 * (as opposed to returning cached values from a prior fetch).
32 */
Santiago Etchebehere1ee76a22018-05-15 15:02:24 -070033 void fetchCategories(CategoryReceiver receiver, boolean forceRefresh);
34
35 int getSize();
36
37 /**
38 * Returns the Category at the given index position.
39 * <p>
40 * Note that this method is expected to be called after the categories have been fetched.
41 * @param index index of the Category to return.
42 *
43 * @throws IllegalStateException if this method is called before fetching happened.
44 * @throws IndexOutOfBoundsException if the given index is either negative or larger than
45 * {@link #getSize()}
46 */
47 Category getCategory(int index);
Jon Miranda16ea1b12017-12-12 14:52:48 -080048
49 /**
50 * Returns the Category having the given collection ID. If not found, returns null.
51 * <p>
52 * This method should only be called for collection IDs for which the corresponding Category was
53 * already fetched, so the null return case should be treated as an error by callers.
54 */
55 @Nullable
Santiago Etchebehere1ee76a22018-05-15 15:02:24 -070056 Category getCategory(String collectionId);
Chuck Liaof6b4b192020-08-07 02:31:32 +080057
58 /**
59 * Checks if the categories are fetched.
60 */
61 boolean isCategoriesFetched();
Chuck Liaoe2d35f52020-09-22 21:20:47 +080062
63 /**
64 * Resets the fetched categories if needed.
65 */
66 void resetIfNeeded();
Jon Miranda16ea1b12017-12-12 14:52:48 -080067}