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 androidx.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 */ fetchCategories(CategoryReceiver receiver, boolean forceRefresh)33 void fetchCategories(CategoryReceiver receiver, boolean forceRefresh); 34 getSize()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 */ getCategory(int index)47 Category getCategory(int index); 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 getCategory(String collectionId)56 Category getCategory(String collectionId); 57 58 /** 59 * Checks if the categories are fetched. 60 */ isCategoriesFetched()61 boolean isCategoriesFetched(); 62 63 /** 64 * Resets the fetched categories if needed. 65 * 66 * @return {@code true} if the fetched categories are reset; {@code false} otherwise. 67 */ resetIfNeeded()68 boolean resetIfNeeded(); 69 70 /** 71 * Checks if featured collection available. 72 */ isFeaturedCollectionAvailable()73 boolean isFeaturedCollectionAvailable(); 74 } 75