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.launcher3.model.data 18 19 import com.android.launcher3.LauncherSettings 20 import com.android.launcher3.util.ContentWriter 21 import java.util.function.Predicate 22 23 abstract class CollectionInfo : ItemInfo() { 24 /** Adds an ItemInfo to the collection. Throws if given an illegal type. */ addnull25 abstract fun add(item: ItemInfo) 26 27 /** Returns the collection's contents as an ArrayList of [ItemInfo]. */ 28 abstract fun getContents(): ArrayList<ItemInfo> 29 30 /** 31 * Returns the collection's contents as an ArrayList of [WorkspaceItemInfo]. Does not include 32 * other collection [ItemInfo]s that are inside this collection; rather, it should collect 33 * *their* contents and adds them to the ArrayList. 34 */ 35 abstract fun getAppContents(): ArrayList<WorkspaceItemInfo> 36 37 /** Convenience function. Checks contents to see if any match a given predicate. */ 38 fun anyMatch(matcher: Predicate<ItemInfo>) = getContents().stream().anyMatch(matcher) 39 40 override fun onAddToDatabase(writer: ContentWriter) { 41 super.onAddToDatabase(writer) 42 writer.put(LauncherSettings.Favorites.TITLE, title) 43 } 44 } 45