Loading src/com/android/customization/picker/icon/data/repository/IconStyleRepository.kt +7 −2 Original line number Diff line number Diff line Loading @@ -18,17 +18,22 @@ package com.android.customization.picker.icon.data.repository import com.android.customization.picker.icon.shared.model.IconStyle import com.android.customization.picker.icon.shared.model.IconStyleModel import com.android.wallpaper.util.BasePreviewUtils import kotlinx.coroutines.flow.Flow interface IconStyleRepository { val isThemedIconAvailable: Flow<Boolean> val previewUtilsFlow: Flow<BasePreviewUtils?> val isCustomizationAvailable: Flow<Boolean> val isThemedIconActivated: Flow<Boolean> suspend fun setThemedIconEnabled(enabled: Boolean) val iconStyleModels: Flow<List<IconStyleModel>> val selectedIconStyle: Flow<IconStyle> suspend fun setThemedIconEnabled(enabled: Boolean) suspend fun setIconStyle(iconStyle: IconStyle) } src/com/android/customization/picker/icon/data/repository/ThemePickerIconStyleRepository.kt +17 −10 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.callbackFlow import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.map Loading @@ -61,7 +62,7 @@ constructor( private val metadataKey = appContext.getString(R.string.themed_icon_metadata_key) // TODO (b/424856247): test the retry logic for getting PreviewUtils private var previewUtils: PreviewUtils? = null private val previewUtilsFlow = flow { override val previewUtilsFlow = flow { // If PreviewUtils is created too early on start up, the provider (e.g. Launcher) may not be // ready, so PreviewUtils#supportsPreview would return false. Only cache previewUtils if it // supports previewing. Otherwise, retry when new flow consumers appear. Loading @@ -74,14 +75,12 @@ constructor( } emit(previewUtils) } private var uri: Uri? = null private val uriFlow: Flow<Uri?> = previewUtilsFlow.map { uri ?: it?.getUri(ICON_THEMED)?.also { result -> uri = result } } val themedIconUri: Flow<Uri?> = previewUtilsFlow.map { it?.getUri(ICON_THEMED) } override val isThemedIconAvailable: Flow<Boolean> = previewUtilsFlow.map { it != null } override val isCustomizationAvailable: Flow<Boolean> = previewUtilsFlow.map { it != null } override val isThemedIconActivated: Flow<Boolean> = uriFlow themedIconUri .flatMapLatest { callbackFlow { var disposableHandle: DisposableHandle? = null Loading Loading @@ -114,7 +113,7 @@ constructor( ) override val iconStyleModels: Flow<List<IconStyleModel>> = isThemedIconAvailable.map { isThemedIconAvailable -> isCustomizationAvailable.map { isThemedIconAvailable -> ThemePickerIconStyle.entries .toList() // Filter entries if themed icon is not available Loading Loading @@ -178,16 +177,24 @@ constructor( } override suspend fun setThemedIconEnabled(enabled: Boolean) { uri?.let { themedIconUri.first()?.let { val values = ContentValues() values.put(COL_ICON_THEMED_VALUE, enabled) contentResolver.update(it, values, /* where= */ null, /* selectionArgs= */ null) } } override suspend fun setIconStyle(iconStyle: IconStyle) { themedIconUri.first()?.let { val values = ContentValues() values.put(COL_ICON_THEMED_VALUE, iconStyle == ThemePickerIconStyle.MONOCHROME) contentResolver.update(it, values, /* where= */ null, /* selectionArgs= */ null) } } companion object { private const val ICON_THEMED = "icon_themed" private const val COL_ICON_THEMED_VALUE = "boolean_value" const val ICON_THEMED = "icon_themed" const val COL_ICON_THEMED_VALUE = "boolean_value" private const val ENABLED = 1 } } src/com/android/customization/picker/icon/domain/interactor/AppIconInteractor.kt +4 −1 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.customization.picker.icon.domain.interactor import com.android.customization.model.grid.ShapeOptionModel import com.android.customization.picker.grid.data.repository.ShapeRepository import com.android.customization.picker.icon.data.repository.IconStyleRepository import com.android.customization.picker.icon.shared.model.IconStyle import javax.inject.Inject import javax.inject.Singleton import kotlinx.coroutines.flow.Flow Loading @@ -42,7 +43,7 @@ constructor( val isShapeOptionsAvailable: Flow<Boolean> = shapeRepository.isShapeOptionsAvailable val isThemedIconAvailable: Flow<Boolean> = iconStyleRepository.isThemedIconAvailable val isThemedIconAvailable: Flow<Boolean> = iconStyleRepository.isCustomizationAvailable val isThemedIconEnabled: Flow<Boolean> = iconStyleRepository.isThemedIconActivated Loading @@ -54,4 +55,6 @@ constructor( iconStyleRepository.setThemedIconEnabled(enabled) suspend fun applyShape(shapeKey: String) = shapeRepository.applyShape(shapeKey) suspend fun applyIconStyle(iconStyle: IconStyle) = iconStyleRepository.setIconStyle(iconStyle) } src/com/android/customization/picker/icon/shared/model/IconStyleModel.kt +1 −1 Original line number Diff line number Diff line Loading @@ -18,7 +18,7 @@ package com.android.customization.picker.icon.shared.model import com.android.wallpaper.picker.common.icon.ui.viewmodel.Icon data class IconStyleModel( open class IconStyleModel( val iconStyle: IconStyle, val nameResId: Int, val icon: Icon?, Loading src/com/android/customization/picker/themedicon/domain/interactor/ThemedIconInteractor.kt +1 −1 Original line number Diff line number Diff line Loading @@ -23,7 +23,7 @@ import kotlinx.coroutines.flow.Flow @Singleton class ThemedIconInteractor @Inject constructor(private val repository: IconStyleRepository) { val isAvailable: Flow<Boolean> = repository.isThemedIconAvailable val isAvailable: Flow<Boolean> = repository.isCustomizationAvailable val isActivated: Flow<Boolean> = repository.isThemedIconActivated suspend fun setThemedIconEnabled(enabled: Boolean) = repository.setThemedIconEnabled(enabled) Loading Loading
src/com/android/customization/picker/icon/data/repository/IconStyleRepository.kt +7 −2 Original line number Diff line number Diff line Loading @@ -18,17 +18,22 @@ package com.android.customization.picker.icon.data.repository import com.android.customization.picker.icon.shared.model.IconStyle import com.android.customization.picker.icon.shared.model.IconStyleModel import com.android.wallpaper.util.BasePreviewUtils import kotlinx.coroutines.flow.Flow interface IconStyleRepository { val isThemedIconAvailable: Flow<Boolean> val previewUtilsFlow: Flow<BasePreviewUtils?> val isCustomizationAvailable: Flow<Boolean> val isThemedIconActivated: Flow<Boolean> suspend fun setThemedIconEnabled(enabled: Boolean) val iconStyleModels: Flow<List<IconStyleModel>> val selectedIconStyle: Flow<IconStyle> suspend fun setThemedIconEnabled(enabled: Boolean) suspend fun setIconStyle(iconStyle: IconStyle) }
src/com/android/customization/picker/icon/data/repository/ThemePickerIconStyleRepository.kt +17 −10 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.callbackFlow import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.map Loading @@ -61,7 +62,7 @@ constructor( private val metadataKey = appContext.getString(R.string.themed_icon_metadata_key) // TODO (b/424856247): test the retry logic for getting PreviewUtils private var previewUtils: PreviewUtils? = null private val previewUtilsFlow = flow { override val previewUtilsFlow = flow { // If PreviewUtils is created too early on start up, the provider (e.g. Launcher) may not be // ready, so PreviewUtils#supportsPreview would return false. Only cache previewUtils if it // supports previewing. Otherwise, retry when new flow consumers appear. Loading @@ -74,14 +75,12 @@ constructor( } emit(previewUtils) } private var uri: Uri? = null private val uriFlow: Flow<Uri?> = previewUtilsFlow.map { uri ?: it?.getUri(ICON_THEMED)?.also { result -> uri = result } } val themedIconUri: Flow<Uri?> = previewUtilsFlow.map { it?.getUri(ICON_THEMED) } override val isThemedIconAvailable: Flow<Boolean> = previewUtilsFlow.map { it != null } override val isCustomizationAvailable: Flow<Boolean> = previewUtilsFlow.map { it != null } override val isThemedIconActivated: Flow<Boolean> = uriFlow themedIconUri .flatMapLatest { callbackFlow { var disposableHandle: DisposableHandle? = null Loading Loading @@ -114,7 +113,7 @@ constructor( ) override val iconStyleModels: Flow<List<IconStyleModel>> = isThemedIconAvailable.map { isThemedIconAvailable -> isCustomizationAvailable.map { isThemedIconAvailable -> ThemePickerIconStyle.entries .toList() // Filter entries if themed icon is not available Loading Loading @@ -178,16 +177,24 @@ constructor( } override suspend fun setThemedIconEnabled(enabled: Boolean) { uri?.let { themedIconUri.first()?.let { val values = ContentValues() values.put(COL_ICON_THEMED_VALUE, enabled) contentResolver.update(it, values, /* where= */ null, /* selectionArgs= */ null) } } override suspend fun setIconStyle(iconStyle: IconStyle) { themedIconUri.first()?.let { val values = ContentValues() values.put(COL_ICON_THEMED_VALUE, iconStyle == ThemePickerIconStyle.MONOCHROME) contentResolver.update(it, values, /* where= */ null, /* selectionArgs= */ null) } } companion object { private const val ICON_THEMED = "icon_themed" private const val COL_ICON_THEMED_VALUE = "boolean_value" const val ICON_THEMED = "icon_themed" const val COL_ICON_THEMED_VALUE = "boolean_value" private const val ENABLED = 1 } }
src/com/android/customization/picker/icon/domain/interactor/AppIconInteractor.kt +4 −1 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.customization.picker.icon.domain.interactor import com.android.customization.model.grid.ShapeOptionModel import com.android.customization.picker.grid.data.repository.ShapeRepository import com.android.customization.picker.icon.data.repository.IconStyleRepository import com.android.customization.picker.icon.shared.model.IconStyle import javax.inject.Inject import javax.inject.Singleton import kotlinx.coroutines.flow.Flow Loading @@ -42,7 +43,7 @@ constructor( val isShapeOptionsAvailable: Flow<Boolean> = shapeRepository.isShapeOptionsAvailable val isThemedIconAvailable: Flow<Boolean> = iconStyleRepository.isThemedIconAvailable val isThemedIconAvailable: Flow<Boolean> = iconStyleRepository.isCustomizationAvailable val isThemedIconEnabled: Flow<Boolean> = iconStyleRepository.isThemedIconActivated Loading @@ -54,4 +55,6 @@ constructor( iconStyleRepository.setThemedIconEnabled(enabled) suspend fun applyShape(shapeKey: String) = shapeRepository.applyShape(shapeKey) suspend fun applyIconStyle(iconStyle: IconStyle) = iconStyleRepository.setIconStyle(iconStyle) }
src/com/android/customization/picker/icon/shared/model/IconStyleModel.kt +1 −1 Original line number Diff line number Diff line Loading @@ -18,7 +18,7 @@ package com.android.customization.picker.icon.shared.model import com.android.wallpaper.picker.common.icon.ui.viewmodel.Icon data class IconStyleModel( open class IconStyleModel( val iconStyle: IconStyle, val nameResId: Int, val icon: Icon?, Loading
src/com/android/customization/picker/themedicon/domain/interactor/ThemedIconInteractor.kt +1 −1 Original line number Diff line number Diff line Loading @@ -23,7 +23,7 @@ import kotlinx.coroutines.flow.Flow @Singleton class ThemedIconInteractor @Inject constructor(private val repository: IconStyleRepository) { val isAvailable: Flow<Boolean> = repository.isThemedIconAvailable val isAvailable: Flow<Boolean> = repository.isCustomizationAvailable val isActivated: Flow<Boolean> = repository.isThemedIconActivated suspend fun setThemedIconEnabled(enabled: Boolean) = repository.setThemedIconEnabled(enabled) Loading