Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package com.android.wallpaper.model; |
| 17 | |
| 18 | import android.support.annotation.Nullable; |
| 19 | |
| 20 | /** |
| 21 | * Fetches and provides wallpaper categories to any registered {@link CategoryReceiver}s. |
| 22 | */ |
| 23 | public 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 Etchebehere | 1ee76a2 | 2018-05-15 15:02:24 -0700 | [diff] [blame] | 33 | 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 Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 48 | |
| 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 Etchebehere | 1ee76a2 | 2018-05-15 15:02:24 -0700 | [diff] [blame] | 56 | Category getCategory(String collectionId); |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 57 | } |