1 /* 2 * Copyright (C) 2018 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.launcher3.icons.cache 17 18 import android.content.ComponentName 19 import android.content.Context 20 import android.content.pm.ApplicationInfo 21 import android.os.UserHandle 22 import com.android.launcher3.icons.BitmapInfo 23 import com.android.launcher3.icons.IconProvider 24 import com.android.launcher3.icons.SourceHint 25 import com.android.launcher3.util.ComponentKey 26 27 interface CachingLogic<T> { 28 /** Returns the source hint for this object that can be sued by theme controllers */ getSourceHintnull29 fun getSourceHint(item: T, cache: BaseIconCache): SourceHint { 30 return SourceHint( 31 key = ComponentKey(getComponent(item), getUser(item)), 32 logic = this, 33 freshnessId = getFreshnessIdentifier(item, cache.iconProvider), 34 ) 35 } 36 getComponentnull37 fun getComponent(item: T): ComponentName 38 39 fun getUser(item: T): UserHandle 40 41 /** Loads the user visible label for the object */ 42 fun getLabel(item: T): CharSequence? 43 44 /** 45 * Returns the application info associated with the object. This is used to maintain the 46 * "freshness" of the disk cache. If null, the item will not be persisted to the disk 47 */ 48 fun getApplicationInfo(item: T): ApplicationInfo? 49 50 fun loadIcon(context: Context, cache: BaseIconCache, item: T): BitmapInfo 51 52 /** 53 * Returns a persistable string that can be used to indicate indicate the correctness of the 54 * cache for the provided item 55 */ 56 fun getFreshnessIdentifier(item: T, iconProvider: IconProvider): String? 57 } 58