1 /* 2 * Copyright (C) 2023 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.avatarpicker 18 19 import android.app.Application 20 import android.content.Intent 21 import com.android.avatarpicker.data.ColoredIconsRepository 22 import com.android.avatarpicker.data.IllustrationsRepository 23 import com.android.avatarpicker.data.MediaRepository 24 import com.android.avatarpicker.domain.GroupedSelectableItemsUseCase 25 import com.android.avatarpicker.domain.GroupedSelectableItemsUseCaseImpl 26 import com.android.avatarpicker.ui.ResultHandler 27 import com.android.avatarpicker.ui.ResultHandlerImpl 28 import com.android.avatarpicker.ui.details.items.ItemViewComposerImpl 29 30 class AvatarPickerApp : Application(), AvatarProviderApp { 31 private var _groupedSelectableItems: GroupedSelectableItemsUseCase? = null 32 private var _resultHandler: ResultHandler? = null 33 private val _itemComposer = ItemViewComposerImpl() 34 getGroupedSelectableItemsnull35 override fun getGroupedSelectableItems(intent: Intent) = 36 _groupedSelectableItems ?: GroupedSelectableItemsUseCaseImpl( 37 MediaRepository(), ColoredIconsRepository(resources), IllustrationsRepository(resources) 38 ).also { _groupedSelectableItems = it } 39 getResultHandlernull40 override fun getResultHandler() = 41 _resultHandler ?: ResultHandlerImpl(applicationContext).also { _resultHandler = it } 42 getItemViewComposernull43 override fun getItemViewComposer() = _itemComposer 44 } 45